From 9bf950125865947b167a228e6a2da86a6be1d81d Mon Sep 17 00:00:00 2001 From: JT Date: Sat, 16 Dec 2023 21:28:01 -0800 Subject: [PATCH] Fix UTF8 encoding including the BOM --- CHANGELOG.md | 4 +++ .../Models/FileInterfaces/FilePath.cs | 25 ++++++------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef2412c8..97b974e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to Stability Matrix will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html). +## v2.7.3 +### Fixed +- Fixed UnicodeDecodeError when using extra_model_paths.yaml in ComfyUI on certain locales + ## v2.7.2 ### Changed - Changed Symlink shared folder link targets for Automatic1111 and ComfyUI. From `ControlNet -> models/controlnet` to `ControlNet -> models/controlnet/ControlNet` and `T2IAdapter -> models/controlnet/T2IAdapter`. diff --git a/StabilityMatrix.Core/Models/FileInterfaces/FilePath.cs b/StabilityMatrix.Core/Models/FileInterfaces/FilePath.cs index a083fba6..494e3aa5 100644 --- a/StabilityMatrix.Core/Models/FileInterfaces/FilePath.cs +++ b/StabilityMatrix.Core/Models/FileInterfaces/FilePath.cs @@ -113,12 +113,13 @@ public partial class FilePath : FileSystemPath, IPathObject } /// Write text - public void WriteAllText(string text) => File.WriteAllText(FullPath, text, Encoding.UTF8); + public void WriteAllText(string text, Encoding? encoding = null) => + File.WriteAllText(FullPath, text, encoding ?? new UTF8Encoding(false)); /// Write text asynchronously - public Task WriteAllTextAsync(string text, CancellationToken ct = default) + public Task WriteAllTextAsync(string text, CancellationToken ct = default, Encoding? encoding = null) { - return File.WriteAllTextAsync(FullPath, text, Encoding.UTF8, ct); + return File.WriteAllTextAsync(FullPath, text, encoding ?? new UTF8Encoding(false), ct); } /// Read bytes @@ -144,19 +145,14 @@ public partial class FilePath : FileSystemPath, IPathObject /// public FilePath Rename(string fileName) { - if ( - Path.GetDirectoryName(FullPath) is { } directory - && !string.IsNullOrWhiteSpace(directory) - ) + if (Path.GetDirectoryName(FullPath) is { } directory && !string.IsNullOrWhiteSpace(directory)) { var target = Path.Combine(directory, fileName); Info.MoveTo(target, true); return new FilePath(target); } - throw new InvalidOperationException( - "Cannot rename a file path that is empty or has no directory" - ); + throw new InvalidOperationException("Cannot rename a file path that is empty or has no directory"); } /// @@ -193,10 +189,7 @@ public partial class FilePath : FileSystemPath, IPathObject /// Move the file to a target path with auto increment if the file already exists. /// /// The new path, possibly with incremented file name - public async Task MoveToWithIncrementAsync( - FilePath destinationFile, - int maxTries = 100 - ) + public async Task MoveToWithIncrementAsync(FilePath destinationFile, int maxTries = 100) { await Task.Yield(); @@ -214,9 +207,7 @@ public partial class FilePath : FileSystemPath, IPathObject ); } - throw new IOException( - $"Could not move file to {destinationFile} because it already exists." - ); + throw new IOException($"Could not move file to {destinationFile} because it already exists."); } ///