Skip to content
Permalink
Browse files

ASYNC EVERYWHERE!!!11!!!11oneoneone

  • Loading branch information...
metonator committed Feb 8, 2019
1 parent c641d69 commit 21265d2b3af4fba3a5405bbeb855750793726599
@@ -66,15 +66,15 @@ class LauncherUpdateCheck
try {
if(updater.Code == 0) {
if (updater.Payload.UpdateExists == false) {
//if(updater.Payload.LatestVersion.CompareTo(updater.Payload.ClientVersion) > 0) {
if(updater.Payload.LatestVersion.CompareTo(updater.Payload.ClientVersion) >= 0) {
text.Text = "Launcher Status - Updated";
status.Image = Properties.Resources.ac_success;
text.ForeColor = Color.FromArgb(0x9fc120);
//} else {
// text.Text = "Launcher Status - Prerelease";
// status.Image = Properties.Resources.ac_warning;
// text.ForeColor = Color.Yellow;
//}
} else {
text.Text = "Launcher Status - Prerelease";
status.Image = Properties.Resources.ac_warning;
text.ForeColor = Color.Yellow;
}

description.Text = "Version : v" + Application.ProductVersion + "build-" + SHA.HashFile(AppDomain.CurrentDomain.FriendlyName).Substring(0, 7);
} else {
@@ -137,7 +137,7 @@ class LauncherUpdateCheck
text.ForeColor = Color.FromArgb(254, 0, 0);
description.Text = "Version : v" + Application.ProductVersion + "build-" + SHA.HashFile(AppDomain.CurrentDomain.FriendlyName).Substring(0, 7);
}
} catch(Exception ex) {
} catch(Exception) {
if(text.InvokeRequired == true) //checks skip, because we only need to know if we can access ui from actual thread
{
text.Invoke(new Action(delegate ()
@@ -22,7 +22,7 @@ public class WebClientWithTimeout : WebClient {

protected override WebRequest GetWebRequest(Uri address) {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
request.UserAgent = "GameLauncher (+https://github.com/SoapboxRaceWorld/GameLauncher_NFSW)";
request.UserAgent = "GameLauncher (+https://github.com/SoapboxRaceWorld/GameLauncher_NFSW)"; //this must remain untouched.
request.Headers["X-HWID"] = Security.FingerPrint.Value();
request.Headers["X-UserAgent"] = "GameLauncherReborn "+Application.ProductVersion+ " WinForms (+https://github.com/worldunitedgg/GameLauncher_NFSW)";
request.Headers["X-GameLauncherHash"] = Value();
@@ -330,6 +330,20 @@ private void moveWindow_MouseMove(object sender, MouseEventArgs e)
_NFSW_Installation_Source = CDN.CDNUrl;
}

try {
WebClientWithTimeout lightfx = new WebClientWithTimeout();
lightfx.DownloadDataAsync(new Uri(Self.mainserver + "/files/lightfx.dll"));
lightfx.DownloadDataCompleted += (sender, e) => {
try {
if (!e.Cancelled && e.Error == null) {
File.WriteAllBytes(_settingFile.Read("InstallationDirectory") + "/lightfx.dll", e.Result);
}
}
catch { /* ignored */ }
};
} catch { /* ignored */ }


var fbd = new CommonOpenFileDialog
{
EnsurePathExists = true,
@@ -384,11 +398,14 @@ private void moveWindow_MouseMove(object sender, MouseEventArgs e)
ServerStatusBar(_colorLoading, _startPoint, _endPoint);

Log.Debug("Checking internet connection");
if (Self.CheckForInternetConnection() == false && !DetectLinux.WineDetected()) {
if (_splashscreen != null) _splashscreen.Hide();
Log.Error("Failed to connect to internet. Please check if your firewall is not blocking launcher.");
MessageBox.Show(null, "Failed to connect to internet. Please check if your firewall is not blocking launcher.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

new Thread(() => {
if (Self.CheckForInternetConnection() == false && !DetectLinux.WineDetected()) {
if (_splashscreen != null) _splashscreen.Hide();
Log.Error("Failed to connect to internet. Please check if your firewall is not blocking launcher.");
MessageBox.Show(null, "Failed to connect to internet. Please check if your firewall is not blocking launcher.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}).Start();

if(_disabledModNet == false) {
Log.Debug("Loading ModManager Cache");
@@ -789,21 +806,16 @@ private void moveWindow_MouseMove(object sender, MouseEventArgs e)
Directory.CreateDirectory(_settingFile.Read("InstallationDirectory"));
if (!File.Exists(_settingFile.Read("InstallationDirectory") + "/lightfx.dll")) {
try {
File.WriteAllBytes(_settingFile.Read("InstallationDirectory") + "/lightfx.dll", new WebClientWithTimeout().DownloadData( Self.mainserver + "/files/lightfx.dll"));
/*string tempNameZip = Path.GetTempFileName();
File.WriteAllBytes(tempNameZip, ExtractResource.AsByte("GameLauncher.SoapBoxModules.lightfx.zip"));
using (ZipArchive archive = ZipFile.OpenRead(tempNameZip)) {
foreach (ZipArchiveEntry entry in archive.Entries) {
string fullName = entry.FullName;
entry.ExtractToFile(Path.Combine(_settingFile.Read("InstallationDirectory"), fullName));
}
}*/
} catch(Exception ex) {
Log.Error(ex.Message);
MessageBox.Show(null, "Failed to fetch 'lightfx.dll' module. Freeroam might not work correctly.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
WebClientWithTimeout lightfx = new WebClientWithTimeout();
lightfx.DownloadDataAsync(new Uri(Self.mainserver + "/files/lightfx.dll"));
lightfx.DownloadDataCompleted += (sender_lfx, e_lfx) => {
try {
if (!e_lfx.Cancelled && e_lfx.Error == null) {
File.WriteAllBytes(_settingFile.Read("InstallationDirectory") + "/lightfx.dll", e_lfx.Result);
}
} catch { /* ignored */ }
};
} catch { /* ignored */ }

Directory.CreateDirectory(_settingFile.Read("InstallationDirectory") + "/modules");
File.WriteAllText(_settingFile.Read("InstallationDirectory") + "/modules/udpcrc.soapbox.module", ExtractResource.AsString("GameLauncher.SoapBoxModules.udpcrc.soapbox.module"));
@@ -40,7 +40,16 @@ internal static class Program {

if(!File.Exists("GameLauncherUpdater.exe")) {
try {
File.WriteAllBytes("GameLauncherUpdater.exe", new WebClientWithTimeout().DownloadData(Self.mainserver + "/files/GameLauncherUpdater.exe"));
//Better update async
WebClientWithTimeout UpdaterExecutable = new WebClientWithTimeout();
UpdaterExecutable.DownloadDataAsync(new Uri(Self.mainserver + "/files/GameLauncherUpdater.exe"));
UpdaterExecutable.DownloadDataCompleted += (sender, e) => {
try {
if (!e.Cancelled && e.Error == null) {
File.WriteAllBytes("GameLauncherUpdater.exe", e.Result);
}
} catch { /* ignored */ }
};
} catch { /* ignored */ }
}

@@ -32,5 +32,5 @@
// Możesz określić wszystkie wartości lub użyć domyślnych numerów kompilacji i poprawki
// przy użyciu symbolu „*”, tak jak pokazano poniżej:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.2.3")]
[assembly: AssemblyFileVersion("2.0.2.3")]
[assembly: AssemblyVersion("2.0.2.4")]
[assembly: AssemblyFileVersion("2.0.2.4")]

0 comments on commit 21265d2

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.