From 4a1a7bc26a4ea7a3f18cb5f4b06f479f9188d76b Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 27 Nov 2014 19:26:42 -0800 Subject: [PATCH] Autoload improvements and a re-trigger option. Click the Save path label! --- Misc/Util.cs | 41 ++++++++++++++++++++++++++++++++++++++++- PKX/f1-Main.Designer.cs | 1 + PKX/f1-Main.cs | 37 ++++++++++++++++++++++++++++++++++--- 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/Misc/Util.cs b/Misc/Util.cs index b424db84c..655ddbeb6 100644 --- a/Misc/Util.cs +++ b/Misc/Util.cs @@ -73,7 +73,13 @@ internal static Color AlphaBlend(Color ForeGround, Color BackGround) B = 255; return Color.FromArgb(Math.Abs(A), Math.Abs(R), Math.Abs(G), Math.Abs(B)); } - + internal static FileInfo GetNewestFile(DirectoryInfo directory) + { + return directory.GetFiles() + .Union(directory.GetDirectories().Select(d => GetNewestFile(d))) + .OrderByDescending(f => (f == null ? DateTime.MinValue : f.LastWriteTime)) + .FirstOrDefault(); + } internal static string GetTempFolder() // From 3DSSE's decompiled source. { string tempPath = Path.GetTempPath(); @@ -116,6 +122,39 @@ internal static string GetBackupLocation() Directory.CreateDirectory(path); return path; } + internal static string GetSDFLocation() + { + // start by checking if the 3DS file path exists or not. + string path_SDF = null; + string[] DriveList = Environment.GetLogicalDrives(); + for (int i = 1; i < DriveList.Length; i++) + { + path_SDF = DriveList[i] + "filer\\UserSaveData\\"; + if (Directory.Exists(path_SDF)) + break; + } + if (path_SDF == null) + return null; + else + { + // 3DS data found in SD card reader. Let's get the title folder location! + string[] folders = Directory.GetDirectories(path_SDF, "*", System.IO.SearchOption.TopDirectoryOnly); + + // 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 + + // 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 + } + return null; + } + } internal static string CleanFileName(string fileName) { return Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(), string.Empty)); diff --git a/PKX/f1-Main.Designer.cs b/PKX/f1-Main.Designer.cs index 7c4fa7602..6fd736fac 100644 --- a/PKX/f1-Main.Designer.cs +++ b/PKX/f1-Main.Designer.cs @@ -2715,6 +2715,7 @@ public void InitializeComponent() this.L_Save.Size = new System.Drawing.Size(54, 13); this.L_Save.TabIndex = 4; this.L_Save.Text = "SAV: N/A"; + this.L_Save.Click += new System.EventHandler(this.L_Save_Click); // // tabBoxMulti // diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index c65279d58..15a376a4e 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -169,10 +169,13 @@ public Form1() CB_PPu1.SelectedIndex = CB_PPu2.SelectedIndex = CB_PPu3.SelectedIndex = CB_PPu4.SelectedIndex = 0; CB_Ball.SelectedIndex = 0; - // Load the command line arguments + // Load the arguments string[] args = Environment.GetCommandLineArgs(); + SDFLoc = Util.GetSDFLocation(); if (args.Length > 1) - openQuick(args[1]); + openQuick(args[1]); + else if (SDFLoc != null) + openQuick(Path.Combine(SDFLoc,"main")); else if (File.Exists(Util.GetTempFolder() + "\\root\\main")) openQuick(Util.GetTempFolder() + "\\root\\main"); @@ -201,6 +204,7 @@ public Form1() public int genderflag, species; public int savindex; public bool savedited; + public string SDFLoc = null; public bool HaX = false; public static int colorizedbox = 32; @@ -3948,6 +3952,7 @@ private void openSave(bool oras) B_OpenSecretBase.Visible = oras; this.Width = largeWidth; + System.Media.SystemSounds.Beep.Play(); } // Secondary Windows for Ribbons/Amie/Memories private void openribbons(object sender, EventArgs e) @@ -4942,7 +4947,15 @@ private void exportSAV(object sender, EventArgs e) // Try for file path string cyberpath = Util.GetTempFolder(); - if (Directory.Exists(cyberpath + "\\root\\")) + if (SDFLoc != null) + { + if (Directory.Exists(SDFLoc)) + { + cySAV.InitialDirectory = SDFLoc; + cySAV.RestoreDirectory = true; + } + } + else if (Directory.Exists(cyberpath + "\\root\\")) { cySAV.InitialDirectory = cyberpath + "\\root\\"; cySAV.RestoreDirectory = true; @@ -6362,6 +6375,24 @@ private void pbBoxSlot_DragEnter(object sender, DragEventArgs e) } private byte[] pkm_from = new Byte[0xE8]; private int pkm_from_offset; + private void L_Save_Click(object sender, EventArgs e) + { + // Get latest SaveDataFiler save location + SDFLoc = Util.GetSDFLocation(); + string path = null; + + if (SDFLoc != null && ModifierKeys != Keys.Control) // if we have a result + path = Path.Combine(SDFLoc, "main"); + else if (File.Exists(Util.GetTempFolder() + "\\root\\main")) // else if cgse exists + path = Util.GetTempFolder() + "\\root\\main"; + + if (path != null) + { + DialogResult sdr = MessageBox.Show("Open save file from the following location?\n\n"+path, "Prompt", MessageBoxButtons.YesNo); + if (sdr == DialogResult.Cancel) + openQuick(path); // load save + } + } } #region Structs & Classes public class cbItem