From 02c2acac9d48d3fc3176867c298720a7ff332d8f Mon Sep 17 00:00:00 2001 From: Dobin Rutishauser Date: Sun, 5 Nov 2023 19:52:19 +0100 Subject: [PATCH] fix: reading results from waasa.json file bug --- waasa/Models/Common.cs | 12 +++++++----- waasa/Services/Io.cs | 18 +++++++++--------- waasa/Services/Requestor.cs | 12 ++++++------ waasa/UI/MainWindow.xaml.cs | 9 ++++++--- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/waasa/Models/Common.cs b/waasa/Models/Common.cs index cf1099d..a3dea03 100644 --- a/waasa/Models/Common.cs +++ b/waasa/Models/Common.cs @@ -1,6 +1,7 @@ using System.Windows.Documents; using waasa.Services; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace waasa.Models { @@ -39,11 +40,6 @@ public class _FileExtension { public string Description { get; set; } = ""; public List Tags { get; set; } = new List(); - - public _FileExtension(string extension) { - Extension = extension.ToLower(); - } - // Pointer to source public Winapi.WinapiEntry WinApiEntry { get; set; } = new Winapi.WinapiEntry(); @@ -53,8 +49,14 @@ public _FileExtension(string extension) { new TestResult(), new TestResult() }; + public string TestResult { get; set; } = ""; + + public _FileExtension(string extension) { + Extension = extension.ToLower(); + } + public void SetCmd(string cmd) { this.CmdLine = cmd; var res = CmdParser.CommandLineToResult(cmd); diff --git a/waasa/Services/Io.cs b/waasa/Services/Io.cs index fc5979e..dafaa50 100644 --- a/waasa/Services/Io.cs +++ b/waasa/Services/Io.cs @@ -22,6 +22,7 @@ class Io { static public List<_FileExtension> ReadResultJson(string filepath) { if (!File.Exists(filepath)) { + Log.Warning("File does not exist: " + filepath); return new List<_FileExtension>(); } @@ -31,6 +32,14 @@ static public List<_FileExtension> ReadResultJson(string filepath) { return fileExtensions; } + static public void WriteResultJson(List<_FileExtension> fileExtensions, string filepath) { + Log.Information("Writing JSON to: " + filepath + " with " + fileExtensions.Count); + using (StreamWriter writer = new StreamWriter(filepath)) { + string strJson = JsonSerializer.Serialize(fileExtensions); + writer.WriteLine(strJson); + } + } + static public void ExecFile(string extension) { string filepath = System.Environment.GetEnvironmentVariable("TEMP") + "\\test" + extension; @@ -47,15 +56,6 @@ static public void OpenDir(string dir) { } - static public void WriteResultJson(List<_FileExtension> fileExtensions, string filepath) { - Log.Information("Writing JSON to: " + filepath + " with " + fileExtensions.Count); - using (StreamWriter writer = new StreamWriter(filepath)) { - string strJson = JsonSerializer.Serialize(fileExtensions); - writer.WriteLine(strJson); - } - } - - static public _GatheredData GatherDataFromSystem() { var gather = new Gatherer(); var gatheredData = gather.GatherAll(); diff --git a/waasa/Services/Requestor.cs b/waasa/Services/Requestor.cs index a8e81d2..97218b3 100644 --- a/waasa/Services/Requestor.cs +++ b/waasa/Services/Requestor.cs @@ -12,18 +12,18 @@ namespace waasa.Services { public class HttpAnswerInfo { - public string Filename { get; set; } = ""; - public bool HashCheck { get; set; } = false; - public bool IsRealFile { get; set; } = false; - public string HttpRequest { get; set; } = ""; public string HttpResponse { get; set; } = ""; public int HttpResponseStatusCode { get; set; } = 0; - public HttpAnswerInfo(string httpRequest, string httpResponse, int statusCode, string filename, bool hashCheck, bool isRealFile) { + public string Filename { get; set; } = ""; + public bool HashCheck { get; set; } = false; + public bool IsRealFile { get; set; } = false; + + public HttpAnswerInfo(string httpRequest, string httpResponse, int httpResponseStatusCode, string filename, bool hashCheck, bool isRealFile) { HttpRequest = httpRequest; HttpResponse = httpResponse; - HttpResponseStatusCode = statusCode; + HttpResponseStatusCode = httpResponseStatusCode; Filename = filename; HashCheck = hashCheck; IsRealFile = isRealFile; diff --git a/waasa/UI/MainWindow.xaml.cs b/waasa/UI/MainWindow.xaml.cs index 59d11c3..804c81e 100644 --- a/waasa/UI/MainWindow.xaml.cs +++ b/waasa/UI/MainWindow.xaml.cs @@ -100,9 +100,12 @@ public MainWindow() { FileExtensions = analyzer.getResolvedFileExtensions(); UpdateStatus("Autoloaded file with gathered data: gathered_data.json"); } else { - Log.Information("Loading from file: " + "waasa.json"); - FileExtensions = Io.ReadResultJson("waasa.json"); - UpdateStatus("Autoloaded file with results: waasa.json"); + var filename = "waasa.json"; + if (File.Exists(filename)) { + Log.Information("Loading from file: " + filename); + FileExtensions = Io.ReadResultJson(filename); + UpdateStatus("Autoloaded file with results: " + filename); + } } MyInit();