Skip to content

Commit

Permalink
Fixed updater when in Program Files
Browse files Browse the repository at this point in the history
- Fixed updater not working or starting when installed to Program Files. This was mainly an issue with the main program, rather than the updater itself. Was hard to finally find what was causing this annoying issue.
  • Loading branch information
TCNOco committed Jun 23, 2021
1 parent 8e07b7f commit 46214a3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 33 deletions.
1 change: 1 addition & 0 deletions TcNo-Acc-Switcher-Client/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ private void UrlChanged(object sender, CoreWebView2NavigationStartingEventArgs a
Globals.WriteToLog(args.Uri);

if (args.Uri.Contains("RESTART_AS_ADMIN")) RestartAsAdmin(args.Uri.Contains("arg=") ? args.Uri.Split("arg=")[1] : "");
if (args.Uri.Contains("EXIT_APP")) Environment.Exit(0);

if (!args.Uri.Contains("?")) return;
// Needs to be here as:
Expand Down
2 changes: 1 addition & 1 deletion TcNo-Acc-Switcher-Globals/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Globals
#pragma warning disable CA2211 // Non-constant fields should not be visible - This is necessary due to it being a launch parameter.
public static bool VerboseMode;
#pragma warning restore CA2211 // Non-constant fields should not be visible
public static readonly string Version = "2021-06-23_00";
public static readonly string Version = "2021-06-23_01";
public static readonly string[] PlatformList = {"Steam", "Origin", "Ubisoft", "BattleNet", "Epic", "Riot"};

#region LOGGER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static void OpenLinkInBrowser(string link)
public static bool ShowModal(string args)
{
Globals.DebugWriteLine($@"[JSInvoke:General\GeneralInvocableFuncs.ShowModal] args={args}");
return AppData.InvokeVoidAsync("showModal", args); ;
return AppData.InvokeVoidAsync("showModal", args);
}

/// <summary>
Expand Down
43 changes: 13 additions & 30 deletions TcNo-Acc-Switcher-Server/Pages/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,35 +106,13 @@ public static void StartUpdaterAsAdmin()
try
{
Process.Start(proc);
Environment.Exit(0);
}
catch (Exception ex)
{
Globals.WriteToLog(@"This program must be run as an administrator!" + Environment.NewLine + ex);
Environment.Exit(0);
}
}

public static void RestartAsAdmin(string args)
{
var proc = new ProcessStartInfo
{
WorkingDirectory = Environment.CurrentDirectory,
FileName = Assembly.GetEntryAssembly()?.Location.Replace(".dll", ".exe") ?? "TcNo-Acc-Switcher.exe",
UseShellExecute = true,
Arguments = args,
Verb = "runas"
};
try
{
Process.Start(proc);
Environment.Exit(0);
}
AppData.ActiveNavMan.NavigateTo("EXIT_APP", true);
}
catch (Exception ex)
{
Globals.WriteToLog(@"This program must be run as an administrator!" + Environment.NewLine + ex);
Environment.Exit(0);
}
AppData.ActiveNavMan.NavigateTo("EXIT_APP", true);
}
}

/// <summary>
Expand All @@ -145,7 +123,10 @@ public void UpdateNow()
try
{
if (Globals.InstalledToProgramFiles() && !IsAdmin() || !Globals.HasFolderAccess(Globals.AppDataFolder))
RestartAsAdmin("");
{
GeneralInvocableFuncs.ShowModal("notice:RestartAsAdmin");
return;
}

Directory.SetCurrentDirectory(Globals.AppDataFolder);
// Download latest hash list
Expand Down Expand Up @@ -178,10 +159,12 @@ public void UpdateNow()
if (Globals.InstalledToProgramFiles() || !Globals.HasFolderAccess(Globals.AppDataFolder))
{
StartUpdaterAsAdmin();
Process.GetCurrentProcess().Kill();
}
Process.Start(new ProcessStartInfo(@"updater\\TcNo-Acc-Switcher-Updater.exe") { UseShellExecute = true });
Process.GetCurrentProcess().Kill();
else
{
Process.Start(new ProcessStartInfo(@"updater\\TcNo-Acc-Switcher-Updater.exe") { UseShellExecute = true });
AppData.ActiveNavMan.NavigateTo("EXIT_APP", true);
}
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion TcNo-Acc-Switcher-Updater/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace TcNo_Acc_Switcher_Updater
/// </summary>
public partial class App
{
private static readonly Mutex Mutex = new(true, "{A240C23D-6F45-4E92-9979-11E6CE10A22C}");
private static readonly Mutex Mutex = new(true, "{1523A82D-9AD3-4B01-B970-4F06633AD41C}");

/// <summary>
/// Shows error and exits program is program is already running
Expand Down

0 comments on commit 46214a3

Please sign in to comment.