aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlkaline Thunder <[email protected]>2018-12-28 01:03:17 -0500
committerAlkaline Thunder <[email protected]>2018-12-28 01:03:17 -0500
commite127819f16d7c87d12b7a76696ca4d84b2c86ddb (patch)
tree5cbf085293a305e128def26fe92d673603fc50b7
parent3db03e7a89d9e701f8aead85ef307fd5f3e4c9ec (diff)
downloadshiftos-challenge-e127819f16d7c87d12b7a76696ca4d84b2c86ddb.tar.gz
shiftos-challenge-e127819f16d7c87d12b7a76696ca4d84b2c86ddb.tar.bz2
shiftos-challenge-e127819f16d7c87d12b7a76696ca4d84b2c86ddb.zip
Add a filesystem context that gets loaded by the system
-rw-r--r--ShiftOS/ShiftOS/FilesystemContext.cs66
-rw-r--r--ShiftOS/ShiftOS/ShiftOS.csproj1
-rw-r--r--ShiftOS/ShiftOS/SystemContext.cs14
3 files changed, 81 insertions, 0 deletions
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<string> PathParts = new Stack<string>();
+
+ 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 @@
<Compile Include="Desktop.Designer.cs">
<DependentUpon>Desktop.cs</DependentUpon>
</Compile>
+ <Compile Include="FilesystemContext.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Skin.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();