From d7f2391fe8859e83225c8719cc22b4f347cebe06 Mon Sep 17 00:00:00 2001 From: Creeper Lv Date: Mon, 23 Mar 2026 00:34:18 +1100 Subject: [PATCH] ClassicStorageProvider will now being used as much as possible to support setting output directory to anywhere. --- Progrart.Core/ProjectSystem/Builder.cs | 23 +++++++++++++++---- .../Core/Storage/AvaloniaStorageProvider.cs | 7 ++++++ Progrart/Views/MainView.axaml.cs | 11 ++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Progrart.Core/ProjectSystem/Builder.cs b/Progrart.Core/ProjectSystem/Builder.cs index 97c5fbe..fed3980 100644 --- a/Progrart.Core/ProjectSystem/Builder.cs +++ b/Progrart.Core/ProjectSystem/Builder.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Diagnostics; +using Newtonsoft.Json; using Progrart.Core.JSExecution; using Progrart.Core.Storage; @@ -33,7 +34,14 @@ namespace Progrart.Core.ProjectSystem return; using var reader = new StreamReader(stream); var img = executor.RenderImage(item.Size, reader.ReadToEnd(), args); - var outputFile= Path.Combine(project.OutputDir, item.Target ?? item.Source + ".png"); + string outputFile; + if (config.OutputDir != null) + outputFile = Path.Combine(project.OutputDir, config.OutputDir ?? "", item.Target ?? item.Source + ".png"); + else + { + outputFile = Path.Combine(project.OutputDir, item.Target ?? item.Source + ".png"); + } + using var img_stream = await provider.TryOpenWrite(outputFile); if (img_stream is null) return; @@ -42,7 +50,7 @@ namespace Progrart.Core.ProjectSystem } public async Task Build(string targetConfig, int maxJobCount = 1) { - int finalJobCount= Math.Max(maxJobCount < 0 ? Environment.ProcessorCount : maxJobCount, 1); + int finalJobCount = Math.Max(maxJobCount < 0 ? Environment.ProcessorCount : maxJobCount, 1); foreach (var config in project.Configurations) { if (config.Name == targetConfig) @@ -67,7 +75,14 @@ namespace Progrart.Core.ProjectSystem await Parallel.ForEachAsync(config.Items, options, async (item, token) => { - await Execute(config, item); + try + { + await Execute(config, item); + } + catch (Exception e) + { + Trace.WriteLine(e); + } int currentCount = Interlocked.Increment(ref index); OnProgressUpdate?.Invoke(config.Items.Count, currentCount); diff --git a/Progrart/Core/Storage/AvaloniaStorageProvider.cs b/Progrart/Core/Storage/AvaloniaStorageProvider.cs index 400f9f6..df39f83 100644 --- a/Progrart/Core/Storage/AvaloniaStorageProvider.cs +++ b/Progrart/Core/Storage/AvaloniaStorageProvider.cs @@ -1,6 +1,7 @@ using Avalonia.Platform.Storage; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Text; using System.Threading.Tasks; @@ -35,6 +36,12 @@ namespace Progrart.Core.Storage { return await file.OpenWriteAsync(); } + var parentPath = Path.GetDirectoryName(path); + if (parentPath is not null) + if ((await baseFolder.GetFolderAsync(parentPath)) == null) + { + await baseFolder.CreateFolderAsync(parentPath); + } file = await baseFolder.CreateFileAsync(path); if (file is not null) return await file.OpenWriteAsync(); diff --git a/Progrart/Views/MainView.axaml.cs b/Progrart/Views/MainView.axaml.cs index 4f09cb0..2f9f61a 100644 --- a/Progrart/Views/MainView.axaml.cs +++ b/Progrart/Views/MainView.axaml.cs @@ -274,7 +274,16 @@ public partial class MainView : UserControl { if (App.LoadedProject is not null) { - Builder builder = new Builder(App.LoadedProject, new AvaloniaStorageProvider(App.CurrentOpenFolder)); + Builder builder; + + var localPath = App.CurrentOpenFolder?.TryGetLocalPath(); + if (localPath != null) + { + builder = new Builder(App.LoadedProject, new ClassicStorageProvider(new DirectoryInfo(localPath))); + } + else + builder = new Builder(App.LoadedProject, new AvaloniaStorageProvider(App.CurrentOpenFolder)); + var config = App.LoadedProject.Configurations[ConfigBox.SelectedIndex]; var name = config.Name; if (config is null) return;