diff options
| author | John T <[email protected]> | 2017-11-11 08:53:55 -0500 |
|---|---|---|
| committer | John T <[email protected]> | 2017-11-11 08:53:55 -0500 |
| commit | 97722fbe9d474adffbba0b92e9727c48a8205234 (patch) | |
| tree | 65dfe45bbfd194ddb534cc80107ab8e6d80cf5bc /ShiftOS.Engine/ShiftFS/ShiftFS.cs | |
| parent | a10440a45c40652b13e883aec832a0c8ded685e8 (diff) | |
| download | shiftos-rewind-97722fbe9d474adffbba0b92e9727c48a8205234.tar.gz shiftos-rewind-97722fbe9d474adffbba0b92e9727c48a8205234.tar.bz2 shiftos-rewind-97722fbe9d474adffbba0b92e9727c48a8205234.zip | |
Only 1/4 broken ShiftFS and WIP File Skimmer
Diffstat (limited to 'ShiftOS.Engine/ShiftFS/ShiftFS.cs')
| -rw-r--r-- | ShiftOS.Engine/ShiftFS/ShiftFS.cs | 74 |
1 files changed, 60 insertions, 14 deletions
diff --git a/ShiftOS.Engine/ShiftFS/ShiftFS.cs b/ShiftOS.Engine/ShiftFS/ShiftFS.cs index d188bee..de406a7 100644 --- a/ShiftOS.Engine/ShiftFS/ShiftFS.cs +++ b/ShiftOS.Engine/ShiftFS/ShiftFS.cs @@ -1,34 +1,80 @@ using System; -using System.Collections.ObjectModel; +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 + public static class ShiftFS { - internal static readonly string SavePath = Path.Combine(Environment.CurrentDirectory, "Save") + "\\"; + static readonly string FilePath = Path.Combine(Environment.CurrentDirectory, "save.bin"); - public static ObservableCollection<ShiftDrive> Drives = new ObservableCollection<ShiftDrive>(); + static readonly FileSystemWatcher _watcher; + + static readonly BinaryFormatter _formatter = new BinaryFormatter(); + + public static EventList<ShiftTree> Drives { get; private set; } = new EventList<ShiftTree>(); - static ShiftFs() + public static void Save() { - if (Directory.Exists(SavePath)) + using (var fs = File.OpenWrite(FilePath)) { - var info = new DirectoryInfo(SavePath); - foreach (var dir in info.EnumerateDirectories()) + //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 ShiftDrive(dir)); + + 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); } - else + + WatcherOnChanged(null, null); + + _watcher = new FileSystemWatcher(Environment.CurrentDirectory) { - CreateSaveFile(); - } + Filter = "save.bin", + }; + + _watcher.Changed += WatcherOnChanged; } - public static void CreateSaveFile() + static void WatcherOnChanged(object sender, FileSystemEventArgs e) { - throw new NotImplementedException(); + 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 |
