Ejemplo n.º 1
0
        // Main wrapper that assembles the ROM based on the following specifications:
        public static bool buildROM(bool Card2, string LOGO_NAME,
                                    string EXEFS_PATH, string ROMFS_PATH, string EXHEADER_PATH,
                                    string SERIAL_TEXT, string SAVE_PATH,
                                    bool trimmed = false, ProgressBar PB_Show = null, RichTextBox TB_Progress = null)
        {
            PB_Show     = PB_Show ?? new ProgressBar();
            TB_Progress = TB_Progress ?? new RichTextBox();

            // Sanity check the input files.
            if (!
                ((File.Exists(EXEFS_PATH) || Directory.Exists(EXEFS_PATH)) &&
                 (File.Exists(ROMFS_PATH) || Directory.Exists(ROMFS_PATH)) &&
                 File.Exists(EXHEADER_PATH)))
            {
                return(false);
            }

            // If ExeFS and RomFS are not built, build.
            if (!File.Exists(EXEFS_PATH) && Directory.Exists(EXEFS_PATH))
            {
                ExeFS.set(Directory.GetFiles(EXEFS_PATH), EXEFS_PATH = "exefs.bin");
            }
            if (!File.Exists(ROMFS_PATH) && Directory.Exists(ROMFS_PATH))
            {
                RomFS.BuildRomFS(ROMFS_PATH, ROMFS_PATH = "romfs.bin", TB_Progress, PB_Show);
            }

            NCCH NCCH    = setNCCH(EXEFS_PATH, ROMFS_PATH, EXHEADER_PATH, SERIAL_TEXT, LOGO_NAME, PB_Show, TB_Progress);
            NCSD NCSD    = setNCSD(NCCH, Card2, PB_Show, TB_Progress);
            bool success = writeROM(NCSD, SAVE_PATH, trimmed, PB_Show, TB_Progress);

            return(success);
        }
Ejemplo n.º 2
0
        private void ExtractRomFS(string NCCH_PATH, string outputDirectory, RichTextBox TB_Progress = null, ProgressBar PB_Show = null)
        {
            updateTB(TB_Progress, "Extracting romfs.bin from CXI...");
            string romfsbinpath = Path.Combine(outputDirectory, "romfs.bin");
            string romfspath    = Path.Combine(outputDirectory, "romfs");

            byte[] romfsBytes = new byte[MEDIA_UNIT_SIZE];

            using (FileStream ncchstream = new FileStream(NCCH_PATH, FileMode.Open, FileAccess.Read),
                   romfsstream = new FileStream(romfsbinpath, FileMode.Append, FileAccess.Write))
            {
                ncchstream.Seek(Convert.ToInt32(header.RomfsOffset * MEDIA_UNIT_SIZE), SeekOrigin.Begin);
                if (PB_Show.InvokeRequired)
                {
                    PB_Show.Invoke((MethodInvoker) delegate { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = Convert.ToInt32(header.RomfsSize); });
                }
                else
                {
                    PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = Convert.ToInt32(header.RomfsSize);
                }
                for (int i = 0; i < header.RomfsSize; i++)
                {
                    ncchstream.Read(romfsBytes, 0, romfsBytes.Length);
                    romfsstream.Write(romfsBytes, 0, romfsBytes.Length);
                    if (PB_Show.InvokeRequired)
                    {
                        PB_Show.Invoke((MethodInvoker)PB_Show.PerformStep);
                    }
                    else
                    {
                        PB_Show.PerformStep();
                    }
                }
            }

            RomFS romfs = new RomFS(romfsbinpath);

            romfs.ExtractRomFS(romfspath, TB_Progress, PB_Show);
            File.Delete(romfsbinpath);
        }