Skip to content

Commit

Permalink
fix: handle paths and file names separately
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Aug 16, 2024
1 parent b593a6c commit a56dc55
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions DownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,15 @@ StateCounter counter
}
}

private static string MakePathSafe(string input) {
var invalid = Path.GetInvalidPathChars()
.Concat(Path.GetInvalidFileNameChars())
.ToArray();
private static string MakePathPartsSafe(string input) {
var cleaned = input
.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar, '\\', '/')
.Select(MakeFileNameSafe);
return string.Join(Path.DirectorySeparatorChar, cleaned);
}

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

var sb = new StringBuilder(input.Length);
foreach (var ch in input) {
Expand All @@ -681,12 +686,12 @@ private static string[] GetOutputPaths(IReadOnlyCollection<List<string?>> files)
.Select(file => {
var outputPath = file[3];
if (outputPath != null) {
return MakePathSafe(outputPath);
return MakePathPartsSafe(outputPath);
}
var group = MakePathSafe(file[0] ?? "_default");
var option = MakePathSafe(file[1] ?? "_default");
var gamePath = MakePathSafe(file[2]!);
var group = MakeFileNameSafe(file[0] ?? "_default");
var option = MakeFileNameSafe(file[1] ?? "_default");
var gamePath = MakePathPartsSafe(file[2]!);
return Path.Join(group, option, gamePath);
})
Expand Down

0 comments on commit a56dc55

Please sign in to comment.