Skip to content

Commit

Permalink
Fixed Display of QVM Version
Browse files Browse the repository at this point in the history
  • Loading branch information
haseeb-heaven committed Sep 8, 2024
1 parent 46095a8 commit 03253a6
Showing 1 changed file with 46 additions and 15 deletions.
61 changes: 46 additions & 15 deletions QVMEditor/QVMEditorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,32 @@ public void InvokeIfNeeded(Action action)
}
}



private void UpdateUILabel(Label label, string newText)
{
try
{
if (label.InvokeRequired)
{
label.Invoke(new Action(() => {
label.Text = newText;
label.Invalidate();
label.Parent?.Invalidate(); // Optional: Invalidate the parent to ensure the layout updates
label.Update(); // Force immediate redraw of the label
}));
}
else
{
label.Text = newText;
label.Invalidate();
label.Parent?.Invalidate(); // Optional: Invalidate the parent to ensure the layout updates
label.Update(); // Force immediate redraw of the label
}
}
catch (Exception ex)
{
QUtils.LogException(MethodBase.GetCurrentMethod().Name, ex);
}
}

#endregion

Expand Down Expand Up @@ -1182,9 +1206,9 @@ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
string scriptFileQvm = scriptFilePathAbsolute + "\\" + fileNameLabel.Text;
string scriptFileQsc = fileNameLabel.Text.Replace(QUtils.qvmFile, QUtils.qscFile);
string scriptData = scintilla.Text;

// check if both file exists.
if (String.IsNullOrEmpty(scriptFilePathAbsolute))
if (String.IsNullOrEmpty(scriptFilePathAbsolute))
{
QUtils.ShowError("Cannot find the path of input script file.");
QUtils.AddLog("Input file path is null or empty.");
Expand Down Expand Up @@ -1236,7 +1260,7 @@ private void DecompileQVM(string fileName)
QUtils.AddLog("Entering method: DecompileQVM()");
QUtils.AddLog("DecompileQVM param fileName = " + fileName);

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

scriptFilePath = QUtils.appOutPath + Path.DirectorySeparatorChar + Path.GetFileName(fileName).Replace(QUtils.qvmFile, QUtils.qscFile);
InvokeIfNeeded(delegate ()
{
fileNameLabel.Text = Path.GetFileNameWithoutExtension(fileName) + QUtils.qvmFile;
});
scriptFilePath = Path.Combine(QUtils.appOutPath, Path.GetFileName(fileName).Replace(QUtils.qvmFile, QUtils.qscFile));

QUtils.AddLog($"Files path are {scriptFilePath} and name {fileNameLabel.Text}");
scintilla.Text = QUtils.LoadFile(scriptFilePath);

// decompile the qvm version.
QUtils.qvmVersion = QUtils.ReadQVMVersion(fileName);
QUtils.AddLog($"appVersionTxt is {appVersionTxt.Text}");
InvokeIfNeeded(delegate ()

string qvmVersionText = QUtils.qvmVersion;
if (string.IsNullOrEmpty(qvmVersionText))
{
appVersionTxt.Text = "QVM Version: " + QUtils.qvmVersion.Replace("_", ".").Replace("v", "");
});
QUtils.AddLog($"QVM Version is {QUtils.qvmVersion}");
QUtils.AddLog($"appVersionTxt is {appVersionTxt.Text}");
QUtils.ShowError("Error reading QVM version from file.");
QUtils.AddLog("Error reading QVM version from file.");
}
QUtils.AddLog($"QVM Version before is {qvmVersionText}");
qvmVersionText = "QVM: " + qvmVersionText.Replace("_", ".").Replace("v", "");
QUtils.AddLog($"QVM Version after is {qvmVersionText}");

string fileNameText = Path.GetFileNameWithoutExtension(fileName) + QUtils.qvmFile;

UpdateUILabel(fileNameLabel, fileNameText);
UpdateUILabel(appVersionTxt, qvmVersionText);

QUtils.AddLog("Exiting method: DecompileQVM()");
}

Expand Down

0 comments on commit 03253a6

Please sign in to comment.