aboutsummaryrefslogtreecommitdiff
path: root/TimeHACK.Engine/DesktopController.cs
blob: a22df959670d8c0822323914b82f1622242cdbfe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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 TimeHACK.Engine
{
    public static class DesktopController
    {
        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;
        }

        public static void RefreshDesktopIcons(ListViewItem[] baseIcons, ref ListView theView, string theDirectory)
        {
            theView.Items.Clear(); // This resets it to it's default
            theView.Items.AddRange(baseIcons);

            foreach (string dir in Directory.GetDirectories(theDirectory))
            {
                string label = ReadDataFile(dir);
                theView.Items.Add(label ?? Path.GetFileName(dir), 1);
                theView.FindItemWithText(Path.GetFileName(dir)).Tag = dir;
            }

            foreach (string dir in Directory.GetFiles(theDirectory))
            {
                if (Path.GetFileName(dir) != "_data.info")
                {
                    theView.Items.Add(Path.GetFileName(dir), 12);
                    theView.FindItemWithText(Path.GetFileName(dir)).Tag = dir;
                }              
            }
        }
    }
}