Skip to content

Commit

Permalink
Merge #4030 Show repo ETag and parsing errors in Failed Downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Feb 14, 2024
2 parents f43dbd3 + a77dc4f commit cd15a0f
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.
- [Core] Fix crash with DLC disabled by Steam (#4002 by: HebaruSan)
- [Multiple] Fixes for installing .ckan files and DarkKAN mods (#4006 by: HebaruSan)
- [Core] Only auto-delete manually installed DLLs if also replacing them (#4024 by: HebaruSan)
- [Multiple] Show repo ETag and parsing errors in Failed Downloads (#4030 by: HebaruSan)

### Internal

Expand Down
17 changes: 13 additions & 4 deletions Core/Net/Net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,19 @@ public static string CurrentETag(Uri url)
WebRequest req = WebRequest.Create(url);
#pragma warning restore SYSLIB0014
req.Method = "HEAD";
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
string val = resp.Headers["ETag"]?.Replace("\"", "");
resp.Close();
return val;
try
{
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
string val = resp.Headers["ETag"]?.Replace("\"", "");
resp.Close();
return val;
}
catch (WebException exc)
{
// Let the calling code keep going to get the actual problem
log.Debug($"Failed to get ETag from {url}", exc);
return null;
}
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Install the `mono-complete` package or equivalent for your operating system.</va
<data name="NetRepoInconsistenciesHeader" xml:space="preserve"><value>The following inconsistencies were found:</value></data>
<data name="NetRepoLoadingModulesFromRepo" xml:space="preserve"><value>Loading modules from downloaded {0} repository...</value><comment>Should contain UserProgressDownloadSubstring from CmdLine</comment></data>
<data name="NetRepoLoadedDownloadCounts" xml:space="preserve"><value>Loaded download counts from {0} repository</value></data>
<data name="NetRepoNotATarGz" xml:space="preserve"><value>Not a .tar.gz or .zip, cannot process: {0}</value></data>
<data name="JsonRelationshipConverterAnyOfCombined" xml:space="preserve"><value>`any_of` should not be combined with `{0}`</value></data>
<data name="RegistryFileConflict" xml:space="preserve"><value>{0} wishes to install {1}, but this file is registered to {2}</value></data>
<data name="RegistryFileNotRemoved" xml:space="preserve"><value>Error unregistering {1}, file not removed: {0}</value></data>
Expand Down
2 changes: 1 addition & 1 deletion Core/Repositories/RepositoryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static RepositoryData FromDownload(string path, IGame game, IProgress<lon
{
case FileType.TarGz: return FromTarGz(path, game, progress);
case FileType.Zip: return FromZip(path, game, progress);
default: throw new UnsupportedKraken($"Not a .tar.gz or .zip, cannot process: {path}");
default: throw new UnsupportedKraken(string.Format(Properties.Resources.NetRepoNotATarGz, path));
}
}

Expand Down
28 changes: 18 additions & 10 deletions Core/Repositories/RepositoryDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,29 @@ public UpdateResult Update(Repository[] repos,
var progress = new ProgressFilesOffsetsToPercent(
new Progress<int>(p => user.RaiseProgress(msg, p)),
targets.Select(t => new FileInfo(t.filename).Length));
foreach ((Repository repo, NetAsyncDownloader.DownloadTarget target) in toUpdate.Zip(targets))
foreach ((var repo, var target) in toUpdate.Zip(targets))
{
var file = target.filename;
msg = string.Format(Properties.Resources.NetRepoLoadingModulesFromRepo,
repo.name);
// Load the file, save to in memory cache
log.InfoFormat("Loading {0}...", file);
var repoData = repositoriesData[repo] =
RepositoryData.FromDownload(file, game, progress);
// Save parsed data to disk
log.DebugFormat("Saving data for {0} repo...", repo.name);
repoData.SaveTo(GetRepoDataPath(repo));
// Delete downloaded archive
log.DebugFormat("Deleting {0}...", file);
File.Delete(file);
try
{
// Load the file, save to in memory cache
var repoData = repositoriesData[repo] =
RepositoryData.FromDownload(file, game, progress);
// Save parsed data to disk
log.DebugFormat("Saving data for {0} repo...", repo.name);
repoData.SaveTo(GetRepoDataPath(repo));
// Delete downloaded archive
log.DebugFormat("Deleting {0}...", file);
File.Delete(file);
}
catch (UnsupportedKraken kraken)
{
// Show parsing errors in the Downloads Failed popup
throw new DownloadErrorsKraken(Array.IndexOf(toUpdate, repo), kraken);
}
progress.NextFile();
}
// Commit these etags to disk
Expand Down
8 changes: 8 additions & 0 deletions Core/Types/Kraken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ public DownloadErrorsKraken(List<KeyValuePair<int, Exception>> errors)
{
Exceptions = new List<KeyValuePair<int, Exception>>(errors);
}

public DownloadErrorsKraken(int index, Exception exc)
{
Exceptions = new List<KeyValuePair<int, Exception>>
{
new KeyValuePair<int, Exception>(index, exc),
};
}
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions GUI/Dialogs/DownloadsFailedDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cd15a0f

Please sign in to comment.