mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-09 01:52:32 +02:00
80a9adbcd0
- **Command line arguments:** - (Add) Convert files: UVtools.exe -c \<inputfile\> \<outputfile1/ext1\> [outputfile2/ext2] - (Add) Extract files: UVtools.exe -e \<inputfile\> [output_folder] - https://github.com/sn4k3/UVtools#command-line-arguments - **File formats:** - (Add) Implement TSMC (Two Stage Motor Control) for the supported formats - (Add) Implement 'Bottom retract speed' for the supported formats - (Add) LGS: Support for lgs120 and lg4k (#218) - (Add) CTB: Special/virtual file extensions .v2.ctb, .v3.ctb, .v4.ctb to force a convertion to the set version (2 to 4). The .ctb is Version 3 by default when creating/converting files - (Improvement) Better performance for file formats that decode images in sequential pixels groups - **GCode:** - (Improvement) Better parsing of the movements / lifts - (Improvement) Better handling of lifts performed after cure the layer - (Improvement) More fail-safe checks and sanitize of gcode while parsing - (Improvement) CTBv3: Enable per layer settings if disabled when fast save without reencode - (Upgrade) .NET from 5.0.8 to 5.0.9 - (Fix) PrusaSlicer printer: Longer Orange 4k with correct resolution and display size - (Fix) Odd error when changing properties too fast in multi-thread
152 lines
5.2 KiB
C#
152 lines
5.2 KiB
C#
/*
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE
|
|
* Version 3, 19 November 2007
|
|
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
* of this license document, but changing it is not allowed.
|
|
*/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using MoreLinq;
|
|
using UVtools.Core.FileFormats;
|
|
|
|
namespace UVtools.WPF
|
|
{
|
|
public static class ConsoleArguments
|
|
{
|
|
/// <summary>
|
|
/// Parse arguments from command line
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns>True if is a valid argument, otherwise false</returns>
|
|
public static bool ParseArgs(string[] args)
|
|
{
|
|
if(args is null || args.Length == 0) return false;
|
|
|
|
// Convert to other file
|
|
if (args[0] is "-c" or "--convert")
|
|
{
|
|
if (args.Length < 3)
|
|
{
|
|
Console.WriteLine("Invalid syntax: <input_file> <output_file1/ext1> [output_file2/ext2]");
|
|
return true;
|
|
}
|
|
if (!File.Exists(args[1]))
|
|
{
|
|
Console.WriteLine($"Input file does not exists: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
var slicerFile = FileFormat.FindByExtension(args[1], true, true);
|
|
if (slicerFile is null)
|
|
{
|
|
Console.WriteLine($"Invalid input file: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
|
|
var filenameNoExt = FileFormat.GetFileNameStripExtensions(args[1], out _);
|
|
|
|
var filesToConvert = new List<KeyValuePair<FileFormat, string>>();
|
|
|
|
for (int i = 2; i < args.Length; i++)
|
|
{
|
|
var outputFile = args[i];
|
|
var targetFormat = FileFormat.FindByExtension(args[i]);
|
|
if (targetFormat is not null)
|
|
{
|
|
outputFile = $"{filenameNoExt}.{args[i]}";
|
|
}
|
|
else
|
|
{
|
|
targetFormat = FileFormat.FindByExtension(args[i], true);
|
|
}
|
|
|
|
if (targetFormat is null)
|
|
{
|
|
Console.WriteLine($"Invalid output file/extension: {args[i]}");
|
|
continue;
|
|
}
|
|
|
|
filesToConvert.Add(new KeyValuePair<FileFormat, string>(targetFormat, outputFile));
|
|
}
|
|
|
|
if (filesToConvert.Count == 0)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//var workingDir = Path.GetDirectoryName(args[1]);
|
|
//if(!string.IsNullOrWhiteSpace(workingDir)) Directory.SetCurrentDirectory(workingDir);
|
|
|
|
Console.WriteLine($"Loading file: {args[1]}");
|
|
slicerFile.Decode(args[1]);
|
|
|
|
foreach (var (outputSlicerFile, outputFile) in filesToConvert.DistinctBy(pair => pair.Value))
|
|
{
|
|
Console.WriteLine($"Converting to: {outputFile}");
|
|
slicerFile.Convert(outputSlicerFile, outputFile);
|
|
Console.WriteLine("Converted");
|
|
|
|
}
|
|
|
|
Console.WriteLine("OK");
|
|
|
|
return true;
|
|
}
|
|
|
|
// Extract the file
|
|
if (args[0] is "-e" or "--extract")
|
|
{
|
|
if (args.Length < 2)
|
|
{
|
|
Console.WriteLine("Invalid syntax: <input_file> [output_folder]");
|
|
return true;
|
|
}
|
|
if (!File.Exists(args[1]))
|
|
{
|
|
Console.WriteLine($"Input file does not exists: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
var slicerFile = FileFormat.FindByExtension(args[1], true, true);
|
|
if (slicerFile is null)
|
|
{
|
|
Console.WriteLine($"Invalid input file: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
var outputFolder = FileFormat.GetFileNameStripExtensions(args[1], out _);
|
|
|
|
if (args.Length >= 3 && !string.IsNullOrWhiteSpace(args[2]))
|
|
{
|
|
try
|
|
{
|
|
Path.GetFullPath(outputFolder);
|
|
outputFolder = args[2];
|
|
}
|
|
catch (Exception)
|
|
{
|
|
Console.WriteLine($"Invalid output directory: {args[2]}");
|
|
return true;
|
|
}
|
|
}
|
|
|
|
//var workingDir = Path.GetDirectoryName(args[1]);
|
|
//if(!string.IsNullOrWhiteSpace(workingDir)) Directory.SetCurrentDirectory(workingDir);
|
|
|
|
Console.WriteLine($"Loading file: {args[1]}");
|
|
slicerFile.Decode(args[1]);
|
|
Console.WriteLine($"Extracting to: {outputFolder}");
|
|
slicerFile.Extract(outputFolder);
|
|
Console.WriteLine("Extracted");
|
|
Console.WriteLine("OK");
|
|
return true;
|
|
}
|
|
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |