Skip to content

Commit 03253a6

Browse files
committed
Fixed Display of QVM Version
1 parent 46095a8 commit 03253a6

File tree

1 file changed

+46
-15
lines changed

1 file changed

+46
-15
lines changed

QVMEditor/QVMEditorForm.cs

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,32 @@ public void InvokeIfNeeded(Action action)
908908
}
909909
}
910910

911-
912-
911+
private void UpdateUILabel(Label label, string newText)
912+
{
913+
try
914+
{
915+
if (label.InvokeRequired)
916+
{
917+
label.Invoke(new Action(() => {
918+
label.Text = newText;
919+
label.Invalidate();
920+
label.Parent?.Invalidate(); // Optional: Invalidate the parent to ensure the layout updates
921+
label.Update(); // Force immediate redraw of the label
922+
}));
923+
}
924+
else
925+
{
926+
label.Text = newText;
927+
label.Invalidate();
928+
label.Parent?.Invalidate(); // Optional: Invalidate the parent to ensure the layout updates
929+
label.Update(); // Force immediate redraw of the label
930+
}
931+
}
932+
catch (Exception ex)
933+
{
934+
QUtils.LogException(MethodBase.GetCurrentMethod().Name, ex);
935+
}
936+
}
913937

914938
#endregion
915939

@@ -1182,9 +1206,9 @@ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
11821206
string scriptFileQvm = scriptFilePathAbsolute + "\\" + fileNameLabel.Text;
11831207
string scriptFileQsc = fileNameLabel.Text.Replace(QUtils.qvmFile, QUtils.qscFile);
11841208
string scriptData = scintilla.Text;
1185-
1209+
11861210
// check if both file exists.
1187-
if (String.IsNullOrEmpty(scriptFilePathAbsolute))
1211+
if (String.IsNullOrEmpty(scriptFilePathAbsolute))
11881212
{
11891213
QUtils.ShowError("Cannot find the path of input script file.");
11901214
QUtils.AddLog("Input file path is null or empty.");
@@ -1236,7 +1260,7 @@ private void DecompileQVM(string fileName)
12361260
QUtils.AddLog("Entering method: DecompileQVM()");
12371261
QUtils.AddLog("DecompileQVM param fileName = " + fileName);
12381262

1239-
if (string.IsNullOrEmpty(fileName) && !File.Exists(fileName))
1263+
if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
12401264
{
12411265
QUtils.AddLog("Invalid file path or file does not exist");
12421266
QUtils.ShowError("Invalid file path or file does not exist");
@@ -1247,23 +1271,30 @@ private void DecompileQVM(string fileName)
12471271
QCompiler.DecompileFile(fileName, QUtils.appOutPath);
12481272
QUtils.AddLog("Decompiling done");
12491273

1250-
scriptFilePath = QUtils.appOutPath + Path.DirectorySeparatorChar + Path.GetFileName(fileName).Replace(QUtils.qvmFile, QUtils.qscFile);
1251-
InvokeIfNeeded(delegate ()
1252-
{
1253-
fileNameLabel.Text = Path.GetFileNameWithoutExtension(fileName) + QUtils.qvmFile;
1254-
});
1274+
scriptFilePath = Path.Combine(QUtils.appOutPath, Path.GetFileName(fileName).Replace(QUtils.qvmFile, QUtils.qscFile));
1275+
12551276
QUtils.AddLog($"Files path are {scriptFilePath} and name {fileNameLabel.Text}");
12561277
scintilla.Text = QUtils.LoadFile(scriptFilePath);
12571278

12581279
// decompile the qvm version.
12591280
QUtils.qvmVersion = QUtils.ReadQVMVersion(fileName);
12601281
QUtils.AddLog($"appVersionTxt is {appVersionTxt.Text}");
1261-
InvokeIfNeeded(delegate ()
1282+
1283+
string qvmVersionText = QUtils.qvmVersion;
1284+
if (string.IsNullOrEmpty(qvmVersionText))
12621285
{
1263-
appVersionTxt.Text = "QVM Version: " + QUtils.qvmVersion.Replace("_", ".").Replace("v", "");
1264-
});
1265-
QUtils.AddLog($"QVM Version is {QUtils.qvmVersion}");
1266-
QUtils.AddLog($"appVersionTxt is {appVersionTxt.Text}");
1286+
QUtils.ShowError("Error reading QVM version from file.");
1287+
QUtils.AddLog("Error reading QVM version from file.");
1288+
}
1289+
QUtils.AddLog($"QVM Version before is {qvmVersionText}");
1290+
qvmVersionText = "QVM: " + qvmVersionText.Replace("_", ".").Replace("v", "");
1291+
QUtils.AddLog($"QVM Version after is {qvmVersionText}");
1292+
1293+
string fileNameText = Path.GetFileNameWithoutExtension(fileName) + QUtils.qvmFile;
1294+
1295+
UpdateUILabel(fileNameLabel, fileNameText);
1296+
UpdateUILabel(appVersionTxt, qvmVersionText);
1297+
12671298
QUtils.AddLog("Exiting method: DecompileQVM()");
12681299
}
12691300

0 commit comments

Comments
 (0)