diff --git a/MBS.Framework/Application.cs b/MBS.Framework/Application.cs index 3b3b3ef..9438d23 100644 --- a/MBS.Framework/Application.cs +++ b/MBS.Framework/Application.cs @@ -63,6 +63,35 @@ namespace MBS.Framework /// public static Application Instance { get; set; } = null; + public string[] FindFiles(string filename, FindFileOptions options = FindFileOptions.All) + { + if (filename.StartsWith("~/")) + { + filename = filename.Substring(2); + } + + List files = new List(); + string[] paths = EnumerateDataPaths(); + foreach (string path in paths) + { + string file = System.IO.Path.Combine(new string[] { path, filename }); + if (System.IO.File.Exists(file)) + { + files.Add(file); + } + } + return files.ToArray(); + } + public string FindFile(string fileName, FindFileOptions options = FindFileOptions.All) + { + string[] files = FindFiles(fileName, options); + if (files.Length > 0) + { + return files[0]; + } + return null; + } + public EventFilter.EventFilterCollection EventFilters { get; } = new EventFilter.EventFilterCollection(); protected virtual Command FindCommandInternal(string commandID) @@ -189,12 +218,7 @@ namespace MBS.Framework } public InstallationStatus InstallationStatus { get { return GetInstallationStatusInternal(); } } - public CommandLine CommandLine { get; protected set; } = null; - - public Application() - { - CommandLine = new DefaultCommandLine(); - } + public CommandLine CommandLine { get; } = new CommandLine(); private Dictionary> _CommandEventHandlers = new Dictionary>(); public Command.CommandCollection Commands { get; } = new Command.CommandCollection(); diff --git a/MBS.Framework/CommandLine.cs b/MBS.Framework/CommandLine.cs index 037aef3..3405149 100644 --- a/MBS.Framework/CommandLine.cs +++ b/MBS.Framework/CommandLine.cs @@ -23,13 +23,13 @@ using System.Collections.Generic; namespace MBS.Framework { - public abstract class CommandLine + public class CommandLine { /// /// Gets the original array of arguments. /// /// The arguments. - public string[] Arguments { get; protected set; } + public string[] Arguments { get; internal set; } /// /// Gets the list of file names passed on the command line. @@ -37,14 +37,13 @@ namespace MBS.Framework /// The file names. public List FileNames { get; } = new List(); + public CommandLineParser Parser { get; set; } = null; + public CommandLineOption.CommandLineOptionCollection Options { get; } = new CommandLineOption.CommandLineOptionCollection(); - protected CommandLine() + public CommandLine() { - } - protected internal CommandLine(string[] arguments) - { - this.Arguments = arguments; + Options.Add(new CommandLineOption() { Name = "activation-type", Description = "The type of activation for this app", Type = CommandLineOptionValueType.Single }); } public override string ToString() diff --git a/MBS.Framework/DefaultCommandLine.cs b/MBS.Framework/CommandLineParser.cs similarity index 72% rename from MBS.Framework/DefaultCommandLine.cs rename to MBS.Framework/CommandLineParser.cs index ea1df81..3a3b315 100644 --- a/MBS.Framework/DefaultCommandLine.cs +++ b/MBS.Framework/CommandLineParser.cs @@ -1,10 +1,10 @@ // -// DefaultCommandLine.cs +// CommandLineParser.cs // // Author: -// Mike Becker +// Michael Becker // -// Copyright (c) 2019 Mike Becker +// Copyright (c) 2022 Mike Becker's Software // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -21,15 +21,19 @@ using System; namespace MBS.Framework { - public class DefaultCommandLine : CommandLine + public class CommandLineParser { - public DefaultCommandLine() + protected virtual void ParseInternal(string[] arguments) { string[] ary1 = Environment.GetCommandLineArgs(); string[] ary2 = new string[ary1.Length - 1]; Array.Copy(ary1, 1, ary2, 0, ary1.Length - 1); - Arguments = ary2; + Application.Instance.CommandLine.Arguments = ary2; + } + public void Parse(string[] arguments) + { + ParseInternal(arguments); } } } diff --git a/MBS.Framework/FindFileOptions.cs b/MBS.Framework/FindFileOptions.cs new file mode 100644 index 0000000..be964f2 --- /dev/null +++ b/MBS.Framework/FindFileOptions.cs @@ -0,0 +1,29 @@ +// +// FindFileOptions.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2022 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace MBS.Framework +{ + public enum FindFileOptions + { + All = 0, + UserWritable = 1 + } +} diff --git a/MBS.Framework/MBS.Framework.csproj b/MBS.Framework/MBS.Framework.csproj index 8c486cb..74ada98 100644 --- a/MBS.Framework/MBS.Framework.csproj +++ b/MBS.Framework/MBS.Framework.csproj @@ -81,7 +81,6 @@ - @@ -128,6 +127,8 @@ + +