From 2b787fe885c19e42f8ac4c99c82e4f88cf86a0c3 Mon Sep 17 00:00:00 2001 From: sshcrack <34072808+sshcrack@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:41:53 +0200 Subject: [PATCH 1/5] Migrating to Velopack (force updates not working yet --- Classes/Program.cs | 35 +++++++++++++++++++++-------------- Classes/Utils/Updater.cs | 35 ++++++++++++++++++++--------------- RePlays.csproj | 12 +----------- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/Classes/Program.cs b/Classes/Program.cs index b79f1290..562ed1aa 100644 --- a/Classes/Program.cs +++ b/Classes/Program.cs @@ -11,20 +11,20 @@ using RePlays.Utils; using RePlays.Services; using static RePlays.Utils.Functions; - - +using Velopack; #if !WINDOWS using RePlays.Classes.Utils; using RePlays.Recorders; #else -using Squirrel; using System.Windows.Forms; +using Velopack.Windows; #endif namespace RePlays { static class Program { [DllImport("kernel32.dll")] static extern bool AttachConsole(int dwProcessId); + const int ATTACH_PARENT_PROCESS = -1; static readonly ManualResetEventSlim ApplicationExitEvent = new(false); @@ -62,7 +62,8 @@ static void Main(string[] args) { // prevent multiple instances var mutex = new Mutex(true, @"Global\RePlays", out var createdNew); if (!createdNew) { - Logger.WriteLine("RePlays is already running! Exiting the application and bringing the other instance to foreground."); + Logger.WriteLine( + "RePlays is already running! Exiting the application and bringing the other instance to foreground."); try { using (var sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { sender.Connect(new IPEndPoint(IPAddress.Loopback, 3333)); @@ -73,10 +74,11 @@ static void Main(string[] args) { catch (Exception ex) { Logger.WriteLine($"Socket client exception: {ex.Message}"); } + return; } -#if DEBUG && WINDOWS && !NO_SERVER +#if DEBUG && WINDOWS // this will run our react app if its not already running var startInfo = new ProcessStartInfo { FileName = "cmd.exe", @@ -102,25 +104,30 @@ static void Main(string[] args) { KeybindService.Start(); PurgeTempVideos(); Updater.CheckForUpdates(); -#if WINDOWS - ScreenSize.UpdateMaximumScreenResolution(); - // squirrel configuration + + // Velopack configuration try { - SquirrelAwareApp.HandleEvents( - onInitialInstall: (_, tools) => tools.CreateShortcutForThisExe(), - onAppUpdate: (_, tools) => tools.CreateShortcutForThisExe(), - onAppUninstall: (_, tools) => tools.RemoveShortcutForThisExe() - ); + VelopackApp.Build() +#if WINDOWS + .WithAfterInstallFastCallback((v) => new Shortcuts().CreateShortcutForThisExe()) + .WithAfterUpdateFastCallback(v => new Shortcuts().CreateShortcutForThisExe()) + .WithBeforeUninstallFastCallback(v => new Shortcuts().RemoveShortcutForThisExe()) +#endif + .Run(); } catch (Exception exception) { Logger.WriteLine(exception.ToString()); } +#if WINDOWS + ScreenSize.UpdateMaximumScreenResolution(); + Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new WindowsInterface()); - (Process.GetCurrentProcess()).Kill(); // this is not a clean exit, need to look into why we can't cleanly exit + (Process.GetCurrentProcess()) + .Kill(); // this is not a clean exit, need to look into why we can't cleanly exit #else Directory.SetCurrentDirectory(AppContext.BaseDirectory); //Necessary for libobs in debug(?) SettingsService.LoadSettings(); diff --git a/Classes/Utils/Updater.cs b/Classes/Utils/Updater.cs index 1c289122..7f8e9b4c 100644 --- a/Classes/Utils/Updater.cs +++ b/Classes/Utils/Updater.cs @@ -1,7 +1,8 @@ using RePlays.Services; -using Squirrel; using System; using System.Threading.Tasks; +using Velopack; +using Velopack.Sources; using static RePlays.Utils.Functions; namespace RePlays.Utils { @@ -16,57 +17,61 @@ public static async void CheckForUpdates(bool forceUpdate = false) { Logger.WriteLine($"Currently in the middle of applying an update. Cannot check for updates."); return; } + + bool isNightly = SettingsService.Settings.generalSettings.updateChannel != "Stable"; try { if (forceUpdate) WebMessage.DisplayToast("CheckUpdateProgress", "Checking for updates", "Update", "none", (long)40, (long)100); - using var manager = await UpdateManager.GitHubUpdateManager("https://github.com/lulzsun/RePlays", - prerelease: SettingsService.Settings.generalSettings.updateChannel != "Stable"); + var manager = new UpdateManager(new GithubSource("https://github.com/lulzsun/RePlays", null, isNigthly)); if (forceUpdate) WebMessage.DisplayToast("CheckUpdateProgress", "Checking for updates", "Update", "none", (long)70, (long)100); - if (manager.CurrentlyInstalledVersion() != null) { - currentVersion = manager.CurrentlyInstalledVersion().ToString(); + if (manager.CurrentVersion != null) { + currentVersion = manager.CurrentVersion.ToString(); } - var updateInfo = await manager.CheckForUpdate(SettingsService.Settings.generalSettings.updateChannel != "Stable"); // if nightly, we ignore deltas + + var updateInfo = await manager.CheckForUpdatesAsync(); if (forceUpdate) { WebMessage.DisplayToast("CheckUpdateProgress", "Checking for updates", "Update", "none", (long)100, (long)100); await Task.Delay(500); WebMessage.DestroyToast("CheckUpdateProgress"); } - latestVersion = updateInfo.FutureReleaseEntry.Version.ToString(); + + // If UpdateInfo is null, we are on the latest version + latestVersion = updateInfo != null ? updateInfo.TargetFullRelease.Version.ToString() : currentVersion; SettingsService.SaveSettings(); WebMessage.SendMessage(GetUserSettings()); if (SettingsService.Settings.generalSettings.update == "none") return; - if (updateInfo.ReleasesToApply.Count > 0) { + if (updateInfo != null) { Action progressCallback = (progressValue) => { WebMessage.DisplayToast("UpdateProgress", "Installing update", "Updating", "none", (long)progressValue, (long)100); }; if (SettingsService.Settings.generalSettings.update == "automatic") { - Logger.WriteLine($"New version found! Preparing to automatically update to version {updateInfo.FutureReleaseEntry.Version} from {updateInfo.CurrentlyInstalledVersion.Version}"); + Logger.WriteLine($"New version found! Preparing to automatically update to version {updateInfo.TargetFullRelease.Version} from {manager.CurrentVersion}"); applyingUpdate = true; - await manager.UpdateApp(progressCallback); + await manager.DownloadUpdatesAsync(updateInfo, progressCallback, isNightly); WebMessage.DestroyToast("UpdateProgress"); applyingUpdate = false; - Logger.WriteLine($"Update to version {updateInfo.FutureReleaseEntry.Version} successful!"); + Logger.WriteLine($"Update to version {updateInfo.TargetFullRelease.Version} successful!"); WebMessage.DisplayModal("New update applied! Click Confirm to restart and complete the update.", "Update", "update"); } else { // manual if (forceUpdate) { - Logger.WriteLine($"New version found! Preparing to automatically update to version {updateInfo.FutureReleaseEntry.Version} from {updateInfo.CurrentlyInstalledVersion.Version}"); + Logger.WriteLine($"New version found! Preparing to automatically update to version {updateInfo.TargetFullRelease.Version} from {manager.CurrentVersion}"); WebMessage.DestroyToast("ManualUpdate"); applyingUpdate = true; - await manager.UpdateApp(progressCallback); + await manager.DownloadUpdatesAsync(updateInfo, progressCallback); WebMessage.DestroyToast("UpdateProgress"); applyingUpdate = false; - Logger.WriteLine($"Update to version {updateInfo.FutureReleaseEntry.Version} successful!"); + Logger.WriteLine($"Update to version {updateInfo.TargetFullRelease.Version} successful!"); WebMessage.DisplayModal("New update applied! Click Confirm to restart and complete the update.", "Update", "update"); } else WebMessage.DisplayToast("ManualUpdate", "New version available!", "Update", "info"); } } else { - Logger.WriteLine($"Found no updates higher than current version {updateInfo.CurrentlyInstalledVersion.Version}"); + Logger.WriteLine($"Found no updates higher than current version {manager.CurrentVersion}"); } } catch (System.Exception exception) { diff --git a/RePlays.csproj b/RePlays.csproj index f6508cef..9ed59c40 100644 --- a/RePlays.csproj +++ b/RePlays.csproj @@ -2,7 +2,6 @@ False - Debug;Release;ReleaseWithSymbols @@ -59,15 +58,6 @@ True app.manifest - - - True - TRACE;DEBUG - - - - false - @@ -93,7 +83,6 @@ - @@ -106,6 +95,7 @@ + From 342dce09fe0cb81484f48ab884292bb2edfe188e Mon Sep 17 00:00:00 2001 From: sshcrack <34072808+sshcrack@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:50:01 +0200 Subject: [PATCH 2/5] Misunderstood forceUpdate argument, updated accordingly --- Classes/Utils/JSONObjects.cs | 16 +++++++++------- Classes/Utils/Messages.cs | 5 +++++ Classes/Utils/Updater.cs | 9 ++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Classes/Utils/JSONObjects.cs b/Classes/Utils/JSONObjects.cs index 221a3af7..c2f92ab9 100644 --- a/Classes/Utils/JSONObjects.cs +++ b/Classes/Utils/JSONObjects.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; using System.IO; +#if WINDOWS +using Velopack.Windows; +#endif namespace RePlays.Utils { public class VideoList { @@ -51,17 +54,16 @@ public bool launchStartup { _launchStartup = value; #if WINDOWS try { - using (var manager = new Squirrel.UpdateManager(Environment.GetEnvironmentVariable("LocalAppData") + @"\RePlays\packages")) { - if (_launchStartup == true) - manager.CreateShortcutsForExecutable("RePlays.exe", Squirrel.ShortcutLocation.Startup, false); - else - manager.RemoveShortcutsForExecutable("RePlays.exe", Squirrel.ShortcutLocation.Startup); - } + var shortcuts = new Shortcuts(); + if (_launchStartup == true) + shortcuts.CreateShortcut("RePlays.exe", ShortcutLocation.Startup, false, null); + else + shortcuts.DeleteShortcuts("RePlays.exe", ShortcutLocation.Startup); } catch (Exception exception) { Logger.WriteLine("Error: Issue editing program startup setting: " + exception.ToString()); } -#endif +#endif } } private bool _startMinimized = false; diff --git a/Classes/Utils/Messages.cs b/Classes/Utils/Messages.cs index 9119b8d6..afaa5444 100644 --- a/Classes/Utils/Messages.cs +++ b/Classes/Utils/Messages.cs @@ -10,6 +10,7 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; +using Velopack; using static RePlays.Services.SettingsService; using static RePlays.Utils.Compression; using static RePlays.Utils.Functions; @@ -418,6 +419,10 @@ public static async Task ReceiveMessage(string message) { break; #if WINDOWS case "Restart": { + if (Updater.manager?.IsUpdatePendingRestart ?? false) { + Updater.manager.ApplyUpdatesAndRestart((VelopackAsset)null); + } + string path = Path.Join(GetStartupPath(), @"../RePlays.exe"); string cmdCommand = $"/C timeout /t 1 & start \"\" \"{path}\""; diff --git a/Classes/Utils/Updater.cs b/Classes/Utils/Updater.cs index 7f8e9b4c..c8be86aa 100644 --- a/Classes/Utils/Updater.cs +++ b/Classes/Utils/Updater.cs @@ -9,6 +9,7 @@ namespace RePlays.Utils { internal class Updater { public static string currentVersion = "?"; public static string latestVersion = "Offline"; + public static UpdateManager? manager; public static bool applyingUpdate { get; internal set; } [Obsolete] @@ -22,7 +23,8 @@ public static async void CheckForUpdates(bool forceUpdate = false) { try { if (forceUpdate) WebMessage.DisplayToast("CheckUpdateProgress", "Checking for updates", "Update", "none", (long)40, (long)100); - var manager = new UpdateManager(new GithubSource("https://github.com/lulzsun/RePlays", null, isNigthly)); + if(manager == null) + manager = new UpdateManager(new GithubSource("https://github.com/lulzsun/RePlays", null, isNightly)); if (forceUpdate) WebMessage.DisplayToast("CheckUpdateProgress", "Checking for updates", "Update", "none", (long)70, (long)100); @@ -32,11 +34,12 @@ public static async void CheckForUpdates(bool forceUpdate = false) { var updateInfo = await manager.CheckForUpdatesAsync(); if (forceUpdate) { - WebMessage.DisplayToast("CheckUpdateProgress", "Checking for updates", "Update", "none", (long)100, (long)100); + WebMessage.DisplayToast("CheckUpdateProgress", "Checking for updates", "Update", "none", (long)100, + (long)100); await Task.Delay(500); WebMessage.DestroyToast("CheckUpdateProgress"); } - + // If UpdateInfo is null, we are on the latest version latestVersion = updateInfo != null ? updateInfo.TargetFullRelease.Version.ToString() : currentVersion; SettingsService.SaveSettings(); From a5ff1a2263753fa376b38ecbd9597dde351d1a5d Mon Sep 17 00:00:00 2001 From: sshcrack <34072808+sshcrack@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:13:27 +0200 Subject: [PATCH 3/5] Modified commands that run after publishing --- .github/wiki/Development-Windows.md | 6 +++--- Classes/Program.cs | 5 ++--- Classes/Utils/Updater.cs | 2 +- RePlays.csproj | 12 ++++-------- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.github/wiki/Development-Windows.md b/.github/wiki/Development-Windows.md index 6f8d7eaf..7d31d9cc 100644 --- a/.github/wiki/Development-Windows.md +++ b/.github/wiki/Development-Windows.md @@ -97,11 +97,11 @@ To manually build a release on your machine, run the following command at the ro `dotnet publish /p:Configuration=Release /p:Version=X.X.X /p:PublishProfile=FolderProfile` -You must specific a version in the numeral format of X.X.X (e.g. 1.69.420). Version numbering does not really matter for local release builds. +You must specify a version in the numeral format of X.X.X (e.g. 1.69.420). Version numbering does not really matter for local release builds. -The build will make use of Squirrel and create deltas or full packages, including a Setup file. You can find these files in `/bin/Deployment/Releases/`. +The build will make use of Velopack and create deltas or full packages, including a Setup file. You can find these files in `/bin/Deployment/Releases/`. -You can learn more about the Squirrel deployment process [here](https://github.com/Squirrel/Squirrel.Windows/blob/develop/docs/getting-started/0-overview.md#overview). +You can learn more about the Velopack deployment process [here](https://docs.velopack.io/). # 7. (Optional) Using Visual Studio Code diff --git a/Classes/Program.cs b/Classes/Program.cs index 562ed1aa..350c53b3 100644 --- a/Classes/Program.cs +++ b/Classes/Program.cs @@ -17,7 +17,6 @@ using RePlays.Recorders; #else using System.Windows.Forms; -using Velopack.Windows; #endif namespace RePlays { @@ -108,11 +107,11 @@ static void Main(string[] args) { // Velopack configuration try { VelopackApp.Build() + /* Add this line if updating should create a shortcut as well #if WINDOWS - .WithAfterInstallFastCallback((v) => new Shortcuts().CreateShortcutForThisExe()) .WithAfterUpdateFastCallback(v => new Shortcuts().CreateShortcutForThisExe()) - .WithBeforeUninstallFastCallback(v => new Shortcuts().RemoveShortcutForThisExe()) #endif + */ .Run(); } catch (Exception exception) { diff --git a/Classes/Utils/Updater.cs b/Classes/Utils/Updater.cs index c8be86aa..cd7d68e0 100644 --- a/Classes/Utils/Updater.cs +++ b/Classes/Utils/Updater.cs @@ -23,7 +23,7 @@ public static async void CheckForUpdates(bool forceUpdate = false) { try { if (forceUpdate) WebMessage.DisplayToast("CheckUpdateProgress", "Checking for updates", "Update", "none", (long)40, (long)100); - if(manager == null) + if (manager == null) manager = new UpdateManager(new GithubSource("https://github.com/lulzsun/RePlays", null, isNightly)); if (forceUpdate) WebMessage.DisplayToast("CheckUpdateProgress", "Checking for updates", "Update", "none", (long)70, (long)100); diff --git a/RePlays.csproj b/RePlays.csproj index 9ed59c40..1337870d 100644 --- a/RePlays.csproj +++ b/RePlays.csproj @@ -50,7 +50,6 @@ $(PkgNuGet_CommandLine)\tools - $(PkgClowd_Squirrel)\tools 1.0.0 RePlays.nuspec annotations @@ -167,13 +166,10 @@ - - - - - - - + + + + From 861c199fad181db70b2672a09f12d851ef7ac5d3 Mon Sep 17 00:00:00 2001 From: sshcrack <34072808+sshcrack@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:28:05 +0200 Subject: [PATCH 4/5] including dotnet-tools manifest in git repo --- .config/dotnet-tools.json | 12 ++++++++++++ .gitignore | 4 ++++ RePlays.csproj | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .config/dotnet-tools.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 00000000..d591af40 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "vpk": { + "version": "0.0.359", + "commands": [ + "vpk" + ] + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8f4bb715..a6925924 100644 --- a/.gitignore +++ b/.gitignore @@ -239,3 +239,7 @@ _Pvt_Extensions # FAKE - F# Make .fake/ Classes/WindowsInterface.resx + + +# Dotnet tool configuration is needed for vpk +!./.config/dotnet-tools.json diff --git a/RePlays.csproj b/RePlays.csproj index 1337870d..e685a5a4 100644 --- a/RePlays.csproj +++ b/RePlays.csproj @@ -167,9 +167,9 @@ - + - + From 9d9f071925a504b68d995f2b936658b5442d0337 Mon Sep 17 00:00:00 2001 From: sshcrack <34072808+sshcrack@users.noreply.github.com> Date: Thu, 25 Apr 2024 18:04:11 +0200 Subject: [PATCH 5/5] added authors and output dirs --- RePlays.csproj | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/RePlays.csproj b/RePlays.csproj index e685a5a4..e6666de8 100644 --- a/RePlays.csproj +++ b/RePlays.csproj @@ -166,10 +166,15 @@ + + + + + - +