Beispiel #1
0
        private static void TestNdsRomWrite(string romPath)
        {
            DataStream outStream = new DataStream(new MemoryStream(), 0, 0);
            DataStream romStream = new DataStream(romPath, FileMode.Open, FileAccess.Read);
            Format romFormat = FileManager.GetFormat("Rom");

            GameFile rom = new GameFile(Path.GetFileName(romPath), romStream, romFormat);
            romFormat.Initialize(rom);

            DateTime t1 = DateTime.Now;
            romFormat.Read();
            DateTime t2 = DateTime.Now;
            romFormat.Write(outStream);
            DateTime t3 = DateTime.Now;
            outStream.WriteTo("/lab/nds/test.nds");
            DateTime t4 = DateTime.Now;

            outStream.Dispose();
            romStream.Dispose();

            // Display time result
            Console.WriteLine("Time results:");
            Console.WriteLine("\tRead                    -> {0}", t2 - t1);
            Console.WriteLine("\tWrite into MemoryStream -> {0}", t3 - t2);
            Console.WriteLine("\tWrite into FileStream   -> {0}", t4 - t3);
        }
Beispiel #2
0
        private static void TestNdsRomRead(string romPath, string filePath, string outPath)
        {
            DataStream romStream = new DataStream(romPath, FileMode.Open, FileAccess.Read);
            Format romFormat = FileManager.GetFormat("Rom");

            GameFolder main = new GameFolder("main");
            GameFile rom  = new GameFile(Path.GetFileName(romPath), romStream, romFormat);
            main.AddFile(rom);
            romFormat.Initialize(rom);

            XDocument xmlGame = new XDocument();	// TODO: Replace with ExampleGame.xml
            xmlGame.Add(new XElement("GameInfo", new XElement("Files")));
            FileManager.Initialize(main, FileInfoCollection.FromXml(xmlGame));

            GameFile file = FileManager.GetInstance().RescueFile(filePath);
            if (file != null)
                file.Stream.WriteTo(outPath);

            romStream.Dispose();
        }
Beispiel #3
0
        public override void Read(DataStream strIn)
        {
            DataStream temp = new DataStream(new System.IO.MemoryStream(), 0, 0);
            strIn.WriteTo(temp);
            temp.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);

            Configuration config = Configuration.GetInstance();

            script = new NinoScritor.Script(
                temp.BaseStream,
                scriptName,
                System.IO.Path.Combine(config.AppPath, "temp_names.xml"),
                System.IO.Path.Combine(config.AppPath, "temp_context.xml"),
                System.IO.Path.Combine(config.AppPath, "temp_replace.xml"),
                ""
            );

            temp.Dispose();
        }
Beispiel #4
0
        public void UpdateCrc()
        {
            // Write temporaly the banner
            DataStream data = new DataStream(new System.IO.MemoryStream(), 0, 0);
            this.Write(data);

            data.Seek(0x20, SeekMode.Origin);
            this.crc16 = Libgame.Utils.Checksums.Crc16(data, 0x0820);

            if (this.version == 2) {
                data.Seek(0x20, SeekMode.Origin);
                this.crc16v2 = Libgame.Utils.Checksums.Crc16(data, 0x0920);
            }

            data.Dispose();
        }
Beispiel #5
0
        public void UpdateCrc()
        {
            // Write temporaly the header
            DataStream data = new DataStream(new System.IO.MemoryStream(), 0, 0);
            this.Write(data);

            data.Seek(0, SeekMode.Origin);
            this.HeaderCRC16 = Libgame.Utils.Checksums.Crc16(data, 0x15E);
            this.HeaderCRC   = true;

            data.Dispose();

            // The checksum of the logo won't be calculated again
            // since it must have always the original value if we
            // want to boot the game correctly (0xCF56)
        }
        public override void Import(params DataStream[] strIn)
        {
            Configuration config = Configuration.GetInstance();
            XElement xmlImport = ((XElement)parameters[0]).Element("Import");

            string inUnixRunOn = xmlImport.Element("InUnixRunOn").Value;
            string arguments   = config.ResolvePathInVariable(xmlImport.Element("Arguments").Value);
            string programPath = config.ResolvePath(xmlImport.Element("Path").Value);
            string copyTo      = config.ResolvePath(xmlImport.Element("CopyTo").Value);
            string outputPath  = config.ResolvePath(xmlImport.Element("OutputFile").Value);
            bool autoremoveOut = bool.Parse(xmlImport.Element("OutputFile").Attribute("autoremove").Value);
            bool autoremoveCpy = bool.Parse(xmlImport.Element("CopyTo").Attribute("autoremove").Value);
            XElement envVars   = xmlImport.Element("EnvironmentVariables");

            // Resolve variables
            var tempFiles = new string[strIn.Length];
            arguments = ResolveVariables(arguments, tempFiles, strIn);
            if (copyTo != "$stdIn")
                copyTo = ResolveVariables(copyTo, tempFiles, strIn);
            if (outputPath != "$stdOut")
                outputPath = ResolveVariables(outputPath, tempFiles, strIn);

            // Write the data stream to a temp file
            if (copyTo != "$stdIn" && !string.IsNullOrEmpty(copyTo))
                data.WriteTo(copyTo);

            if (config.OsName == "Unix" && !string.IsNullOrEmpty(inUnixRunOn)) {
                arguments = string.Format("\"{0}\" {1}", programPath, arguments);
                programPath = inUnixRunOn;
            }

            // Call to the program
            var startInfo = new ProcessStartInfo();
            startInfo.FileName        = programPath;
            startInfo.Arguments       = arguments;
            startInfo.UseShellExecute = false;
            startInfo.CreateNoWindow  = true;
            startInfo.ErrorDialog     = false;
            startInfo.RedirectStandardInput  = (copyTo == "$stdIn");
            startInfo.RedirectStandardOutput = true;

            // Set environmet variables
            if (envVars != null) {
                foreach (XElement variable in envVars.Elements("Variable"))
                    startInfo.EnvironmentVariables.Add(
                        variable.Element("Name").Value,
                        variable.Element("Value").Value
                    );
            }

            var program = new Process();
            program.StartInfo = startInfo;
            program.Start();

            if (copyTo == "$stdIn") {
                data.BaseStream.Seek(data.Offset, System.IO.SeekOrigin.Begin);
                data.BaseStream.CopyTo(program.StandardInput.BaseStream);
                program.StandardInput.Dispose();
            }

            if (data != null)
                data.Dispose();

            if (outputPath == "$stdOut") {
                var ms = new System.IO.MemoryStream();
                program.StandardOutput.BaseStream.CopyTo(ms);
                data = new DataStream(ms, 0, ms.Length);
            }

            program.WaitForExit();
            program.Dispose();

            // Read the data from the output file
            if (outputPath != "$stdOut") {
                var fileStream = new DataStream(
                    outputPath,
                    System.IO.FileMode.Open,
                    System.IO.FileAccess.Read,
                    System.IO.FileShare.ReadWrite
                );
                data = new DataStream(new System.IO.MemoryStream(), 0, 0);

                fileStream.WriteTo(data);
                fileStream.Dispose();
            }

            // Remove temp files
            for (int i = 0; i < tempFiles.Length && !UseFilePaths; i++)
                if (!string.IsNullOrEmpty(tempFiles[i]))
                    SafeDeleting(tempFiles[i]);

            if (autoremoveCpy && System.IO.File.Exists(copyTo))
                SafeDeleting(copyTo);

            if (autoremoveOut && System.IO.File.Exists(outputPath))
                SafeDeleting(outputPath);
        }
