mirror of
https://github.com/Alee14/shiftos-challenge.git
synced 2025-01-22 11:11:47 -05:00
Add a filesystem context that gets loaded by the system
This commit is contained in:
parent
3db03e7a89
commit
e127819f16
3 changed files with 81 additions and 0 deletions
66
ShiftOS/ShiftOS/FilesystemContext.cs
Normal file
66
ShiftOS/ShiftOS/FilesystemContext.cs
Normal file
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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" />
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue