From e127819f16d7c87d12b7a76696ca4d84b2c86ddb Mon Sep 17 00:00:00 2001 From: Alkaline Thunder Date: Fri, 28 Dec 2018 01:03:17 -0500 Subject: [PATCH] Add a filesystem context that gets loaded by the system --- ShiftOS/ShiftOS/FilesystemContext.cs | 66 ++++++++++++++++++++++++++++ ShiftOS/ShiftOS/ShiftOS.csproj | 1 + ShiftOS/ShiftOS/SystemContext.cs | 14 ++++++ 3 files changed, 81 insertions(+) create mode 100644 ShiftOS/ShiftOS/FilesystemContext.cs diff --git a/ShiftOS/ShiftOS/FilesystemContext.cs b/ShiftOS/ShiftOS/FilesystemContext.cs new file mode 100644 index 0000000..2d68794 --- /dev/null +++ b/ShiftOS/ShiftOS/FilesystemContext.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using System.Threading.Tasks; + +namespace ShiftOS +{ + public class FilesystemContext + { + private string _workingDirectory; + + public FilesystemContext() + { + _workingDirectory = Path.Combine(Environment.CurrentDirectory, "ShiftFS"); + + // Create the directory if it does not exist. + if (!Directory.Exists(_workingDirectory)) + { + Directory.CreateDirectory(_workingDirectory); + } + } + + private string ResolveToAbsolutePath(string InPath) + { + if (!InPath.StartsWith("/")) + throw new FormatException(); + + Stack PathParts = new Stack(); + + foreach(string Part in InPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)) + { + if(Part == "..") + { + // Pop the last part off the absolute path only if there's a part to pop. + if(PathParts.Count == 0) + { + continue; + } + PathParts.Pop(); + } + if(Part == ".") + { + // Skip "current directory" marker. + continue; + } + // Push the path part onto the stack. + PathParts.Push(Part); + } + + // Resolution completed. Now let's get it into a string array. + string OutPath = ""; + foreach(var Part in PathParts) + { + OutPath = "/" + Part; + } + return OutPath; + } + + private string MapToEnvironmentPath(string InPath) + { + return Path.Combine(_workingDirectory, ResolveToAbsolutePath(InPath).Replace("/", Path.DirectorySeparatorChar.ToString())); + } + } +} diff --git a/ShiftOS/ShiftOS/ShiftOS.csproj b/ShiftOS/ShiftOS/ShiftOS.csproj index d8e4c7b..8cbaa6a 100644 --- a/ShiftOS/ShiftOS/ShiftOS.csproj +++ b/ShiftOS/ShiftOS/ShiftOS.csproj @@ -52,6 +52,7 @@ Desktop.cs + diff --git a/ShiftOS/ShiftOS/SystemContext.cs b/ShiftOS/ShiftOS/SystemContext.cs index 13c7561..ef6972f 100644 --- a/ShiftOS/ShiftOS/SystemContext.cs +++ b/ShiftOS/ShiftOS/SystemContext.cs @@ -11,6 +11,7 @@ namespace ShiftOS { private Desktop _desktop = null; private SkinContext _skinContext = null; + private FilesystemContext _filesystem = null; private int _codepoints = 0; private void LoadCurrentSkin() @@ -19,6 +20,12 @@ namespace ShiftOS _skinContext = new SkinContext(); } + private void LoadFilesystem() + { + Console.WriteLine("Loading filesystem context..."); + this._filesystem = new FilesystemContext(); + } + public void Dispose() { _desktop = null; @@ -29,6 +36,11 @@ namespace ShiftOS return this._codepoints; } + public FilesystemContext GetFilesystem() + { + return this._filesystem; + } + public SkinContext GetSkinContext() { return this._skinContext; @@ -46,6 +58,8 @@ namespace ShiftOS Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); + this.LoadFilesystem(); + Console.WriteLine("Loading current skin..."); this.LoadCurrentSkin();