Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ShinRyuModManager-CE/ShinRyuModManager-CE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>

<!-- Versioning -->
<AssemblyVersion>1.2.4</AssemblyVersion>
<AssemblyVersion>1.2.5</AssemblyVersion>
<VersionPrefix>$(AssemblyVersion)</VersionPrefix>
<AssemblyTitle>ShinRyuModManager-CE</AssemblyTitle>
<Company>SRMM Studio</Company>
Expand Down
9 changes: 9 additions & 0 deletions ShinRyuModManager-CE/UserInterface/Assets/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
> ### **%{color:orange} Version 1.2.5 %** ###
* Added progress window to mod installation
* Fixed *.7z files not being able to be installed
* Fixed a bug with RebuildMLO
* Fixed a CPK encoding bug
* Fixed a bug with the progress window

---

> ### **%{color:orange} Version 1.2.4 %** ###
* Upgraded to .NET 10
* General Cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace ShinRyuModManager.UserInterface.ViewModels;

public partial class ProgressWindowViewModel : ViewModelBase {
[ObservableProperty] private string _title;
[ObservableProperty] private string _messageText;
[ObservableProperty] private bool _isIndeterminate;

public ProgressWindowViewModel() { }

public ProgressWindowViewModel(string messageText, bool isIndeterminate) {
public ProgressWindowViewModel(string title, string messageText, bool isIndeterminate) {
Title = title;
MessageText = messageText;
IsIndeterminate = isIndeterminate;
}
Expand Down
47 changes: 31 additions & 16 deletions ShinRyuModManager-CE/UserInterface/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,20 @@ private async void ModSave_OnClick(object sender, RoutedEventArgs e) {
var progressWindow = new ProgressWindow("Applying mods. Please wait...", true);

progressWindow.Show(this);

await Task.Yield();

try {
await Program.RunGeneration(Program.ConvertNewToOldModList(viewModel.ModList.ToList()));
} catch (Exception ex) {
Log.Error(ex, "Could not generate MLO!");

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

_ = await MessageBoxWindow.Show(this, "Error", "Mods could not be applied. Please make sure that the game directory has write access." +
"\n\nPlease check\"srmm_errors.txt\" for more info.");
}
});

progressWindow.Close();
} else {
_ = await MessageBoxWindow.Show(this, "Error", "Mod list is empty and was not saved.");
Expand Down Expand Up @@ -260,18 +264,29 @@ private async void ModInstall_OnClick(object sender, RoutedEventArgs e) {

if (files.Count == 0)
return;

var progressWindow = new ProgressWindow("Installing mod(s). Please wait...", true);

_ = progressWindow.ShowDialog(this);

foreach (var file in files) {
if (!File.Exists(file.TryGetLocalPath()))
return;
await Task.Yield();

if (!await Utils.TryInstallModZipAsync(file.TryGetLocalPath()))
continue;
await Task.Run(async () => {
foreach (var file in files) {
var localPath = file.TryGetLocalPath();

if (!File.Exists(localPath))
return;

RefreshModList();
}
await Utils.TryInstallModZipAsync(localPath);
}

await Program.InstallAllModDependenciesAsync();
});

RefreshModList();

await Program.InstallAllModDependenciesAsync();
progressWindow.Close();
} catch (Exception ex) {
Log.Fatal(ex, "ModInstalled failed!");

Expand Down
6 changes: 4 additions & 2 deletions ShinRyuModManager-CE/UserInterface/Views/ProgressWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
x:Class="ShinRyuModManager.UserInterface.Views.ProgressWindow"
x:DataType="vm:ProgressWindowViewModel"
Icon="/UserInterface/Assets/Icons/SRMM_icon.ico"
Title="ProgressWindow"
Title="{Binding Title}"
Height="175"
Width="400"
Background="#FF373535"
Foreground="White"
CanResize="False">
CanResize="False"
CanMinimize="False"
CanMaximize="False">

<Design.DataContext>
<!-- This only sets the DataContext for the previewer in an IDE,
Expand Down
24 changes: 15 additions & 9 deletions ShinRyuModManager-CE/UserInterface/Views/ProgressWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@
namespace ShinRyuModManager.UserInterface.Views;

public partial class ProgressWindow : Window {
// ReSharper disable once MemberCanBePrivate.Global
public ProgressWindow() {
InitializeComponent();
}

public ProgressWindow(string text, bool isIndeterminate) : this() {
DataContext = new ProgressWindowViewModel(text, isIndeterminate);
DataContext = new ProgressWindowViewModel("Please wait...", text, isIndeterminate);
}

public static async Task<bool> Show(Window owner, string message, bool isIndeterminate) {
var win = new ProgressWindow(message, isIndeterminate) {
Title = "Please wait...",
Icon = owner.Icon
};

public new Task ShowDialog(Window owner) {
Closing += OnClosing;

return await win.ShowDialog<bool>(owner);
return base.ShowDialog(owner);
}

public new void Close() {
Closing -= OnClosing;

base.Close();
}

private static void OnClosing(object sender, WindowClosingEventArgs e) {
e.Cancel = true;
}
}

27 changes: 26 additions & 1 deletion ShinRyuModManager-CE/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using SharpCompress.Archives.SevenZip;
using SharpCompress.Common;
using SharpCompress.Readers;
using Utils;
Expand Down Expand Up @@ -54,8 +55,18 @@ private static string NormalizeSeparator(string path, char? separator = null) {
internal static async Task<bool> TryInstallModZipAsync(string path) {
if (!File.Exists(path))
return false;

await using var fs = File.OpenRead(path);

// TEMP: Handle .7z files. Remove when SharpCompress fixes this issue.
var is7Z = SevenZipArchive.IsSevenZipFile(fs);

fs.Seek(0, SeekOrigin.Begin);

if (is7Z) {
return Extract7ZFile(fs);
}

using var reader = ReaderFactory.Open(fs);

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

return true;
}

// For some reason the SharpCompress doesn't handle .7z files automatically.
// This looks to be a working workaround for the time being.
private static bool Extract7ZFile(Stream stream) {
using var archive = SevenZipArchive.Open(stream);
using var reader = archive.ExtractAllEntries();

reader.WriteAllToDirectory(GamePath.ModsPath, new ExtractionOptions {
ExtractFullPath = true,
Overwrite = true
});

return true;
}

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