Skip to content

Commit

Permalink
refactor: Refactored large parts of the code related to SkinMod (#63)
Browse files Browse the repository at this point in the history
chore: An error window is now shown on crash/exceptions

chore: Ability to disable all mods as a part of first time startup

tweak: Improved key relevance in character search

fix: JASM will no longer crash if you move 3Dmigoto folder without changing it in the settings
  • Loading branch information
Jorixon authored Oct 8, 2023
1 parent 579abbf commit b334e97
Show file tree
Hide file tree
Showing 79 changed files with 2,146 additions and 1,250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface ICharacterModList
/// Remove a mod from the mod list. Stops tracking the mod.
/// </summary>
/// <param name="mod"></param>
internal void UnTrackMod(IMod mod);
internal void UnTrackMod(ISkinMod mod);

/// <summary>
/// Enable a mod. This enables the mod.
Expand All @@ -40,9 +40,8 @@ public interface ICharacterModList
/// </summary>
public void DisableMod(Guid modId);

public bool IsModEnabled(IMod mod);
public bool IsModEnabled(ISkinMod mod);

public void SetCustomModName(Guid modId, string newName);

public bool IsMultipleModsActive(bool perSkin = false);

Expand All @@ -66,9 +65,7 @@ public interface ICharacterModList
public bool FolderAlreadyExists(string folderName);

/// <summary>
/// Permanently deletes a mod from the mod list. This deletes entire mod from the mod folder.
/// Deletes a mod from the mod list. This deletes entire mod from the mod folder.
/// </summary>
public void DeleteMod(Guid modId, bool moveToRecycleBin = true);

public void DeleteModBySkinEntryId(Guid skinEntryId, bool moveToRecycleBin = true);
}
20 changes: 4 additions & 16 deletions src/GIMI-ModManager.Core/Contracts/Entities/IMod.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using GIMI_ModManager.Core.Entities;

namespace GIMI_ModManager.Core.Contracts.Entities;
namespace GIMI_ModManager.Core.Contracts.Entities;

/// <summary>
/// The Idea behind this interface was that mods might not be folders but could also be archives or some other format
Expand All @@ -22,17 +20,6 @@ public interface IMod : IEqualityComparer<IMod>
/// </summary>
public string OnlyPath { get; }

/// <summary>
/// Custom name of the mod.
/// </summary>
public string CustomName { get; }

/// <summary>
/// Set the custom name of the mod.
/// </summary>
/// <param name="customName"></param>
public void SetCustomName(string customName);

/// <summary>
/// Move the mod to the specified folder. This does not change the folder name.
/// If the drive is different, the mod will be copied and then deleted.
Expand All @@ -42,6 +29,7 @@ public interface IMod : IEqualityComparer<IMod>
/// This needs to be an absolute path to the folder you want to move the mod to.
/// </param>
public void MoveTo(string absPath);

/// <summary>
/// Copies the mod to the specified folder. This does not change the folder name.
/// </summary>
Expand All @@ -60,12 +48,12 @@ public interface IMod : IEqualityComparer<IMod>
public bool Exists();

public bool IsEmpty();

/// <summary>
/// This uses the contents of the mods to compare them
/// </summary>
/// <returns></returns>
public bool DeepEquals(IMod? x, IMod? y);

public byte[] GetContentsHash();

public byte[] GetContentsHash();
}
21 changes: 5 additions & 16 deletions src/GIMI-ModManager.Core/Contracts/Entities/ISkinMod.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
using GIMI_ModManager.Core.Entities;
using GIMI_ModManager.Core.Entities.Mods.SkinMod;

namespace GIMI_ModManager.Core.Contracts.Entities;

public interface ISkinMod : IMod, IEqualityComparer<ISkinMod>
{
public IReadOnlyCollection<string> ImagePaths { get; } // Support multiple images at some point ???
public SkinModSettings? CachedSkinModSettings { get; }
public IReadOnlyCollection<SkinModKeySwap>? CachedKeySwaps { get; }
Guid Id { get; }
public bool HasMergedInI { get; }

public void ClearCache();
public SkinModSettingsManager Settings { get; }
public SkinModKeySwapManager? KeySwaps { get; }

public Task<IReadOnlyCollection<SkinModKeySwap>> ReadKeySwapConfiguration(bool forceReload = false,
CancellationToken cancellationToken = default);

public Task SaveKeySwapConfiguration(ICollection<SkinModKeySwap> updatedKeySwaps,
CancellationToken cancellationToken = default);


public Task<SkinModSettings> ReadSkinModSettings(bool forceReload = false, CancellationToken cancellationToken = default);

public Task SaveSkinModSettings(SkinModSettings skinModSettings,
CancellationToken cancellationToken = default);
public bool ContainsOnlyJasmFiles();
}
16 changes: 13 additions & 3 deletions src/GIMI-ModManager.Core/Contracts/Services/ISkinManagerService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using GIMI_ModManager.Core.Contracts.Entities;
using GIMI_ModManager.Core.Entities.Genshin;
using GIMI_ModManager.Core.Services;
using OneOf;
using OneOf.Types;

namespace GIMI_ModManager.Core.Contracts.Services;

Expand All @@ -19,15 +21,18 @@ public Task Initialize(string activeModsFolderPath, string? unloadedModsFolderPa
///
/// </summary>
/// <param name="characterFolderToReorganize">If null, reorganize all mods outside of characters mod folders</param>
/// <param name="disableMods">If true will also disable the mods</param>
/// <returns>Mods moved</returns>
public int ReorganizeMods(GenshinCharacter? characterFolderToReorganize = null);
public Task<int> ReorganizeModsAsync(GenshinCharacter? characterFolderToReorganize = null,
bool disableMods = false);

/// <summary>
/// This looks for mods in characters mod folder that are not tracked by the mod manager and adds them to the mod manager.
/// </summary>
public Task<RefreshResult> RefreshModsAsync(GenshinCharacter? refreshForCharacter = null);

public Task TransferMods(ICharacterModList source, ICharacterModList destination, IEnumerable<Guid> modsEntryIds);
public Task<OneOf<Success, Error<string>[]>> TransferMods(ICharacterModList source, ICharacterModList destination,
IEnumerable<Guid> modsEntryIds);

public Task<string> GetCurrentSwapVariationAsync(Guid characterSkinEntryId);

Expand All @@ -46,6 +51,8 @@ public void ExportMods(ICollection<ICharacterModList> characterModLists, string
SetModStatus setModStatus = SetModStatus.KeepCurrent);

public event EventHandler<ExportProgress>? ModExportProgress;

public ISkinMod? GetModById(Guid id);
}

public enum SetModStatus
Expand All @@ -58,16 +65,19 @@ public enum SetModStatus
public readonly struct RefreshResult
{
public RefreshResult(IReadOnlyCollection<string> modsUntracked, IReadOnlyCollection<ISkinMod> modsTracked,
IReadOnlyCollection<DuplicateMods> modsDuplicate)
IReadOnlyCollection<DuplicateMods> modsDuplicate, IReadOnlyCollection<string> errors)
{
ModsUntracked = modsUntracked;
ModsTracked = modsTracked;
ModsDuplicate = modsDuplicate;
Errors = errors;
}

public IReadOnlyCollection<string> ModsUntracked { get; }
public IReadOnlyCollection<ISkinMod> ModsTracked { get; }

public IReadOnlyCollection<string> Errors { get; }

public IReadOnlyCollection<DuplicateMods> ModsDuplicate { get; }

public readonly struct DuplicateMods
Expand Down
Loading

0 comments on commit b334e97

Please sign in to comment.