Histacom2/TimeHACK.Engine/DesktopController.cs

59 lines
1.9 KiB
C#
Raw 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;
namespace TimeHACK.Engine
{
public static class DesktopController
{
2017-07-23 11:22:32 -04:00
public static string ReadDataFile(string reqDirectory, bool returnYesIfProtected = false)
{
string Val = "";
string directoryFileInfo;
directoryFileInfo = File.ReadAllText(Path.Combine(reqDirectory, "_data.info"));
FileSystemFolderInfo toRead = new FileSystemFolderInfo();
toRead = JsonConvert.DeserializeObject<FileSystemFolderInfo>(directoryFileInfo);
if (returnYesIfProtected == true)
{
if (toRead.Isprotected == true)
{
return "yes";
}
}
else
{
return toRead.label;
}
return Val;
}
2017-07-23 10:37:27 -04:00
public static void RefreshDesktopIcons(ListViewItem[] baseIcons, ref ListView theView, string theDirectory)
{
2017-07-23 10:37:27 -04:00
theView.Items.Clear(); // This resets it to it's default
theView.Items.AddRange(baseIcons);
2017-07-23 10:37:27 -04:00
foreach (string dir in Directory.GetDirectories(theDirectory))
{
2017-07-23 11:22:32 -04:00
string label = ReadDataFile(dir);
theView.Items.Add(label ?? Path.GetFileName(dir), 1);
theView.FindItemWithText(Path.GetFileName(dir)).Tag = dir;
2017-07-23 10:37:27 -04:00
}
foreach (string dir in Directory.GetFiles(theDirectory))
{
2017-07-23 11:22:32 -04:00
if (Path.GetFileName(dir) != "_data.info")
{
theView.Items.Add(Path.GetFileName(dir), 12);
theView.FindItemWithText(Path.GetFileName(dir)).Tag = dir;
}
2017-07-23 10:37:27 -04:00
}
}
}
}