Skip to content

Commit a5a91ae

Browse files
committed
Add URL property to Component class, more error-checking
1 parent 5498234 commit a5a91ae

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

src/Common.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,32 @@ namespace Common
1313
// Component object definition
1414
public class Component : Category
1515
{
16+
public string URL { get; set; }
1617
public string Hash { get; set; }
1718
public long Size { get; set; }
1819
public string[] Depends { get; set; } = new string[] { };
1920

2021
public Component(XmlNode node) : base(node)
2122
{
23+
// URL
24+
25+
var root = node.OwnerDocument.GetElementsByTagName("list")[0];
26+
27+
if (root.Attributes != null && root.Attributes["url"] != null)
28+
{
29+
URL = root.Attributes["url"].Value + ID + ".zip";
30+
}
31+
else
32+
{
33+
MessageBox.Show(
34+
"An error occurred while parsing the component list XML. Please alert Flashpoint staff ASAP!\n\n" +
35+
"Description: Root element does not contain URL attribute",
36+
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
37+
);
38+
39+
Environment.Exit(1);
40+
}
41+
2242
// Hash
2343

2444
string hash = GetAttribute(node, "hash", true);
@@ -34,6 +54,8 @@ public Component(XmlNode node) : base(node)
3454
$"Description: Hash of component \"{Title}\" is invalid",
3555
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
3656
);
57+
58+
Environment.Exit(1);
3759
}
3860

3961
// Size
@@ -61,9 +83,6 @@ public Component(XmlNode node) : base(node)
6183

6284
if (depends.Length > 0) Depends = depends.Split(' ');
6385
}
64-
65-
// Get internet location of component's ZIP archive
66-
public string GetURL() => FPM.XmlTree.GetElementsByTagName("list")[0].Attributes["url"].Value + ID + ".zip";
6786
}
6887

6988
// Category object definition

src/Forms/MainDownload.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,23 @@ private async void Main_Load(object sender, EventArgs e)
2323

2424
FPM.XmlTree = new XmlDocument();
2525
FPM.XmlTree.Load(listStream);
26-
27-
FPM.RecursiveAddToList(FPM.XmlTree.GetElementsByTagName("list")[0], ComponentList.Nodes, true);
26+
27+
XmlNodeList rootElement = FPM.XmlTree.GetElementsByTagName("list");
28+
29+
if (rootElement.Count > 0)
30+
{
31+
FPM.RecursiveAddToList(FPM.XmlTree.GetElementsByTagName("list")[0], ComponentList.Nodes, true);
32+
}
33+
else
34+
{
35+
MessageBox.Show(
36+
"An error occurred while parsing the component list XML. Please alert Flashpoint staff ASAP!\n\n" +
37+
"Description: Root element was not found",
38+
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
39+
);
40+
41+
Environment.Exit(1);
42+
}
2843
}
2944

3045
private void Link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

src/Forms/Operation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private async void Operation_Load(object sender, EventArgs e)
111111
foreach (var component in addedComponents)
112112
{
113113
workingComponent = component;
114-
stream = await downloader.DownloadFileTaskAsync(component.GetURL());
114+
stream = await downloader.DownloadFileTaskAsync(component.URL);
115115

116116
if (cancelStatus != 0) return;
117117

0 commit comments

Comments
 (0)