Skip to content

Commit a426633

Browse files
committed
Added More logs
1 parent e5327df commit a426633

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

QVMEditor/QUtils.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ namespace QVM_Editor
1515
internal class QUtils
1616
{
1717
private static string logFile;
18-
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";
18+
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";
1919
internal static bool logEnabled = false;
20-
internal static string appdataPath, qvmEditorQEdPath, objectsModelsFile, editorAppName, qfilesPath = @"\QFiles", qEditor = "QEditor", qconv = "QConv", qCompiler = "QCompiler", qCompilerPath, tempPathFile,tempPathFileName = "TempPath.txt",
20+
internal static string appdataPath, qvmEditorQEdPath, objectsModelsFile, editorAppName, qfilesPath = @"\QFiles", qEditor = "QEditor", qconv = "QConv", qCompiler = "QCompiler", qCompilerPath, tempPathFile, tempPathFileName = "TempPath.txt",
2121
igiQsc = "IGI_QSC", igiQvm = "IGI_QVM", cfgGamePathEx = @"\missions\location0\level", weaponsDirPath = @"\weapons";
2222
internal static string keywordsFile = "keywords.txt", objectsQsc = "objects.qsc", objectsQvm = "objects.qvm";
2323

@@ -126,7 +126,7 @@ internal static bool InitEditorAppData()
126126
else if (!Directory.Exists(qCompilerPath)) { initErrReason = @"QEditor\QCompiler"; initStatus = false; }
127127

128128
initErrReason = "'" + initErrReason + "' Directory is missing";
129-
129+
130130
//Show error if 'QEditor' path has invalid structure..
131131
if (!initStatus)
132132
{
@@ -221,6 +221,19 @@ internal static void AddLog(string methodName, string logMsg)
221221
}
222222
}
223223

224+
internal static void AddLog(string logMsg)
225+
{
226+
if (logEnabled)
227+
{
228+
var methodName = new StackTrace().GetFrame(1).GetMethod().Name
229+
.Replace("_Click", "")
230+
.Replace("_SelectedIndexChanged", "")
231+
.Replace("_SelectedValueChanged", "");
232+
233+
File.AppendAllText(logFile, "[" + DateTime.Now.ToString("yyyy-MM-dd - HH:mm:ss") + "] " + methodName + "(): " + logMsg + "\n");
234+
}
235+
}
236+
224237
internal static void SaveFile(string data = null, bool appendData = false, string qscFile = "objects.qsc")
225238
{
226239
SaveFile(qscFile, data, appendData);

QVMEditor/QVMEditorForm.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public QVMEditorForm()
2626
qvmInstance = this;
2727
QUtils.InitEditorAppData();
2828
appVersionTxt.Text = "Version: " + QUtils.appVersion;
29+
QUtils.enableLogs = true;
2930

31+
QUtils.AddLog("QVM Editor Started.");
3032
// Init Scintilla component.
3133
scintilla = new StandardScintilla();
3234
TextPanel.Controls.Add(scintilla);
@@ -36,18 +38,21 @@ public QVMEditorForm()
3638
QUtils.appOutPath = QUtils.LoadFile(QUtils.tempPathFile);
3739
if (!String.IsNullOrEmpty(QUtils.appOutPath))
3840
{
41+
QUtils.AddLog("Output path loaded: " + QUtils.appOutPath);
3942
}
4043

4144
//Setting output path.
4245
else
4346
{
4447
QUtils.appOutPath = QUtils.qCompilerPath + @"\Decompile\output\";
4548
QUtils.SaveFile(QUtils.tempPathFile, QUtils.appOutPath);
49+
QUtils.AddLog("Output path set to default: " + QUtils.appOutPath);
4650
}
4751

4852
//Decompile the QVM File for Args (CLI).
4953
if (!String.IsNullOrEmpty(openFileName))
5054
{
55+
QUtils.AddLog("Decompiling QVM File: " + openFileName);
5156
DecompileQVM(openFileName);
5257
}
5358
}
@@ -907,13 +912,13 @@ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
907912
string scriptFileQvm = scriptFilePathAbsolute + "\\" + fileNameLabel.Text;
908913
string scriptFileQsc = fileNameLabel.Text.Replace(QUtils.qvmFile, QUtils.qscFile);
909914
string scriptData = scintilla.Text;
910-
915+
QUtils.AddLog("Saving file: " + scriptFileQsc + " scriptFileQvm: " + scriptFileQvm) + " scriptData: " + scriptData;
911916
bool status = QCompiler.Compile(scriptData, scriptFilePathAbsolute, false, fileNameLabel.Text.Replace(QUtils.qvmFile, QUtils.qscFile));
912917

913918
if (status)
914919
{
915920
QUtils.FileIODelete(scriptFileQsc);
916-
//fileNameLabel.Text = "File saved successfully";
921+
QUtils.AddLog("File saved successfully");
917922
}
918923
}
919924

@@ -924,11 +929,14 @@ private void exitToolStripMenuItem_Click(object sender, EventArgs e)
924929

925930
private void DecompileQVM(string fileName)
926931
{
932+
QUtils.AddLog("Decompiling file: " + fileName);
927933
QCompiler.DecompileFile(fileName, QUtils.appOutPath);
934+
QUtils.AddLog("Decompiling done");
928935

929936
scriptFilePath = QUtils.appOutPath + Path.DirectorySeparatorChar + Path.GetFileName(fileName).Replace(QUtils.qvmFile, QUtils.qscFile);
930937
fileNameLabel.Text = Path.GetFileNameWithoutExtension(fileName) + QUtils.qvmFile;
931938
scintilla.Text = QUtils.LoadFile(scriptFilePath);
939+
QUtils.AddLog("Files path are {scriptFilePath} {fileNameLabel.Text}");
932940
}
933941

934942
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)

0 commit comments

Comments
 (0)