Histacom2/Histacom2.Engine/DesktopController.cs

73 lines
2.6 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
2017-07-23 11:22:32 -04:00
using Newtonsoft.Json;
2017-08-23 13:38:40 -04:00
namespace Histacom2.Engine
{
public static class DesktopController
{
2017-07-23 11:22:32 -04:00
public static string ReadDataFile(string reqDirectory, bool returnYesIfProtected = false)
{
string Val = "";
2017-07-27 00:25:37 -04:00
string directoryFileInfo = File.ReadAllText(Path.Combine(reqDirectory, "_data.info"));
2017-08-01 10:28:47 -04:00
FileSystemFolderInfo toRead = JsonConvert.DeserializeObject<FileSystemFolderInfo>(directoryFileInfo);
2017-07-23 11:22:32 -04:00
if (returnYesIfProtected)
2017-07-23 11:22:32 -04:00
{
if (toRead.IsProtected)
2017-07-23 11:22:32 -04:00
{
return "yes";
}
}
else
{
2017-07-27 00:25:37 -04:00
return toRead.Label;
2017-07-23 11:22:32 -04:00
}
return Val;
}
2017-07-27 15:58:05 -04:00
public static void RefreshDesktopIcons(ListViewItem[] baseIcons, ref ListView view, string folder)
{
2017-07-27 15:58:05 -04:00
view.Items.Clear(); // This resets it to it's default
view.Items.AddRange(baseIcons);
2017-07-27 15:58:05 -04:00
foreach (string dir in Directory.GetDirectories(folder))
2017-07-23 10:37:27 -04:00
{
2017-07-23 11:22:32 -04:00
string label = ReadDataFile(dir);
2017-07-27 15:58:05 -04:00
view.Items.Add(label ?? Path.GetFileName(dir), 1);
view.FindItemWithText(Path.GetFileName(dir)).Tag = dir;
2017-07-23 10:37:27 -04:00
}
2017-07-27 15:58:05 -04:00
foreach (string dir in Directory.GetFiles(folder))
2017-07-23 10:37:27 -04:00
{
2017-07-23 11:22:32 -04:00
if (Path.GetFileName(dir) != "_data.info")
{
2017-07-27 00:25:37 -04:00
THFileInfo file = new THFileInfo();
2017-07-27 15:58:05 -04:00
FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject<FileSystemFolderInfo>(File.ReadAllText(Path.Combine(folder, "_data.info")));
2017-07-27 00:25:37 -04:00
foreach (THFileInfo f in fsfi.Files)
{
if (f.Name.ToLower() == Path.GetFileName(dir).ToLower())
{
file = f; break;
}
}
2017-07-27 00:25:37 -04:00
if (new FileInfo(dir).Extension == ".exe" && file.FileIcon == 8) file.FileIcon = 10;
2017-07-31 21:04:18 -04:00
if (new FileInfo(dir).Extension == ".txt" && file.FileIcon == 8) file.FileIcon = 12;
2017-07-27 15:58:05 -04:00
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);
2017-07-23 11:22:32 -04:00
}
2017-07-23 10:37:27 -04:00
}
}
}
}