Skip to content

Commit

Permalink
fix: reading results from waasa.json file bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dobin committed Nov 5, 2023
1 parent fb48eaa commit 02c2aca
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
12 changes: 7 additions & 5 deletions waasa/Models/Common.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Windows.Documents;
using waasa.Services;
using System.Collections.Generic;
using System.Text.Json.Serialization;


namespace waasa.Models {
Expand Down Expand Up @@ -39,11 +40,6 @@ public class _FileExtension {
public string Description { get; set; } = "";
public List<string> Tags { get; set; } = new List<string>();


public _FileExtension(string extension) {
Extension = extension.ToLower();
}

// Pointer to source
public Winapi.WinapiEntry WinApiEntry { get; set; } = new Winapi.WinapiEntry();

Expand All @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions waasa/Services/Io.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
}

Expand All @@ -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;
Expand All @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions waasa/Services/Requestor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions waasa/UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 02c2aca

Please sign in to comment.