Skip to content

Commit 8f7cb34

Browse files
committed
Updated for Models.json
1 parent e7601e6 commit 8f7cb34

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

QVMEditor/QUtils.cs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using FileSystem = Microsoft.VisualBasic.FileIO.FileSystem;
99
using System.Collections.Generic;
1010
using System.Drawing;
11+
using Newtonsoft.Json;
1112

1213
namespace QVM_Editor
1314
{
@@ -118,8 +119,7 @@ internal static bool InitEditorAppData()
118119
appdataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
119120
qvmEditorQEdPath = appdataPath + Path.DirectorySeparatorChar + qEditor;
120121
qCompilerPath = qvmEditorQEdPath + @"\QCompiler";
121-
objectsModelsFile = qvmEditorQEdPath + Path.DirectorySeparatorChar + "IGIModels.txt";
122-
masterobjList = LoadFile(QUtils.objectsModelsFile);
122+
objectsModelsFile = qvmEditorQEdPath + Path.DirectorySeparatorChar + "IGIModels.json";
123123
tempPathFile = qvmEditorQEdPath + "\\" + tempPathFileName;
124124

125125
if (!Directory.Exists(qvmEditorQEdPath)) { initErrReason = "QEditor"; initStatus = false; }
@@ -274,6 +274,24 @@ internal static DialogResult ShowInputDialog(ref string input)
274274
return result;
275275
}
276276

277+
278+
// Read models from JSON file
279+
internal static dynamic ReadModels()
280+
{
281+
try
282+
{
283+
string jsonModels = LoadFile(QUtils.objectsModelsFile);
284+
dynamic jsonModelsData = JsonConvert.DeserializeObject(jsonModels);
285+
return jsonModelsData;
286+
}
287+
catch (Exception ex)
288+
{
289+
LogException(MethodBase.GetCurrentMethod().Name, ex);
290+
return null;
291+
}
292+
}
293+
294+
// Find model name from ID
277295
internal static string FindModelName(string modelId, bool addLogs = false)
278296
{
279297
string modelName = "UNKNOWN_OBJECT";
@@ -282,37 +300,35 @@ internal static string FindModelName(string modelId, bool addLogs = false)
282300
if (modelId.Contains("\""))
283301
modelId = modelId.Replace("\"", String.Empty);
284302

285-
if (File.Exists(QUtils.objectsModelsFile))
286-
{
287-
if (String.IsNullOrEmpty(masterobjList)) return String.Empty;
288-
289-
var objList = masterobjList.Split('\n');
303+
dynamic jsonModelsData = ReadModels();
290304

291-
foreach (var obj in objList)
305+
// Loop through the data to find the matching model ID
306+
foreach (var data in jsonModelsData)
307+
{
308+
if (data.ModelId.ToString().Equals(modelId))
292309
{
293-
if (obj.Contains(modelId))
310+
modelName = data.ModelName.ToString();
311+
if (modelName.Length < 3 || String.IsNullOrEmpty(modelName))
294312
{
295-
modelName = obj.Split('=')[0];
296-
if (modelName.Length < 3 || String.IsNullOrEmpty(modelName))
297-
{
298-
if (addLogs)
299-
QUtils.AddLog(MethodBase.GetCurrentMethod().Name, "couldn't find model name for Model id : " + modelId);
300-
return modelName;
301-
}
313+
if (addLogs)
314+
QUtils.AddLog(MethodBase.GetCurrentMethod().Name, "couldn't find model name for Model id : " + modelId);
315+
return modelName;
302316
}
303317
}
304-
305-
if (modelName.Length > 3 && !String.IsNullOrEmpty(modelName) && addLogs)
306-
QUtils.AddLog(MethodBase.GetCurrentMethod().Name, "Found model name '" + modelName + "' for id : " + modelId);
307318
}
319+
320+
if (modelName.Length > 3 && !String.IsNullOrEmpty(modelName) && addLogs)
321+
QUtils.AddLog(MethodBase.GetCurrentMethod().Name, "Found model name '" + modelName + "' for id : " + modelId);
308322
}
309323
catch (Exception ex)
310324
{
311325
QUtils.LogException(MethodBase.GetCurrentMethod().Name, ex);
312326
}
313-
return modelName.Trim();
327+
328+
return modelName;
314329
}
315330

331+
316332
//Execute shell command and get std-output.
317333
internal static string ShellExec(string cmdArgs, bool runAsAdmin = false, bool waitForExit = true, string shell = "cmd.exe")
318334
{

QVMEditor/QVMEditor.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
</PropertyGroup>
3737
<ItemGroup>
3838
<Reference Include="Microsoft.VisualBasic" />
39+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
40+
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
41+
</Reference>
3942
<Reference Include="ScintillaNET, Version=3.6.3.0, Culture=neutral, processorArchitecture=MSIL">
4043
<HintPath>..\packages\jacobslusser.ScintillaNET.3.6.3\lib\net40\ScintillaNET.dll</HintPath>
4144
</Reference>

QVMEditor/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="jacobslusser.ScintillaNET" version="3.6.3" targetFramework="net40" />
4+
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net40" />
45
</packages>

0 commit comments

Comments
 (0)