Skip to content

Commit

Permalink
fix installer crashes to desktop when network is not available (Babyl…
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogsInSpace committed Oct 30, 2024
1 parent bb224c6 commit 4a6ddbc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
13 changes: 10 additions & 3 deletions BabylonJS_Installer/BabylonJS_Installer/Downloader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.IO.Compression;
using System.Net;
Expand Down Expand Up @@ -205,8 +205,15 @@ public async Task<string> GetJSONBodyRequest(string requestURI)
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("User-Agent", "BJS_Installer");
HttpResponseMessage response = await client.GetAsync(requestURI);
return await response.Content.ReadAsStringAsync();
try
{
HttpResponseMessage response = await client.GetAsync(requestURI);
return await response.Content.ReadAsStringAsync();
}
catch(Exception ex)
{
return string.Empty;
}
}

public string GetURLGitHubAPI()
Expand Down
55 changes: 34 additions & 21 deletions BabylonJS_Installer/BabylonJS_Installer/SoftwareChecker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Win32;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -190,6 +190,11 @@ public void setLatestVersionDate()
Task<string> jsonRequest = Task.Run(async () => { return await downloader.GetJSONBodyRequest(downloader.GetURLGitHubAPI()); });
//TO DO Find a better way to parse JSON aswell
string json = jsonRequest.Result;
if(string.IsNullOrEmpty(json) ) {
this.latestVersionDate = DateTime.Now.ToLongTimeString();
return;
}

string created_at = json.Substring(json.IndexOf("\"created_at\":"));
created_at = created_at.Remove(created_at.IndexOf("\","));
this.latestVersionDate = created_at.Remove(0, "\"created_at\":\"".Length);
Expand Down Expand Up @@ -229,33 +234,41 @@ public void checkNewInstallerVersion()

string assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

System.Net.WebClient wc = new System.Net.WebClient();
string versionFile = wc.DownloadString(url_versionFile);
int avFrom = versionFile.IndexOf("<ApplicationVersion>") + "<ApplicationVersion>".Length;
int avTo = versionFile.LastIndexOf("</ApplicationVersion>");
String serverVersion = versionFile.Substring(avFrom, avTo - avFrom);
try
{
System.Net.WebClient wc = new System.Net.WebClient();
string versionFile = wc.DownloadString(url_versionFile);
int avFrom = versionFile.IndexOf("<ApplicationVersion>") + "<ApplicationVersion>".Length;
int avTo = versionFile.LastIndexOf("</ApplicationVersion>");
String serverVersion = versionFile.Substring(avFrom, avTo - avFrom);

String[] currVersion = assemblyVersion.Split('.');
String[] servVersion = serverVersion.Split('.');
String[] currVersion = assemblyVersion.Split('.');
String[] servVersion = serverVersion.Split('.');

this.form.log("Current app version : " + currVersion[0] + '.' + currVersion[1] + '.' + currVersion[2]);
this.form.log("Server last version : " + servVersion[0] + '.' + servVersion[1] + '.' + servVersion[2]);
this.form.log("Current app version : " + currVersion[0] + '.' + currVersion[1] + '.' + currVersion[2]);
this.form.log("Server last version : " + servVersion[0] + '.' + servVersion[1] + '.' + servVersion[2]);

bool isUpToDate = true;
if (int.Parse(servVersion[0]) > int.Parse(currVersion[0])) isUpToDate = false;
else if (int.Parse(servVersion[0]) == int.Parse(currVersion[0]))
{
if (int.Parse(servVersion[1]) > int.Parse(currVersion[1])) isUpToDate = false;
else if (int.Parse(servVersion[1]) == int.Parse(currVersion[1]))
bool isUpToDate = true;
if (int.Parse(servVersion[0]) > int.Parse(currVersion[0])) isUpToDate = false;
else if (int.Parse(servVersion[0]) == int.Parse(currVersion[0]))
{
if (int.Parse(servVersion[2]) > int.Parse(currVersion[2])) isUpToDate = false;
if (int.Parse(servVersion[1]) > int.Parse(currVersion[1])) isUpToDate = false;
else if (int.Parse(servVersion[1]) == int.Parse(currVersion[1]))
{
if (int.Parse(servVersion[2]) > int.Parse(currVersion[2])) isUpToDate = false;
}
}
}

if (isUpToDate) this.form.log("Application up to date !\n\n");
else
if (isUpToDate) this.form.log("Application up to date !\n\n");
else
{
this.form.warn("A new version is available here : https://github.com/BabylonJS/Exporters/releases \n\n");
this.form.goTab("Logs");
}
}
catch( Exception ex )
{
this.form.warn("A new version is available here : https://github.com/BabylonJS/Exporters/releases \n\n");
this.form.error($"Error : failed to check for new installer version\n{ex.Message}\n");
this.form.goTab("Logs");
}
}
Expand Down

0 comments on commit 4a6ddbc

Please sign in to comment.