refactor CommandLine and move package file determination into MBS Framework base
This commit is contained in:
parent
55867cd1fb
commit
e026d576ad
@ -63,6 +63,35 @@ namespace MBS.Framework
|
||||
/// </value>
|
||||
public static Application Instance { get; set; } = null;
|
||||
|
||||
public string[] FindFiles(string filename, FindFileOptions options = FindFileOptions.All)
|
||||
{
|
||||
if (filename.StartsWith("~/"))
|
||||
{
|
||||
filename = filename.Substring(2);
|
||||
}
|
||||
|
||||
List<string> files = new List<string>();
|
||||
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<string, List<EventHandler>> _CommandEventHandlers = new Dictionary<string, List<EventHandler>>();
|
||||
public Command.CommandCollection Commands { get; } = new Command.CommandCollection();
|
||||
|
||||
@ -23,13 +23,13 @@ using System.Collections.Generic;
|
||||
|
||||
namespace MBS.Framework
|
||||
{
|
||||
public abstract class CommandLine
|
||||
public class CommandLine
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the original <see cref="String" /> array of arguments.
|
||||
/// </summary>
|
||||
/// <value>The arguments.</value>
|
||||
public string[] Arguments { get; protected set; }
|
||||
public string[] Arguments { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of file names passed on the command line.
|
||||
@ -37,14 +37,13 @@ namespace MBS.Framework
|
||||
/// <value>The file names.</value>
|
||||
public List<string> FileNames { get; } = new List<string>();
|
||||
|
||||
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()
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
//
|
||||
// DefaultCommandLine.cs
|
||||
// CommandLineParser.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Becker <alcexhim@gmail.com>
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
MBS.Framework/FindFileOptions.cs
Normal file
29
MBS.Framework/FindFileOptions.cs
Normal file
@ -0,0 +1,29 @@
|
||||
//
|
||||
// FindFileOptions.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
namespace MBS.Framework
|
||||
{
|
||||
public enum FindFileOptions
|
||||
{
|
||||
All = 0,
|
||||
UserWritable = 1
|
||||
}
|
||||
}
|
||||
@ -81,7 +81,6 @@
|
||||
<Compile Include="CommandLine.cs" />
|
||||
<Compile Include="CommandLineOption.cs" />
|
||||
<Compile Include="CommandLineOptionValueType.cs" />
|
||||
<Compile Include="DefaultCommandLine.cs" />
|
||||
<Compile Include="Context.cs" />
|
||||
<Compile Include="Command.cs" />
|
||||
<Compile Include="CommandEvent.cs" />
|
||||
@ -128,6 +127,8 @@
|
||||
<Compile Include="EventFilterType.cs" />
|
||||
<Compile Include="EventFilterDelegate.cs" />
|
||||
<Compile Include="NativeHandle.cs" />
|
||||
<Compile Include="CommandLineParser.cs" />
|
||||
<Compile Include="FindFileOptions.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Logic\" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user