Skip to content

Commit

Permalink
Add JKSV detection
Browse files Browse the repository at this point in the history
  • Loading branch information
kwsch committed Apr 9, 2016
1 parent 4fa777d commit cfe982d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Misc/SAV6.cs
Expand Up @@ -25,6 +25,10 @@ public class SAV6 : PKX
internal const int SIZE_ORAS = 0x76000;
internal const int SIZE_ORASDEMO = 0x5A00;
internal const int BEEF = 0x42454546;
internal static bool SizeValid(int size)
{
return new[] {SIZE_XY, SIZE_ORAS, SIZE_ORASDEMO}.Contains(size);
}

// Global Settings
internal static bool SetUpdateDex = true;
Expand Down
27 changes: 20 additions & 7 deletions PKX/f1-Main.cs
Expand Up @@ -113,9 +113,19 @@ public Main()
openQuick(Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup", "main"));
else if (pathSDF != null)
openQuick(Path.Combine(pathSDF, "main"));
else if (path3DS != null && Directory.Exists(Path.Combine(path3DS, "JKSV", "Saves")))
{
string[] files = Directory.GetFiles(Path.Combine(path3DS, "JKSV", "Saves"), "main", SearchOption.AllDirectories);
string file = files.Where(f => SAV6.SizeValid((int)new FileInfo(f).Length)) // filter
.OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault();

if (file != null)
openQuick(file);
}
else if (Directory.Exists(pathCache))
{
string file = Directory.GetFiles(pathCache).OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault();
string file = Directory.GetFiles(pathCache).Where(f => SAV6.SizeValid((int)new FileInfo(f).Length)) // filter
.OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault();
if (file != null)
openQuick(file);
}
Expand Down Expand Up @@ -218,6 +228,8 @@ private void mainMenuOpen(object sender, EventArgs e)
ofd.InitialDirectory = Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup");
else if (pathSDF != null)
ofd.InitialDirectory = pathSDF;
else if (path3DS != null && Directory.Exists(Path.Combine(path3DS, "JKSV", "Saves")))
ofd.InitialDirectory = Path.Combine(path3DS, "JKSV", "Saves");
else if (path3DS != null)
ofd.InitialDirectory = Path.GetPathRoot(path3DS);
else if (Directory.Exists(Path.Combine(cyberpath, "root")))
Expand Down Expand Up @@ -575,11 +587,7 @@ private void openFile(byte[] input, string path, string ext)
}
#endregion
#region Saves
if ((input.Length == SAV6.SIZE_ORAS) && BitConverter.ToUInt32(input, SAV6.SIZE_ORAS - 0x1F0) == SAV6.BEEF) // ORAS
openMAIN(input, path);
else if ((input.Length == SAV6.SIZE_XY) && BitConverter.ToUInt32(input, SAV6.SIZE_XY - 0x1F0) == SAV6.BEEF) // XY
openMAIN(input, path);
else if ((input.Length == SAV6.SIZE_ORASDEMO) && BitConverter.ToUInt32(input, SAV6.SIZE_ORASDEMO - 0x1F0) == SAV6.BEEF) // ORAS Demo
if (SAV6.SizeValid(input.Length) && BitConverter.ToUInt32(input, input.Length - 0x1F0) == SAV6.BEEF)
openMAIN(input, path);
// Verify the Data Input Size is Proper
else if (input.Length == 0x100000)
Expand Down Expand Up @@ -3376,8 +3384,13 @@ private void clickSaveFileName(object sender, EventArgs e)
path = Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup", "main");
else if (pathSDF != null && ModifierKeys != Keys.Shift) // if we have a result
path = Path.Combine(pathSDF, "main");
else if (path3DS != null && Directory.Exists(Path.Combine(path3DS, "JKSV", "Saves")))
path = Directory.GetFiles(Path.Combine(path3DS, "JKSV", "Saves"), "main", SearchOption.AllDirectories)
.Where(f => SAV6.SizeValid((int)new FileInfo(f).Length)) // filter
.OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault();
else if (Directory.Exists(pathCache))
path = Directory.GetFiles(pathCache).OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault();
path = Directory.GetFiles(pathCache).Where(f => SAV6.SizeValid((int)new FileInfo(f).Length)) // filter
.OrderByDescending(f => new FileInfo(f).LastWriteTime).FirstOrDefault();
else if (File.Exists(Util.NormalizePath(Path.Combine(Util.GetTempFolder(), "root", "main"))))
// else if cgse exists
path = Util.NormalizePath(Path.Combine(Util.GetTempFolder(), "root", "main"));
Expand Down

0 comments on commit cfe982d

Please sign in to comment.