Add a filesystem context that gets loaded by the system

This commit is contained in:
Alkaline Thunder 2018-12-28 01:03:17 -05:00
parent 3db03e7a89
commit e127819f16
3 changed files with 81 additions and 0 deletions

View 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()));
}
}
}

View file

@ -52,6 +52,7 @@
<Compile Include="Desktop.Designer.cs"> <Compile Include="Desktop.Designer.cs">
<DependentUpon>Desktop.cs</DependentUpon> <DependentUpon>Desktop.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="FilesystemContext.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Skin.cs" /> <Compile Include="Skin.cs" />

View file

@ -11,6 +11,7 @@ namespace ShiftOS
{ {
private Desktop _desktop = null; private Desktop _desktop = null;
private SkinContext _skinContext = null; private SkinContext _skinContext = null;
private FilesystemContext _filesystem = null;
private int _codepoints = 0; private int _codepoints = 0;
private void LoadCurrentSkin() private void LoadCurrentSkin()
@ -19,6 +20,12 @@ namespace ShiftOS
_skinContext = new SkinContext(); _skinContext = new SkinContext();
} }
private void LoadFilesystem()
{
Console.WriteLine("Loading filesystem context...");
this._filesystem = new FilesystemContext();
}
public void Dispose() public void Dispose()
{ {
_desktop = null; _desktop = null;
@ -29,6 +36,11 @@ namespace ShiftOS
return this._codepoints; return this._codepoints;
} }
public FilesystemContext GetFilesystem()
{
return this._filesystem;
}
public SkinContext GetSkinContext() public SkinContext GetSkinContext()
{ {
return this._skinContext; return this._skinContext;
@ -46,6 +58,8 @@ namespace ShiftOS
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
this.LoadFilesystem();
Console.WriteLine("Loading current skin..."); Console.WriteLine("Loading current skin...");
this.LoadCurrentSkin(); this.LoadCurrentSkin();