From 36115d61fa585d89f73a958fde5cf7148792d8ba Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 10 Mar 2022 16:34:36 -0500 Subject: [PATCH 1/6] Merge branch 'master' of github.com:alcexhim/MBS.Framework --- MBS.Framework.CLI/MBS.Framework.CLI.csproj | 4 +- MBS.Framework/MBS.Framework.csproj | 3 +- MBS.Framework/NativeHandle.cs | 47 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 MBS.Framework/NativeHandle.cs 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/MBS.Framework.csproj b/MBS.Framework/MBS.Framework.csproj index 9d6d295..8c486cb 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 @@ -127,6 +127,7 @@ + diff --git a/MBS.Framework/NativeHandle.cs b/MBS.Framework/NativeHandle.cs new file mode 100644 index 0000000..e0b9081 --- /dev/null +++ b/MBS.Framework/NativeHandle.cs @@ -0,0 +1,47 @@ +using System; +namespace MBS.Framework +{ + public class NativeHandle + { + } + public class NativeHandle : NativeHandle + { + public THandle Handle { get; private set; } + + public NativeHandle(THandle handle) + { + Handle = handle; + } + + public override int GetHashCode() + { + return Handle.GetHashCode(); + } + 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); + } + } +} From ef9292689c1b37781c8ae82d969ed26d8ef14504 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Mon, 14 Mar 2022 21:02:18 -0400 Subject: [PATCH 2/6] install pre-commit --- .pre-commit-config.yaml | 2 ++ 1 file changed, 2 insertions(+) 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 From f3f9cf47f2dc7757fc5f3dce0d5ec9972cd43adc Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Mon, 14 Mar 2022 21:02:46 -0400 Subject: [PATCH 3/6] fix major latent stack overflow error --- MBS.Framework/NativeHandle.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MBS.Framework/NativeHandle.cs b/MBS.Framework/NativeHandle.cs index e0b9081..a4b26dc 100644 --- a/MBS.Framework/NativeHandle.cs +++ b/MBS.Framework/NativeHandle.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace MBS.Framework { public class NativeHandle @@ -17,6 +17,11 @@ namespace MBS.Framework { 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) From 2da999008c89275ea45fee68f54256eb1ee42c13 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Mon, 14 Mar 2022 21:03:17 -0400 Subject: [PATCH 4/6] bring in useful InvokeMethod functionality from MBS.Framework.UI --- MBS.Framework/Reflection.cs | 47 +++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) 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 + "'"); + } + } } } From 55867cd1fb3bfa54a5c167c96e26e487231bdcf1 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Tue, 15 Mar 2022 00:33:22 -0400 Subject: [PATCH 5/6] ensure NativeHandle implements IEquatable --- MBS.Framework/NativeHandle.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MBS.Framework/NativeHandle.cs b/MBS.Framework/NativeHandle.cs index a4b26dc..f911bdb 100644 --- a/MBS.Framework/NativeHandle.cs +++ b/MBS.Framework/NativeHandle.cs @@ -4,7 +4,7 @@ namespace MBS.Framework public class NativeHandle { } - public class NativeHandle : NativeHandle + public class NativeHandle : NativeHandle, IEquatable> { public THandle Handle { get; private set; } From e026d576adad0476f6c7bd4d2152ccfa02b5cdbc Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 16 Mar 2022 14:11:06 -0400 Subject: [PATCH 6/6] refactor CommandLine and move package file determination into MBS Framework base --- MBS.Framework/Application.cs | 36 +++++++++++++++---- MBS.Framework/CommandLine.cs | 13 ++++--- ...ultCommandLine.cs => CommandLineParser.cs} | 16 +++++---- MBS.Framework/FindFileOptions.cs | 29 +++++++++++++++ MBS.Framework/MBS.Framework.csproj | 3 +- 5 files changed, 77 insertions(+), 20 deletions(-) rename MBS.Framework/{DefaultCommandLine.cs => CommandLineParser.cs} (72%) create mode 100644 MBS.Framework/FindFileOptions.cs 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 @@ + +