Merge branch 'master' of github.com:alcexhim/MBS.Framework
This commit is contained in:
commit
3a5a9a35e8
@ -9,6 +9,8 @@ repos:
|
||||
- id: check-xml
|
||||
- id: check-executables-have-shebangs
|
||||
- id: end-of-file-fixer
|
||||
- id: mixed-line-ending
|
||||
args: [--fix, auto]
|
||||
- id: fix-byte-order-marker
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/jumanjihouse/pre-commit-hooks
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>MBS.Framework.Console</RootNamespace>
|
||||
<AssemblyName>MBS.Framework.CLI</AssemblyName>
|
||||
<ReleaseVersion>4.0.2019.12</ReleaseVersion>
|
||||
<ReleaseVersion>1.0.*</ReleaseVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@ -43,4 +43,4 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,7 @@
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>..\..\Production.snk</AssemblyOriginatorKeyFile>
|
||||
<ReleaseVersion>4.0.2021.01</ReleaseVersion>
|
||||
<ReleaseVersion>4.0.2021.12</ReleaseVersion>
|
||||
<SynchReleaseVersion>false</SynchReleaseVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
@ -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" />
|
||||
@ -127,6 +126,9 @@
|
||||
<Compile Include="EventFilter.cs" />
|
||||
<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\" />
|
||||
|
||||
52
MBS.Framework/NativeHandle.cs
Normal file
52
MBS.Framework/NativeHandle.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
namespace MBS.Framework
|
||||
{
|
||||
public class NativeHandle
|
||||
{
|
||||
}
|
||||
public class NativeHandle<THandle> : NativeHandle, IEquatable<NativeHandle<THandle>>
|
||||
{
|
||||
public THandle Handle { get; private set; }
|
||||
|
||||
public NativeHandle(THandle handle)
|
||||
{
|
||||
Handle = handle;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Handle.GetHashCode();
|
||||
}
|
||||
|
||||
public bool Equals(NativeHandle<THandle> other)
|
||||
{
|
||||
return this.Handle.Equals(other.Handle);
|
||||
}
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if ((object)obj == null && (object)this == null)
|
||||
return true;
|
||||
if ((object)obj == null || (object)this == null)
|
||||
return false;
|
||||
|
||||
if (obj is NativeHandle<THandle>)
|
||||
return Equals(obj as NativeHandle<THandle>);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator ==(NativeHandle<THandle> left, NativeHandle<THandle> right)
|
||||
{
|
||||
if ((object)left == null && (object)right == null)
|
||||
return true;
|
||||
if ((object)left == null || (object)right == null)
|
||||
return false;
|
||||
|
||||
return left.Equals(right);
|
||||
}
|
||||
public static bool operator !=(NativeHandle<THandle> left, NativeHandle<THandle> right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,7 @@ using System.Reflection;
|
||||
|
||||
namespace MBS.Framework
|
||||
{
|
||||
public class Reflection
|
||||
public static class Reflection
|
||||
{
|
||||
public class ManifestResourceStream
|
||||
{
|
||||
@ -168,10 +168,10 @@ namespace MBS.Framework
|
||||
catch (ReflectionTypeLoadException ex)
|
||||
{
|
||||
Console.Error.WriteLine("ReflectionTypeLoadException(" + ex.LoaderExceptions.Length.ToString() + "): " + asm.FullName);
|
||||
for (int i = 0; i < ex.LoaderExceptions.Length; i++)
|
||||
for (int i = 0; i < ex.LoaderExceptions.Length; i++)
|
||||
{
|
||||
Console.Error.WriteLine("\t" + ex.LoaderExceptions[i].Message);
|
||||
Console.Error.WriteLine();
|
||||
Console.Error.WriteLine("\t" + ex.LoaderExceptions[i].Message);
|
||||
Console.Error.WriteLine();
|
||||
}
|
||||
|
||||
types1 = ex.Types;
|
||||
@ -272,5 +272,44 @@ namespace MBS.Framework
|
||||
|
||||
return default(T);
|
||||
}
|
||||
|
||||
public static void InvokeMethod(object obj, string meth, params object[] parms)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
Console.WriteLine("Engine::InvokeMethod: obj is null");
|
||||
return;
|
||||
}
|
||||
|
||||
Type t = obj.GetType();
|
||||
System.Reflection.MethodInfo mi = t.GetMethod(meth, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||
if (mi != null)
|
||||
{
|
||||
mi.Invoke(obj, parms);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Engine::InvokeMethod: method not found '" + meth + "' on '" + t.FullName + "'");
|
||||
}
|
||||
}
|
||||
public static void InvokeMethod(Type type, string meth, params object[] parms)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
Console.WriteLine("Engine::InvokeMethod: obj is null");
|
||||
return;
|
||||
}
|
||||
|
||||
Type t = type;
|
||||
System.Reflection.MethodInfo mi = t.GetMethod(meth, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
|
||||
if (mi != null)
|
||||
{
|
||||
mi.Invoke(null, parms);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Engine::InvokeMethod: static method not found '" + meth + "' on '" + t.FullName + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user