Skip to content

Commit 3784327

Browse files
committed
Added Zip Archives support to importing
1 parent b410543 commit 3784327

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

Source/AssetRipper.GUI/MainWindow.ViewModel.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Avalonia.Threading;
1111
using System.Collections.ObjectModel;
1212
using System.Diagnostics;
13+
using System.IO.Compression;
1314

1415
namespace AssetRipper.GUI
1516
{
@@ -172,6 +173,36 @@ public void OnFileDropped(DragEventArgs e)
172173
DoLoad(filesDropped);
173174
}
174175

176+
private void DoLoadArchives(string[]? filesDropped)
177+
{
178+
if (!Directory.Exists("temp"))
179+
{
180+
Directory.CreateDirectory("temp");
181+
}
182+
183+
string path = "temp/ZIP_COMBINE_" + DateTime.Now.ToString("yyyyMMddHHmm");
184+
185+
if (filesDropped == null || filesDropped.Length < 1)
186+
{
187+
return;
188+
}
189+
190+
try
191+
{
192+
foreach(string v in filesDropped)
193+
{
194+
Logger.Log(LogType.Info, LogCategory.Import, $"Unzipping '{v}'");
195+
ZipFile.ExtractToDirectory(v, path, true);
196+
}
197+
198+
DoLoad([path]);
199+
}
200+
catch (Exception ex)
201+
{
202+
this.ShowPopup($"Exception on combining archives: {ex.Message}", MainWindow.Instance.LocalizationManager["error"]);
203+
}
204+
}
205+
175206
private void DoLoad(string[]? filesDropped)
176207
{
177208
if (filesDropped == null || filesDropped.Length < 1)
@@ -404,6 +435,22 @@ public async void ShowOpenFileDialog()
404435
}
405436
}
406437

438+
//Called from UI
439+
public async void ShowOpenFileDialogZipArchives()
440+
{
441+
FilePickerOpenOptions options = new() { AllowMultiple = true };
442+
IReadOnlyList<IStorageFile> fileList = await MainWindow.Instance.StorageProvider.OpenFilePickerAsync(options);
443+
444+
string[] result = fileList.Select(f => f.Path.LocalPath)
445+
.Where(s => !string.IsNullOrEmpty(s))
446+
.ToArray();
447+
448+
if (result.Length > 0)
449+
{
450+
DoLoadArchives(result);
451+
}
452+
}
453+
407454
//Called from UI
408455
public async void ShowOpenFolderDialog()
409456
{

Source/AssetRipper.GUI/MainWindow.axaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,21 @@
6565
</MenuItem.IsEnabled>
6666
</MenuItem>
6767

68-
<MenuItem Header="{i18n:Localize menu_file_reset}" Command="{Binding Reset}">
68+
<!--File->Import Multiple (Zip Archives)-->
69+
<MenuItem Header="Import Multiple (Zip Archives)" Command="{Binding ShowOpenFileDialogZipArchives}">
70+
<MenuItem.IsEnabled>
71+
<MultiBinding Converter="{x:Static BoolConverters.And}">
72+
<Binding Path="!IsExporting" />
73+
<MultiBinding Converter="{x:Static BoolConverters.Or}">
74+
<Binding Path="!HasFile" />
75+
<Binding Path="HasLoaded" />
76+
</MultiBinding>
77+
</MultiBinding>
78+
</MenuItem.IsEnabled>
79+
</MenuItem>
80+
81+
82+
<MenuItem Header="{i18n:Localize menu_file_reset}" Command="{Binding Reset}">
6983
<MenuItem.IsEnabled>
7084
<MultiBinding Converter="{x:Static BoolConverters.And}">
7185
<Binding Path="HasFile" />

0 commit comments

Comments
 (0)