Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NKit/Settings/RecoveryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal RecoveryData(Settings settings, ILog log, bool isGameCube, string id8)

public static string GetUpdatePartition(Settings settings, uint crc)
{
Regex m = new Regex(@"\\([A-Z0-9]{40})_([A-Z]+)_" + crc.ToString("X8") + "$", RegexOptions.IgnoreCase);
Regex m = new Regex(@"[/|\\]([A-Z0-9]{40})_([A-Z]+)_" + crc.ToString("X8") + "$", RegexOptions.IgnoreCase);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be wiser to use the Path.DirectorySeparatorChar character provided by the IO library. This will make sure that the regex is platform agnostic. I do not have visual studio installed at the moment but I think the code would look something like this

Suggested change
Regex m = new Regex(@"[/|\\]([A-Z0-9]{40})_([A-Z]+)_" + crc.ToString("X8") + "$", RegexOptions.IgnoreCase);
Regex m = new Regex(Path.DirectorySeparatorChar+@"([A-Z0-9]{40})_([A-Z]+)_" + crc.ToString("X8") + "$", RegexOptions.IgnoreCase);

Nonetheless, I am a bit skeptical on whether the Path.DirectorySeparatorChar would be properly parsed by the Regex builder if the Path.DirectorySeparatorChar is ""
We could propose a switch statement that properly builds the regexp.

The reason I want to avoid using [/|\] is because in extreme cases it could match wrongly

string fn = null;
if (Directory.Exists(settings.RecoveryFilesPath) && (fn = Directory.GetFiles(settings.RecoveryFilesPath).FirstOrDefault(a => m.IsMatch(a))) != null)
return fn;
Expand Down