-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Add Convert Folder to VP tool -Fix filenames were missing the initial "_" character is they had them
- Loading branch information
Showing
8 changed files
with
258 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
using Avalonia.Platform.Storage; | ||
using Avalonia.Threading; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using VP.NET.GUI.Models; | ||
using VP.NET.GUI.Views; | ||
|
||
namespace VP.NET.GUI.ViewModels | ||
{ | ||
public partial class FolderToVPViewModel : ViewModelBase | ||
{ | ||
private CancellationTokenSource? cancellationTokenSource = null; | ||
[ObservableProperty] | ||
internal int progressMax = 1; | ||
[ObservableProperty] | ||
internal int progressCurrent = 0; | ||
[ObservableProperty] | ||
internal string progressFilename = string.Empty; | ||
[ObservableProperty] | ||
internal string folderPath = string.Empty; | ||
[ObservableProperty] | ||
internal string folderSize = string.Empty; | ||
[ObservableProperty] | ||
internal string vPPath = string.Empty; | ||
[ObservableProperty] | ||
internal bool buttonsEnabled = true; | ||
[ObservableProperty] | ||
internal bool compressVP = false; | ||
[ObservableProperty] | ||
internal bool canCreate = false; | ||
|
||
public FolderToVPViewModel() | ||
{ | ||
|
||
} | ||
|
||
private async void GetFolderSize() | ||
{ | ||
try | ||
{ | ||
FolderSize = ""; | ||
if (Directory.Exists(FolderPath)) | ||
{ | ||
FolderSize = "Estimated Size: " + Utils.FormatBytes(await Utils.GetSizeOfFolderInBytes(FolderPath)); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Add(Log.LogSeverity.Error, "FolderToVPViewModel.GetFolderSize()", ex); | ||
} | ||
} | ||
|
||
public async void Start() | ||
{ | ||
await Task.Run(async () => { | ||
cancellationTokenSource = new CancellationTokenSource(); | ||
Dispatcher.UIThread.Invoke(() => { | ||
ButtonsEnabled = false; | ||
ProgressCurrent = 0; | ||
ProgressMax = 1; | ||
ProgressFilename = string.Empty; | ||
}); | ||
if (Directory.Exists(FolderPath)) | ||
{ | ||
var vp = new VPContainer(); | ||
if (CompressVP) | ||
{ | ||
vp.EnableCompression(); | ||
VPPath = Path.ChangeExtension(VPPath, ".vpc"); | ||
} | ||
else | ||
{ | ||
vp.DisableCompression(); | ||
VPPath = Path.ChangeExtension(VPPath, ".vp"); | ||
} | ||
vp.AddFolderToRoot(FolderPath); | ||
await vp.SaveAsAsync(VPPath, progressCallback, cancellationTokenSource).ConfigureAwait(false); | ||
if(File.Exists(VPPath)) | ||
{ | ||
FolderSize = "Final Size: " + Utils.FormatBytes(new FileInfo(VPPath).Length); | ||
} | ||
} | ||
Dispatcher.UIThread.Invoke(() => { | ||
ButtonsEnabled = true; | ||
cancellationTokenSource = null; | ||
}); | ||
}).ConfigureAwait(false); | ||
} | ||
|
||
internal void Cancel() | ||
{ | ||
cancellationTokenSource?.Cancel(); | ||
} | ||
|
||
internal void progressCallback(string name, int max) | ||
{ | ||
Dispatcher.UIThread.Invoke(() => { | ||
ProgressFilename = "_"+name;//visual hack | ||
ProgressMax = max; | ||
ProgressCurrent++; | ||
}); | ||
} | ||
|
||
public async void BrowseFolder() | ||
{ | ||
FolderPickerOpenOptions options = new FolderPickerOpenOptions(); | ||
options.Title = "Select the source folder"; | ||
if (MainWindowViewModel.Settings.ToolLastFolderToVPFolderPath != null) | ||
{ | ||
options.SuggestedStartLocation = await MainWindow.Instance!.StorageProvider.TryGetFolderFromPathAsync(MainWindowViewModel.Settings.ToolLastFolderToVPFolderPath); | ||
} | ||
var result = await MainWindow.Instance!.StorageProvider.OpenFolderPickerAsync(options); | ||
|
||
if (result != null && result.Count > 0) | ||
{ | ||
var newPath = (await result[0].GetParentAsync())?.Path.LocalPath; | ||
if (MainWindowViewModel.Settings.ToolLastFolderToVPFolderPath != newPath) | ||
{ | ||
MainWindowViewModel.Settings.ToolLastFolderToVPFolderPath = newPath; | ||
MainWindowViewModel.Settings.Save(); | ||
} | ||
FolderPath = result[0].Path.LocalPath; | ||
CanCreate = FolderPath.Trim().Length > 0 && VPPath.Trim().Length > 0; | ||
GetFolderSize(); | ||
} | ||
} | ||
|
||
public async void BrowseFile() | ||
{ | ||
FilePickerSaveOptions options = new FilePickerSaveOptions(); | ||
options.Title = "Destination VP name"; | ||
if (MainWindowViewModel.Settings.ToolLastFolderToVPVPSavePath != null) | ||
{ | ||
options.SuggestedStartLocation = await MainWindow.Instance!.StorageProvider.TryGetFolderFromPathAsync(MainWindowViewModel.Settings.ToolLastFolderToVPVPSavePath); | ||
options.DefaultExtension = ".vp"; | ||
options.FileTypeChoices = new List<FilePickerFileType> { new("VP (*.vp)") { Patterns = new[] { "*.vp" } } }; | ||
} | ||
var result = await MainWindow.Instance!.StorageProvider.SaveFilePickerAsync(options); | ||
|
||
if (result != null) | ||
{ | ||
var newPath = (await result.GetParentAsync())?.Path.LocalPath; | ||
if (MainWindowViewModel.Settings.ToolLastFolderToVPVPSavePath != newPath) | ||
{ | ||
MainWindowViewModel.Settings.ToolLastFolderToVPVPSavePath = newPath; | ||
MainWindowViewModel.Settings.Save(); | ||
} | ||
VPPath = result.Path.LocalPath; | ||
VPPath = Path.ChangeExtension(VPPath, ".vp"); | ||
CanCreate = FolderPath.Trim().Length > 0 && VPPath.Trim().Length > 0; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<Window xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="VP.NET.GUI.Views.FolderToVPView" | ||
xmlns:vm="using:VP.NET.GUI.ViewModels" | ||
Icon="/Assets/vpneticon.ico" | ||
Width="600" | ||
MinWidth="600" | ||
Height="470" | ||
MinHeight="470" | ||
WindowStartupLocation="CenterOwner" | ||
Title="Folder to VP"> | ||
|
||
<Design.DataContext> | ||
<vm:FolderToVPViewModel/> | ||
</Design.DataContext> | ||
|
||
<Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto,Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> | ||
<TextBlock Grid.Row="0" TextWrapping="Wrap" Margin="10">This tool creates a VP out of a folder. The selected folder should have the "data" folder inside of it. DO NOT select the "data" folder itself as that will add all folders inside of it to the VP root and thats is not the correct VP structure. Remember that the max VP size is 2GB, if you select "compress" files will be compressed while added to the vp and the final size may be lower than the one indicated here.</TextBlock> | ||
|
||
<Label Grid.Row="1" Margin="5">Source Folder</Label> | ||
<WrapPanel Grid.Row="2" HorizontalAlignment="Center" IsEnabled="{Binding ButtonsEnabled}" Margin="10"> | ||
<TextBox MinWidth="400" Text="{Binding FolderPath}"></TextBox> | ||
<Button Content="Browse" Command="{Binding BrowseFolder}"></Button> | ||
</WrapPanel> | ||
|
||
<Label Grid.Row="3" Margin="5">Destination VP</Label> | ||
<WrapPanel HorizontalAlignment="Center" Grid.Row="4" IsEnabled="{Binding ButtonsEnabled}" Margin="10"> | ||
<TextBox MinWidth="400" Text="{Binding VPPath}"></TextBox> | ||
<Button Content="Browse" Command="{Binding BrowseFile}"></Button> | ||
</WrapPanel> | ||
<CheckBox IsEnabled="{Binding ButtonsEnabled}" HorizontalAlignment="Center" Grid.Row="5" Margin="5" IsChecked="{Binding CompressVP}">Compress VP (Creates a .vpc)</CheckBox> | ||
|
||
<ProgressBar Grid.Row="6" Minimum="0" Maximum="{Binding ProgressMax}" Value="{Binding ProgressCurrent}" Margin="20,10,20,10" Height="20" ShowProgressText="True"></ProgressBar> | ||
<Label Grid.Row="7" Content="{Binding ProgressFilename}" HorizontalContentAlignment="Center"></Label> | ||
<StackPanel Margin="5" HorizontalAlignment="Center" Grid.Row="8"> | ||
<Button Width="100" HorizontalContentAlignment="Center" IsVisible="{Binding ButtonsEnabled}" IsEnabled="{Binding CanCreate}" Content="Make VP" Command="{Binding Start}"></Button> | ||
<Button Width="100" HorizontalContentAlignment="Center" IsVisible="{Binding !ButtonsEnabled}" Command="{Binding Cancel}">Cancel</Button> | ||
</StackPanel> | ||
|
||
<Label Content="{Binding FolderSize}" Grid.Row="9" HorizontalAlignment="Center" Margin="5"></Label> | ||
</Grid> | ||
|
||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
|
||
namespace VP.NET.GUI.Views; | ||
|
||
public partial class FolderToVPView : Window | ||
{ | ||
public FolderToVPView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters