Skip to content

Commit

Permalink
Updated for JSON and Support for DAT,QSC
Browse files Browse the repository at this point in the history
  • Loading branch information
Jones-HM committed Mar 19, 2023
1 parent 8f7cb34 commit e5327df
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion QVMEditor/QUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
43 changes: 38 additions & 5 deletions QVMEditor/QVMEditorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using ScintillaNET;
using System.Reflection;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace QVM_Editor
{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e5327df

Please sign in to comment.