Skip to content

Commit

Permalink
fix: add extension if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Aug 23, 2024
1 parent 5e4fee0 commit fe4a853
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions DownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,22 +699,22 @@ StateCounter counter

// the file is now fully written to, so duplicate it if
// necessary
await DuplicateFile(filesPath, outputPaths, path);
await this.DuplicateFile(filesPath, outputPaths, path);

this.StateData += 1;
counter.Added += 1;
}
}
}

internal static string MakePathPartsSafe(string input) {
private static string MakePathPartsSafe(string input) {
var cleaned = input
.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar, '\\', '/')
.Select(MakeFileNameSafe);
return string.Join(Path.DirectorySeparatorChar, cleaned);
}

internal static string MakeFileNameSafe(string input) {
private static string MakeFileNameSafe(string input) {
var invalid = Path.GetInvalidFileNameChars();

var sb = new StringBuilder(input.Length);
Expand All @@ -729,7 +729,7 @@ internal static string MakeFileNameSafe(string input) {
return sb.ToString();
}

internal static string[] GetOutputPaths(IReadOnlyCollection<List<string?>> files) {
private static string[] GetOutputPaths(IReadOnlyCollection<List<string?>> files) {
return files
.Select(file => {
var outputPath = file[3];
Expand Down Expand Up @@ -810,6 +810,11 @@ private void RemoveOldFiles() {
this.State = State.RemovingOldFiles;
this.SetStateData(0, 0);

Plugin.Log.Info("expected files:");
foreach (var exp in this.ExpectedFiles) {
Plugin.Log.Info($" {exp}");
}

// find old, normal files no longer being used to remove
var filesPath = Path.Join(this.PenumbraModPath, "files");

Expand All @@ -820,6 +825,11 @@ private void RemoveOldFiles() {
.Select(path => path.ToLowerInvariant())
.ToHashSet();

Plugin.Log.Info("present files:");
foreach (var exp in presentFiles) {
Plugin.Log.Info($" {exp}");
}

// remove the files that we expect from the list of already-existing
// files - these are the files to remove now
presentFiles.ExceptWith(this.ExpectedFiles);
Expand Down Expand Up @@ -1007,16 +1017,21 @@ private async Task<HeliosphereMeta> ConstructHeliosphereMeta(IDownloadTask_GetVe
}

private static string GetReplacedPath(List<string?> file) {
var gamePath = file[2]!;
var outputPath = file[3];

var replacedPath = outputPath == null
? Path.Join(
file[0] ?? DefaultFolder,
file[1] ?? DefaultFolder,
MakePathPartsSafe(file[2]!)
MakePathPartsSafe(gamePath)
)
: MakePathPartsSafe(outputPath);

if (Path.GetExtension(replacedPath) == string.Empty) {
replacedPath = Path.ChangeExtension(replacedPath, Path.GetExtension(gamePath));
}

return replacedPath;
}

Expand Down

0 comments on commit fe4a853

Please sign in to comment.