Skip to content

Commit

Permalink
Fix exception when directory doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Mag-nus committed Nov 30, 2019
1 parent 95318fe commit 63552a8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Source/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public MainWindow()
{
InitializeComponent();

Title += " 1.3"; // TODO: !!!!! ATTENTION ===== Update line 55 in AssemblyInfo.cs ===== ATTENTION !!!!!
Title += " 1.4"; // TODO: !!!!! ATTENTION ===== Update line 55 in AssemblyInfo.cs ===== ATTENTION !!!!!

if (Properties.Settings.Default.WindowPositionLeft > 0 && Properties.Settings.Default.WindowPositionTop > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.3")] // TODO: !!!!! ATTENTION ===== Update line 28 in MainWindow.xaml.cs ===== ATTENTION !!!!!
[assembly: AssemblyFileVersion("1.4")] // TODO: !!!!! ATTENTION ===== Update line 28 in MainWindow.xaml.cs ===== ATTENTION !!!!!
34 changes: 16 additions & 18 deletions Source/ServerManagement/PublicServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Mag_ACClientLauncher.ServerManagement
{
static class PublicServerManager
{
public static readonly List<ServerItem> ServerList = new List<ServerItem>();
public static List<ServerItem> ServerList = new List<ServerItem>();

public static readonly string ServerListFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Mag-ACClientLauncher\\PublicServerList.xml";

Expand All @@ -21,17 +21,22 @@ static PublicServerManager()
if (!File.Exists(ServerListFileName))
return;

var xs = new XmlSerializer(typeof(List<ServerItem>));

using (var reader = new StreamReader(ServerListFileName))
ServerList = (List<ServerItem>)xs.Deserialize(reader);
ServerList = Deserialize(reader);
}
catch
{
// ignored
}
}

public static List<ServerItem> Deserialize(TextReader textReader)
{
var xs = new XmlSerializer(typeof(List<ServerItem>));

return (List<ServerItem>)xs.Deserialize(textReader);
}

public static DateTime GetLastUpdated()
{
if (!File.Exists(ServerListFileName))
Expand All @@ -51,11 +56,16 @@ public static async Task<bool> UpdateFromPublicServerList(HttpClient httpClient,
if (String.IsNullOrWhiteSpace(responseBody))
return false;

if (!ValidateContents(responseBody))
return false;
var directoryName = Path.GetDirectoryName(ServerListFileName);

if (!Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);

File.WriteAllText(ServerListFileName, responseBody);

using (var reader = new StringReader(responseBody))
ServerList = Deserialize(reader);

return true;

}
Expand All @@ -66,17 +76,5 @@ public static async Task<bool> UpdateFromPublicServerList(HttpClient httpClient,

return false;
}

public static bool ValidateContents(string input)
{
var xs = new XmlSerializer(typeof(List<ServerItem>));

var tempServerList = new List<ServerItem>();

using (var reader = new StringReader(input))
tempServerList = (List<ServerItem>)xs.Deserialize(reader);

return tempServerList.Count > 0;
}
}
}
1 change: 1 addition & 0 deletions Source/ServerManagement/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static ServerManager()
{
if (server.ServerType == "ACE")
server.EmuType = EmuType.ACE;

server.ServerType = null;
}
}
Expand Down

0 comments on commit 63552a8

Please sign in to comment.