Skip to content

Commit 648ee29

Browse files
committed
[FlashpointManager] Add offline mode
1 parent 22b9e77 commit 648ee29

7 files changed

Lines changed: 125 additions & 105 deletions

File tree

FlashpointManager/src/Common.cs

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@ public Component(XmlNode node) : base(node)
3535
}
3636
else
3737
{
38-
MessageBox.Show(
39-
"An error occurred while parsing the component list XML. Please alert Flashpoint staff ASAP!\n\n" +
40-
"Description: Root element does not contain URL attribute",
41-
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
42-
);
43-
44-
Environment.Exit(1);
38+
FPM.ParseError("Root element does not contain URL attribute.");
4539
}
4640

4741
// Hash
@@ -54,13 +48,7 @@ public Component(XmlNode node) : base(node)
5448
}
5549
else
5650
{
57-
MessageBox.Show(
58-
"An error occurred while parsing the component list XML. Please alert Flashpoint staff ASAP!\n\n" +
59-
$"Description: Hash of component \"{Title}\" is invalid",
60-
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
61-
);
62-
63-
Environment.Exit(1);
51+
FPM.ParseError($"Hash of component \"{Title}\" is invalid.");
6452
}
6553

6654
// Size
@@ -70,13 +58,7 @@ public Component(XmlNode node) : base(node)
7058

7159
if (stringSize != "" && !long.TryParse(stringSize, out size))
7260
{
73-
MessageBox.Show(
74-
"An error occurred while parsing the component list XML. Please alert Flashpoint staff ASAP!\n\n" +
75-
$"Description: Size of component \"{Title}\" is not a number",
76-
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
77-
);
78-
79-
Environment.Exit(1);
61+
FPM.ParseError($"Size of component \"{Title}\" is not a number.");
8062
}
8163

8264
Size = size;
@@ -93,13 +75,7 @@ public Component(XmlNode node) : base(node)
9375
}
9476
else
9577
{
96-
MessageBox.Show(
97-
"An error occurred while parsing the component list XML. Please alert Flashpoint staff ASAP!\n\n" +
98-
$"Description: Modified date of component \"{Title}\" is invalid",
99-
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
100-
);
101-
102-
Environment.Exit(1);
78+
FPM.ParseError($"Date modified of component \"{Title}\" is invalid.");
10379
}
10480

10581
// Path
@@ -156,13 +132,7 @@ protected static string GetAttribute(XmlNode node, string attribute, bool throwE
156132
}
157133
else if (throwError)
158134
{
159-
MessageBox.Show(
160-
"An error occurred while parsing the component list XML. Please alert Flashpoint staff ASAP!\n\n" +
161-
$"Description: Required {node.Name} attribute \"{attribute}\" was not found",
162-
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
163-
);
164-
165-
Environment.Exit(1);
135+
FPM.ParseError($"Required {node.Name} attribute \"{attribute}\" was not found");
166136
}
167137

168138
return "";
@@ -193,6 +163,8 @@ public static class RepoXmlTemplates
193163
// 1 = Reinstall outdated components
194164
// 2 = Reinstall broken components
195165
public static int OperateMode { get; set; } = 0;
166+
// Controls whether to apply accommodations for offline use
167+
public static bool OfflineMode { get; set; } = false;
196168
// Controls whether the update tab is selected at launch
197169
public static bool OpenUpdateTab { get; set; } = false;
198170
// Controls whether the launcher should be opened upon the manager closing
@@ -300,14 +272,16 @@ public static void SyncManager(bool init = false)
300272
ComponentTracker.Downloaded.Add(component);
301273
if (!node.Checked) node.Checked = true;
302274
}
303-
else if (node.Checked)
275+
else
304276
{
305-
node.Checked = false;
277+
if (OfflineMode) node.ForeColor = Color.FromArgb(255, 96, 96, 96);
278+
if (node.Checked) node.Checked = false;
306279
}
307280
}
308-
else if (init)
281+
else
309282
{
310-
node.Checked = node.Checked;
283+
if (OfflineMode) node.ForeColor = Color.FromArgb(255, 96, 96, 96);
284+
if (init) node.Checked = node.Checked;
311285
}
312286
});
313287

