diff options
| author | lempamo <[email protected]> | 2017-08-23 13:38:40 -0400 |
|---|---|---|
| committer | lempamo <[email protected]> | 2017-08-23 13:38:40 -0400 |
| commit | 3306d36ecbc024775972e5cf7971b2a7a70671d0 (patch) | |
| tree | 0a79e67b6723a8c75ffd66c7828bdd0ebb1bf74d /Histacom2.Engine/DesktopController.cs | |
| parent | 99fef5c57360f07259fc86f433bed8a9ab59c48e (diff) | |
| download | histacom2-3306d36ecbc024775972e5cf7971b2a7a70671d0.tar.gz histacom2-3306d36ecbc024775972e5cf7971b2a7a70671d0.tar.bz2 histacom2-3306d36ecbc024775972e5cf7971b2a7a70671d0.zip | |
Renaming the game!
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); + } + } + } + } +} |
