diff --git a/QVMEditor/QUtils.cs b/QVMEditor/QUtils.cs index a4f9a7a..47532d9 100644 --- a/QVMEditor/QUtils.cs +++ b/QVMEditor/QUtils.cs @@ -15,7 +15,7 @@ namespace QVM_Editor internal class QUtils { private static string logFile; - internal const string appVersion = "0.2",qvmFile = ".qvm",qscFile = ".qsc", CAPTION_CONFIG_ERR = "Config - Error", CAPTION_FATAL_SYS_ERR = "Fatal sytem - Error", CAPTION_APP_ERR = "Application - Error", CAPTION_COMPILER_ERR = "Compiler - Error", EDITOR_LEVEL_ERR = "EDITOR ERROR"; + internal const string appVersion = "0.3",qvmFile = ".qvm",qscFile = ".qsc", CAPTION_CONFIG_ERR = "Config - Error", CAPTION_FATAL_SYS_ERR = "Fatal sytem - Error", CAPTION_APP_ERR = "Application - Error", CAPTION_COMPILER_ERR = "Compiler - Error", EDITOR_LEVEL_ERR = "EDITOR ERROR"; internal static bool logEnabled = false; internal static string appdataPath, qvmEditorQEdPath, objectsModelsFile, editorAppName, qfilesPath = @"\QFiles", qEditor = "QEditor", qconv = "QConv", qCompiler = "QCompiler", qCompilerPath, tempPathFile,tempPathFileName = "TempPath.txt", igiQsc = "IGI_QSC", igiQvm = "IGI_QVM", cfgGamePathEx = @"\missions\location0\level", weaponsDirPath = @"\weapons"; diff --git a/QVMEditor/QVMEditorForm.cs b/QVMEditor/QVMEditorForm.cs index 5bc5be8..722b34c 100644 --- a/QVMEditor/QVMEditorForm.cs +++ b/QVMEditor/QVMEditorForm.cs @@ -5,6 +5,8 @@ using ScintillaNET; using System.Reflection; using System.Text.RegularExpressions; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; namespace QVM_Editor { @@ -109,8 +111,29 @@ private void scriptViewerText_MouseDoubleClick(object sender, MouseEventArgs e) if (!String.IsNullOrEmpty(modelInput)) { modelInput = modelInput.ToUpper(); - string objectData = "\n" + modelInput + " = " + modelId; - QUtils.SaveFile(objectData, true, QUtils.objectsModelsFile); + + // Read the contents of the file into a string + string fileContents = QUtils.LoadFile(QUtils.objectsModelsFile); + + // Parse the JSON string into a JArray object + JArray modelsArray = JArray.Parse(fileContents); + + // Create a new JObject for the new data + JObject newModel = new JObject( + new JProperty("ModelName", modelInput), + new JProperty("ModelId", modelId) + ); + + // Add the new data to the array + modelsArray.Add(newModel); + + // Serialize the updated array back to JSON format + string updatedFileContents = JsonConvert.SerializeObject(modelsArray, Formatting.Indented); + + // Write the updated JSON string to the file + QUtils.SaveFile(updatedFileContents, false, QUtils.objectsModelsFile); + + // Show a message to confirm that the model has been saved QUtils.ShowInfo("Model saved " + modelId + " : " + modelInput); //Reload the Master objects list. @@ -336,10 +359,21 @@ private void LoadDataFromFile() { try { - var fopenIO = QUtils.ShowOpenFileDlg("Select QVM file", ".qvm", "QVM files (*.qvm)|*.qvm|All files (*.*)|*.*", true); + var fopenIO = QUtils.ShowOpenFileDlg("Select QVM file",".qvm", "QVM files (*.qvm)|*.qvm|DAT files (*.dat)|*.dat|QSC files (*.qsc)|*.qsc|All files (*.*)|*.*",true); string fileName = fopenIO.FileName; scriptFilePathAbsolute = Path.GetDirectoryName(fileName); - DecompileQVM(fileName); + + string fileExtension = Path.GetExtension(fopenIO.FileName); + if (fileExtension.ToLower() == ".dat" || + fileExtension.ToLower() == ".qsc" || + fileExtension.ToLower() == ".txt") + { + scintilla.Text = QUtils.LoadFile(fopenIO.FileName); + } + else + { + DecompileQVM(fileName); + } } catch (Exception ex) { @@ -888,7 +922,6 @@ private void exitToolStripMenuItem_Click(object sender, EventArgs e) Environment.Exit(0); } - private void DecompileQVM(string fileName) { QCompiler.DecompileFile(fileName, QUtils.appOutPath);