Skip to content

Commit

Permalink
v3.14.3
Browse files Browse the repository at this point in the history
- **Settings:**
  - (Add) After save the file replace on it name with the updated print time and material if possible
  - (Add) File 'Save as' default name with extended variables (#725)
  - (Add) File 'Save as' name cleanup regex
  - (Add) When save as a file and if the file name already exists on that directory it will append a number up to one available
  - (Remove) File 'Save as' suffix and prefix
- (Add) About: Graphic card name
- (Fix) CTB Encrypted: Check the checksum as last step to be compatible with new Chitubox 1.4.5 CTB files (#696, #726)
  • Loading branch information
sn4k3 committed Jun 11, 2023
1 parent 92fb2bc commit 4e0e1e2
Show file tree
Hide file tree
Showing 36 changed files with 499 additions and 219 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 11/06/2023 - v3.14.3

- **Settings:**
- (Add) After save the file replace on it name with the updated print time and material if possible
- (Add) File 'Save as' default name with extended variables (#725)
- (Add) File 'Save as' name cleanup regex
- (Add) When save as a file and if the file name already exists on that directory it will append a number up to one available
- (Remove) File 'Save as' suffix and prefix
- (Add) About: Graphic card name
- (Fix) CTB Encrypted: Check the checksum as last step to be compatible with new Chitubox 1.4.5 CTB files (#696, #726)

## 07/06/2023 - v3.14.2

- **PrusaSlicer printers:**
Expand Down Expand Up @@ -232,7 +243,7 @@
- First parameter is the first request to get response content from
- Second parameter is the regex pattern to match content with
- Third parameter is the final request that supports a parameter from regex matching group, eg: **{#1}** is match Group[1] value
- **Example:** <\? getfiles > {0}\/(\d+\.[\da-zA-Z]+), > printfile,{#1} ?>
- **Example:** <\? getfiles > {0}\/([0-9]+[.][0-9a-zA-Z]+), > printfile,{#1} ?>
- (Change) Allow to print a filename without send it when upload request path is empty
- (Fix) Do not show printers with empty requests
- (Change) Default layer compression to Lz4 instead of Png
Expand Down
13 changes: 8 additions & 5 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
- **PrusaSlicer printers:**
- (Add) Elegoo Mars 4 Ultra
- (Add) Elegoo Saturn 3
- (Add) Elegoo Saturn 3 Ultra
- (Fix) AnyCubic file format: Retract speed (slow/fast) variables was swapped (#722)
- **Settings:**
- (Add) After save the file replace on it name with the updated print time and material if possible
- (Add) File 'Save as' default name with extended variables (#725)
- (Add) File 'Save as' name cleanup regex
- (Add) When save as a file and if the file name already exists on that directory it will append a number up to one available
- (Remove) File 'Save as' suffix and prefix
- (Add) About: Graphic card name
- (Fix) CTB Encrypted: Check the checksum as last step to be compatible with new Chitubox 1.4.5 CTB files (#696, #726)

6 changes: 4 additions & 2 deletions Scripts/010 Editor/ctb_encrypted.bt
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ struct PREVIEW {

PREVIEW SmallPreview;

local ushort machineNameLength = 1;
local ushort machineNameLength = 0;
while (ReadString(FTell()+machineNameLength, 17 ) != "Layout and record") {
machineNameLength++;
if(machineNameLength > 255) return;
}

char MachineName[machineNameLength] <fgcolor=cBlack, bgcolor=cYellow>;
if(machineNameLength > 0){
char MachineName[machineNameLength] <fgcolor=cBlack, bgcolor=cYellow>;
}

char Disclaimer[320] <fgcolor=cBlack, bgcolor=cPurple>;

Expand Down
10 changes: 5 additions & 5 deletions Scripts/install-uvtools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ if [ "$arch" != "x86_64" -a "$arch" != "arm64" ]; then
fi

# Tag validation
if [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [[ "$tag" =~ ^v[0-9]+[.][0-9]+[.][0-9]+$ ]]; then
api_url="https://api.github.com/repos/sn4k3/UVtools/releases/tags/$tag"
elif [[ "$tag" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
elif [[ "$tag" =~ ^[0-9]+[.][0-9]+[.][0-9]+$ ]]; then
api_url="https://api.github.com/repos/sn4k3/UVtools/releases/tags/v$tag"
elif [ "$tag" != "latest" -a -n "$tag" ]; then
echo "Error: Invalid '$tag' tag/version was provided."
Expand Down Expand Up @@ -132,7 +132,7 @@ if [ "$osVariant" == "osx" ]; then
echo '- Detecting download'

download_url="$(curl -s "$api_url" \
| grep "browser_download_url.*_${osVariant}-${archCode}_.*\.zip" \
| grep "browser_download_url.*_${osVariant}-${archCode}_.*[.]zip" \
| head -1 \
| cut -d : -f 2,3 \
| tr -d \")"
Expand Down Expand Up @@ -210,14 +210,14 @@ else
response="$(curl -s "$api_url")"

download_url="$(echo "$response" \
| grep "browser_download_url.*_${osVariant}-x64_.*\.AppImage" \
| grep "browser_download_url.*_${osVariant}-x64_.*[.]AppImage" \
| head -1 \
| cut -d : -f 2,3 \
| tr -d \")"

if [ -z "$download_url" ]; then
download_url="$(echo "$response" \
| grep "browser_download_url.*_linux-x64_.*\.AppImage" \
| grep "browser_download_url.*_linux-x64_.*[.]AppImage" \
| head -1 \
| cut -d : -f 2,3 \
| tr -d \")"
Expand Down
2 changes: 1 addition & 1 deletion UVtools.Core/Excellon/ExcellonDrillFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private void Load(string filePath)
{
if (!endOfHeader)
{
var match = Regex.Match(line, @"^T(\d+)C(([0-9]*[.])?[0-9]+)");
var match = Regex.Match(line, @"^T([0-9]+)C(([0-9]*[.])?[0-9]+)");
if (match is
{
Success: true,
Expand Down
10 changes: 5 additions & 5 deletions UVtools.Core/Extensions/SizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class SizeExtensions
public static readonly string[] SizeSuffixes =
{ "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };

public static string SizeSuffix(long value, byte decimalPlaces = 2)
public static string SizeSuffix(long value, byte decimalPlaces = 2, bool suffixSpaced = true)
{
//if (decimalPlaces < 0) { throw new ArgumentOutOfRangeException("decimalPlaces"); }
if (value < 0) { return "-" + SizeSuffix(-value); }
Expand All @@ -30,17 +30,17 @@ public static string SizeSuffix(long value, byte decimalPlaces = 2)

// make adjustment when the value is large enough that
// it would round up to 1000 or more
if (Math.Round(adjustedSize, decimalPlaces) >= 1000)
if (Math.Round(adjustedSize, decimalPlaces, MidpointRounding.AwayFromZero) >= 1000)
{
mag += 1;
adjustedSize /= 1024;
}

return string.Format("{0:n" + decimalPlaces + "} {1}",
adjustedSize,
SizeSuffixes[mag]);
return string.Format($"{{0:n{decimalPlaces}}}{(suffixSpaced ? ' ' : string.Empty)}{SizeSuffixes[mag]}", adjustedSize);
}

public static string SizeSuffix(long value, bool suffixSpaced) => SizeSuffix(value, 2, suffixSpaced);

public static Size Add(this Size size, Size otherSize) => new (size.Width + otherSize.Width, size.Height + otherSize.Height);
public static Size Add(this Size size) => size.Add(size);
public static Size Add(this Size size, int pixels) => new (size.Width + pixels, size.Height + pixels);
Expand Down
14 changes: 10 additions & 4 deletions UVtools.Core/FileFormats/CTBEncryptedFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,12 +1110,13 @@ protected override void DecodeInternally(OperationProgress progress)
var checksumHash = CryptExtensions.ComputeSHA256Hash(checksumBytes);
var encryptedHash = CryptExtensions.AesCryptBytes(checksumHash, Bigfoot, CipherMode.CBC, PaddingMode.None, true, CookieMonster);

inputFile.Seek(-HASH_LENGTH, SeekOrigin.End);
// Does not work with recent Chitubox 1.4.5
/*inputFile.Seek(-HASH_LENGTH, SeekOrigin.End);
var hash = inputFile.ReadBytes(HASH_LENGTH);
if (!hash.SequenceEqual(encryptedHash))
if (!hash.SequenceEqual(encryptedHash))
{
throw new FileLoadException("The file checksum does not match, malformed file.", FileFullPath);
}
}*/

progress.Reset(OperationProgress.StatusDecodePreviews, ThumbnailsCount);

Expand Down Expand Up @@ -1264,7 +1265,12 @@ protected override void DecodeInternally(OperationProgress progress)
"Please increase the portion of the plate in use and re-slice the file.");
}
}
//inputFile.ReadBytes(HashLength);

var hash = inputFile.ReadBytes(HASH_LENGTH);
if (!hash.SequenceEqual(encryptedHash))
{
throw new FileLoadException("The file checksum does not match, malformed file.", FileFullPath);
}
}

protected override void OnBeforeEncode(bool isPartialEncode)
Expand Down
2 changes: 1 addition & 1 deletion UVtools.Core/FileFormats/CWSFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ protected override void DecodeInternally(OperationProgress progress)
foreach (var pngEntry in inputFile.Entries)
{
if (!pngEntry.Name.EndsWith(".png")) continue;
var match = Regex.Match(pngEntry.Name, @"(\d+).png");
var match = Regex.Match(pngEntry.Name, @"([0-9]+)[.]png$");
if (!match.Success || match.Groups.Count < 2) continue;
if (!uint.TryParse(match.Groups[1].Value, out var layerIndex)) continue;

Expand Down
2 changes: 1 addition & 1 deletion UVtools.Core/FileFormats/CXDLPFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ public override string MachineName
if (!string.IsNullOrWhiteSpace(value) && !value.StartsWith("CL-") && !value.StartsWith("CT-"))
{
// Parse from machine name, if coming from PrusaSlicer this will help
var match = Regex.Match(value, @"(CL|CT)-?\d+[a-zA-Z]?");
var match = Regex.Match(value, @"(CL|CT)-?[0-9]+[a-zA-Z]?");
if (match is {Success: true, Groups.Count: > 1})
{
value = match.Value;
Expand Down
91 changes: 77 additions & 14 deletions UVtools.Core/FileFormats/FileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
using UVtools.Core.Objects;
using UVtools.Core.Operations;
using UVtools.Core.PixelEditor;
using Range = System.Range;

namespace UVtools.Core.FileFormats;

Expand Down Expand Up @@ -984,6 +983,9 @@ public static int MutateGetIterationChamfer(uint layerIndex, uint startLayerInde
#region Members
public object Mutex = new();

private string? _fileFullPath;


protected Layer[] _layers = Array.Empty<Layer>();

private bool _haveModifiedLayers;
Expand Down Expand Up @@ -1166,11 +1168,34 @@ public string FileFilterExtensionsOnly
/// <summary>
/// Gets the input file path loaded into this <see cref="FileFormat"/>
/// </summary>
public string? FileFullPath { get; set; }
public string? FileFullPath
{
get => _fileFullPath;
set
{
if(!RaiseAndSetIfChanged(ref _fileFullPath, value)) return;
RaisePropertyChanged(DirectoryPath);
RaisePropertyChanged(Filename);
RaisePropertyChanged(FilenameNoExt);
RaisePropertyChanged(FilenameStripExtensions);
RaisePropertyChanged(FileExtension);
RaisePropertyChanged(FileAbsoluteExtension);
}
}

public string? DirectoryPath => Path.GetDirectoryName(FileFullPath);
public string? Filename => Path.GetFileName(FileFullPath);

/// <summary>
/// Returns the file name without the extension
/// </summary>
public string? FilenameNoExt => GetFileNameStripExtensions(FileFullPath);

/// <summary>
/// Returns the file name without the extension(s)
/// </summary>
public string? FilenameStripExtensions => FileFullPath is null ? null : GetFileNameStripExtensions(FileFullPath, out _);

/// <summary>
/// Returns the file extension. The returned value includes the period (".") character of the
/// extension except when you have a terminal period when you get string.Empty, such as ".exe" or ".cpp".
Expand All @@ -1180,9 +1205,20 @@ public string FileFilterExtensionsOnly
public string? FileExtension => Path.GetExtension(FileFullPath);

/// <summary>
/// Returns the file name without the extension
/// Returns the file extension as safe method where it can include more than one extension. The returned value includes the period (".") character of the
/// extension except when you have a terminal period when you get string.Empty, such as ".exe" or ".cpp".
/// The returned value is null if the given path is null or empty if the given path does not include an
/// extension.
/// </summary>
public string? FilenameNoExt => GetFileNameStripExtensions(FileFullPath);
public string? FileAbsoluteExtension
{
get
{
if(FileFullPath is null) return null;
GetFileNameStripExtensions(FileFullPath, out var ext);
return ext;
}
}

/// <summary>
/// Gets the available versions to set in this file format
Expand Down Expand Up @@ -1851,7 +1887,6 @@ public virtual byte AntiAliasing
/// </summary>
public ushort LayerHeightUm => (ushort) (LayerHeight * 1000);


/// <summary>
/// Gets or sets the print height in mm
/// </summary>
Expand Down Expand Up @@ -2955,6 +2990,7 @@ public virtual float MaterialMilliliters {
}

if(!RaiseAndSetIfChanged(ref _materialMilliliters, value)) return;
RaisePropertyChanged(nameof(MaterialMillilitersInteger));

if (StartingMaterialMilliliters > 0 && StartingMaterialCost > 0)
{
Expand All @@ -2964,12 +3000,17 @@ public virtual float MaterialMilliliters {
}
}

/// <summary>
/// Gets the estimate used material in ml and rounded to next integer
/// </summary>
public uint MaterialMillilitersInteger => (uint)Math.Ceiling(MaterialMilliliters);

//public float MaterialMillilitersComputed =>


/// <summary>
/// Gets the estimate material in grams
/// </summary>
/// <summary>
/// Gets the estimate material in grams
/// </summary>
public virtual float MaterialGrams
{
get => _materialGrams;
Expand Down Expand Up @@ -3160,7 +3201,7 @@ public Layer this[long index]
set => SetLayer((uint)index, value);
}

public Layer[] this[Range range] => _layers[range];
public Layer[] this[System.Range range] => _layers[range];

/// <summary>
/// Sets a layer
Expand Down Expand Up @@ -3343,6 +3384,28 @@ public bool FileEndsWith(string extension)
FileFullPath.EndsWith($"{extension}{TemporaryFileAppend}", StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Renames the current file with a new name in the same directory.
/// </summary>
/// <param name="newFileName">New filename without the extension</param>
/// <param name="overwrite">True to overwrite file if exists, otherwise false</param>
/// <returns>True if renamed, otherwise false.</returns>
public bool RenameFile(string newFileName, bool overwrite = false)
{
if(string.IsNullOrWhiteSpace(newFileName)) return false;
if (!File.Exists(FileFullPath)) return false;

var filename = GetFileNameStripExtensions(FileFullPath, out var ext);

if (string.Equals(filename, newFileName, StringComparison.Ordinal)) return false;

var newFileFullPath = Path.Combine(DirectoryPath!, $"{newFileName}.{ext}");
File.Move(FileFullPath, newFileFullPath, overwrite);
FileFullPath = newFileFullPath;

return true;
}

/// <summary>
/// Gets a thumbnail by it height or lower
/// </summary>
Expand Down Expand Up @@ -3910,20 +3973,20 @@ public void DecodeLayersFromZipRegex(ZipArchive zipArchive, string regex, IndexS
}

public void DecodeLayersFromZip(ZipArchive zipArchive, byte padDigits, IndexStartNumber layerIndexStartNumber = IndexStartNumber.Zero, OperationProgress? progress = null, Func<uint, byte[], Mat>? matGenFunc = null)
=> DecodeLayersFromZipRegex(zipArchive, $@"(\d{{{padDigits}}}).png$", layerIndexStartNumber, progress, matGenFunc);
=> DecodeLayersFromZipRegex(zipArchive, @$"([0-9]{{{padDigits}}})[.]png$", layerIndexStartNumber, progress, matGenFunc);

public void DecodeLayersFromZip(ZipArchive zipArchive, string prepend, IndexStartNumber layerIndexStartNumber = IndexStartNumber.Zero, OperationProgress? progress = null, Func<uint, byte[], Mat>? matGenFunc = null)
=> DecodeLayersFromZipRegex(zipArchive, $@"^{Regex.Escape(prepend)}(\d+).png$", layerIndexStartNumber, progress, matGenFunc);
=> DecodeLayersFromZipRegex(zipArchive, @$"^{Regex.Escape(prepend)}([0-9]+)[.]png$", layerIndexStartNumber, progress, matGenFunc);

public void DecodeLayersFromZip(ZipArchive zipArchive, IndexStartNumber layerIndexStartNumber = IndexStartNumber.Zero, OperationProgress? progress = null, Func<uint, byte[], Mat>? matGenFunc = null)
=> DecodeLayersFromZipRegex(zipArchive, @"^(\d+).png$", layerIndexStartNumber, progress, matGenFunc);
=> DecodeLayersFromZipRegex(zipArchive, @"^([0-9]+)[.]png$", layerIndexStartNumber, progress, matGenFunc);

public void DecodeLayersFromZip(ZipArchive zipArchive, OperationProgress progress, Func<uint, byte[], Mat>? matGenFunc = null)
=> DecodeLayersFromZipRegex(zipArchive, @"^(\d+).png$", IndexStartNumber.Zero, progress, matGenFunc);
=> DecodeLayersFromZipRegex(zipArchive, @"^([0-9]+)[.]png$", IndexStartNumber.Zero, progress, matGenFunc);

public void DecodeLayersFromZipIgnoreFilename(ZipArchive zipArchive, IndexStartNumber layerIndexStartNumber = IndexStartNumber.Zero, OperationProgress? progress = null, Func<uint, byte[], Mat>? matGenFunc = null)
{
DecodeLayersFromZipRegex(zipArchive, @$"({@"\d?".Repeat(LayerDigits - 1)}\d).png$", layerIndexStartNumber, progress, matGenFunc);
DecodeLayersFromZipRegex(zipArchive, @$"([0-9]{{1,{LayerDigits}}})[.]png$", layerIndexStartNumber, progress, matGenFunc);
}

public void DecodeLayersFromZipIgnoreFilename(ZipArchive zipArchive, OperationProgress progress, Func<uint, byte[], Mat>? matGenFunc = null)
Expand Down
4 changes: 2 additions & 2 deletions UVtools.Core/FileFormats/JXSFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private void RebuildFileProperties()

if (line.StartsWith(GCode.CommandShowImageM6054.Command))
{
var match = Regex.Match(line, GCode.GetShowImageString(@"(\d+)"));
var match = Regex.Match(line, GCode.GetShowImageString(@"([0-9]+)"));

if (!match.Success || match.Groups.Count <= 1)
{
Expand All @@ -383,7 +383,7 @@ private void RebuildFileProperties()

if (line.StartsWith(GCode.CommandWaitG4.Command))
{
var match = Regex.Match(line, GCode.CommandWaitG4.ToStringWithoutComments(@"(\d+)"));
var match = Regex.Match(line, GCode.CommandWaitG4.ToStringWithoutComments(@"([0-9]+)"));

if (!match.Success || match.Groups.Count <= 1)
{
Expand Down
Loading

0 comments on commit 4e0e1e2

Please sign in to comment.