-
Notifications
You must be signed in to change notification settings - Fork 0
/
NirPack.cs
76 lines (71 loc) · 3.01 KB
/
NirPack.cs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using static Micro.Menu.Core;
namespace Micro.Menu {
public class NirPack {
const string general = "General";
public string Name;
public int SoftwareCount, GroupCount;
public NirGroup[] Groups;
public NirPack(string path) {
SoftwareCount = int.Parse(IniReadValue(path, general, "SoftwareCount"));
GroupCount = int.Parse(IniReadValue(path, general, "GroupCount"));
Name = IniReadValue(path, general, "Name");
Groups = new NirGroup[GroupCount];
for (int g = 0; g < GroupCount; g++) {
Groups[g] = new NirGroup(
IniReadValue(path, $"Group{g}", "name"),
IniReadValue(path, $"Group{g}", "ShowAll") == "1"
);
}
for (int s = 0; s < SoftwareCount; s++) {
var grp = Groups[int.Parse(IniReadValue(path, $"Software{s}", "group"))];
var soft = new NirExe(
grp,
IniReadValue(path, $"Software{s}", "AppName"),
getAbsolutePath(Directory.GetParent(path).FullName, IniReadValue(path, $"Software{s}", "exe")),
getAbsolutePath(Directory.GetParent(path).FullName, IniReadValue(path, $"Software{s}", "exe64")),
IniReadValue(path, $"Software{s}", "shortDesc"),
"", //IniReadValue(path, $"Software{s}", "LongDesc"),
"", //IniReadValue(path, $"Software{s}", "url"),
"" //getAbsolutePath(Directory.GetParent(path).FullName, IniReadValue(path, $"Software{s}", "help"))
);
if (string.IsNullOrWhiteSpace(soft.Name))
soft.Name = FileVersionInfo.GetVersionInfo(soft.BestExe).ProductName;
grp.Add(soft);
}
foreach (var g1 in Groups) {
if (g1.ShowAll) {
foreach (var g2 in Groups) {
if (g1 != g2)
g1.AddRange(g2);
}
}
g1.Sort((a, b) => a.Name.CompareTo(b.Name));
}
}
}
public class NirGroup : List<NirExe> {
public string Name;
public bool ShowAll;
public NirGroup(string name, bool showAll) {
Name = name;
ShowAll = showAll;
}
}
public class NirExe {
public string BestExe => is64Bit && File.Exists(Exe64) ? Exe64 : Exe;
public string Exe, Exe64, Name, ShortDesc, LongDesc, Help, Url;
public NirGroup Group;
public NirExe(NirGroup group, string appName, string exe, string exe64 = "", string shortDesc = "", string longDesc = "", string url = "", string help = "") {
Group = group;
Exe = exe;
Exe64 = exe64;
Name = appName;
ShortDesc = shortDesc;
LongDesc = longDesc;
Url = url;
}
}
}