From 00cd41ea928781ad760cff3d14bd78d60758679d Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 28 Jun 2017 08:19:44 -0400 Subject: [PATCH] Slight... very slight... fileskimmer mods --- ShiftOS.WinForms/Applications/Artpad.cs | 12 +++++- ShiftOS.WinForms/Applications/Installer.cs | 10 ++++- ShiftOS.WinForms/Applications/NameChanger.cs | 11 +++++- ShiftOS.WinForms/Applications/Skin Loader.cs | 10 ++++- ShiftOS.WinForms/Applications/Terminal.cs | 41 +++++++++++++++++++- ShiftOS.WinForms/Applications/TextPad.cs | 9 ++++- ShiftOS.WinForms/Applications/TriWrite.cs | 9 ++++- ShiftOS_TheReturn/CommandParser.cs | 2 +- ShiftOS_TheReturn/FileSkimmerBackend.cs | 20 ++++++---- ShiftOS_TheReturn/IFileHandler.cs | 30 ++++++++++++++ ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 + 11 files changed, 139 insertions(+), 16 deletions(-) create mode 100644 ShiftOS_TheReturn/IFileHandler.cs diff --git a/ShiftOS.WinForms/Applications/Artpad.cs b/ShiftOS.WinForms/Applications/Artpad.cs index e4d16bd..b584ac8 100644 --- a/ShiftOS.WinForms/Applications/Artpad.cs +++ b/ShiftOS.WinForms/Applications/Artpad.cs @@ -42,13 +42,17 @@ using System.Diagnostics; namespace ShiftOS.WinForms.Applications { + [FileHandler("Artpad Picture", ".pic", "fileiconpicture")] + [FileHandler("JPEG Picture", ".jpg", "fileiconpicture")] + [FileHandler("PNG Picture", ".png", "fileiconpicture")] + [FileHandler("Bitmap Picture", ".bmp", "fileiconpicture")] [MultiplayerOnly] [Launcher("{TIITLE_ARTPAD}", true, "al_artpad", "{AL_GRAPHICS}")] [RequiresUpgrade("artpad")] [WinOpen("{WO_ARTPAD}")] [DefaultIcon("iconArtpad")] [DefaultTitle("{TITLE_ARTPAD}")] - public partial class Artpad : UserControl, IShiftOSWindow + public partial class Artpad : UserControl, IShiftOSWindow, IFileHandler { /// /// artpad_'s GUI. @@ -1589,6 +1593,12 @@ namespace ShiftOS.WinForms.Applications setmagnification(); } + + public void OpenFile(string file) + { + AppearanceManager.SetupWindow(this); + LoadPicture(file); + } } public class undo diff --git a/ShiftOS.WinForms/Applications/Installer.cs b/ShiftOS.WinForms/Applications/Installer.cs index 284ac2c..ec93735 100644 --- a/ShiftOS.WinForms/Applications/Installer.cs +++ b/ShiftOS.WinForms/Applications/Installer.cs @@ -19,7 +19,8 @@ namespace ShiftOS.WinForms.Applications [MultiplayerOnly] [DefaultTitle("{TITLE_INSTALLER}")] [Launcher("{TITLE_INSTALLER}", true, "al_installer", "{AL_UTILITIES}")] - public partial class Installer : UserControl, IShiftOSWindow + [FileHandler("Name Pack", ".names", "fileiconnames")] + public partial class Installer : UserControl, IShiftOSWindow, IFileHandler { public Installer() { @@ -27,6 +28,13 @@ namespace ShiftOS.WinForms.Applications lbtitle.Text = "Select file"; } + public void OpenFile(string path) + { + var stpInstall = new StpInstallation(path); + AppearanceManager.SetupWindow(this); + InitiateInstall(stpInstall); + } + public void InitiateInstall(Installation install) { pnlselectfile.Hide(); diff --git a/ShiftOS.WinForms/Applications/NameChanger.cs b/ShiftOS.WinForms/Applications/NameChanger.cs index 4695c8a..67c64fd 100644 --- a/ShiftOS.WinForms/Applications/NameChanger.cs +++ b/ShiftOS.WinForms/Applications/NameChanger.cs @@ -37,20 +37,27 @@ using ShiftOS.Objects.ShiftFS; using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { - + [FileHandler("Name Pack", ".nme", "fileiconnames")] [MultiplayerOnly] [Launcher("{TITLE_NAMECHANGER}", false, null, "{AL_CUSTOMIZATION}")] [AppscapeEntry("name_changer", "{TITLE_NAMECHANGER}", "{DESC_NAMECHANGER}", 342, 500, "skinning;file_skimmer;wm_titlebar", "{AL_CUSTOMIZATION}")] [WinOpen("{WO_NAMECHANGER}")] [DefaultTitle("{TITLE_NAMECHANGER}")] [DefaultIcon("iconNameChanger")] - public partial class NameChanger : UserControl, IShiftOSWindow + public partial class NameChanger : UserControl, IShiftOSWindow, IFileHandler { public NameChanger() { InitializeComponent(); } + public void OpenFile(string file) + { + AppearanceManager.SetupWindow(this); + names = JsonConvert.DeserializeObject>(ShiftOS.Objects.ShiftFS.Utils.ReadAllText(file)); + SetupUI(); + } + private Dictionary names = new Dictionary(); public void OnLoad() diff --git a/ShiftOS.WinForms/Applications/Skin Loader.cs b/ShiftOS.WinForms/Applications/Skin Loader.cs index b70d3ea..de30360 100644 --- a/ShiftOS.WinForms/Applications/Skin Loader.cs +++ b/ShiftOS.WinForms/Applications/Skin Loader.cs @@ -37,12 +37,13 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { + [FileHandler("ShiftOS Skin", ".skn", "fileiconskin")] [Launcher("{TITLE_SKINLOADER}", true, "al_skin_loader", "{AL_CUSTOMIZATION}")] [RequiresUpgrade("skinning")] [WinOpen("skin_loader")] [DefaultTitle("{TITLE_SKINLOADER}")] [DefaultIcon("iconSkinLoader")] - public partial class Skin_Loader : UserControl, IShiftOSWindow + public partial class Skin_Loader : UserControl, IShiftOSWindow, IFileHandler { public Skin_Loader() { @@ -54,6 +55,13 @@ namespace ShiftOS.WinForms.Applications } + public void OpenFile(string file) + { + AppearanceManager.SetupWindow(this); + LoadedSkin = JsonConvert.DeserializeObject(Objects.ShiftFS.Utils.ReadAllText(file)); + SetupUI(); + } + public void SetupControls(Control ctrl) { ctrl.Tag = "keepbg keepfg keepfont"; diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 51ad42b..794edf7 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -47,12 +47,51 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { + [FileHandler("Shell script", ".trm", "fileicontrm")] [Launcher("{TITLE_TERMINAL}", false, null, "{AL_UTILITIES}")] [WinOpen("{WO_TERMINAL}")] [DefaultTitle("{TITLE_TERMINAL}")] [DefaultIcon("iconTerminal")] - public partial class Terminal : UserControl, IShiftOSWindow + public partial class Terminal : UserControl, IShiftOSWindow, IFileHandler { + public void OpenFile(string file) + { + int lastline = 0; + string lastlinetext = ""; + + try + { + var lines = new List(ShiftOS.Objects.ShiftFS.Utils.ReadAllText(file).Split(new[] { Environment.NewLine.ToString() }, StringSplitOptions.RemoveEmptyEntries)); + AppearanceManager.SetupWindow(this); + var parser = CommandParser.GenerateSample(); + foreach (var line in lines) + { + lastline = lines.IndexOf(line) + 1; + lastlinetext = line; + var command = parser.ParseCommand(line); + TerminalBackend.InvokeCommand(command.Key, command.Value); + } + } + catch(Exception ex) + { + ConsoleEx.ForegroundColor = ConsoleColor.Red; + ConsoleEx.Bold = true; + Console.WriteLine("Script exception"); + ConsoleEx.ForegroundColor = ConsoleColor.Yellow; + ConsoleEx.Bold = false; + ConsoleEx.Italic = true; +#if DEBUG + Console.WriteLine(ex.Message); +#endif + Console.WriteLine(ex.StackTrace); + if(lastline > 0) + { + Console.WriteLine(" at " + lastlinetext + " (line " + lastline + ") in " + file); + } + } + TerminalBackend.PrintPrompt(); + } + public static Stack ConsoleStack = new Stack(); public static System.Windows.Forms.Timer ti = new System.Windows.Forms.Timer(); diff --git a/ShiftOS.WinForms/Applications/TextPad.cs b/ShiftOS.WinForms/Applications/TextPad.cs index 403b4ef..0411e83 100644 --- a/ShiftOS.WinForms/Applications/TextPad.cs +++ b/ShiftOS.WinForms/Applications/TextPad.cs @@ -36,18 +36,25 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { + [FileHandler("Text File", ".txt", "fileicontext")] [Launcher("{TITLE_TEXTPAD}", true, "al_textpad", "{AL_ACCESSORIES}")] [RequiresUpgrade("textpad")] [WinOpen("{WO_TEXTPAD}")] [DefaultTitle("{TITLE_TEXTPAD}")] [DefaultIcon("iconTextPad")] - public partial class TextPad : UserControl, IShiftOSWindow + public partial class TextPad : UserControl, IShiftOSWindow, IFileHandler { public TextPad() { InitializeComponent(); } + public void OpenFile(string file) + { + AppearanceManager.SetupWindow(this); + LoadFile(file); + } + private void newToolStripMenuItem_Click(object sender, EventArgs e) { txtcontents.Text = ""; diff --git a/ShiftOS.WinForms/Applications/TriWrite.cs b/ShiftOS.WinForms/Applications/TriWrite.cs index f565328..293d30c 100644 --- a/ShiftOS.WinForms/Applications/TriWrite.cs +++ b/ShiftOS.WinForms/Applications/TriWrite.cs @@ -12,11 +12,12 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { + [FileHandler("TriWrite Document", ".rtf", "fileicontext")] [WinOpen("triwrite")] [AppscapeEntry("triwrite", "TriWrite", "Part of the trilogy of office applications for enhancement of your system. TriWrite is easliy the best text editor out there for ShiftOS.", 1024, 750, "file_skimmer;textpad", "Office")] [DefaultTitle("TriWrite")] [Launcher("TriWrite", false, null, "Office")] - public partial class TriWrite : UserControl, IShiftOSWindow + public partial class TriWrite : UserControl, IShiftOSWindow, IFileHandler { public TriWrite() @@ -24,6 +25,12 @@ namespace ShiftOS.WinForms.Applications InitializeComponent(); //From the library of babel: "FIRST COMMIT FROM A MAC WOOOO TURIANS ARE COOL" } + public void OpenFile(string file) + { + AppearanceManager.SetupWindow(this); + LoadFile(file); + } + private void newToolStripMenuItem_Click(object sender, EventArgs e) { txtcontents.Text = ""; diff --git a/ShiftOS_TheReturn/CommandParser.cs b/ShiftOS_TheReturn/CommandParser.cs index 2f0d249..d56e7bd 100644 --- a/ShiftOS_TheReturn/CommandParser.cs +++ b/ShiftOS_TheReturn/CommandParser.cs @@ -208,7 +208,7 @@ namespace ShiftOS.Engine } } - internal static CommandParser GenerateSample() + public static CommandParser GenerateSample() { var parser = new CommandParser(); parser.AddPart(new CommandFormatCommand()); diff --git a/ShiftOS_TheReturn/FileSkimmerBackend.cs b/ShiftOS_TheReturn/FileSkimmerBackend.cs index 090dc8e..ac20d34 100644 --- a/ShiftOS_TheReturn/FileSkimmerBackend.cs +++ b/ShiftOS_TheReturn/FileSkimmerBackend.cs @@ -46,14 +46,20 @@ namespace ShiftOS.Engine /// The path to open. public static void OpenFile(string path) { - _fs.OpenFile(path); + if (!Objects.ShiftFS.Utils.FileExists(path)) + throw new System.IO.FileNotFoundException("ShiftFS could not find the file specified.", path); + foreach (var type in ReflectMan.Types.Where(x => x.GetInterfaces().Contains(typeof(IFileHandler)) && Shiftorium.UpgradeAttributesUnlocked(x))) + { + foreach(FileHandlerAttribute attrib in type.GetCustomAttributes(false).Where(x => x is FileHandlerAttribute)) + { + if (path.ToLower().EndsWith(attrib.Extension)) + { + var obj = (IFileHandler)Activator.CreateInstance(type); + obj.OpenFile(path); + } + } + } } - - /// - /// Gets the file type of a given path. - /// - /// The path to check - /// The FileType of the path public static FileType GetFileType(string path) { diff --git a/ShiftOS_TheReturn/IFileHandler.cs b/ShiftOS_TheReturn/IFileHandler.cs new file mode 100644 index 0000000..3187c9a --- /dev/null +++ b/ShiftOS_TheReturn/IFileHandler.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Engine +{ + public interface IFileHandler + { + void OpenFile(string file); + } + + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public class FileHandlerAttribute : Attribute + { + public FileHandlerAttribute(string name, string extension, string iconid) + { + Name = name; + Extension = extension; + IconID = iconid; + } + + public string Name { get; set; } + public string Extension { get; set; } + public string IconID { get; set; } + } +} + + diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index 4bb930e..9bfa5f9 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -132,6 +132,7 @@ +