private bool SaveTplFile() { // If there isn't currently any path set (e.g. we've just imported a model), // we have to request one to the user if (TplPath == null) { if (sfdSaveTpl.ShowDialog() != DialogResult.OK) { return(false); } TplPath = sfdSaveTpl.FileName; } using (Stream tplStream = File.OpenWrite(TplPath)) { Tpl.Save(tplStream, GcGame.SuperMonkeyBall1); } HaveUnsavedTplChanges = false; //UpdateTextureButtons(); return(true); }
private void backgroundWorkerRunTests_DoWork(object sender, DoWorkEventArgs e) { RunTestsWorkerParams args = (RunTestsWorkerParams)e.Argument; // Find the list of files to process in the input directory string[] fileNames = Directory.EnumerateFiles(args.inputPath, "*.*", SearchOption.AllDirectories).Where(fn => (args.runLzTest && fn.EndsWith(".lz")) || (args.runArcTest && fn.EndsWith(".arc")) || (args.runTplTest && fn.EndsWith(".tpl")) || (args.runGmaTest && fn.EndsWith(".gma"))).ToArray(); // Process each file int nErrors = 0; for (int i = 0; i < fileNames.Length; i++) { string fileName = fileNames[i]; byte[] originalFileData = File.ReadAllBytes(fileName); try { // Load and resave the file using the appropiate class MemoryStream originalStream = new MemoryStream(originalFileData); MemoryStream resavedStream = new MemoryStream(); if (args.runLzTest && fileName.EndsWith(".lz")) { MemoryStream decodedStream = new MemoryStream(); Lz.Unpack(originalStream, decodedStream, args.game); decodedStream.Position = 0; Lz.Pack(decodedStream, resavedStream, args.game); } else if (args.runArcTest && fileName.EndsWith(".arc")) { ArcContainer arc = new ArcContainer(originalStream); arc.Save(resavedStream); } else if (args.runTplTest && fileName.EndsWith(".tpl")) { Tpl tpl = new Tpl(originalStream, args.game); tpl.Save(resavedStream, args.game); } else if (args.runGmaTest && fileName.EndsWith(".gma")) { Gma gma = new Gma(originalStream, args.game); gma.Save(resavedStream, args.game); } // Check that the resaved file is equal to the original file byte[] resavedFileData = resavedStream.ToArray(); if (!ByteArrayUtils.ByteArrayDataEquals(originalFileData, resavedFileData)) { if (args.saveDiffErrors) { File.WriteAllBytes(fileName + "-error", resavedFileData); } throw new Exception("The resaved file is different than the original file.\n"); } } catch (Exception ex) { txtLog.Invoke(new Action(() => txtLog.AppendText( string.Format("{0}: {1}\n", fileName, ex.Message)))); nErrors++; } backgroundWorkerRunTests.ReportProgress(i * 100 / fileNames.Length); if (backgroundWorkerRunTests.CancellationPending) { return; } } backgroundWorkerRunTests.ReportProgress(100); txtLog.Invoke(new Action(() => txtLog.AppendText( string.Format("Test finished. {0} tested, {1} errors.\n", fileNames.Length, nErrors)))); }