@@ -32,41 +32,27 @@ public Encoding TextEncoding {
3232 get => textEncoding ;
3333 set => this . RaiseAndSetIfChanged ( ref textEncoding , value ) ;
3434 }
35- public bool CanInstall {
36- get => canInstall ;
37- set => this . RaiseAndSetIfChanged ( ref canInstall , value ) ;
38- }
39- public bool CreateRootDirectory {
40- get => createRootDirectory ;
41- set => this . RaiseAndSetIfChanged ( ref createRootDirectory , value ) ;
42- }
43- public bool CreateCharacterTxt {
44- get => createCharacterTxt ;
45- set => this . RaiseAndSetIfChanged ( ref createCharacterTxt , value ) ;
46- }
47- public string CreateRootDirectoryName {
48- get => createRootDirectoryName ;
49- set => this . RaiseAndSetIfChanged ( ref createRootDirectoryName , value ) ;
50- }
51- public string CreateCharacterTxtName {
52- get => createCharacterTxtName ;
53- set => this . RaiseAndSetIfChanged ( ref createCharacterTxtName , value ) ;
35+ public string [ ] SingerTypes => singerTypes ;
36+ public string SingerType {
37+ get => singerType ;
38+ set => this . RaiseAndSetIfChanged ( ref singerType , value ) ;
5439 }
5540
5641 private int step ;
42+ private string [ ] singerTypes ;
43+ private string singerType ;
5744 private ObservableCollectionExtended < string > textItems ;
5845 private string archiveFilePath ;
5946 private Encoding [ ] encodings ;
6047 private Encoding archiveEncoding ;
6148 private Encoding textEncoding ;
6249
63- private bool canInstall ;
64- private bool createRootDirectory ;
65- private bool createCharacterTxt ;
66- private string createRootDirectoryName = string . Empty ;
67- private string createCharacterTxtName = string . Empty ;
68-
6950 public SingerSetupViewModel ( ) {
51+ #if DEBUG
52+ Encoding . RegisterProvider ( CodePagesEncodingProvider . Instance ) ;
53+ #endif
54+ singerTypes = new [ ] { "utau" , "enunu" } ;
55+ singerType = singerTypes [ 0 ] ;
7056 archiveFilePath = string . Empty ;
7157 encodings = new Encoding [ ] {
7258 Encoding . GetEncoding ( "shift_jis" ) ,
@@ -82,20 +68,10 @@ public SingerSetupViewModel() {
8268 textEncoding = encodings [ 0 ] ;
8369 textItems = new ObservableCollectionExtended < string > ( ) ;
8470
85- this . WhenAnyValue ( vm => vm . Step )
86- . Subscribe ( _ => OnStep ( ) ) ;
8771 this . WhenAnyValue ( vm => vm . Step , vm => vm . ArchiveEncoding , vm => vm . ArchiveFilePath )
8872 . Subscribe ( _ => RefreshArchiveItems ( ) ) ;
8973 this . WhenAnyValue ( vm => vm . Step , vm => vm . TextEncoding )
9074 . Subscribe ( _ => RefreshTextItems ( ) ) ;
91- this . WhenAnyValue (
92- vm => vm . CreateRootDirectory ,
93- vm => vm . CreateRootDirectoryName ,
94- vm => vm . CreateCharacterTxt ,
95- vm => vm . CreateCharacterTxtName )
96- . Subscribe ( _ => CanInstall =
97- ( ! CreateRootDirectory || ! string . IsNullOrWhiteSpace ( CreateRootDirectoryName ) ) &&
98- ( ! CreateCharacterTxt || ! string . IsNullOrWhiteSpace ( CreateCharacterTxtName ) ) ) ;
9975 }
10076
10177 public void Back ( ) {
@@ -166,72 +142,6 @@ public Character(string file) {
166142 }
167143 }
168144
169- private void OnStep ( ) {
170- if ( Step == 2 ) {
171- BuildTree ( ) ;
172- }
173- }
174-
175- private void BuildTree ( ) {
176- var readerOptions = new ReaderOptions {
177- ArchiveEncoding = new ArchiveEncoding ( ArchiveEncoding , ArchiveEncoding ) ,
178- } ;
179- using var archive = ArchiveFactory . Open ( ArchiveFilePath , readerOptions ) ;
180- var banks = archive . Entries
181- . Where ( entry => ! entry . IsDirectory && Path . GetFileName ( entry . Key ) == "character.txt" )
182- . OrderByDescending ( bank => bank . Key . Length )
183- . Select ( bank => new Character ( bank . Key ) )
184- . ToList ( ) ;
185- var otoSets = archive . Entries
186- . Where ( entry => ! entry . IsDirectory && Path . GetFileName ( entry . Key ) == "oto.ini" )
187- . ToArray ( ) ;
188- var prefixMaps = archive . Entries
189- . Where ( entry => ! entry . IsDirectory && Path . GetFileName ( entry . Key ) == "prefix.map" )
190- . ToArray ( ) ;
191- var bankDirs = banks
192- . Select ( bank => Path . GetDirectoryName ( bank . file ) ! )
193- . ToArray ( ) ;
194- var unknownBank = new Character ( "(Unknown)" ) ;
195- foreach ( var otoSet in otoSets ) {
196- var dir = Path . GetDirectoryName ( otoSet . Key ) ;
197- if ( dir == null ) {
198- continue ;
199- }
200- bool foundBank = false ;
201- for ( int i = 0 ; i < bankDirs . Length ; ++ i ) {
202- if ( dir . StartsWith ( bankDirs [ i ] ) ) {
203- string relPath = Path . GetRelativePath ( bankDirs [ i ] , dir ) ;
204- if ( relPath == "." ) {
205- relPath = string . Empty ;
206- }
207- banks [ i ] . otoSets . Add ( otoSet . Key ) ;
208- foundBank = true ;
209- break ;
210- }
211- }
212- if ( ! foundBank ) {
213- unknownBank . otoSets . Add ( otoSet . Key ) ;
214- }
215- }
216- textItems . Clear ( ) ;
217- foreach ( var bank in banks ) {
218- textItems . Add ( $ "{ bank . file } ") ;
219- textItems . AddRange ( bank . otoSets . Select ( set => $ " | { set } ") ) ;
220- }
221-
222- if ( unknownBank . otoSets . Count > 0 ) {
223- CreateCharacterTxt = true ;
224- banks . Add ( unknownBank ) ;
225- }
226-
227- List < string > dirs = banks . Select ( b => Path . GetDirectoryName ( b . file ) ) . OfType < string > ( ) . ToList ( ) ;
228- dirs . AddRange ( otoSets . Select ( set => Path . GetDirectoryName ( set . Key ) ) . OfType < string > ( ) ) ;
229- string ? root = dirs . OrderBy ( dir => dir . Length ) . FirstOrDefault ( ) ;
230- if ( string . IsNullOrEmpty ( root ) || root == "." ) {
231- CreateRootDirectory = true ;
232- }
233- }
234-
235145 public Task Install ( ) {
236146 string archiveFilePath = ArchiveFilePath ;
237147 var archiveEncoding = ArchiveEncoding ;
@@ -242,7 +152,7 @@ public Task Install() {
242152 var installer = new Classic . VoicebankInstaller ( basePath , ( progress , info ) => {
243153 DocManager . Inst . ExecuteCmd ( new ProgressBarNotification ( progress , info ) ) ;
244154 } , archiveEncoding , textEncoding ) ;
245- installer . LoadArchive ( archiveFilePath ) ;
155+ installer . Install ( archiveFilePath , SingerType ) ;
246156 } finally {
247157 new Task ( ( ) => {
248158 DocManager . Inst . ExecuteCmd ( new ProgressBarNotification ( 0 , "" ) ) ;
0 commit comments