Skip to content

Commit

Permalink
Attempt to increase resilience when downloading game list from consoles
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden committed Nov 4, 2024
1 parent 7d7665c commit a562c09
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Refresher.Core/Accessors/ConsolePatchAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ConsolePatchAccessor(string remoteIp)

this._client = new FtpClient(remoteIp, "anonymous", "");
this._client.Config.LogToConsole = true;
this._client.Config.ConnectTimeout = 5000;
this._client.Config.ConnectTimeout = 10000;

FtpProfile? profile = this._client.AutoConnect();
if (profile == null) throw new FTPConnectionFailureException();
Expand Down
49 changes: 36 additions & 13 deletions Refresher.Core/Pipelines/Steps/DownloadGameListStep.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Refresher.Core.Patching;
using Refresher.Core.Accessors;
using Refresher.Core.Patching;

namespace Refresher.Core.Pipelines.Steps;

Expand All @@ -16,28 +17,50 @@ public override async Task ExecuteAsync(CancellationToken cancellationToken = de
.Where(p => Path.GetFileName(p).Length == "NPUA80662".Length)
.ToList();

bool isConsole = this.Pipeline.Accessor is ConsolePatchAccessor;

int i = 0;
foreach (string gamePath in games)
{
State.Logger.LogInfo(InfoRetrieval, $"Downloading information for game '{gamePath}'...");
if (!this.Pipeline.Accessor.FileExists(Path.Combine(gamePath, "PARAM.SFO")))
{
State.Logger.LogDebug(InfoRetrieval, $"{gamePath} has no PARAM.SFO, skipping...");
continue;
}

GameInformation game = new()
{
TitleId = Path.GetFileName(gamePath),
};
this.Pipeline.GameInformation = game;

DownloadParamSfoStep paramStep = new(this.Pipeline);
await paramStep.ExecuteAsync(cancellationToken);

DownloadIconStep iconStep = new(this.Pipeline);
await iconStep.ExecuteAsync(cancellationToken);


const int maxTries = 5;
int tries = maxTries + 1;
while (--tries != 0)
{
try
{
DownloadParamSfoStep paramStep = new(this.Pipeline);
await paramStep.ExecuteAsync(cancellationToken);

DownloadIconStep iconStep = new(this.Pipeline);
await iconStep.ExecuteAsync(cancellationToken);

break;
}
catch(Exception e)
{
State.Logger.LogWarning(InfoRetrieval, $"Failed to get information for '{game.TitleId}'. {tries} tries remaining...");
State.Logger.LogWarning(InfoRetrieval, e.ToString());
if (isConsole)
await Task.Delay(5000, cancellationToken);
}
}

if (tries == 0)
{
State.Logger.LogWarning(InfoRetrieval, $"Couldn't get information for '{game.TitleId}' after {maxTries} tries. Giving up.");
}

if (isConsole)
await Task.Delay(100, cancellationToken);

this.Pipeline.GameList.Add(game);
this.Progress = i++ / (float)games.Count;
}
Expand Down
3 changes: 2 additions & 1 deletion Refresher.Core/Pipelines/Steps/DownloadParamSfoStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public override Task ExecuteAsync(CancellationToken cancellationToken = default)
{
if (sfoStream == null)
{
throw new FileNotFoundException("The PARAM.SFO file does not exist. This usually means you haven't installed any updates for your game.");
State.Logger.LogWarning(InfoRetrieval, "The PARAM.SFO file does not exist. This usually means you haven't installed any updates for your game. Will try to proceed anyways...");
return Task.CompletedTask;
}
this.ParseSfoStream(sfoStream, out sfo);
}
Expand Down

0 comments on commit a562c09

Please sign in to comment.