Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Conceição <Tiago_caza@hotmail.com>2022-04-03 21:26:45 +0300
committerTiago Conceição <Tiago_caza@hotmail.com>2022-04-03 21:26:45 +0300
commita77b9187a2985e02c328187c9584b019b9e404d9 (patch)
tree29d10e68ecf862a2cbedd6f920f1841e85b09538 /UVtools.WPF
parentba71ff3db9ac39a0ebd5c131c73bc3530ddb386b (diff)
Auto Remove source file after convertion (#444)
- **Settings:** - (Add) Remove source file after automatic conversion (#444) - (Add) Remove source file after manuall conversion (#444)
Diffstat (limited to 'UVtools.WPF')
-rw-r--r--UVtools.WPF/MainWindow.axaml.cs110
-rw-r--r--UVtools.WPF/UserSettings.cs14
-rw-r--r--UVtools.WPF/Windows/SettingsWindow.axaml26
3 files changed, 121 insertions, 29 deletions
diff --git a/UVtools.WPF/MainWindow.axaml.cs b/UVtools.WPF/MainWindow.axaml.cs
index c5a16bb..3a53925 100644
--- a/UVtools.WPF/MainWindow.axaml.cs
+++ b/UVtools.WPF/MainWindow.axaml.cs
@@ -1479,8 +1479,10 @@ public partial class MainWindow : WindowEx
if (fileExtension is not null && convertToFormat is not null)
{
var directory = SlicerFile.DirectoryPath;
- var filename = FileFormat.GetFileNameStripExtensions(SlicerFile.FileFullPath);
- var targetFilename = $"{filename}.{convertFileExtension}";
+ var oldFile = SlicerFile.FileFullPath;
+ var oldFileName = SlicerFile.Filename;
+ var filenameNoExt = SlicerFile.FilenameNoExt;
+ var targetFilename = $"{filenameNoExt}.{convertFileExtension}";
var outputFile = Path.Combine(directory, targetFilename);
FileFormat convertedFile = null;
@@ -1507,7 +1509,7 @@ public partial class MainWindow : WindowEx
var dialog = new SaveFileDialog
{
Directory = directory,
- InitialFileName = filename,
+ InitialFileName = filenameNoExt,
DefaultExtension = $".{convertFileExtension}",
Filters = new List<FileDialogFilter>
{
@@ -1563,6 +1565,31 @@ public partial class MainWindow : WindowEx
{
SlicerFile = convertedFile;
AddRecentFile(SlicerFile.FileFullPath);
+
+ bool removeSourceFile = false;
+ switch (Settings.Automations.RemoveSourceFileAfterAutoConversion)
+ {
+ case RemoveSourceFileAction.Yes:
+ removeSourceFile = true;
+ break;
+ case RemoveSourceFileAction.Prompt:
+ if (await this.MessageBoxQuestion($"File was successfully converted to: {targetFilename}\n" +
+ $"Do you want to remove the source file: {oldFileName}", $"Remove source file: {oldFileName}") == ButtonResult.Yes) removeSourceFile = true;
+ break;
+ }
+
+ if (removeSourceFile)
+ {
+ try
+ {
+ File.Delete(oldFile!);
+ RemoveRecentFile(oldFile);
+ }
+ catch (Exception e)
+ {
+ Debug.WriteLine(e);
+ }
+ }
}
}
}
@@ -1838,17 +1865,19 @@ public partial class MainWindow : WindowEx
: Settings.General.DefaultDirectoryConvertFile
};
- var result = await saveDialog.ShowAsync(this);
- if (string.IsNullOrEmpty(result)) return;
+ var newFilePath = await saveDialog.ShowAsync(this);
+ if (string.IsNullOrEmpty(newFilePath)) return;
IsGUIEnabled = false;
- ShowProgressWindow($"Converting {Path.GetFileName(SlicerFile.FileFullPath)} to {Path.GetExtension(result)}");
+ var oldFileName = SlicerFile.Filename!;
+ var oldFile = SlicerFile.FileFullPath!;
+ ShowProgressWindow($"Converting {oldFileName} to {Path.GetExtension(newFilePath)}");
var task = await Task.Factory.StartNew(() =>
{
try
{
- return SlicerFile.Convert(fileFormat, result, version, Progress) is not null;
+ return SlicerFile.Convert(fileFormat, newFilePath, version, Progress) is not null;
}
catch (OperationCanceledException)
{
@@ -1856,7 +1885,7 @@ public partial class MainWindow : WindowEx
catch (Exception ex)
{
string extraMessage = string.Empty;
- if (SlicerFile.FileFullPath.EndsWith(".sl1"))
+ if (SlicerFile.FileFullPath!.EndsWith(".sl1"))
{
extraMessage = "Note: When converting from SL1 make sure you have the correct printer selected, you MUST use a UVtools base printer.\n" +
"Go to \"Help\" -> \"Install profiles into PrusaSlicer\" to install printers.\n";
@@ -1870,38 +1899,50 @@ public partial class MainWindow : WindowEx
});
IsGUIEnabled = true;
-
+
if (task)
{
var question = await this.MessageBoxQuestion(
$"Conversion completed in {LastStopWatch.ElapsedMilliseconds / 1000}s\n\n" +
- $"Do you want to open '{Path.GetFileName(result)}' in a new window?\n" +
+ $"Do you want to open '{Path.GetFileName(newFilePath)}' in a new window?\n" +
"Yes: Open in a new window.\n" +
"No: Open in this window.\n" +
"Cancel: Do not perform any action.\n",
"Conversion complete", ButtonEnum.YesNoCancel);
+
switch (question)
{
case ButtonResult.No:
- ProcessFile(result, _actualLayer);
+ ProcessFile(newFilePath, _actualLayer);
break;
case ButtonResult.Yes:
- App.NewInstance(result);
+ App.NewInstance(newFilePath);
break;
}
- }
- else
- {
- try
+
+ bool removeSourceFile = false;
+ switch (Settings.Automations.RemoveSourceFileAfterAutoConversion)
{
- if (File.Exists(result))
- {
- File.Delete(result);
- }
+ case RemoveSourceFileAction.Yes:
+ removeSourceFile = true;
+ break;
+ case RemoveSourceFileAction.Prompt:
+ if (await this.MessageBoxQuestion($"File was successfully converted to: {Path.GetFileName(newFilePath)}\n" +
+ $"Do you want to remove the source file: {oldFileName}", $"Remove source file: {oldFileName}") == ButtonResult.Yes) removeSourceFile = true;
+ break;
}
- catch (Exception ex)
+
+ if (removeSourceFile)
{
- Debug.WriteLine(ex);
+ try
+ {
+ File.Delete(oldFile!);
+ RemoveRecentFile(oldFile);
+ }
+ catch (Exception ex)
+ {
+ Debug.WriteLine(ex);
+ }
}
}
}
@@ -2219,6 +2260,25 @@ public partial class MainWindow : WindowEx
MenuFileOpenRecentItems = items.ToArray();
}
+ private void RemoveRecentFile(string file)
+ {
+ RecentFiles.Load();
+ RecentFiles.Instance.Remove(file);
+ RecentFiles.Save();
+ RefreshRecentFiles();
+ }
+
+ private void RemoveRecentFile(IEnumerable<string> files)
+ {
+ RecentFiles.Load();
+ foreach (var file in files)
+ {
+ RecentFiles.Instance.Remove(file);
+ }
+ RecentFiles.Save();
+ RefreshRecentFiles();
+ }
+
private void AddRecentFile(string file)
{
if (file == Path.Combine(App.ApplicationPath, About.DemoFile)) return;
@@ -2256,11 +2316,7 @@ public partial class MainWindow : WindowEx
if (await this.MessageBoxQuestion($"Are you sure you want to remove the selected file from the recent list?\n{file}",
"Remove the file from recent list?") == ButtonResult.Yes)
{
- RecentFiles.Load();
- RecentFiles.Instance.Remove(file);
- RecentFiles.Save();
-
- RefreshRecentFiles();
+ RemoveRecentFile(file);
}
return;
diff --git a/UVtools.WPF/UserSettings.cs b/UVtools.WPF/UserSettings.cs
index 73f3d37..72591dd 100644
--- a/UVtools.WPF/UserSettings.cs
+++ b/UVtools.WPF/UserSettings.cs
@@ -1404,6 +1404,8 @@ public sealed class UserSettings : BindableBase
{
private bool _saveFileAfterModifications = true;
private bool _autoConvertFiles = true;
+ private RemoveSourceFileAction _removeSourceFileAfterAutoConversion = RemoveSourceFileAction.No;
+ private RemoveSourceFileAction _removeSourceFileAfterManualConversion = RemoveSourceFileAction.No;
public bool SaveFileAfterModifications
{
@@ -1417,6 +1419,18 @@ public sealed class UserSettings : BindableBase
set => RaiseAndSetIfChanged(ref _autoConvertFiles, value);
}
+ public RemoveSourceFileAction RemoveSourceFileAfterAutoConversion
+ {
+ get => _removeSourceFileAfterAutoConversion;
+ set => RaiseAndSetIfChanged(ref _removeSourceFileAfterAutoConversion, value);
+ }
+
+ public RemoveSourceFileAction RemoveSourceFileAfterManualConversion
+ {
+ get => _removeSourceFileAfterManualConversion;
+ set => RaiseAndSetIfChanged(ref _removeSourceFileAfterManualConversion, value);
+ }
+
public AutomationsUserSettings Clone()
{
return MemberwiseClone() as AutomationsUserSettings;
diff --git a/UVtools.WPF/Windows/SettingsWindow.axaml b/UVtools.WPF/Windows/SettingsWindow.axaml
index d1013d4..9740d8b 100644
--- a/UVtools.WPF/Windows/SettingsWindow.axaml
+++ b/UVtools.WPF/Windows/SettingsWindow.axaml
@@ -1878,7 +1878,7 @@
<StackPanel Orientation="Vertical">
<TextBlock Classes="GroupBoxHeader" Text="Common"/>
<StackPanel Margin="10" Orientation="Vertical" Spacing="10">
- <CheckBox IsChecked="{Binding Settings.Automations.SaveFileAfterModifications}" Content="Auto save the file after apply any automation(s)"/>
+ <CheckBox IsChecked="{Binding Settings.Automations.SaveFileAfterModifications}" Content="Automatically save the file after apply any automation(s)"/>
</StackPanel>
</StackPanel>
@@ -1896,7 +1896,29 @@
&#x0a;2) Converts the VDT files to the format specified on 'Voxeldance Tango - Printer settings - Notes' on 'FILEFORMAT_XXX' variable.
&#x0a;A new file with same name but a new extension will be created and overwrite any previous file.
&#x0a;After a successful conversion the new file will automatically load in instead of the loaded SL1 file."
- Content="Auto convert SL1 and VDT files to the target format when possible and load it back"/>
+ Content="Automatically convert SL1 and VDT files to the target format when possible and load it back"/>
+
+ <Grid RowDefinitions="Auto,10,Auto" ColumnDefinitions="Auto,10,*">
+ <TextBlock Grid.Row="0" Grid.Column="0"
+ VerticalAlignment="Center"
+ Text="Remove source file after automatic conversion:"/>
+ <ComboBox Grid.Row="0" Grid.Column="2"
+ HorizontalAlignment="Stretch"
+ Items="{Binding Settings.Automations.RemoveSourceFileAfterAutoConversion, Converter={StaticResource EnumToCollectionConverter}, Mode=OneTime}"
+ SelectedItem="{Binding Settings.Automations.RemoveSourceFileAfterAutoConversion, Converter={StaticResource FromValueDescriptionToEnumConverter}}"/>
+
+ <TextBlock Grid.Row="2" Grid.Column="0"
+ VerticalAlignment="Center"
+ Text="Remove source file after manual conversion:"/>
+ <ComboBox Grid.Row="2" Grid.Column="2"
+ HorizontalAlignment="Stretch"
+ Items="{Binding Settings.Automations.RemoveSourceFileAfterManualConversion, Converter={StaticResource EnumToCollectionConverter}, Mode=OneTime}"
+ SelectedItem="{Binding Settings.Automations.RemoveSourceFileAfterManualConversion, Converter={StaticResource FromValueDescriptionToEnumConverter}}"/>
+
+ </Grid>
+
+
+
</StackPanel>
</StackPanel>