@@ -459,10 +433,9 @@ public static void DeleteFileAndDirectories(string file)
459433
}
460434
catch (Exception e) when (!(e is DirectoryNotFoundException))
461435
{
462-
MessageBox.Show(
436+
GenericError(
463437
"Failed to delete the following file:\n" + file + "\n\n" +
464-
"Make sure it is not open or being used by another program.",
465-
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
438+
"Make sure it is not open or being used by another program."
466439
);
467440

468441
return;
@@ -509,10 +482,9 @@ public static bool WriteConfig(string path, string source)
509482
}
510483
catch
511484
{
512-
MessageBox.Show(
485+
GenericError(
513486
"Could not write to configuration file (fpm.cfg)." +
514-
"Make sure it is not being used by another program.",
515-
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
487+
"Make sure it is not being used by another program."
516488
);
517489

518490
return false;
@@ -579,9 +551,9 @@ void AddDependencies(string[] depends)
579551
{
580552
if (alertDepends)
581553
{
582-
MessageBox.Show(
554+
GenericError(
583555
"The following components cannot be removed because one or more components depend on them:\n\n" +
584-
string.Join(", ", persistDepends), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error
556+
string.Join(", ", persistDepends)
585557
);
586558
}
587559

@@ -630,6 +602,22 @@ public static string GetFormattedBytes(long bytes)
630602

631603
return "0 bytes";
632604
}
605+
606+
// Function for errors unrelated to the component list
607+
public static void GenericError(string message) => MessageBox.Show(
608+
message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error
609+
);
610+
611+
// Function for errors related to the component list
612+
public static void ParseError(string message)
613+
{
614+
MessageBox.Show(
615+
$"The following error occurred while parsing the component list:\n\n{message}",
616+
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
617+
);
618+
619+
Environment.Exit(1);
620+
}
633621
}
634622
}
635623
}

FlashpointManager/src/Forms/CheckFiles.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,19 @@ await Task.Run(() =>
5151

5252
FileListLoading.Visible = false;
5353
FileList.Visible = true;
54-
RedownloadButton.Enabled = FileList.Items.Count > 0;
54+
55+
if (FPM.ComponentTracker.Outdated.Count > 0)
56+
{
57+
RedownloadButton.Text = "Cannot redownload components with pending updates";
58+
}
59+
else if (FPM.OfflineMode)
60+
{
61+
RedownloadButton.Text = "Cannot redownload components in offline mode";
62+
}
63+
else
64+
{
65+
RedownloadButton.Enabled = FileList.Items.Count > 0;
66+
}
5567
}
5668

5769
private void FileMessage_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

FlashpointManager/src/Forms/Main.Designer.cs

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FlashpointManager/src/Forms/Main.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Diagnostics;
3+
using System.Drawing;
34
using System.IO;
45
using System.Linq;
56
using System.Windows.Forms;
@@ -17,6 +18,12 @@ private void Main_Load(object sender, EventArgs e)
1718
{
1819
Text += $" v{Application.ProductVersion}";
1920

21+
if (FPM.OfflineMode)
22+
{
23+
TabControl.TabPages.RemoveAt(1);
24+
OfflineIndicator.Visible = true;
25+
}
26+
2027
using (XmlNodeList rootElements = FPM.XmlTree.GetElementsByTagName("list"))
2128
{
2229
if (rootElements.Count > 0)
@@ -25,17 +32,12 @@ private void Main_Load(object sender, EventArgs e)
2532
}
2633
else
2734
{
28-
MessageBox.Show(
29-
"An error occurred while parsing the component list XML. Please alert Flashpoint staff ASAP!\n\n" +
30-
"Description: Root element was not found",
31-
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
32-
);
33-
34-
Environment.Exit(1);
35+
FPM.ParseError("Root element was not found.");
3536
}
3637
}
3738

3839
FPM.SyncManager(true);
40+
ComponentList.BeforeCheck += ComponentList_BeforeCheck;
3941

4042
if (FPM.AutoDownload.Count > 0)
4143
{
@@ -57,11 +59,10 @@ private void Main_Load(object sender, EventArgs e)
5759

5860
public void ComponentList_BeforeCheck(object sender, TreeViewCancelEventArgs e)
5961
{
60-
bool required = e.Node.Tag.GetType().ToString().EndsWith("Component")
61-
? (e.Node.Tag as Component).Required
62-
: (e.Node.Tag as Category).Required;
63-
64-
if (required && e.Node.Checked) e.Cancel = true;
62+
if (e.Node.ForeColor == Color.FromArgb(255, 96, 96, 96))
63+
{
64+
e.Cancel = true;
65+
}
6566
}
6667

6768
public void ComponentList_AfterCheck(object sender, TreeViewEventArgs e)

FlashpointManager/src/Forms/Operate.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,9 @@ void MoveDelete(string source, string dest)
299299
}
300300
catch
301301
{
302-
MessageBox.Show(
302+
FPM.GenericError(
303303
"Failed to move the following file:\n" + source + "\n\n" +
304-
"You will have to move it manually from the Temp folder.",
305-
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
304+
"You will have to move it manually from the Temp folder."
306305
);
307306
}
308307
}

FlashpointManager/src/Forms/Settings.cs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ private void BrowseButton_Click(object sender, EventArgs e)
3636
}
3737
else
3838
{
39-
MessageBox.Show(
40-
"The specified Flashpoint directory is invalid!",
41-
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
42-
);
39+
FPM.GenericError("The specified Flashpoint directory is invalid!");
4340
}
4441
}
4542
}
@@ -51,22 +48,7 @@ private void SaveButton_Click(object sender, EventArgs e)
5148
Application.Restart();
5249
}
5350

54-
private void CheckFilesButton_Click(object sender, EventArgs e)
55-
{
56-
if (FPM.ComponentTracker.Outdated.Count == 0)
57-
{
58-
new CheckFiles().ShowDialog();
59-
}
60-
else
61-
{
62-
MessageBox.Show(
63-
"Flashpoint must be up-to-date to check for missing files!",
64-
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
65-
);
66-
67-
TabControl.SelectTab(1);
68-
}
69-
}
51+
private void CheckFilesButton_Click(object sender, EventArgs e) => new CheckFiles().ShowDialog();
7052

7153
private void ComponentRepo_CheckedChanged(object sender, EventArgs e)
7254
{

0 commit comments

Comments
 (0)