diff options
Diffstat (limited to 'ShiftOS_TheReturn')
| -rw-r--r-- | ShiftOS_TheReturn/CommandParser.cs | 2 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/FileSkimmerBackend.cs | 20 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/IFileHandler.cs | 30 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 |
4 files changed, 45 insertions, 8 deletions
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 /// <param name="path">The path to open.</param> 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); + } + } + } } - - /// <summary> - /// Gets the file type of a given path. - /// </summary> - /// <param name="path">The path to check</param> - /// <returns>The FileType of the path</returns> 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 @@ </Compile> <Compile Include="Desktop.cs" /> <Compile Include="FileSkimmerBackend.cs" /> + <Compile Include="IFileHandler.cs" /> <Compile Include="Infobox.cs" /> <Compile Include="IShiftOSWindow.cs" /> <Compile Include="IStatusIcon.cs" /> |
