11using CustomAlbums . Data ;
22using CustomAlbums . ModExtensions ;
33using CustomAlbums . Utilities ;
4+ using Il2CppAssets . Scripts . PeroTools . Commons ;
5+ using Il2CppAssets . Scripts . PeroTools . GeneralLocalization ;
46using Il2CppPeroTools2 . Resources ;
57using UnityEngine ;
68using Logger = CustomAlbums . Utilities . Logger ;
@@ -29,20 +31,55 @@ public static class AlbumManager
2931 internal static Events . LoadAlbumEvent OnAlbumLoaded ;
3032
3133 private static int MaxCount { get ; set ; }
34+ internal static string CurrentPack { get ; set ; } = null ;
3235 public static Dictionary < string , Album > LoadedAlbums { get ; } = new ( ) ;
3336
37+
38+ public static void LoadMany ( string directory )
39+ {
40+ // Get the files from the directory
41+ var files = Directory . EnumerateFiles ( directory ) ;
42+
43+ // Filter for .mdm files and find the pack.json file
44+ var mdms = files . Where ( file => Path . GetExtension ( file ) . EqualsCaseInsensitive ( ".mdm" ) ) . ToList ( ) ;
45+ var json = files . FirstOrDefault ( file => Path . GetFileName ( file ) . EqualsCaseInsensitive ( "pack.json" ) ) ;
46+
47+ // Initialize pack and variables
48+ var pack = PackManager . CreatePack ( json ) ;
49+ CurrentPack = pack . Title ;
50+ pack . StartIndex = MaxCount ;
51+
52+ // Count successfully loaded .mdm files
53+ pack . Length = mdms . Count ( file => LoadOne ( file ) != null ) ;
54+
55+ // Set the current pack to null and add the pack to the pack list
56+ CurrentPack = null ;
57+ PackManager . AddPack ( pack ) ;
58+ }
59+
3460 public static Album LoadOne ( string path )
3561 {
3662 MaxCount = Math . Max ( LoadedAlbums . Count , MaxCount ) ;
37- var fileName = File . GetAttributes ( path ) . HasFlag ( FileAttributes . Directory ) ? Path . GetFileName ( path ) : Path . GetFileNameWithoutExtension ( path ) ;
63+ var isDirectory = File . GetAttributes ( path ) . HasFlag ( FileAttributes . Directory ) ;
64+ var fileName = isDirectory ? Path . GetFileName ( path ) : Path . GetFileNameWithoutExtension ( path ) ;
65+
3866 if ( LoadedAlbums . ContainsKey ( fileName ) ) return null ;
39-
67+
4068 try
4169 {
42- var album = new Album ( path , MaxCount ) ;
70+ if ( isDirectory && Directory . EnumerateFiles ( path )
71+ . Any ( file => Path . GetFileName ( file )
72+ . EqualsCaseInsensitive ( "pack.json" ) ) )
73+ {
74+ LoadMany ( path ) ;
75+ return null ;
76+ }
77+
78+ var album = new Album ( path , MaxCount , CurrentPack ) ;
4379 if ( album . Info is null ) return null ;
4480
4581 var albumName = album . AlbumName ;
82+
4683 LoadedAlbums . Add ( albumName , album ) ;
4784
4885 if ( album . HasFile ( "cover.png" ) || album . HasFile ( "cover.gif" ) )
@@ -94,5 +131,17 @@ public static IEnumerable<string> GetAlbumUidsFromNames(this IEnumerable<string>
94131 return albumNames . Where ( name => LoadedAlbums . ContainsKey ( name ) )
95132 . Select ( name => $ "{ Uid } -{ LoadedAlbums [ name ] . Index } ") ;
96133 }
134+
135+ /// <summary>
136+ /// Gets the current "Custom Albums" title based on language.
137+ /// </summary>
138+ /// <returns>The current "Custom Albums" title based on language.</returns>
139+ public static string GetCustomAlbumsTitle ( )
140+ {
141+ return Languages . GetValueOrDefault (
142+ SingletonScriptableObject < LocalizationSettings >
143+ . instance ?
144+ . GetActiveOption ( "Language" ) ?? "English" ) ;
145+ }
97146 }
98147}
0 commit comments