Beispiel #7
0
        /// <summary>
        /// Read the file system of the ROM and create the folder tree.
        /// </summary>
        /// <param name="str">Stream to read the file system.</param>
        public override void Read(DataStream str)
        {
            // Read File Allocation Table
            // I'm creating a new DataStream variable because Fat class needs to know its length.
            DataStream fatStr = new DataStream(str, this.header.FatOffset, this.header.FatSize);
            Fat fat = new Fat();
            fat.Read(fatStr);
            fatStr.Dispose();

            // Read File Name Table
            str.Seek(header.FntOffset, SeekMode.Origin);
            Fnt fnt = new Fnt();
            fnt.Read(str);

            // Get root folder
            this.root = fnt.CreateTree(fat.GetFiles());

            // Get ARM and Overlay files
            this.sysFolder = new GameFolder("System");

            this.sysFolder.AddFile(ArmFile.FromStream(str, this.header, true));
            this.sysFolder.AddFolder(OverlayFolder.FromTable(str, this.header, true, fat.GetFiles()));

            this.sysFolder.AddFile(ArmFile.FromStream(str, this.header, false));
            this.sysFolder.AddFolder(OverlayFolder.FromTable(str, this.header, false, fat.GetFiles()));
        }
Beispiel #8
0
        /// <summary>
        /// Write a new ROM data.
        /// </summary>
        /// <param name="str">Stream to write to.</param>
        public override void Write(DataStream strOut)
        {
            DataStream headerStr  = new DataStream(new System.IO.MemoryStream(), 0, 0);
            DataStream fileSysStr = new DataStream(new System.IO.MemoryStream(), 0, 0);
            DataStream bannerStr  = new DataStream(new System.IO.MemoryStream(), 0, 0);

            this.fileSys.Write(fileSysStr);

            this.banner.UpdateCrc();
            this.banner.Write(bannerStr);

            this.header.BannerOffset = (uint)(this.header.HeaderSize + fileSysStr.Length);
            this.header.UpdateCrc();
            this.header.Write(headerStr);

            headerStr.WriteTo(strOut);
            fileSysStr.WriteTo(strOut);
            bannerStr.WriteTo(strOut);
            this.fileSys.WriteFiles(strOut);
            strOut.WriteUntilLength(FileSystem.PaddingByte, (int)this.header.CartridgeSize);

            headerStr.Dispose();
            fileSysStr.Dispose();
            bannerStr.Dispose();
        }
Beispiel #9
0
        private static void TestNinokuniExportImport(string romPath, string filePath)
        {
            DataStream romStream = new DataStream(romPath, FileMode.Open, FileAccess.Read);
            Format romFormat = FileManager.GetFormat("Rom");
            Format subtitleFormat = FileManager.GetFormat("Subtitle");

            GameFile rom  = new GameFile(Path.GetFileName(romPath), romStream, romFormat);
            romFormat.Initialize(rom);

            XDocument xmlGame = XDocument.Load(Path.Combine(AppPath, "ExampleGame.xml"));
            XDocument xmlEdit = XDocument.Load(Path.Combine(AppPath, "ExampleEdition.xml"));
            FileManager.Initialize(rom, FileInfoCollection.FromXml(xmlGame));
            Configuration.Initialize(xmlEdit);

            GameFile file = FileManager.GetInstance().RescueFile(filePath);
            subtitleFormat.Initialize(file);
            file.Format.Read();
            file.Format.Import("/home/benito/Dropbox/Ninokuni español/Texto/Subs peli/s01.xml");
            file.Format.Write();

            romFormat.Write();
            rom.Stream.WriteTo("/lab/nds/projects/generic/test.nds");
            romStream.Dispose();
        }