|
1 | 1 | using System; |
2 | | -using System.Collections.Generic; |
3 | 2 | using System.Collections.ObjectModel; |
4 | 3 | using System.IO; |
5 | 4 | using System.Linq; |
6 | 5 | using System.Text; |
7 | 6 | using System.Threading.Tasks; |
8 | 7 | using DynamicData.Binding; |
| 8 | +using OpenUtau.Classic; |
9 | 9 | using OpenUtau.Core; |
10 | 10 | using ReactiveUI; |
| 11 | +using ReactiveUI.Fody.Helpers; |
11 | 12 | using SharpCompress.Archives; |
12 | 13 | using SharpCompress.Common; |
13 | 14 | using SharpCompress.Readers; |
14 | 15 |
|
15 | 16 | namespace OpenUtau.App.ViewModels { |
16 | 17 | public class SingerSetupViewModel : ViewModelBase { |
17 | | - public int Step { |
18 | | - get => step; |
19 | | - set => this.RaiseAndSetIfChanged(ref step, value); |
20 | | - } |
| 18 | + [Reactive] public int Step { get; set; } |
21 | 19 | public ObservableCollection<string> TextItems => textItems; |
22 | | - public string ArchiveFilePath { |
23 | | - get => archiveFilePath; |
24 | | - set => this.RaiseAndSetIfChanged(ref archiveFilePath, value); |
25 | | - } |
26 | | - public Encoding[] Encodings => encodings; |
27 | | - public Encoding ArchiveEncoding { |
28 | | - get => archiveEncoding; |
29 | | - set => this.RaiseAndSetIfChanged(ref archiveEncoding, value); |
30 | | - } |
31 | | - public Encoding TextEncoding { |
32 | | - get => textEncoding; |
33 | | - set => this.RaiseAndSetIfChanged(ref textEncoding, value); |
34 | | - } |
35 | | - public string[] SingerTypes => singerTypes; |
36 | | - public string SingerType { |
37 | | - get => singerType; |
38 | | - set => this.RaiseAndSetIfChanged(ref singerType, value); |
39 | | - } |
| 20 | + [Reactive] public string ArchiveFilePath { get; set; } = string.Empty; |
| 21 | + public Encoding[] Encodings { get; set; } = new Encoding[] { |
| 22 | + Encoding.GetEncoding("shift_jis"), |
| 23 | + Encoding.UTF8, |
| 24 | + Encoding.GetEncoding("gb2312"), |
| 25 | + Encoding.GetEncoding("big5"), |
| 26 | + Encoding.GetEncoding("ks_c_5601-1987"), |
| 27 | + Encoding.GetEncoding("Windows-1252"), |
| 28 | + Encoding.GetEncoding("macintosh"), |
| 29 | + }; |
| 30 | + [Reactive] public Encoding ArchiveEncoding { get; set; } |
| 31 | + [Reactive] public Encoding TextEncoding { get; set; } |
| 32 | + [Reactive] public bool MissingInfo { get; set; } |
| 33 | + public string[] SingerTypes { get; set; } = new[] { "utau", "enunu" }; |
| 34 | + [Reactive] public string SingerType { get; set; } |
40 | 35 |
|
41 | | - private int step; |
42 | | - private string[] singerTypes; |
43 | | - private string singerType; |
44 | 36 | private ObservableCollectionExtended<string> textItems; |
45 | | - private string archiveFilePath; |
46 | | - private Encoding[] encodings; |
47 | | - private Encoding archiveEncoding; |
48 | | - private Encoding textEncoding; |
49 | 37 |
|
50 | 38 | public SingerSetupViewModel() { |
51 | 39 | #if DEBUG |
52 | 40 | Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); |
53 | 41 | #endif |
54 | | - singerTypes = new[] { "utau", "enunu" }; |
55 | | - singerType = singerTypes[0]; |
56 | | - archiveFilePath = string.Empty; |
57 | | - encodings = new Encoding[] { |
58 | | - Encoding.GetEncoding("shift_jis"), |
59 | | - Encoding.ASCII, |
60 | | - Encoding.UTF8, |
61 | | - Encoding.GetEncoding("gb2312"), |
62 | | - Encoding.GetEncoding("big5"), |
63 | | - Encoding.GetEncoding("ks_c_5601-1987"), |
64 | | - Encoding.GetEncoding("Windows-1252"), |
65 | | - Encoding.GetEncoding("macintosh"), |
66 | | - }; |
67 | | - archiveEncoding = encodings[0]; |
68 | | - textEncoding = encodings[0]; |
| 42 | + SingerType = SingerTypes[0]; |
| 43 | + ArchiveEncoding = Encodings[0]; |
| 44 | + TextEncoding = Encodings[0]; |
69 | 45 | textItems = new ObservableCollectionExtended<string>(); |
70 | 46 |
|
| 47 | + this.WhenAnyValue(vm => vm.ArchiveFilePath) |
| 48 | + .Subscribe(_ => { |
| 49 | + if (!string.IsNullOrEmpty(ArchiveFilePath)) { |
| 50 | + var config = LoadCharacterYaml(ArchiveFilePath); |
| 51 | + MissingInfo = string.IsNullOrEmpty(config?.SingerType); |
| 52 | + if (!string.IsNullOrEmpty(config?.TextFileEncoding)) { |
| 53 | + try { |
| 54 | + TextEncoding = Encoding.GetEncoding(config.TextFileEncoding); |
| 55 | + } catch { } |
| 56 | + } |
| 57 | + } |
| 58 | + }); |
71 | 59 | this.WhenAnyValue(vm => vm.Step, vm => vm.ArchiveEncoding, vm => vm.ArchiveFilePath) |
72 | 60 | .Subscribe(_ => RefreshArchiveItems()); |
73 | 61 | this.WhenAnyValue(vm => vm.Step, vm => vm.TextEncoding) |
@@ -101,6 +89,18 @@ private void RefreshArchiveItems() { |
101 | 89 | } |
102 | 90 | } |
103 | 91 |
|
| 92 | + private VoicebankConfig? LoadCharacterYaml(string archiveFilePath) { |
| 93 | + using (var archive = ArchiveFactory.Open(archiveFilePath)) { |
| 94 | + var entry = archive.Entries.FirstOrDefault(e => e.Key.EndsWith("character.yaml")); |
| 95 | + if (entry == null) { |
| 96 | + return null; |
| 97 | + } |
| 98 | + using (var stream = entry.OpenEntryStream()) { |
| 99 | + return VoicebankConfig.Load(stream); |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + |
104 | 104 | private void RefreshTextItems() { |
105 | 105 | if (Step != 1) { |
106 | 106 | return; |
@@ -134,22 +134,14 @@ private void RefreshTextItems() { |
134 | 134 | } |
135 | 135 | } |
136 | 136 |
|
137 | | - class Character { |
138 | | - public string file; |
139 | | - public List<string> otoSets = new List<string>(); |
140 | | - public Character(string file) { |
141 | | - this.file = file; |
142 | | - } |
143 | | - } |
144 | | - |
145 | 137 | public Task Install() { |
146 | 138 | string archiveFilePath = ArchiveFilePath; |
147 | 139 | var archiveEncoding = ArchiveEncoding; |
148 | 140 | var textEncoding = TextEncoding; |
149 | 141 | return Task.Run(() => { |
150 | 142 | try { |
151 | 143 | var basePath = PathManager.Inst.SingersInstallPath; |
152 | | - var installer = new Classic.VoicebankInstaller(basePath, (progress, info) => { |
| 144 | + var installer = new VoicebankInstaller(basePath, (progress, info) => { |
153 | 145 | DocManager.Inst.ExecuteCmd(new ProgressBarNotification(progress, info)); |
154 | 146 | }, archiveEncoding, textEncoding); |
155 | 147 | installer.Install(archiveFilePath, SingerType); |
|
0 commit comments