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.
pull/32/head
Miepee 4 years ago
parent c1936305b7
commit 649c9bd290

@ -2,9 +2,11 @@
using Eto.Forms; using Eto.Forms;
using log4net; using log4net;
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Net; using System.Net;
using System.Reflection;
namespace AM2RLauncher; namespace AM2RLauncher;
@ -24,8 +26,20 @@ public static class LauncherUpdater
private static readonly string oldConfigPath = CrossPlatformOperations.CurrentPath + "/" + CrossPlatformOperations.LauncherName + ".oldCfg"; private static readonly string oldConfigPath = CrossPlatformOperations.CurrentPath + "/" + CrossPlatformOperations.LauncherName + ".oldCfg";
/// <summary>The actual Path where the executable is stored, only used for updating.</summary> /// <summary>The actual Path where the executable is stored, only used for updating.</summary>
private static readonly string updatePath = OS.IsWindows ? CrossPlatformOperations.CurrentPath private static string updatePath
: (OS.IsLinux ? Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) : Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory + "../../../")); {
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!");
}
}
/// <summary> /// <summary>
/// Our log object, that handles logging the current execution to a file. /// Our log object, that handles logging the current execution to a file.
@ -154,7 +168,7 @@ public static class LauncherUpdater
try try
{ {
using var client = new WebClient(); using WebClient client = new WebClient();
string platformSuffix = ""; string platformSuffix = "";
if (OS.IsWindows) platformSuffix = "_win"; if (OS.IsWindows) platformSuffix = "_win";
else if (OS.IsLinux) platformSuffix = "_lin"; else if (OS.IsLinux) platformSuffix = "_lin";
@ -179,7 +193,7 @@ public static class LauncherUpdater
File.Move(updatePath + "/" + CrossPlatformOperations.LauncherName, CrossPlatformOperations.CurrentPath + "/AM2RLauncher.bak"); File.Move(updatePath + "/" + CrossPlatformOperations.LauncherName, CrossPlatformOperations.CurrentPath + "/AM2RLauncher.bak");
if (OS.IsWindows) File.Move(CrossPlatformOperations.LauncherName + ".config", CrossPlatformOperations.LauncherName + ".oldCfg"); 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); log.Info("Moving " + file.FullName + " to " + CrossPlatformOperations.CurrentPath + "/" + file.Name);
File.Copy(file.FullName, updatePath + "/" + file.Name, true); File.Copy(file.FullName, updatePath + "/" + file.Name, true);
@ -214,9 +228,9 @@ public static class LauncherUpdater
MainForm.CopyOldConfigToNewConfig(); MainForm.CopyOldConfigToNewConfig();
log.Info("Files extracted. Preparing to restart executable..."); 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); Environment.Exit(0);
} }
else else

@ -181,9 +181,10 @@ public partial class MainForm : Form
MinimumSize = new Size(500, 400); MinimumSize = new Size(500, 400);
// TODO: for some reason, this doesn't work on Linux. Was reported at eto, stays here until its fixed // 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"))); 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); ClientSize = new Size(500, ClientSize.Height);
if (ClientSize.Height < 400) if (OS.IsWindows && (ClientSize.Height < 400))
ClientSize = new Size(ClientSize.Width, 400); ClientSize = new Size(ClientSize.Width, 400);
log.Info("Start the launcher with Size: " + ClientSize.Width + ", " + ClientSize.Height); log.Info("Start the launcher with Size: " + ClientSize.Width + ", " + ClientSize.Height);
if (Boolean.Parse(ReadFromConfig("IsMaximized"))) Maximize(); if (Boolean.Parse(ReadFromConfig("IsMaximized"))) Maximize();
@ -398,7 +399,6 @@ public partial class MainForm : Form
if (OS.IsUnix && !isInternetThere) if (OS.IsUnix && !isInternetThere)
changelogWebView = new WebView(); changelogWebView = new WebView();
//TODO: these clip on gtk, Eto issue
Label changelogNoConnectionLabel = new Label Label changelogNoConnectionLabel = new Label
{ {
Text = Text.NoInternetConnection, Text = Text.NoInternetConnection,

@ -2,9 +2,7 @@
using log4net; using log4net;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Linq; using System.Linq;

Loading…
Cancel
Save