Skip to content

Commit

Permalink
migrate updates to velopack
Browse files Browse the repository at this point in the history
  • Loading branch information
flustix committed Sep 8, 2024
1 parent f2b843b commit 0d1bc80
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 225 deletions.
2 changes: 1 addition & 1 deletion fluXis.Desktop/FluXisGameDesktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ protected override void Dispose(bool isDisposing)
}

public override LightController CreateLightController() => new OpenRGBController();
public override IUpdatePerformer CreateUpdatePerformer() => OperatingSystem.IsWindows() ? new WindowsUpdatePerformer(NotificationManager) : null;
public override IUpdatePerformer CreateUpdatePerformer() => OperatingSystem.IsWindows() ? new VelopackUpdatePerformer(NotificationManager) : null;
}
3 changes: 3 additions & 0 deletions fluXis.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using osu.Framework;
using osu.Framework.Localisation;
using osu.Framework.Logging;
using Velopack;

namespace fluXis.Desktop;

Expand All @@ -21,6 +22,8 @@ public static class Program

public static void Main(string[] args)
{
VelopackApp.Build().Run();

if (args.Contains("--generate-langfiles"))
{
generateDefaultLangfiles();
Expand Down
61 changes: 61 additions & 0 deletions fluXis.Desktop/VelopackUpdatePerformer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using fluXis.Game;
using fluXis.Game.Graphics.Sprites;
using fluXis.Game.Overlay.Notifications;
using fluXis.Game.Overlay.Notifications.Tasks;
using fluXis.Game.Updater;
using osu.Framework.Logging;
using Velopack;
using Velopack.Sources;

namespace fluXis.Desktop;

public partial class VelopackUpdatePerformer : IUpdatePerformer
{
private NotificationManager notifications { get; }
private readonly Logger logger = Logger.GetLogger("update");

public VelopackUpdatePerformer(NotificationManager notifications)
{
this.notifications = notifications;
}

public void Perform(bool silent, bool beta)
{
if (FluXisGameBase.IsDebug)
{
logger.Add("Skipping update in debug.");
return;
}

logger.Add("Checking for updates...");
var mgr = new UpdateManager(new GithubSource("https://github.com/TeamFluXis/fluXis", "", beta));

var update = mgr.CheckForUpdates();

if (update is null)
{
logger.Add("No update found.");

if (!silent)
notifications.SendText("No updates available.", "You are running the latest version.", FontAwesome6.Solid.Check);

return;
}

var notification = new TaskNotificationData
{
Text = "New update available!",
TextWorking = "Downloading...",
TextFailed = "Failed! Check update.log for more information.",
TextFinished = "Done! Starting update..."
};

notifications.AddTask(notification);
logger.Add($"Downloading {update.TargetFullRelease.Version}...");
mgr.DownloadUpdates(update, i => notification.Progress = i / 100f);

logger.Add("Applying...");
notification.State = LoadingState.Complete;
mgr.ApplyUpdatesAndRestart(update);
}
}
167 changes: 0 additions & 167 deletions fluXis.Desktop/WindowsUpdatePerformer.cs

This file was deleted.

1 change: 1 addition & 0 deletions fluXis.Desktop/fluXis.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</ItemGroup>
<ItemGroup Label="Package References">
<PackageReference Include="OpenRGB.NET" Version="3.0.1" />
<PackageReference Include="Velopack" Version="0.0.594" />
</ItemGroup>
<ItemGroup Label="Resources">
<EmbeddedResource Include="game.ico" />
Expand Down
23 changes: 6 additions & 17 deletions fluXis.Game/FluXisGameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,26 +289,15 @@ protected override void LoadComplete()
}, true);
}

public void PerformUpdateCheck(bool silent, bool forceUpdate = false)
public void PerformUpdateCheck(bool silent) => Task.Run(() =>
{
Task.Run(() =>
{
var checker = new UpdateChecker(Config.Get<ReleaseChannel>(FluXisSetting.ReleaseChannel));
var performer = CreateUpdatePerformer();
if (forceUpdate || checker.UpdateAvailable)
{
var performer = CreateUpdatePerformer();
var version = checker.LatestVersion;
if (performer is null)
return;
if (performer != null)
performer.Perform(version);
else
NotificationManager.SendText($"New update available! ({version})", "Check the github releases to download the latest version.", FontAwesome6.Solid.Download);
}
else if (!silent)
NotificationManager.SendText("No updates available.", "You are running the latest version.", FontAwesome6.Solid.Check);
});
}
performer.Perform(silent, Config.Get<ReleaseChannel>(FluXisSetting.ReleaseChannel) == ReleaseChannel.Beta);
});

private Season getSeason()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ public class SettingsDebugStrings : LocalizationCategory

public TranslatableString ShowLogOverlay => Get("show-log-overlay", "Show Log Overlay");
public TranslatableString ImportFile => Get("import-file", "Import File");
public TranslatableString InstallUpdateFromFile => Get("update-from-file", "Install Update From File");

public TranslatableString InstallUpdateFromFileDescription =>
Get("update-from-file-description", "Installs an update from a .zip file. Be careful from where you download the file from though!");

public TranslatableString LogAPI => Get("log-api", "Log API Responses.");
public TranslatableString LogAPIDescription => Get("log-api-description", "Logs all API request responses to the console and log files. This might contain sensitive info like emails and tokens.");
Expand Down
14 changes: 0 additions & 14 deletions fluXis.Game/Overlay/Settings/Sections/DebugSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ private void load(FrameworkConfigManager frameworkConfig, FluXisConfig config, F
};
}
},
new SettingsButton
{
Label = strings.InstallUpdateFromFile,
Description = strings.InstallUpdateFromFileDescription,
ButtonText = "Find",
Action = () =>
{
panels.Content = new FileSelect
{
AllowedExtensions = new[] { ".zip" },
OnFileSelected = file => game.CreateUpdatePerformer()?.UpdateFromFile(file)
};
}
},
new SettingsToggle
{
Label = strings.LogAPI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Framework.Localisation;

namespace fluXis.Game.Overlay.Settings.Sections.General;
Expand All @@ -19,8 +18,6 @@ public partial class GeneralUpdatesSection : SettingsSubSection

private SettingsGeneralStrings strings => LocalizationStrings.Settings.General;

private InputManager inputManager;

[BackgroundDependencyLoader]
private void load(FluXisGameBase game)
{
Expand All @@ -38,14 +35,8 @@ private void load(FluXisGameBase game)
Label = strings.UpdatesCheck,
Description = strings.UpdatesCheckDescription,
ButtonText = "Check",
Action = () => game.PerformUpdateCheck(false, inputManager.CurrentState.Keyboard.AltPressed)
Action = () => game.PerformUpdateCheck(false)
}
});
}

protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager();
}
}
15 changes: 15 additions & 0 deletions fluXis.Game/Updater/GitHub/GitHubAsset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Newtonsoft.Json;

namespace fluXis.Game.Updater.GitHub;

public class GitHubAsset
{
[JsonProperty("url")]
public string Url { get; set; } = string.Empty;

[JsonProperty("id")]
public int Id { get; set; }

[JsonProperty("name")]
public string Name { get; set; } = string.Empty;
}
Loading

0 comments on commit 0d1bc80

Please sign in to comment.