-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue #5: Fix files containing invalid file name characters
Some games created with a operating system supporting wider encoding scheme might not extract correctl on all systems. File paths extracted from the archives are now cleaned before trying to use them when writing a file.
- Loading branch information
Showing
4 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Changed in this release | ||
|
||
* **Fix wrong output names on UNIX**: Fix files extracted from a RGASSAD going to a wrong directories on a UNIX-like systems because of hardcoded path delimeters. Thank you @tyrone-sudeium for contribution! | ||
* **Fix [issue #5](https://github.com/uuksu/RPGMakerDecrypter/issues/5)**: Some games created with a operating system supporting wider encoding scheme might not extract correctly on all systems. File paths extracted from the archives are now cleaned before trying to use them when writing a file. Thanks @izayoi256 for reporting the issue! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Xml.Linq; | ||
|
||
namespace RPGMakerDecrypter.Decrypter | ||
{ | ||
public static class ArchivedFileNameUtils | ||
{ | ||
public static string GetFileName(string name) | ||
{ | ||
return GetPathParts(name).Last(); | ||
} | ||
|
||
public static string GetPlatformSpecificPath(string name) | ||
{ | ||
var pathParts = GetPathParts(name); | ||
|
||
pathParts = CleanUnicodeCharacters(pathParts); | ||
pathParts = CleanInvalidPathCharacters(pathParts); | ||
|
||
return Path.Combine(pathParts); | ||
} | ||
|
||
private static string[] GetPathParts(string name) | ||
{ | ||
// Paths in RGSSAD file names are always with Windows-style delimeters | ||
return name.Split('\\'); | ||
} | ||
|
||
private static string[] CleanUnicodeCharacters(string[] pathParts) | ||
{ | ||
var cleanedPathParts = new List<string>(); | ||
var unicodeConstantRegex = new Regex(@"(?i)\\(u|U)([0-9]|[A-F])([0-9]|[A-F])([0-9]|[A-F])([0-9]|[A-F])"); | ||
|
||
foreach (var pathPart in pathParts) | ||
{ | ||
cleanedPathParts.Add(unicodeConstantRegex.Replace(pathPart, string.Empty)); | ||
} | ||
|
||
return cleanedPathParts.ToArray(); | ||
} | ||
|
||
private static string[] CleanInvalidPathCharacters(string[] pathParts) | ||
{ | ||
var cleanedPathParts = new List<string>(); | ||
|
||
foreach (var pathPart in pathParts) | ||
{ | ||
var cleanedPathPart = pathPart; | ||
|
||
foreach(var invalidFileNameChar in Path.GetInvalidFileNameChars()) | ||
{ | ||
cleanedPathPart = cleanedPathPart.Replace($"{invalidFileNameChar}", string.Empty); | ||
} | ||
|
||
cleanedPathParts.Add(cleanedPathPart); | ||
} | ||
|
||
return cleanedPathParts.ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters