Skip to content

Commit 1d14b11

Browse files
Fixed .7z file installation (#19)
1 parent f087eff commit 1d14b11

7 files changed

Lines changed: 89 additions & 30 deletions

File tree

ShinRyuModManager-CE/ShinRyuModManager-CE.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
1515

1616
<!-- Versioning -->
17-
<AssemblyVersion>1.2.4</AssemblyVersion>
17+
<AssemblyVersion>1.2.5</AssemblyVersion>
1818
<VersionPrefix>$(AssemblyVersion)</VersionPrefix>
1919
<AssemblyTitle>ShinRyuModManager-CE</AssemblyTitle>
2020
<Company>SRMM Studio</Company>

ShinRyuModManager-CE/UserInterface/Assets/changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
> ### **%{color:orange} Version 1.2.5 %** ###
2+
* Added progress window to mod installation
3+
* Fixed *.7z files not being able to be installed
4+
* Fixed a bug with RebuildMLO
5+
* Fixed a CPK encoding bug
6+
* Fixed a bug with the progress window
7+
8+
---
9+
110
> ### **%{color:orange} Version 1.2.4 %** ###
211
* Upgraded to .NET 10
312
* General Cleanup

ShinRyuModManager-CE/UserInterface/ViewModels/ProgressWindowViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
namespace ShinRyuModManager.UserInterface.ViewModels;
44

55
public partial class ProgressWindowViewModel : ViewModelBase {
6+
[ObservableProperty] private string _title;
67
[ObservableProperty] private string _messageText;
78
[ObservableProperty] private bool _isIndeterminate;
89

910
public ProgressWindowViewModel() { }
1011

11-
public ProgressWindowViewModel(string messageText, bool isIndeterminate) {
12+
public ProgressWindowViewModel(string title, string messageText, bool isIndeterminate) {
13+
Title = title;
1214
MessageText = messageText;
1315
IsIndeterminate = isIndeterminate;
1416
}

ShinRyuModManager-CE/UserInterface/Views/MainWindow.axaml.cs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,20 @@ private async void ModSave_OnClick(object sender, RoutedEventArgs e) {
172172
var progressWindow = new ProgressWindow("Applying mods. Please wait...", true);
173173

174174
progressWindow.Show(this);
175+
176+
await Task.Yield();
175177

176-
try {
177-
await Program.RunGeneration(Program.ConvertNewToOldModList(viewModel.ModList.ToList()));
178-
} catch (Exception ex) {
179-
Log.Error(ex, "Could not generate MLO!");
180-
181-
_ = await MessageBoxWindow.Show(this, "Error", "Mods could not be applied. Please make sure that the game directory has write access." +
182-
"\n\nPlease check\"srmm_errors.txt\" for more info.");
183-
}
178+
await Task.Run(async () => {
179+
try {
180+
await Program.RunGeneration(Program.ConvertNewToOldModList(viewModel.ModList.ToList()));
181+
} catch (Exception ex) {
182+
Log.Error(ex, "Could not generate MLO!");
184183

184+
_ = await MessageBoxWindow.Show(this, "Error", "Mods could not be applied. Please make sure that the game directory has write access." +
185+
"\n\nPlease check\"srmm_errors.txt\" for more info.");
186+
}
187+
});
188+
185189
progressWindow.Close();
186190
} else {
187191
_ = await MessageBoxWindow.Show(this, "Error", "Mod list is empty and was not saved.");
@@ -260,18 +264,29 @@ private async void ModInstall_OnClick(object sender, RoutedEventArgs e) {
260264

261265
if (files.Count == 0)
262266
return;
267+
268+
var progressWindow = new ProgressWindow("Installing mod(s). Please wait...", true);
269+
270+
_ = progressWindow.ShowDialog(this);
263271

264-
foreach (var file in files) {
265-
if (!File.Exists(file.TryGetLocalPath()))
266-
return;
272+
await Task.Yield();
267273

268-
if (!await Utils.TryInstallModZipAsync(file.TryGetLocalPath()))
269-
continue;
274+
await Task.Run(async () => {
275+
foreach (var file in files) {
276+
var localPath = file.TryGetLocalPath();
277+
278+
if (!File.Exists(localPath))
279+
return;
270280

271-
RefreshModList();
272-
}
281+
await Utils.TryInstallModZipAsync(localPath);
282+
}
283+
284+
await Program.InstallAllModDependenciesAsync();
285+
});
286+
287+
RefreshModList();
273288

274-
await Program.InstallAllModDependenciesAsync();
289+
progressWindow.Close();
275290
} catch (Exception ex) {
276291
Log.Fatal(ex, "ModInstalled failed!");
277292

ShinRyuModManager-CE/UserInterface/Views/ProgressWindow.axaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
x:Class="ShinRyuModManager.UserInterface.Views.ProgressWindow"
88
x:DataType="vm:ProgressWindowViewModel"
99
Icon="/UserInterface/Assets/Icons/SRMM_icon.ico"
10-
Title="ProgressWindow"
10+
Title="{Binding Title}"
1111
Height="175"
1212
Width="400"
1313
Background="#FF373535"
1414
Foreground="White"
15-
CanResize="False">
15+
CanResize="False"
16+
CanMinimize="False"
17+
CanMaximize="False">
1618

1719
<Design.DataContext>
1820
<!-- This only sets the DataContext for the previewer in an IDE,

ShinRyuModManager-CE/UserInterface/Views/ProgressWindow.axaml.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,28 @@
44
namespace ShinRyuModManager.UserInterface.Views;
55

66
public partial class ProgressWindow : Window {
7-
// ReSharper disable once MemberCanBePrivate.Global
87
public ProgressWindow() {
98
InitializeComponent();
109
}
1110

1211
public ProgressWindow(string text, bool isIndeterminate) : this() {
13-
DataContext = new ProgressWindowViewModel(text, isIndeterminate);
12+
DataContext = new ProgressWindowViewModel("Please wait...", text, isIndeterminate);
1413
}
15-
16-
public static async Task<bool> Show(Window owner, string message, bool isIndeterminate) {
17-
var win = new ProgressWindow(message, isIndeterminate) {
18-
Title = "Please wait...",
19-
Icon = owner.Icon
20-
};
14+
15+
public new Task ShowDialog(Window owner) {
16+
Closing += OnClosing;
2117

22-
return await win.ShowDialog<bool>(owner);
18+
return base.ShowDialog(owner);
19+
}
20+
21+
public new void Close() {
22+
Closing -= OnClosing;
23+
24+
base.Close();
25+
}
26+
27+
private static void OnClosing(object sender, WindowClosingEventArgs e) {
28+
e.Cancel = true;
2329
}
2430
}
2531

ShinRyuModManager-CE/Utils.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text;
2+
using SharpCompress.Archives.SevenZip;
23
using SharpCompress.Common;
34
using SharpCompress.Readers;
45
using Utils;
@@ -54,8 +55,18 @@ private static string NormalizeSeparator(string path, char? separator = null) {
5455
internal static async Task<bool> TryInstallModZipAsync(string path) {
5556
if (!File.Exists(path))
5657
return false;
57-
58+
5859
await using var fs = File.OpenRead(path);
60+
61+
// TEMP: Handle .7z files. Remove when SharpCompress fixes this issue.
62+
var is7Z = SevenZipArchive.IsSevenZipFile(fs);
63+
64+
fs.Seek(0, SeekOrigin.Begin);
65+
66+
if (is7Z) {
67+
return Extract7ZFile(fs);
68+
}
69+
5970
using var reader = ReaderFactory.Open(fs);
6071

6172
var options = new ExtractionOptions {
@@ -71,6 +82,20 @@ internal static async Task<bool> TryInstallModZipAsync(string path) {
7182

7283
return true;
7384
}
85+
86+
// For some reason the SharpCompress doesn't handle .7z files automatically.
87+
// This looks to be a working workaround for the time being.
88+
private static bool Extract7ZFile(Stream stream) {
89+
using var archive = SevenZipArchive.Open(stream);
90+
using var reader = archive.ExtractAllEntries();
91+
92+
reader.WriteAllToDirectory(GamePath.ModsPath, new ExtractionOptions {
93+
ExtractFullPath = true,
94+
Overwrite = true
95+
});
96+
97+
return true;
98+
}
7499

75100
/// <summary>
76101
/// Compares two versions and returns true if the target version is higher than the current one.

0 commit comments

Comments
 (0)