diff --git a/Misc/Util.cs b/Misc/Util.cs index aaa0fff02..9a583f64c 100644 --- a/Misc/Util.cs +++ b/Misc/Util.cs @@ -138,7 +138,36 @@ namespace PKHeX string[] DriveList = Environment.GetLogicalDrives(); for (int i = 1; i < DriveList.Length; i++) { - string potentialPath_SDF = Path.Combine(DriveList[i], "filer\\UserSaveData\\"); + /* + Comment from SoujiSeta. I am putting this here as example of the NoralizePath function + To be more portable the the "filer\\UserSaveData\\" string should be changed to + "filer" + Path.DirectorySeparator + "UserSaveData" + Path.DirectorySeparator, but this + example is used to illustrate whath NormalizePath does. + It uses the URI class URI.LocalPath function to get an operating specific file path. + It then uses the Path.GetFullPath function to get an absoulute canonical path to the file + or directory. Path.GetFullPath function would also convert any backslashes to forward slashes if + it is running on a non-Windows platform. + Finally the TrimEnd function is to remove any trailing backslashes or forward slashes for + consistency so that the user always knows that any path that this function returns will + never end in a slash. + + Below are examples of how this works + Windows Examples + F:\filer\UserSaveData\ -> F:\filer\UserSaveData + G:/filer/UserSaveData/ -> G:\filer\UserSaveData + + Unix Example + /mnt/usb_drive/filer\UserSaveData\ -> /mnt/usb_drive/filer/UserSaveData + + FYI: The Directory.Exists function does not need to have a trailing slash to work as it looks + at the name without any trailing path seperators + + I have tested this both on Windows and linux + I don't mind if you remove this comment if you fill it is no longer needed + + */ + + string potentialPath_SDF = NormalizePath(Path.Combine(DriveList[i], "filer\\UserSaveData\\")); if (Directory.Exists(potentialPath_SDF)) { path_SDF = potentialPath_SDF; @@ -155,14 +184,14 @@ namespace PKHeX // Loop through all the folders in the Nintendo 3DS folder to see if any of them contain 'title'. for (int i = folders.Length - 1; i > 0; i--) { - if (File.Exists(Path.Combine(folders[i], "000011c4\\main"))) return Path.Combine(folders[i], "000011c4"); // OR - if (File.Exists(Path.Combine(folders[i], "000011c5\\main"))) return Path.Combine(folders[i], "000011c5"); // AS - if (File.Exists(Path.Combine(folders[i], "0000055d\\main"))) return Path.Combine(folders[i], "0000055d"); // X - if (File.Exists(Path.Combine(folders[i], "0000055e\\main"))) return Path.Combine(folders[i], "0000055e"); // Y + if (File.Exists(Path.Combine(folders[i], "000011c4" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "000011c4"); // OR + if (File.Exists(Path.Combine(folders[i], "000011c5" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "000011c5"); // AS + if (File.Exists(Path.Combine(folders[i], "0000055d" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "0000055d"); // X + if (File.Exists(Path.Combine(folders[i], "0000055e" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "0000055e"); // Y // I don't know - if (File.Exists(Path.Combine(folders[i], "00055d00\\main"))) return Path.Combine(folders[i], "00055d00"); // X - if (File.Exists(Path.Combine(folders[i], "00055e00\\main"))) return Path.Combine(folders[i], "00055e00"); // Y + if (File.Exists(Path.Combine(folders[i], "00055d00" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "00055d00"); // X + if (File.Exists(Path.Combine(folders[i], "00055e00" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "00055e00"); // Y } return null; } diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index e18e8f4b5..cb63cb4d3 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -3612,7 +3612,7 @@ namespace PKHeX OpenPKX.RestoreDirectory = true; OpenPKX.FilterIndex = 4; } - else if (Path.Combine(cyberpath, "root"))) + else if (Directory.Exists(Path.Combine(cyberpath, "root"))) { OpenPKX.InitialDirectory = Path.Combine(cyberpath, "root"); OpenPKX.RestoreDirectory = true;