Skip to content

Commit

Permalink
Merge pull request #192 from rankynbass/fix-aria2-closing
Browse files Browse the repository at this point in the history
fix: aria2 will pause and close on exit
  • Loading branch information
Blooym authored Nov 12, 2024
2 parents 980f3b9 + bf77d70 commit cd69a2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/XIVLauncher.Core/Components/MainPage/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,9 @@ private async Task<bool> TryHandlePatchAsync(Repository repository, PatchListEnt
}

using var installer = new PatchInstaller(App.Settings.KeepPatches ?? false);
var patcher = new PatchManager(App.Settings.PatchAcquisitionMethod ?? AcquisitionMethod.Aria, App.Settings.PatchSpeedLimit, repository, pendingPatches, App.Settings.GamePath,
Program.Patcher = new PatchManager(App.Settings.PatchAcquisitionMethod ?? AcquisitionMethod.Aria, App.Settings.PatchSpeedLimit, repository, pendingPatches, App.Settings.GamePath,
App.Settings.PatchPath, installer, App.Launcher, sid);
patcher.OnFail += PatcherOnFail;
Program.Patcher.OnFail += PatcherOnFail;
installer.OnFail += this.InstallerOnFail;

/*
Expand Down Expand Up @@ -1039,18 +1039,18 @@ void UpdatePatchStatus()
{
Thread.Sleep(30);

App.LoadingPage.Line2 = string.Format("Working on {0}/{1}", patcher.CurrentInstallIndex, patcher.Downloads.Count);
App.LoadingPage.Line3 = string.Format("{0} left to download at {1}/s", ApiHelpers.BytesToString(patcher.AllDownloadsLength < 0 ? 0 : patcher.AllDownloadsLength),
ApiHelpers.BytesToString(patcher.Speeds.Sum()));
App.LoadingPage.Line2 = string.Format("Working on {0}/{1}", Program.Patcher.CurrentInstallIndex, Program.Patcher.Downloads.Count);
App.LoadingPage.Line3 = string.Format("{0} left to download at {1}/s", ApiHelpers.BytesToString(Program.Patcher.AllDownloadsLength < 0 ? 0 : Program.Patcher.AllDownloadsLength),
ApiHelpers.BytesToString(Program.Patcher.Speeds.Sum()));

App.LoadingPage.Progress = patcher.CurrentInstallIndex / (float)patcher.Downloads.Count;
App.LoadingPage.Progress = Program.Patcher.CurrentInstallIndex / (float)Program.Patcher.Downloads.Count;
}
}

try
{
var aria2LogFile = new FileInfo(Path.Combine(App.Storage.GetFolder("logs").FullName, "launcher.log"));
await patcher.PatchAsync(aria2LogFile, false).ConfigureAwait(false);
await Program.Patcher.PatchAsync(aria2LogFile, false).ConfigureAwait(false);
}
finally
{
Expand Down
15 changes: 14 additions & 1 deletion src/XIVLauncher.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using XIVLauncher.Common;
using XIVLauncher.Common.Dalamud;
using XIVLauncher.Common.Game.Patch;
using XIVLauncher.Common.Game.Patch.Acquisition;
using XIVLauncher.Common.PlatformAbstractions;
using XIVLauncher.Common.Support;
Expand Down Expand Up @@ -50,6 +51,7 @@ sealed class Program
{
Timeout = TimeSpan.FromSeconds(5)
};
public static PatchManager Patcher { get; set; } = null!;

private static readonly Vector3 ClearColor = new(0.1f, 0.1f, 0.1f);

Expand Down Expand Up @@ -357,12 +359,23 @@ private static void Main(string[] args)
gd.SwapBuffers(gd.MainSwapchain);
}

HttpClient.Dispose();
// Clean up Veldrid resources
gd.WaitForIdle();
bindings.Dispose();
cl.Dispose();
gd.Dispose();

HttpClient.Dispose();

if (Patcher is not null)
{
Patcher.CancelAllDownloads();
Task.Run(async() =>
{
await PatchManager.UnInitializeAcquisition().ConfigureAwait(false);
Environment.Exit(0);
});
}
}

public static void CreateCompatToolsInstance()
Expand Down

0 comments on commit cd69a2d

Please sign in to comment.