aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Engine/ShiftFS/ShiftFS.cs
diff options
context:
space:
mode:
authorAlex-TIMEHACK <[email protected]>2017-11-18 16:29:54 +0000
committerAlex-TIMEHACK <[email protected]>2017-11-18 16:29:54 +0000
commit4037be53b29a122732cfc10693e9c0027f606bb0 (patch)
tree8533ea9ee0ac8f5f7f696b85cb039f783657ada0 /ShiftOS.Engine/ShiftFS/ShiftFS.cs
parent65b7ac2b8cbc4478f6d31a21f106048aeb075078 (diff)
parent97722fbe9d474adffbba0b92e9727c48a8205234 (diff)
downloadshiftos-rewind-4037be53b29a122732cfc10693e9c0027f606bb0.tar.gz
shiftos-rewind-4037be53b29a122732cfc10693e9c0027f606bb0.tar.bz2
shiftos-rewind-4037be53b29a122732cfc10693e9c0027f606bb0.zip
Updated my fork!
Conflicts: ShiftOS.Engine/ShiftOS.Engine.csproj ShiftOS.Engine/Terminal/Commands/Hello.cs ShiftOS.Engine/Terminal/TerminalBackend.cs ShiftOS.Engine/Terminal/TerminalCommand.cs ShiftOS.Main/ShiftOS.Main.csproj ShiftOS.Main/ShiftOS/Apps/Terminal.cs ShiftOS.Main/ShiftOS/Desktop.cs
Diffstat (limited to 'ShiftOS.Engine/ShiftFS/ShiftFS.cs')
-rw-r--r--ShiftOS.Engine/ShiftFS/ShiftFS.cs80
1 files changed, 80 insertions, 0 deletions
diff --git a/ShiftOS.Engine/ShiftFS/ShiftFS.cs b/ShiftOS.Engine/ShiftFS/ShiftFS.cs
new file mode 100644
index 0000000..de406a7
--- /dev/null
+++ b/ShiftOS.Engine/ShiftFS/ShiftFS.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.Windows.Forms;
+using ShiftOS.Engine.Misc;
+
+namespace ShiftOS.Engine.ShiftFS
+{
+ public static class ShiftFS
+ {
+ static readonly string FilePath = Path.Combine(Environment.CurrentDirectory, "save.bin");
+
+ static readonly FileSystemWatcher _watcher;
+
+ static readonly BinaryFormatter _formatter = new BinaryFormatter();
+
+ public static EventList<ShiftTree> Drives { get; private set; } = new EventList<ShiftTree>();
+
+ public static void Save()
+ {
+ using (var fs = File.OpenWrite(FilePath))
+ {
+ //Whoa.Whoa.SerialiseObject(fs, Drives);
+ _formatter.Serialize(fs, Drives);
+ }
+ }
+
+
+ static ShiftFS()
+ {
+ Drives.ItemAdded += (sender, e) => Debug.WriteLine(e.Item.Name + e.Item.Letter);
+
+ if (!File.Exists(FilePath))
+ {
+ using (File.Create(FilePath))
+ {
+
+ Drives.Add(new ShiftTree("Local Disk", 'C')
+ {
+ new ShiftDirectory("usr")
+ {
+ //i'll put in extensions later
+ new ShiftFile<string>("stringfile.txt", "THIS IS SECRETEXT")
+ },
+ new ShiftDirectory("libs")
+ {
+ new ShiftFile<string>("thing.dll", "oh no it's not code FACH")
+ }
+
+ });
+ }
+
+ Save();
+
+ MessageBox.Show("Save file created.");
+ Debug.WriteLine("Drives: " + Drives.Count);
+ }
+
+ WatcherOnChanged(null, null);
+
+ _watcher = new FileSystemWatcher(Environment.CurrentDirectory)
+ {
+ Filter = "save.bin",
+ };
+
+ _watcher.Changed += WatcherOnChanged;
+ }
+
+ static void WatcherOnChanged(object sender, FileSystemEventArgs e)
+ {
+ using (var fs = File.OpenRead(FilePath))
+ {
+ //Drives = Whoa.Whoa.DeserialiseObject<EventList<ShiftTree>>(fs);
+ Drives = (EventList<ShiftTree>) _formatter.Deserialize(fs);
+ }
+ }
+ }
+} \ No newline at end of file