-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSetupControl.cs
More file actions
168 lines (144 loc) · 5.21 KB
/
SetupControl.cs
File metadata and controls
168 lines (144 loc) · 5.21 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
using Autofac;
using HgmViewer.Classes;
using HgmViewer.Service;
using Krypton.Navigator;
namespace HgmViewer
{
public partial class SetupControl : UserControl
{
private readonly ConfigService _configService;
private readonly ApplicationService _applicationService;
public SetupControl(
ConfigService configService,
ApplicationService applicationService)
{
InitializeComponent();
_configService = configService;
_applicationService = applicationService;
Load += SetupControl_Load;
}
private async void SetupControl_Load(object sender, EventArgs e)
{
kpgConfig.SelectedObject = new ConfigProxy(_configService.Config, () =>
{
if (_configService.IsValid())
{
_configService.SaveConfig();
_applicationService.SetupUi();
}
});
await Task.Delay(2500);
var downloaded = await Task.Run(async () =>
{
return await QueryUserDownloadHpkExeIfMissing();
});
if (downloaded)
kpgConfig.Refresh();
}
private async Task<bool> QueryUserDownloadHpkExeIfMissing()
{
if (_configService.Config.HpkExeFilePath == null || !File.Exists(_configService.Config.HpkExeFilePath))
{
if (MessageBox.Show("Hpk Archiver (hpk.exe) is required to unpack game assets from .hpk archives. Would you like to download it now?", "Automatic download", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
var hpk = await ApplicationService.DownloadHpkIfMissing();
if (hpk)
{
var configProxy = kpgConfig.SelectedObject as ConfigProxy;
configProxy.HpkExeFilePath = "hpk.exe";
return true;
}
}
}
return false;
}
/// <summary>
/// Act as proxy for a config item to control the exposed properties to the property grid.
/// </summary>
protected class ConfigProxy
{
private readonly Config _item;
private readonly Action _revalidate;
public ConfigProxy(Config item, Action revalidate)
{
_item = item;
_revalidate = revalidate;
}
[Category(@"Config")]
[DisplayName("HPK Archiver (hpk.exe)")]
[Description("Used to unpack .hpk archives.\n\nDownload from:\nhttps://github.com/nickelc/hpk/releases/latest")]
[Editor(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(UITypeEditor))]
public string HpkExeFilePath
{
get => _item.HpkExeFilePath;
set
{
if (!File.Exists(value)) return;
_item.HpkExeFilePath = value;
_revalidate();
}
}
[Category(@"Config")]
[DisplayName("Game directory")]
[Editor(typeof(FolderNameEditorEx), typeof(UITypeEditor))]
public string GameDirPath
{
get => _item.GameDirPath;
set
{
if (!Directory.Exists(value)) return;
_item.GameDirPath = value;
_revalidate();
}
}
[Category(@"Config")]
[DisplayName("Unpacked files directory")]
[Editor(typeof(FolderNameEditorEx), typeof(UITypeEditor))]
public string UnpackDirPath
{
get => _item.UnpackDirPath;
set
{
if (!Directory.Exists(value)) return;
_item.UnpackDirPath = value;
_revalidate();
}
}
[Category(@"Config")]
[DisplayName("Exported files directory")]
[Editor(typeof(FolderNameEditorEx), typeof(UITypeEditor))]
public string ExportDirPath
{
get => _item.ExportDirPath;
set
{
if (!Directory.Exists(value)) return;
_item.ExportDirPath = value;
_revalidate();
}
}
}
/// <summary>
/// Krypton Docking page for <see cref="SetupControl"/>
/// </summary>
public class SetupPage : KryptonPage
{
private readonly ILifetimeScope _scope;
private readonly SetupControl _ctrl;
public SetupControl Ctrl => _ctrl;
public SetupPage(ILifetimeScope scope)
{
_scope = scope;
_ctrl = scope.Resolve<SetupControl>();
_ctrl.Dock = DockStyle.Fill;
Controls.Add(_ctrl);
}
}
}
}