diff options
| author | Alex-TIMEHACK <[email protected]> | 2017-08-27 11:32:44 +0100 |
|---|---|---|
| committer | Alex-TIMEHACK <[email protected]> | 2017-08-27 11:32:44 +0100 |
| commit | f8f3bd0b1eb57c5a289513200b192e1d54d58292 (patch) | |
| tree | c9b79515fb81d90320ef386a522a5830875f6d49 /Histacom2.Engine/DesktopController.cs | |
| parent | bffcb720f811623015ed4795032e5c57d1064c8a (diff) | |
| parent | cd6273d7c95098e0e0dd9948c6b5cec1c5f9cd3f (diff) | |
| download | histacom2-f8f3bd0b1eb57c5a289513200b192e1d54d58292.tar.gz histacom2-f8f3bd0b1eb57c5a289513200b192e1d54d58292.tar.bz2 histacom2-f8f3bd0b1eb57c5a289513200b192e1d54d58292.zip | |
Updated my fork!
Diffstat (limited to 'Histacom2.Engine/DesktopController.cs')
| -rw-r--r-- | Histacom2.Engine/DesktopController.cs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/Histacom2.Engine/DesktopController.cs b/Histacom2.Engine/DesktopController.cs new file mode 100644 index 0000000..8ea9775 --- /dev/null +++ b/Histacom2.Engine/DesktopController.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.IO; +using Newtonsoft.Json; + +namespace Histacom2.Engine +{ + public static class DesktopController + { + public static string ReadDataFile(string reqDirectory, bool returnYesIfProtected = false) + { + string Val = ""; + string directoryFileInfo = File.ReadAllText(Path.Combine(reqDirectory, "_data.info")); + FileSystemFolderInfo toRead = JsonConvert.DeserializeObject<FileSystemFolderInfo>(directoryFileInfo); + + if (returnYesIfProtected == true) + { + if (toRead.IsProtected == true) + { + return "yes"; + } + } + else + { + return toRead.Label; + } + return Val; + } + + public static void RefreshDesktopIcons(ListViewItem[] baseIcons, ref ListView view, string folder) + { + view.Items.Clear(); // This resets it to it's default + view.Items.AddRange(baseIcons); + + foreach (string dir in Directory.GetDirectories(folder)) + { + string label = ReadDataFile(dir); + view.Items.Add(label ?? Path.GetFileName(dir), 1); + view.FindItemWithText(Path.GetFileName(dir)).Tag = dir; + } + + foreach (string dir in Directory.GetFiles(folder)) + { + if (Path.GetFileName(dir) != "_data.info") + { + THFileInfo file = new THFileInfo(); + FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject<FileSystemFolderInfo>(File.ReadAllText(Path.Combine(folder, "_data.info"))); + foreach (THFileInfo f in fsfi.Files) + { + if (f.Name.ToLower() == Path.GetFileName(dir).ToLower()) + { + file = f; break; + } + } + + if (new FileInfo(dir).Extension == ".exe" && file.FileIcon == 8) file.FileIcon = 10; + if (new FileInfo(dir).Extension == ".txt" && file.FileIcon == 8) file.FileIcon = 12; + + view.Items.Add(Path.GetFileName(dir), file.FileIcon); + view.FindItemWithText(Path.GetFileName(dir)).Tag = dir; + string toWrite = JsonConvert.SerializeObject(fsfi, Formatting.Indented); + + File.WriteAllText(Path.Combine(folder, "_data.info"), toWrite); + } + } + } + } +} |
