Skip to content

Commit 9643c32

Browse files
committed
validate input file extension for current import format, fix null ref if json log enabled and cancelled conversion in gui
1 parent 2ed4a0b commit 9643c32

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

MainWindow.xaml.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,11 @@ private static async Task ProcessAllFiles(object workerParamsObject)
447447
Interlocked.Increment(ref errorCounter); // thread-safe error counter increment
448448
if (importSettings.useJSONLog)
449449
{
450-
//Trace.WriteLine("useJSONLoguseJSONLoguseJSONLoguseJSONLog");
451-
Log.Write("{\"event\": \"" + LogEvent.File + "\", \"path\": " + System.Text.Json.JsonSerializer.Serialize(importSettings.inputFiles[i]) + ", \"status\": \"" + LogStatus.Processing + "\"}", LogEvent.Error);
450+
// if canceled, we dont want to log this (causes nullref)
451+
if (cancellationToken.IsCancellationRequested == false)
452+
{
453+
Log.Write("{\"event\": \"" + LogEvent.File + "\", \"path\": " + System.Text.Json.JsonSerializer.Serialize(importSettings.inputFiles[i]) + ", \"status\": \"" + LogStatus.Processing + "\"}", LogEvent.Error);
454+
}
452455
}
453456
else
454457
{

Tools/ArgParser.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,38 @@ public static ImportSettings Parse(string[] args, string rootFolder, ILogger log
922922
importSettings.errors.Add("No export format defined (Example: -exportformat" + argValueSeparator + "PCROOT)");
923923
}
924924

925+
// check that files are in correct format
926+
if (importSettings.inputFiles != null && importSettings.inputFiles.Count > 0)
927+
{
928+
var currentExtension = importSettings.importFormat.ToString().ToLower();
929+
bool wrongExtension = false;
930+
931+
for (int i = 0; i < importSettings.inputFiles.Count; i++)
932+
{
933+
var ext = Path.GetExtension(importSettings.inputFiles[i]).ToLower();
934+
935+
if (currentExtension == "las")
936+
{
937+
if (ext != ".las" && ext != ".laz")
938+
{
939+
wrongExtension = true;
940+
break;
941+
}
942+
}
943+
else if (currentExtension == "ply")
944+
{
945+
if (ext != ".ply")
946+
{
947+
wrongExtension = true;
948+
break;
949+
}
950+
}
951+
}
952+
953+
if (wrongExtension) importSettings.errors.Add("Input files are not in the selected format (" + importSettings.importFormat + ")");
954+
}
955+
956+
925957
// cannot have both rgb & intensity
926958
//if (importSettings.importRGB == true && importSettings.importIntensity == true)
927959
//{

0 commit comments

Comments
 (0)