Skip to content

Commit 8bef422

Browse files
authored
Merge pull request #32 from jetelain/helper
Config Helper Application
2 parents 0d2535d + 37b792d commit 8bef422

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2531
-0
lines changed

Helper/Helper.sln

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32929.385
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Helper", "Helper\Helper.csproj", "{CED6453D-664A-4A60-AEDF-5F0C6B53EC3D}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BIS.Core", "..\..\bis-file-formats\BIS.Core\BIS.Core.csproj", "{D248C687-C704-4658-8134-8329ACE4F6EF}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelperUI", "HelperUI\HelperUI.csproj", "{109A4D15-7DDF-4F55-B03B-9183D1B22652}"
11+
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BIS.PBO", "..\..\bis-file-formats\BIS.PBO\BIS.PBO.csproj", "{CC24C932-60B5-40E4-A426-651F456C0C6C}"
13+
EndProject
14+
Global
15+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16+
Debug|Any CPU = Debug|Any CPU
17+
Release|Any CPU = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20+
{CED6453D-664A-4A60-AEDF-5F0C6B53EC3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{CED6453D-664A-4A60-AEDF-5F0C6B53EC3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{CED6453D-664A-4A60-AEDF-5F0C6B53EC3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{CED6453D-664A-4A60-AEDF-5F0C6B53EC3D}.Release|Any CPU.Build.0 = Release|Any CPU
24+
{D248C687-C704-4658-8134-8329ACE4F6EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{D248C687-C704-4658-8134-8329ACE4F6EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{D248C687-C704-4658-8134-8329ACE4F6EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{D248C687-C704-4658-8134-8329ACE4F6EF}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{109A4D15-7DDF-4F55-B03B-9183D1B22652}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{109A4D15-7DDF-4F55-B03B-9183D1B22652}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{109A4D15-7DDF-4F55-B03B-9183D1B22652}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{109A4D15-7DDF-4F55-B03B-9183D1B22652}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{CC24C932-60B5-40E4-A426-651F456C0C6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{CC24C932-60B5-40E4-A426-651F456C0C6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{CC24C932-60B5-40E4-A426-651F456C0C6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{CC24C932-60B5-40E4-A426-651F456C0C6C}.Release|Any CPU.Build.0 = Release|Any CPU
36+
EndGlobalSection
37+
GlobalSection(SolutionProperties) = preSolution
38+
HideSolutionNode = FALSE
39+
EndGlobalSection
40+
GlobalSection(ExtensibilityGlobals) = postSolution
41+
SolutionGuid = {FCAC46E7-E1BF-4662-8E57-A0130EC80F0F}
42+
EndGlobalSection
43+
EndGlobal
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using BIS.Core.Config;
7+
using BIS.Core.Streams;
8+
using BIS.PBO;
9+
using Microsoft.Win32;
10+
11+
namespace Helper
12+
{
13+
static class ConfigHelper
14+
{
15+
public static IEnumerable<T> Get<T>(this IEnumerable<ParamFile> files, string name) where T : ParamEntry
16+
{
17+
return files.Where(f => f.Root != null).Select(f => f.Root).Get<T>(name);
18+
}
19+
20+
public static IEnumerable<T> Get<T>(this IEnumerable<ParamClass> entries) where T : ParamEntry
21+
{
22+
return entries.SelectMany(e => e.Entries.OfType<T>());
23+
}
24+
25+
public static IEnumerable<T> Get<T>(this IEnumerable<ParamClass> entries, string name) where T : ParamEntry
26+
{
27+
return entries.SelectMany(e => e.Entries.OfType<T>()).Where(e => string.Equals(e.Name, name, StringComparison.OrdinalIgnoreCase));
28+
}
29+
30+
public static IEnumerable<T> Get<T>(this ParamClass entry, string name) where T : ParamEntry
31+
{
32+
return entry.Entries.OfType<T>().Where(e => string.Equals(e.Name, name, StringComparison.OrdinalIgnoreCase));
33+
}
34+
35+
public static IEnumerable<T> Get<T>(this ParamClass entry) where T : ParamEntry
36+
{
37+
return entry.Entries.OfType<T>();
38+
}
39+
40+
public static T Get<T>(this ParamClass entry, string name, IEnumerable<ParamClass> cfgClassRoot) where T : ParamEntry
41+
{
42+
var value = entry.Get<T>(name).FirstOrDefault();
43+
if (value != null)
44+
{
45+
return value;
46+
}
47+
if (!string.IsNullOrEmpty(entry.BaseClassName))
48+
{
49+
return
50+
cfgClassRoot
51+
.Get<ParamClass>(entry.BaseClassName)
52+
.Select(e => e.Get<T>(name, cfgClassRoot))
53+
.Where(v => v != null)
54+
.FirstOrDefault();
55+
}
56+
return null;
57+
}
58+
59+
public static T GetValue<T>(this ParamClass entry, string name, IEnumerable<ParamClass> classes)
60+
{
61+
var value = entry.Get<ParamValue>(name, classes);
62+
if (value != null)
63+
{
64+
return value.Get<T>();
65+
}
66+
return default(T);
67+
}
68+
69+
public static T[] GetArray<T>(this ParamClass entry, string name, IEnumerable<ParamClass> classes)
70+
{
71+
return entry.Get<ParamArray>(name, classes)?.ToArray<T>();
72+
}
73+
74+
public static bool Inherits(this ParamClass entry, string wantedBaseClassName, IEnumerable<ParamClass> cfgClassRoot)
75+
{
76+
if (!string.IsNullOrEmpty(entry.BaseClassName))
77+
{
78+
if (string.Equals(wantedBaseClassName, entry.BaseClassName))
79+
{
80+
return true;
81+
}
82+
return cfgClassRoot
83+
.Get<ParamClass>(entry.BaseClassName)
84+
.Any(c => c.Inherits(wantedBaseClassName, cfgClassRoot));
85+
}
86+
return false;
87+
}
88+
89+
90+
internal static ParamFile ReadParamFile(string file)
91+
{
92+
var ext = Path.GetExtension(file);
93+
ParamFile paramFile;
94+
if (string.Equals(ext, ".cpp", System.StringComparison.OrdinalIgnoreCase))
95+
{
96+
paramFile = ParseCpp(file);
97+
}
98+
else if (string.Equals(ext, ".pbo", System.StringComparison.OrdinalIgnoreCase))
99+
{
100+
var pbo = new PBO(file);
101+
var configBin = pbo.Files.FirstOrDefault(f => f.FileName == "config.bin");
102+
if (configBin != null)
103+
{
104+
using (var stream = configBin.OpenRead())
105+
{
106+
paramFile = StreamHelper.Read<ParamFile>(stream);
107+
}
108+
}
109+
else
110+
{
111+
var src = Path.GetTempFileName();
112+
var configCpp = pbo.Files.FirstOrDefault(f => f.FileName == "config.cpp");
113+
if (configCpp != null)
114+
{
115+
using (var streamFile = File.Create(src))
116+
using (var stream = configCpp.OpenRead())
117+
{
118+
stream.CopyTo(streamFile);
119+
}
120+
paramFile = ParseCpp(src);
121+
File.Delete(src);
122+
}
123+
else
124+
{
125+
paramFile = new ParamFile();
126+
}
127+
}
128+
}
129+
else
130+
{
131+
paramFile = StreamHelper.Read<ParamFile>(file);
132+
}
133+
return paramFile;
134+
}
135+
136+
private static ParamFile ParseCpp(string src)
137+
{
138+
ParamFile paramFile;
139+
var dst = Path.GetTempFileName();
140+
Process.Start(new ProcessStartInfo(Path.Combine(GetArma3ToolsPath(), "CfgConvert", "CfgConvert.exe"), $@"-bin -dst ""{dst}"" ""{src}""")
141+
{
142+
WindowStyle = ProcessWindowStyle.Hidden,
143+
CreateNoWindow = true,
144+
UseShellExecute = false
145+
}).WaitForExit();
146+
paramFile = StreamHelper.Read<ParamFile>(dst);
147+
File.Delete(dst);
148+
return paramFile;
149+
150+
}
151+
152+
internal static string GetArma3ToolsPath()
153+
{
154+
string path = "";
155+
#pragma warning disable CA1416 // Valider la compatibilité de la plateforme
156+
using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 233800"))
157+
{
158+
if (key != null)
159+
{
160+
path = (key.GetValue("InstallLocation") as string) ?? path;
161+
}
162+
}
163+
#pragma warning restore CA1416 // Valider la compatibilité de la plateforme
164+
if (string.IsNullOrEmpty(path))
165+
{
166+
throw new ApplicationException("Arma 3 Tools are not installed.\r\nUnable to process a text config file.\r\nPlease install Arma 3 Tools with Steam, or open a binarized config file.");
167+
}
168+
return path;
169+
}
170+
}
171+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Collections.Generic;
2+
using System.Diagnostics;
3+
4+
namespace Helper.Detector
5+
{
6+
[DebuggerDisplay("{ClassName}")]
7+
public class DetectedConfigInfo
8+
{
9+
public string ClassRoot { get; set; }
10+
public string ClassName { get; set; }
11+
public string P3dModel { get; set; }
12+
public Dictionary<string, string> HiddenSelections { get; set; } = new Dictionary<string, string>();
13+
public string DisplayName { get; set; }
14+
public string FileName { get; set; }
15+
public string Definition { get; internal set; }
16+
17+
public string GetHiddenSelection(string name) => HiddenSelections.TryGetValue(name, out var v) ? v : null;
18+
}
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Collections.Generic;
2+
using System.Diagnostics;
3+
4+
namespace Helper
5+
{
6+
[DebuggerDisplay("{Name}")]
7+
public class DetectedHiddenSelection
8+
{
9+
public string Name { get; set; }
10+
public List<DetectedHiddenSelectionValue> Values { get; set; }
11+
}
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Diagnostics;
2+
3+
namespace Helper
4+
{
5+
[DebuggerDisplay("{SuggestedName}")]
6+
public class DetectedHiddenSelectionValue
7+
{
8+
public string Value { get; set; }
9+
public string SuggestedName { get; set; }
10+
}
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections.Generic;
2+
using System.Diagnostics;
3+
using Helper.Detector;
4+
5+
namespace Helper
6+
{
7+
[DebuggerDisplay("{Name}")]
8+
public class DetectedModelInfo
9+
{
10+
public string Name { get; set; }
11+
public string P3dModel { get; set; }
12+
public List<DetectedConfigInfo> Configs { get; set; }
13+
public List<DetectedHiddenSelection> HiddenSelections { get; set; }
14+
public string ClassRoot { get; set; }
15+
public List<string> FileNames { get; set; }
16+
public string PackageName { get; set; }
17+
}
18+
}

0 commit comments

Comments
 (0)