From 649c9bd290e8c3861fff4dff3ce8f6891518e80e Mon Sep 17 00:00:00 2001
From: Miepee <38186597+Miepee@users.noreply.github.com>
Date: Mon, 23 May 2022 20:49:11 +0200
Subject: [PATCH] remove usings, fix bug in auto updater
If on windows an environment variable would be used for the am2rlauncher, then the auto updater would try to update to taht location instead of the location where the launcher actually was located.
---
AM2RLauncher/AM2RLauncher/LauncherUpdater.cs | 26 ++++++++++++++-----
.../AM2RLauncher/MainForm/MainForm.UI.cs | 6 ++---
AM2RLauncher/AM2RLauncherLib/Profile.cs | 2 --
3 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs b/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs
index 99a4095..6558801 100644
--- a/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs
+++ b/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs
@@ -2,9 +2,11 @@
using Eto.Forms;
using log4net;
using System;
+using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
+using System.Reflection;
namespace AM2RLauncher;
@@ -24,8 +26,20 @@ public static class LauncherUpdater
private static readonly string oldConfigPath = CrossPlatformOperations.CurrentPath + "/" + CrossPlatformOperations.LauncherName + ".oldCfg";
/// The actual Path where the executable is stored, only used for updating.
- private static readonly string updatePath = OS.IsWindows ? CrossPlatformOperations.CurrentPath
- : (OS.IsLinux ? Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) : Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory + "../../../"));
+ private static string updatePath
+ {
+ get
+ {
+ if (OS.IsWindows)
+ return Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
+ if (OS.IsLinux)
+ return Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
+ if (OS.IsMac)
+ // TODO: double check on mac if this is correct
+ return Path.GetDirectoryName($"{AppDomain.CurrentDomain.BaseDirectory}../../../");
+ throw new NotSupportedException($"{OS.Name} does not have an update path!");
+ }
+ }
///
/// Our log object, that handles logging the current execution to a file.
@@ -154,7 +168,7 @@ public static class LauncherUpdater
try
{
- using var client = new WebClient();
+ using WebClient client = new WebClient();
string platformSuffix = "";
if (OS.IsWindows) platformSuffix = "_win";
else if (OS.IsLinux) platformSuffix = "_lin";
@@ -179,7 +193,7 @@ public static class LauncherUpdater
File.Move(updatePath + "/" + CrossPlatformOperations.LauncherName, CrossPlatformOperations.CurrentPath + "/AM2RLauncher.bak");
if (OS.IsWindows) File.Move(CrossPlatformOperations.LauncherName + ".config", CrossPlatformOperations.LauncherName + ".oldCfg");
- foreach (var file in new DirectoryInfo(tmpUpdatePath).GetFiles())
+ foreach (FileInfo file in new DirectoryInfo(tmpUpdatePath).GetFiles())
{
log.Info("Moving " + file.FullName + " to " + CrossPlatformOperations.CurrentPath + "/" + file.Name);
File.Copy(file.FullName, updatePath + "/" + file.Name, true);
@@ -214,9 +228,9 @@ public static class LauncherUpdater
MainForm.CopyOldConfigToNewConfig();
log.Info("Files extracted. Preparing to restart executable...");
- if (OS.IsLinux) System.Diagnostics.Process.Start("chmod", "+x " + updatePath + "./AM2RLauncher.Gtk");
+ if (OS.IsLinux) Process.Start("chmod", "+x " + updatePath + "./AM2RLauncher.Gtk");
- System.Diagnostics.Process.Start(updatePath + "/" + CrossPlatformOperations.LauncherName);
+ Process.Start(updatePath + "/" + CrossPlatformOperations.LauncherName);
Environment.Exit(0);
}
else
diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs
index 82dd15f..5a97da3 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs
@@ -181,9 +181,10 @@ public partial class MainForm : Form
MinimumSize = new Size(500, 400);
// TODO: for some reason, this doesn't work on Linux. Was reported at eto, stays here until its fixed
ClientSize = new Size(Int32.Parse(ReadFromConfig("Width")), Int32.Parse(ReadFromConfig("Height")));
- if (ClientSize.Width < 500)
+ // Workaround for above problem
+ if (OS.IsWindows && (ClientSize.Width < 500))
ClientSize = new Size(500, ClientSize.Height);
- if (ClientSize.Height < 400)
+ if (OS.IsWindows && (ClientSize.Height < 400))
ClientSize = new Size(ClientSize.Width, 400);
log.Info("Start the launcher with Size: " + ClientSize.Width + ", " + ClientSize.Height);
if (Boolean.Parse(ReadFromConfig("IsMaximized"))) Maximize();
@@ -398,7 +399,6 @@ public partial class MainForm : Form
if (OS.IsUnix && !isInternetThere)
changelogWebView = new WebView();
- //TODO: these clip on gtk, Eto issue
Label changelogNoConnectionLabel = new Label
{
Text = Text.NoInternetConnection,
diff --git a/AM2RLauncher/AM2RLauncherLib/Profile.cs b/AM2RLauncher/AM2RLauncherLib/Profile.cs
index a7fa626..74d4ba7 100644
--- a/AM2RLauncher/AM2RLauncherLib/Profile.cs
+++ b/AM2RLauncher/AM2RLauncherLib/Profile.cs
@@ -2,9 +2,7 @@
using log4net;
using System;
using System.Collections.Generic;
-using System.Collections.Specialized;
using System.Diagnostics;
-using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;