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); }
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(); }
public override void Write(DataStream strOut) { var data = new DataStream(new System.IO.MemoryStream(), 0, 0); var writer = new DataWriter(data, EndiannessMode.LittleEndian, Encoding.GetEncoding("shift_jis")); if (hasNumBlock) writer.Write((ushort)blocks.Length); foreach (Block b in blocks) { if (fileName == "MagicParam") writer.Write(b.Text.ApplyTable("replace", true), textSize + 8, nullTermina); else writer.Write(b.Text.ApplyTable("replace", true), textSize, nullTermina); writer.Write(b.Data); // Hack for imagen name: new long name field if (longTxtSize > 0) { writer.Write(b.LongText ?? b.Text, longTxtSize, "replace", true); } } if (isEncoded) { data.Seek(0, SeekMode.Origin); Codec(data, strOut); // Encode data to strOut } else { data.WriteTo(strOut); } }
public override void Read(DataStream strIn) { // Copy to a new DataStream to allow write operations // We don't want to change the original file data this.data = new DataStream(new System.IO.MemoryStream(), 0, 0); strIn.WriteTo(this.data); }
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); }
/// <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(); }