forked from VRPirates/rookie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsForm.cs
321 lines (281 loc) · 12.2 KB
/
SettingsForm.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
using AndroidSideloader.Utilities;
using JR.Utils.GUI.Forms;
using System;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace AndroidSideloader
{
public partial class SettingsForm : Form
{
private static readonly SettingsManager _settings = SettingsManager.Instance;
public SettingsForm()
{
InitializeComponent();
}
private void SettingsForm_Load(object sender, EventArgs e)
{
CenterToParent();
initSettings();
initToolTips();
}
private void initSettings()
{
checkForUpdatesCheckBox.Checked = _settings.CheckForUpdates;
enableMessageBoxesCheckBox.Checked = _settings.EnableMessageBoxes;
deleteAfterInstallCheckBox.Checked = _settings.DeleteAllAfterInstall;
updateConfigCheckBox.Checked = _settings.AutoUpdateConfig;
userJsonOnGameInstall.Checked = _settings.UserJsonOnGameInstall;
nodevicemodeBox.Checked = _settings.NodeviceMode;
bmbfBox.Checked = _settings.BMBFChecked;
AutoReinstBox.Checked = _settings.AutoReinstall;
trailersOn.Checked = _settings.TrailersOn;
chkSingleThread.Checked = _settings.SingleThreadMode;
virtualFilesystemCompatibilityCheckbox.Checked = _settings.VirtualFilesystemCompatibility;
hideAdultContentCheckBox.Checked = _settings.HideAdultContent;
bandwidthLimitTextBox.Text = _settings.BandwidthLimit.ToString();
if (nodevicemodeBox.Checked)
{
deleteAfterInstallCheckBox.Checked = false;
deleteAfterInstallCheckBox.Enabled = false;
}
chkUseDownloadedFiles.Checked = _settings.UseDownloadedFiles;
}
private void initToolTips()
{
ToolTip checkForUpdatesToolTip = new ToolTip();
checkForUpdatesToolTip.SetToolTip(checkForUpdatesCheckBox, "If this is checked, the software will check for available updates");
ToolTip enableMessageBoxesToolTip = new ToolTip();
enableMessageBoxesToolTip.SetToolTip(enableMessageBoxesCheckBox, "If this is checked, the software will display message boxes after every completed task");
ToolTip deleteAfterInstallToolTip = new ToolTip();
deleteAfterInstallToolTip.SetToolTip(deleteAfterInstallCheckBox, "If this is checked, the software will delete all game files after downloading and installing a game from a remote server");
ToolTip chkUseDownloadedFilesTooltip = new ToolTip();
chkUseDownloadedFilesTooltip.SetToolTip(chkUseDownloadedFiles, "If this is checked, Rookie will always install Downloaded files without Re-Downloading or Asking to Re-Download");
}
public void btnUploadDebug_click(object sender, EventArgs e)
{
if (File.Exists($"{_settings.CurrentLogPath}"))
{
string UUID = SideloaderUtilities.UUID();
string debugLogPath = $"{Environment.CurrentDirectory}\\{UUID}.log";
System.IO.File.Copy("debuglog.txt", debugLogPath);
Clipboard.SetText(UUID);
_ = RCLONE.runRcloneCommand_UploadConfig($"copy \"{debugLogPath}\" RSL-gameuploads:DebugLogs");
_ = MessageBox.Show($"Your debug log has been copied to the server. ID: {UUID}");
}
}
public void btnResetDebug_click(object sender, EventArgs e)
{
if (File.Exists($"{_settings.CurrentLogPath}"))
{
File.Delete($"{_settings.CurrentLogPath}");
}
if (File.Exists($"{Environment.CurrentDirectory}\\debuglog.txt"))
{
File.Delete($"{Environment.CurrentDirectory}\\debuglog.txt");
}
}
private void applyButton_Click(object sender, EventArgs e)
{
string input = bandwidthLimitTextBox.Text;
Regex regex = new Regex(@"^\d+(\.\d+)?$");
if (regex.IsMatch(input) && float.TryParse(input, out float bandwidthLimit))
{
_settings.BandwidthLimit = bandwidthLimit;
_settings.Save();
this.Close();
}
else
{
MessageBox.Show("Please enter a valid number for the bandwidth limit.");
}
}
private void checkForUpdatesCheckBox_CheckedChanged(object sender, EventArgs e)
{
_settings.CheckForUpdates = checkForUpdatesCheckBox.Checked;
_settings.Save();
}
private void chkUseDownloadedFiles_CheckedChanged(object sender, EventArgs e)
{
_settings.UseDownloadedFiles = chkUseDownloadedFiles.Checked;
_settings.Save();
}
private void enableMessageBoxesCheckBox_CheckedChanged(object sender, EventArgs e)
{
_settings.EnableMessageBoxes = enableMessageBoxesCheckBox.Checked;
_settings.Save();
}
private void resetSettingsButton_Click(object sender, EventArgs e)
{
// Reset the specific properties
_settings.CustomDownloadDir = false;
_settings.CustomBackupDir = false;
// Set backup folder and download directory
MainForm.backupFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Rookie Backups");
_settings.DownloadDir = Environment.CurrentDirectory;
_settings.CreatePubMirrorFile = true;
// Optionally, call initSettings if it needs to initialize anything based on these settings
initSettings();
// Save the updated settings
_settings.Save();
}
private void deleteAfterInstallCheckBox_CheckedChanged(object sender, EventArgs e)
{
_settings.DeleteAllAfterInstall = deleteAfterInstallCheckBox.Checked;
_settings.Save();
}
private void updateConfigCheckBox_CheckedChanged(object sender, EventArgs e)
{
_settings.AutoUpdateConfig = updateConfigCheckBox.Checked;
if (_settings.AutoUpdateConfig)
{
_settings.CreatePubMirrorFile = true;
}
_settings.Save();
}
private void userJsonOnGameInstall_CheckedChanged(object sender, EventArgs e)
{
_settings.UserJsonOnGameInstall = userJsonOnGameInstall.Checked;
_settings.Save();
}
private void SettingsForm_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Escape)
{
Close();
}
}
private void SettingsForm_Leave(object sender, EventArgs e)
{
Close();
}
private void Form_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Close();
}
}
protected override bool ProcessDialogKey(Keys keyData)
{
if (Form.ModifierKeys == Keys.None && keyData == Keys.Escape)
{
Close();
return true;
}
return base.ProcessDialogKey(keyData);
}
private void nodevicemodeBox_CheckedChanged(object sender, EventArgs e)
{
_settings.NodeviceMode = nodevicemodeBox.Checked;
if (!nodevicemodeBox.Checked)
{
deleteAfterInstallCheckBox.Checked = true;
_settings.DeleteAllAfterInstall = true;
deleteAfterInstallCheckBox.Enabled = true;
}
else
{
deleteAfterInstallCheckBox.Checked = false;
_settings.DeleteAllAfterInstall = false;
deleteAfterInstallCheckBox.Enabled = false;
}
_settings.Save();
}
private void bmbfBox_CheckedChanged(object sender, EventArgs e)
{
_settings.BMBFChecked = bmbfBox.Checked;
_settings.Save();
}
private void AutoReinstBox_CheckedChanged(object sender, EventArgs e)
{
_settings.AutoReinstall = AutoReinstBox.Checked;
_settings.Save();
}
private void AutoReinstBox_Click(object sender, EventArgs e)
{
if (AutoReinstBox.Checked)
{
DialogResult dialogResult = FlexibleMessageBox.Show(this, "WARNING: This box enables automatic reinstall when installs fail,\ndue to some games not allowing " +
"access to their save data (less than 5%) this\noption can lead to losing your progress." +
" However with this option\nchecked when installs fail you won't have to agree to a prompt to perform\nthe reinstall. " +
"(ideal when installing from a queue).\n\nNOTE: If your usb/wireless adb connection is extremely slow this option can\ncause larger" +
"apk file installations to fail. Enable anyway?", "WARNING", MessageBoxButtons.OKCancel);
if (dialogResult == DialogResult.Cancel)
{
AutoReinstBox.Checked = false;
}
}
}
private void trailersOn_CheckedChanged(object sender, EventArgs e)
{
_settings.TrailersOn = trailersOn.Checked;
_settings.Save();
}
private void btnOpenDebug_Click(object sender, EventArgs e)
{
if (File.Exists($"{Environment.CurrentDirectory}\\debuglog.txt"))
{
_ = Process.Start($"{Environment.CurrentDirectory}\\debuglog.txt");
}
}
private void setDownloadDirectory_Click(object sender, EventArgs e)
{
if (downloadDirectorySetter.ShowDialog() == DialogResult.OK)
{
_settings.CustomDownloadDir = true;
_settings.DownloadDir = downloadDirectorySetter.SelectedPath;
_settings.Save();
}
}
private void setBackupDirectory_Click(object sender, EventArgs e)
{
if (backupDirectorySetter.ShowDialog() == DialogResult.OK)
{
_settings.CustomBackupDir = true;
_settings.BackupDir = backupDirectorySetter.SelectedPath;
MainForm.backupFolder = _settings.BackupDir;
_settings.Save();
}
}
private void chkSingleThread_CheckedChanged(object sender, EventArgs e)
{
_settings.SingleThreadMode = chkSingleThread.Checked;
_settings.Save();
}
private void virtualFilesystemCompatibilityCheckbox_CheckedChanged(object sender, EventArgs e)
{
_settings.VirtualFilesystemCompatibility = virtualFilesystemCompatibilityCheckbox.Checked;
_settings.Save();
}
private void openDownloadDirectory_Click(object sender, EventArgs e)
{
string pathToOpen = _settings.CustomDownloadDir ? _settings.DownloadDir : Environment.CurrentDirectory;
MainForm.OpenDirectory(pathToOpen);
}
private void openBackupDirectory_Click(object sender, EventArgs e)
{
string pathToOpen = _settings.CustomBackupDir
? Path.Combine(_settings.BackupDir, "Rookie Backups")
: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Rookie Backups");
MainForm.OpenDirectory(pathToOpen);
}
private void bandwidthLimitTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
private void hideAdultContentCheckBox_CheckedChanged(object sender, EventArgs e)
{
_settings.HideAdultContent = hideAdultContentCheckBox.Checked;
_settings.Save();
}
}
}