Exemple #1
0
        private void importSMDH(byte[] data, bool prompt = false)
        {
            if (prompt && DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Replace SMDH?"))
            {
                return;
            }

            CTR.SMDH newSMDH = new CTR.SMDH(data);
            if (newSMDH.LargeIcon.Icon == null)
            {
                return;
            }

            SMDH  = newSMDH;
            entry = -1; // allow proper refreshing
            LoadSMDH();
        }
Exemple #2
0
        public Icon()
        {
            InitializeComponent();
            SMDH = Main.SMDH;
            if (SMDH == null || SMDH.AppSettings == null || SMDH.LargeIcon.Bytes == null)
            {
                byte[] data = new byte[0x3C0]; // Feed a blank SMDH
                Array.Copy(BitConverter.GetBytes(0x48444D53), data, 4); // SMDH header
                SMDH = new CTR.SMDH(data);
                B_Save.Enabled = false;
            }
            for (int i = 0; i < 16; i++)
                CB_AppInfo.Items.Add(i);

            LoadSMDH();

            AllowDrop = true;
            DragEnter += tabMain_DragEnter;
            DragDrop += tabMain_DragDrop;
        }
Exemple #3
0
        public Icon()
        {
            InitializeComponent();
            SMDH = Main.SMDH;
            if (SMDH?.AppSettings == null || SMDH.LargeIcon.Bytes == null)
            {
                byte[] data = new byte[0x3C0];                          // Feed a blank SMDH
                Array.Copy(BitConverter.GetBytes(0x48444D53), data, 4); // SMDH header
                SMDH           = new CTR.SMDH(data);
                B_Save.Enabled = false;
            }
            for (int i = 0; i < 16; i++)
            {
                CB_AppInfo.Items.Add(i);
            }

            LoadSMDH();

            AllowDrop  = true;
            DragEnter += tabMain_DragEnter;
            DragDrop  += tabMain_DragDrop;
        }
Exemple #4
0
        private void importSMDH(byte[] data, bool prompt = false)
        {
            if (prompt && DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Replace SMDH?"))
                return;

            CTR.SMDH newSMDH = new CTR.SMDH(data);
            if (newSMDH.LargeIcon.Icon == null) return;

            SMDH = newSMDH;
            entry = -1; // allow proper refreshing
            LoadSMDH();
        }
Exemple #5
0
        private void openQuick(string path)
        {
            if (threadActive()) return;

            if (!Directory.Exists(path)) // File
            {
                FileInfo fi = new FileInfo(path);
                if (fi.Name.Contains("code.bin")) // Compress/Decompress .code.bin
                {
                    if (fi.Length % 0x200 == 0 && (Util.Prompt(MessageBoxButtons.YesNo, "Detected Decompressed code.bin.", "Compress? File will be replaced.") == DialogResult.Yes))
                        new Thread(() => { threads++; new CTR.BLZCoder(new[] { "-en", path }, pBar1); threads--; Util.Alert("Compressed!"); }).Start();
                    else if (Util.Prompt(MessageBoxButtons.YesNo, "Detected Compressed code.bin.", "Decompress? File will be replaced.") == DialogResult.Yes)
                        new Thread(() => { threads++; new CTR.BLZCoder(new[] { "-d", path }, pBar1); threads--; Util.Alert("Decompressed!"); }).Start();
                }
                else if (fi.Name.ToLower().Contains("exe")) // Unpack exefs
                {
                    if (fi.Length % 0x200 == 0 && (Util.Prompt(MessageBoxButtons.YesNo, "Detected ExeFS.bin.", "Unpack?") == DialogResult.Yes))
                        new Thread(() => { threads++; CTR.ExeFS.get(path, Path.GetDirectoryName(path)); threads--; Util.Alert("Unpacked!"); }).Start();
                }
                else if (fi.Name.ToLower().Contains("rom"))
                {
                    Util.Alert("RomFS unpacking not implemented.");
                }
                else
                {
                    DialogResult dr = Util.Prompt(MessageBoxButtons.YesNo, "Unpack sub-files?", "Cancel: Abort");
                    if (dr == DialogResult.Cancel)
                        return;
                    bool recurse = dr == DialogResult.Yes;
                    ToolsUI.openARC(path, pBar1, recurse);
                }
            }
            else // Directory
            {
                // Check for ROMFS/EXEFS/EXHEADER
                RomFSPath = ExeFSPath = null; // Reset
                Config = null;
                string[] folders = Directory.GetDirectories(path);
                int count = folders.Length;

                // Find RomFS folder
                foreach (string f in folders.Where(f => new DirectoryInfo(f).Name.ToLower().Contains("rom") && Directory.Exists(f)))
                    checkIfRomFS(f);
                // Find ExeFS folder
                foreach (string f in folders.Where(f => new DirectoryInfo(f).Name.ToLower().Contains("exe") && Directory.Exists(f)))
                    checkIfExeFS(f);

                if (count > 3)
                    Util.Alert("pk3DS will function best if you keep your Game Files folder clean and free of unnecessary folders.");

                // Enable buttons if applicable
                Tab_RomFS.Enabled = Menu_Restore.Enabled = Tab_CRO.Enabled = Menu_CRO.Enabled = Menu_Shuffler.Enabled = RomFSPath != null;
                Tab_ExeFS.Enabled = RomFSPath != null && ExeFSPath != null;
                if (RomFSPath != null)
                {
                    toggleSubEditors();
                    string newtext = $"Game Loaded: {Config.Version}";
                    if (L_Game.Text != newtext && Directory.Exists("personal"))
                    { Directory.Delete("personal", true); } // Force reloading of personal data if the game is switched.
                    L_Game.Text = newtext; TB_Path.Text = path;
                }
                else if (ExeFSPath != null)
                { L_Game.Text = "ExeFS loaded - no RomFS"; TB_Path.Text = path; }
                else
                { L_Game.Text = "No Game Loaded"; TB_Path.Text = ""; }

                if (RomFSPath != null)
                {
                    // Trigger Data Loading
                    if (RTB_Status.Text.Length > 0) RTB_Status.Clear();
                    updateStatus("Data found! Loading persistent data for subforms...", false);
                    Config.Initialize(RomFSPath, ExeFSPath, Language);
                    backupGARCs(false, Config.Files.Select(file => file.Name).ToArray());
                    backupCROs(false, RomFSPath);
                }

                // Enable Rebuilding options if all files have been found
                checkIfExHeader(path);
                Menu_ExeFS.Enabled = ExeFSPath != null;
                Menu_RomFS.Enabled = Menu_Restore.Enabled = Menu_GARCs.Enabled = RomFSPath != null;
                Menu_Patch.Enabled = RomFSPath != null && ExeFSPath != null;
                Menu_3DS.Enabled =
                    ExHeaderPath != null && RomFSPath != null && ExeFSPath != null;

                // Change L_Game if RomFS and ExeFS exists to a better descriptor
                SMDH = ExeFSPath != null ? File.Exists(Path.Combine(ExeFSPath, "icon.bin")) ? new CTR.SMDH(Path.Combine(ExeFSPath, "icon.bin")) : null : null;
                HANSgameID = SMDH != null ? (SMDH.AppSettings?.StreetPassID ?? 0) : 0;
                L_Game.Visible = SMDH == null && RomFSPath != null;
                updateGameInfo();
                TB_Path.Select(TB_Path.TextLength, 0);
                // Method finished.
                System.Media.SystemSounds.Asterisk.Play();
                resetStatus();
                Properties.Settings.Default.GamePath = path;
                Properties.Settings.Default.Save();
            }
        }
Exemple #6
0
        private void openQuick(string path)
        {
            if (threads > 0) { Util.Alert("Please wait for all operations to finish first."); return; }

            if (!Directory.Exists(path)) // File
            {
                FileInfo fi = new FileInfo(path);
                if (fi.Name.Contains("code.bin")) // Compress/Decompress .code.bin
                {
                    if (fi.Length % 0x200 == 0 && (Util.Prompt(MessageBoxButtons.YesNo, "Detected Decompressed code.bin.", "Compress? File will be replaced.") == DialogResult.Yes))
                        new Thread(() => { threads++; new CTR.BLZCoder(new[] { "-en", path }, pBar1); threads--; Util.Alert("Compressed!"); }).Start();
                    else if (Util.Prompt(MessageBoxButtons.YesNo, "Detected Compressed code.bin.", "Decompress? File will be replaced.") == DialogResult.Yes)
                        new Thread(() => { threads++; new CTR.BLZCoder(new[] { "-d", path }, pBar1); threads--; Util.Alert("Decompressed!"); }).Start();
                }
                else if (fi.Name.ToLower().Contains("exe")) // Unpack exefs
                {
                    if (fi.Length % 0x200 == 0 && (Util.Prompt(MessageBoxButtons.YesNo, "Detected ExeFS.bin.", "Unpack?") == DialogResult.Yes))
                        new Thread(() => { threads++; CTR.ExeFS.get(path, Path.GetDirectoryName(path)); threads--; Util.Alert("Unpacked!"); }).Start();
                }
                else if (fi.Name.ToLower().Contains("rom"))
                {
                    Util.Alert("RomFS unpacking not implemented.");
                }
            }
            else // Directory
            {
                // Check for ROMFS/EXEFS/EXHEADER
                RomFSPath = ExeFSPath = null; // Reset
                string[] folders = Directory.GetDirectories(path);
                int count = folders.Length;

                // Find RomFS folder
                foreach (string f in folders.Where(f => new DirectoryInfo(f).Name.ToLower().Contains("rom") && Directory.Exists(f)))
                    checkIfRomFS(f);
                // Find ExeFS folder
                foreach (string f in folders.Where(f => new DirectoryInfo(f).Name.ToLower().Contains("exe") && Directory.Exists(f)))
                    checkIfExeFS(f);

                if (count > 3)
                    Util.Alert("pk3DS will function best if you keep your Game Files folder clean and free of unnecessary folders.");

                // Enable buttons if applicable
                GB_RomFS.Enabled = Menu_Restore.Enabled = GB_CRO.Enabled = Menu_CRO.Enabled = (RomFSPath != null);
                GB_ExeFS.Enabled = (RomFSPath != null && ExeFSPath != null);
                B_MoveTutor.Enabled = oras; // Default false unless loaded
                if (RomFSPath != null)
                {
                    if (L_Game.Text == "Game Loaded: ORAS" || L_Game.Text == "Game Loaded: XY")
                    { Directory.Delete("personal", true); } // Force reloading of personal data if the game is switched.
                    L_Game.Text = (oras) ? "Game Loaded: ORAS" : "Game Loaded: XY"; TB_Path.Text = path;
                }
                else if (ExeFSPath != null)
                { L_Game.Text = "ExeFS loaded - no RomFS"; TB_Path.Text = path; }
                else
                { L_Game.Text = "No Game Loaded"; TB_Path.Text = ""; }

                if (RomFSPath != null)
                {
                    // Trigger Data Loading
                    if (RTB_Status.Text.Length > 0) RTB_Status.Clear();
                    updateStatus("Data found! Loading persistent data for subforms...", false);
                    changeLanguage(null, null);
                }

                // Enable Rebuilding options if all files have been found
                checkIfExHeader(path);
                Menu_ExeFS.Enabled = ExeFSPath != null;
                Menu_RomFS.Enabled = Menu_Restore.Enabled = Menu_GARCs.Enabled = RomFSPath != null;
                Menu_Patch.Enabled = RomFSPath != null && ExeFSPath != null;
                Menu_3DS.Enabled =
                    (ExHeaderPath != null && RomFSPath != null && ExeFSPath != null);

                // Change L_Game if RomFS and ExeFS exists to a better descriptor
                SMDH = ExeFSPath != null ? (File.Exists(Path.Combine(ExeFSPath, "icon.bin"))) ? new CTR.SMDH(Path.Combine(ExeFSPath, "icon.bin")) : null : null;
                L_Game.Visible = (SMDH == null && RomFSPath != null);
                updateGameInfo();
                TB_Path.Select(TB_Path.TextLength, 0);
                // Method finished.
                SystemSounds.Asterisk.Play();
            }
        }