1
+ using CollapseLauncher . GameSettings . Zenless ;
2
+ using CollapseLauncher . GameSettings . Zenless . Enums ;
1
3
using CollapseLauncher . InstallManager . Base ;
2
4
using CollapseLauncher . Interfaces ;
3
5
using Microsoft . UI . Xaml ;
6
+ using System ;
7
+ using System . Collections . Generic ;
8
+ using System . IO ;
9
+ using System . Linq ;
4
10
5
11
// ReSharper disable GrammarMistakeInComment
6
12
// ReSharper disable CommentTypo
11
17
// ReSharper disable InconsistentNaming
12
18
// ReSharper disable ConvertToPrimaryConstructor
13
19
20
+ #nullable enable
14
21
namespace CollapseLauncher . InstallManager . Zenless
15
22
{
16
23
internal class ZenlessInstall : InstallManagerBase
17
24
{
25
+ #region Private Properties
26
+ private ZenlessSettings ? ZenlessSettings { get ; set ; }
27
+ #endregion
28
+
18
29
#region Override Properties
30
+ protected override int _gameVoiceLanguageID
31
+ {
32
+ get => ZenlessSettings ? . GeneralData ? . DeviceLanguageVoiceType switch
33
+ {
34
+ LanguageVoice . zh_cn => 0 ,
35
+ LanguageVoice . en_us => 1 ,
36
+ LanguageVoice . ja_jp => 2 ,
37
+ LanguageVoice . ko_kr => 3 ,
38
+ LanguageVoice . Unset => 2 , // Default to ja_jp
39
+ _ => throw new NotSupportedException ( "Type of the language voice type is not valid!" )
40
+ } ;
41
+ }
19
42
43
+ protected override string ? _gameAudioLangListPath
44
+ {
45
+ get
46
+ {
47
+ // If the persistent folder is not exist, then return null
48
+ if ( ! Directory . Exists ( _gameDataPersistentPath ) )
49
+ return null ;
50
+
51
+ // Get the audio lang path index
52
+ string audioLangPath = _gameAudioLangListPathStatic ;
53
+ return File . Exists ( audioLangPath ) ? audioLangPath : null ;
54
+ }
55
+ }
56
+
57
+ private string ? _gameAudioLangListPathAlternate
58
+ {
59
+ get
60
+ {
61
+ // If the persistent folder is not exist, then return null
62
+ if ( ! Directory . Exists ( _gameDataPersistentPath ) )
63
+ return null ;
64
+
65
+ // Get the audio lang path index
66
+ string audioLangPath = _gameAudioLangListPathAlternateStatic ;
67
+ return File . Exists ( audioLangPath ) ? audioLangPath : null ;
68
+ }
69
+ }
70
+
71
+ protected override string _gameAudioLangListPathStatic =>
72
+ Path . Combine ( _gameDataPersistentPath , "audio_lang_launcher" ) ;
73
+ private string _gameAudioLangListPathAlternateStatic =>
74
+ Path . Combine ( _gameDataPersistentPath , "audio_lang" ) ;
20
75
#endregion
21
76
22
- public ZenlessInstall ( UIElement parentUI , IGameVersionCheck GameVersionManager )
77
+ public ZenlessInstall ( UIElement parentUI , IGameVersionCheck GameVersionManager , ZenlessSettings zenlessSettings )
23
78
: base ( parentUI , GameVersionManager )
24
79
{
80
+ ZenlessSettings = zenlessSettings ;
81
+ }
82
+
83
+ #region Override Methods - Audio Lang List
84
+ protected override void WriteAudioLangList ( List < GameInstallPackage > gamePackage )
85
+ {
86
+ // Run the writing method from the base first
87
+ base . WriteAudioLangList ( gamePackage ) ;
88
+
89
+ // Then create the one from the alternate one
90
+ // Read all the existing list
91
+ List < string > langList = File . Exists ( _gameAudioLangListPathAlternateStatic )
92
+ ? File . ReadAllLines ( _gameAudioLangListPathAlternateStatic ) . ToList ( )
93
+ : [ ] ;
94
+
95
+ // Try lookup if there is a new language list, then add it to the list
96
+ foreach ( GameInstallPackage package in
97
+ _assetIndex . Where ( x => x . PackageType == GameInstallPackageType . Audio ) )
98
+ {
99
+ string langString = GetLanguageStringByLocaleCodeAlternate ( package . LanguageID ) ;
100
+ if ( ! langList . Contains ( langString , StringComparer . OrdinalIgnoreCase ) )
101
+ {
102
+ langList . Add ( langString ) ;
103
+ }
104
+ }
105
+
106
+ // Create the audio lang list file
107
+ using StreamWriter sw = new StreamWriter ( _gameAudioLangListPathAlternateStatic ,
108
+ new FileStreamOptions
109
+ { Mode = FileMode . Create , Access = FileAccess . Write } ) ;
110
+ // Iterate the package list
111
+ foreach ( string langString in langList )
112
+ {
113
+ // Write the language string as per ID
114
+ sw . WriteLine ( langString ) ;
115
+ }
25
116
}
26
117
118
+ protected override void WriteAudioLangListSophon ( List < string > sophonVOList )
119
+ {
120
+ // Run the writing method from the base first
121
+ base . WriteAudioLangListSophon ( sophonVOList ) ;
122
+
123
+ // Then create the one from the alternate one
124
+ // Read all the existing list
125
+ List < string > langList = File . Exists ( _gameAudioLangListPathAlternateStatic )
126
+ ? File . ReadAllLines ( _gameAudioLangListPathAlternateStatic ) . ToList ( )
127
+ : [ ] ;
128
+
129
+ // Try lookup if there is a new language list, then add it to the list
130
+ for ( int index = 0 ; index < sophonVOList . Count ; index ++ )
131
+ {
132
+ var packageLocaleCodeString = sophonVOList [ index ] ;
133
+ string langString = GetLanguageStringByLocaleCodeAlternate ( packageLocaleCodeString ) ;
134
+ if ( ! langList . Contains ( langString , StringComparer . OrdinalIgnoreCase ) )
135
+ {
136
+ langList . Add ( langString ) ;
137
+ }
138
+ }
139
+
140
+ // Create the audio lang list file
141
+ using var sw = new StreamWriter ( _gameAudioLangListPathAlternateStatic ,
142
+ new FileStreamOptions
143
+ { Mode = FileMode . Create , Access = FileAccess . Write } ) ;
144
+ // Iterate the package list
145
+ foreach ( var voIds in langList )
146
+ // Write the language string as per ID
147
+ {
148
+ sw . WriteLine ( voIds ) ;
149
+ }
150
+ }
151
+
152
+ private string GetLanguageStringByLocaleCodeAlternate ( string localeCode )
153
+ {
154
+ return localeCode switch
155
+ {
156
+ "zh-cn" => "Cn" ,
157
+ "en-us" => "En" ,
158
+ "ja-jp" => "Jp" ,
159
+ "ko-kr" => "Kr" ,
160
+ _ => throw new KeyNotFoundException ( $ "Alternate locale code: { localeCode } is not supported!")
161
+ } ;
162
+ }
163
+ #endregion
164
+
27
165
#region Override Methods - UninstallGame
28
166
29
167
protected override UninstallGameProperty AssignUninstallFolders ( )
@@ -43,4 +181,5 @@ protected override UninstallGameProperty AssignUninstallFolders()
43
181
44
182
#endregion
45
183
}
46
- }
184
+ }
185
+ #nullable restore
0 commit comments