Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add must donload for downloading.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Apr 16, 2023
1 parent 783f023 commit e68d620
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public unsafe RotationSolverPlugin(DalamudPluginInterface pluginInterface)
#endif
ChangeUITranslation();

RotationUpdater.GetAllCustomRotations(true);
RotationUpdater.GetAllCustomRotations(true, false);
RotationHelper.LoadList();

LinkPayload = pluginInterface.AddChatLinkHandler(0, (id, str) =>
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/UI/RotationConfigWindow_Rotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private static void DrawInfos()
{
if (ImGui.Button(LocalizationManager.RightLang.ConfigWindow_Rotation_DownloadRotationsButton))
{
RotationUpdater.GetAllCustomRotations(true);
RotationUpdater.GetAllCustomRotations(true, true);
}

ImGui.SameLine();
Expand Down
4 changes: 2 additions & 2 deletions RotationSolver/UI/RotationConfigWindow_RotationDev.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ private void DrawRotationDevTab()

if (ImGui.Button(LocalizationManager.RightLang.ConfigWindow_Rotation_DownloadRotationsButton))
{
RotationUpdater.GetAllCustomRotations(true);
RotationUpdater.GetAllCustomRotations(true, true);
}

ImGui.SameLine();

if (ImGui.Button("Load Rotations Local"))
{
RotationUpdater.GetAllCustomRotations(false);
RotationUpdater.GetAllCustomRotations(false, false);
}

ImGui.SameLine();
Expand Down
14 changes: 7 additions & 7 deletions RotationSolver/Updaters/RotationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ public record CustomRotationGroup(ClassJobID jobId, ClassJobID[] classJobIds, IC
internal static SortedList<string, string> AuthorHashes { get; private set; } = new SortedList<string, string>();
static CustomRotationGroup[] _customRotations { get; set; } = new CustomRotationGroup[0];

public static async void GetAllCustomRotations(bool download)
public static async void GetAllCustomRotations(bool download, bool mustDownload)
{
var relayFolder = Service.Interface.ConfigDirectory.FullName;
if (!Directory.Exists(relayFolder)) Directory.CreateDirectory(relayFolder);

LoadRotationsFromLocal(relayFolder);

if(download && Service.Config.DownloadRotations)await DownloadRotationsAsync(relayFolder);
if(download && Service.Config.DownloadRotations)await DownloadRotationsAsync(relayFolder, mustDownload);
}

static bool _isDownloading = false;
private static async Task DownloadRotationsAsync(string relayFolder)
private static async Task DownloadRotationsAsync(string relayFolder, bool mustDownload)
{
if (_isDownloading) return;
_isDownloading= true;
Expand All @@ -45,16 +45,16 @@ private static async Task DownloadRotationsAsync(string relayFolder)

foreach (var url in libs)
{
hasDownload |= await DownloadOneUrlAsync(url, relayFolder, client);
hasDownload |= await DownloadOneUrlAsync(url, relayFolder, client, mustDownload);
var pdbUrl = Path.ChangeExtension(url, ".pdb");
await DownloadOneUrlAsync(pdbUrl, relayFolder, client);
await DownloadOneUrlAsync(pdbUrl, relayFolder, client, mustDownload);
}
}
if (hasDownload) LoadRotationsFromLocal(relayFolder);
_isDownloading = false;
}

private static async Task<bool> DownloadOneUrlAsync(string url, string relayFolder, HttpClient client)
private static async Task<bool> DownloadOneUrlAsync(string url, string relayFolder, HttpClient client, bool mustDownload)
{
try
{
Expand All @@ -77,7 +77,7 @@ private static async Task<bool> DownloadOneUrlAsync(string url, string relayFold
//Download
using (HttpResponseMessage response = await client.GetAsync(url))
{
if (File.Exists(filePath))
if (File.Exists(filePath) && !mustDownload)
{
if (new FileInfo(filePath).Length == response.Content.Headers.ContentLength)
{
Expand Down

0 comments on commit e68d620

Please sign in to comment.