private void LoadGmaFile(string newGmaPath) { // Try to load the GMA file if (newGmaPath != null) { try { using (Stream gmaStream = File.OpenRead(newGmaPath)) { Gma = new Gma(gmaStream, GcGame.SuperMonkeyBall1); GmaPath = newGmaPath; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); Gma = null; GmaPath = null; } } else { Gma = null; GmaPath = null; } HaveUnsavedGmaChanges = false; // Update model list paneModels.UpdateTree(); // Update material tab paneMaterials.UpdateTrees(); // Update model viewer paneStageViewer.InvalidateGL(); }
private void importObjMtlToolStripMenuItem_Click(object sender, EventArgs e) { if (!CheckSaveUnsavedChanges()) { return; } if (ofdLoadObj.ShowDialog() != DialogResult.OK) { return; } List <string> modelWarningLog; ObjMtlModel model; try { model = new ObjMtlModel(ofdLoadObj.FileName, out modelWarningLog); if (modelWarningLog.Count != 0) { ObjMtlWarningLogDialog warningDlg = new ObjMtlWarningLogDialog(modelWarningLog); if (warningDlg.ShowDialog() != DialogResult.Yes) { return; } } } catch (Exception ex) { MessageBox.Show("Error loading the OBJ file. " + ex.Message, "Error loading the OBJ file.", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Dictionary <Bitmap, int> textureIndexMapping; Tpl = new Tpl(model, out textureIndexMapping); Gma = new Gma(model, textureIndexMapping); paneStageViewer.SetDrawTextures(true); // Set TPL / GMA as changed HaveUnsavedGmaChanges = true; HaveUnsavedTplChanges = true; // Update model list paneModels.UpdateTree(); paneModels.UpdateModelButtons(); // Update material tab paneMaterials.UpdateTrees(); //UpdateTextureButtons(); // Update stage viewer paneStageViewer.InvalidateGL(); }
/// <summary> /// Get Error Correction Blocks by level /// </summary> //[method internal ErrorCorrectionBlocks GetECBlocksByLevel(Gma.QrCodeNet.Encoding.ErrorCorrectionLevel ECLevel) { switch(ECLevel) { case ErrorCorrectionLevel.L: return m_ECBlocks[0]; case ErrorCorrectionLevel.M: return m_ECBlocks[1]; case ErrorCorrectionLevel.Q: return m_ECBlocks[2]; case ErrorCorrectionLevel.H: return m_ECBlocks[3]; default: throw new System.ArgumentOutOfRangeException("Invalide ErrorCorrectionLevel"); } }
private void LoadGmaFile(string newGmaPath) { // Try to load the GMA file if (newGmaPath != null) { try { using (Stream gmaStream = File.OpenRead(newGmaPath)) { gma = new Gma(gmaStream, GetSelectedGame()); gmaPath = newGmaPath; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); gma = null; gmaPath = null; } } else { gma = null; gmaPath = null; } haveUnsavedGmaChanges = false; // Update model list UpdateModelTree(); UpdateModelButtons(); UpdateModelDisplay(); // Update material tab UpdateMaterialList(); UpdateMaterialDisplay(); // Update model viewer reloadOnNextRedraw = true; glControlModel.Invalidate(); }
private bool SaveGmaFile() { // 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 (GmaPath == null) { if (sfdSaveGma.ShowDialog() != DialogResult.OK) { return(false); } GmaPath = sfdSaveGma.FileName; } using (Stream gmaStream = File.OpenWrite(GmaPath)) { Gma.Save(gmaStream, GcGame.SuperMonkeyBall1); } HaveUnsavedGmaChanges = false; paneModels.UpdateModelButtons(); return(true); }
private void tsBtnImportObjMtl_Click(object sender, EventArgs e) { if (!CheckSaveUnsavedChanges()) { return; } if (ofdLoadObj.ShowDialog() != DialogResult.OK) { return; } List <string> modelWarningLog; ObjMtlModel model; try { model = new ObjMtlModel(ofdLoadObj.FileName, out modelWarningLog); if (modelWarningLog.Count != 0) { ObjMtlWarningLogDialog warningDlg = new ObjMtlWarningLogDialog(modelWarningLog); if (warningDlg.ShowDialog() != DialogResult.Yes) { return; } } } catch (Exception ex) { MessageBox.Show("Error loading the OBJ file. " + ex.Message, "Error loading the OBJ file.", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Dictionary <Bitmap, int> textureIndexMapping; tpl = new Tpl(model, out textureIndexMapping); gma = new Gma(model, textureIndexMapping); // Set TPL / GMA as changed haveUnsavedGmaChanges = true; haveUnsavedTplChanges = true; // Update model list UpdateModelTree(); UpdateModelButtons(); UpdateModelDisplay(); // Update material tab UpdateMaterialList(); UpdateMaterialDisplay(); // Update texture list UpdateTextureTree(); UpdateTextureButtons(); UpdateTextureDisplay(); // Update model viewer reloadOnNextRedraw = true; glControlModel.Invalidate(); }
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)))); }