diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index f43d926..fa4a979 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -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
diff --git a/MBS.Framework.CLI/MBS.Framework.CLI.csproj b/MBS.Framework.CLI/MBS.Framework.CLI.csproj
index fe9817f..b06efbe 100644
--- a/MBS.Framework.CLI/MBS.Framework.CLI.csproj
+++ b/MBS.Framework.CLI/MBS.Framework.CLI.csproj
@@ -7,7 +7,7 @@
Library
MBS.Framework.Console
MBS.Framework.CLI
- 4.0.2019.12
+ 1.0.*
true
@@ -43,4 +43,4 @@
-
+
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 9d6d295..74ada98 100644
--- a/MBS.Framework/MBS.Framework.csproj
+++ b/MBS.Framework/MBS.Framework.csproj
@@ -11,7 +11,7 @@
2.0
true
..\..\Production.snk
- 4.0.2021.01
+ 4.0.2021.12
false
@@ -81,7 +81,6 @@
-
@@ -127,6 +126,9 @@
+
+
+
diff --git a/MBS.Framework/NativeHandle.cs b/MBS.Framework/NativeHandle.cs
new file mode 100644
index 0000000..f911bdb
--- /dev/null
+++ b/MBS.Framework/NativeHandle.cs
@@ -0,0 +1,52 @@
+using System;
+namespace MBS.Framework
+{
+ public class NativeHandle
+ {
+ }
+ public class NativeHandle : NativeHandle, IEquatable>
+ {
+ public THandle Handle { get; private set; }
+
+ public NativeHandle(THandle handle)
+ {
+ Handle = handle;
+ }
+
+ public override int GetHashCode()
+ {
+ return Handle.GetHashCode();
+ }
+
+ public bool Equals(NativeHandle 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)
+ return Equals(obj as NativeHandle);
+
+ return false;
+ }
+
+ public static bool operator ==(NativeHandle left, NativeHandle 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 left, NativeHandle right)
+ {
+ return !left.Equals(right);
+ }
+ }
+}
diff --git a/MBS.Framework/Reflection.cs b/MBS.Framework/Reflection.cs
index 5fbb741..d1df0bc 100644
--- a/MBS.Framework/Reflection.cs
+++ b/MBS.Framework/Reflection.cs
@@ -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 + "'");
+ }
+ }
}
}