|
| 1 | +using System.Text; |
1 | 2 | using System.Diagnostics; |
| 3 | +using System.Security.Cryptography; |
2 | 4 | using System.Text.RegularExpressions; |
3 | 5 |
|
4 | 6 | using YamlDotNet.Serialization; |
5 | | -using YamlDotNet.Serialization.NamingConventions; |
6 | 7 |
|
7 | 8 | using Volatility.Resources; |
8 | 9 | using Volatility.Utilities; |
@@ -73,7 +74,7 @@ public async Task Execute() |
73 | 74 | .DisableAliases() |
74 | 75 | .WithTypeInspector(inner => new IncludeFieldsTypeInspector(inner)) |
75 | 76 | .WithTypeConverter(new ResourceYamlTypeConverter()) |
76 | | - .WithTypeConverter(new ResourceIDYamlTypeConverter()) |
| 77 | + .WithTypeConverter(new StrongIDYamlTypeConverter()) |
77 | 78 | .WithTypeConverter(new StringEnumYamlTypeConverter()) |
78 | 79 | .Build(); |
79 | 80 |
|
@@ -157,62 +158,75 @@ public async Task Execute() |
157 | 158 |
|
158 | 159 | Splicer? splicer = resource as Splicer; |
159 | 160 |
|
160 | | - byte[][]? samples = splicer?.GetLoadedSamples(); |
161 | | - |
162 | | - for (int i = 0; i < samples?.Length; i++) |
163 | | - { |
164 | | - string sampleName = $"{resource.AssetName}_{i}"; |
165 | | - |
166 | | - string sampleDirectory = Path.Combine(directoryPath, $"{resource.AssetName}_Samples"); |
| 161 | + List<Splicer.Sample>? samples = splicer?.GetLoadedSamples(); |
| 162 | + for (int i = 0; i < samples?.Count; i++) |
| 163 | + { |
| 164 | + string sampleDirectory = Path.Combine("data", "Splicer", "Samples"); |
167 | 165 |
|
168 | 166 | Directory.CreateDirectory(sampleDirectory); |
169 | 167 |
|
170 | | - Console.WriteLine($"Writing extracted sample {sampleName}.snr"); |
171 | | - await File.WriteAllBytesAsync(Path.Combine(sampleDirectory, $"{sampleName}.snr"), samples[i]); |
| 168 | + string sampleName = $"{samples[i].SampleID}"; |
172 | 169 |
|
173 | | - if (sxExists) |
| 170 | + string samplePathName = Path.Combine(sampleDirectory, sampleName); |
| 171 | + |
| 172 | + if (!File.Exists($"{samplePathName}.snr") || Overwrite) |
| 173 | + { |
| 174 | + Console.WriteLine($"Writing extracted sample {sampleName}.snr"); |
| 175 | + await File.WriteAllBytesAsync($"{samplePathName}.snr", samples[i].Data); |
| 176 | + } |
| 177 | + else |
174 | 178 | { |
175 | | - string samplePathName = Path.Combine(sampleDirectory, sampleName); |
| 179 | + Console.WriteLine($"Skipping extracted sample {sampleName}.snr"); |
| 180 | + } |
176 | 181 |
|
| 182 | + if (sxExists) |
| 183 | + { |
177 | 184 | string convertedSamplePathName = Path.Combine(sampleDirectory, "_extracted"); |
178 | 185 |
|
179 | 186 | Directory.CreateDirectory(convertedSamplePathName); |
180 | 187 |
|
181 | | - convertedSamplePathName = Path.Combine(convertedSamplePathName, sampleName); |
182 | | - |
183 | | - ProcessStartInfo start = new ProcessStartInfo |
184 | | - { |
185 | | - FileName = sxPath, |
186 | | - Arguments = $"-wave -s16l_int -v0 \"{samplePathName}.snr\" -=\"{convertedSamplePathName}.wav\"", |
187 | | - RedirectStandardOutput = true, |
188 | | - RedirectStandardError = true, |
189 | | - UseShellExecute = false, |
190 | | - CreateNoWindow = true |
191 | | - }; |
192 | | - |
193 | | - using (Process process = new Process()) |
194 | | - { |
195 | | - process.StartInfo = start; |
196 | | - process.OutputDataReceived += (sender, e) => |
197 | | - { |
198 | | - if (!string.IsNullOrEmpty(e.Data)) Console.WriteLine(e.Data); |
199 | | - }; |
200 | | - |
201 | | - process.ErrorDataReceived += (sender, e) => |
202 | | - { |
203 | | - if (!string.IsNullOrEmpty(e.Data)) Console.WriteLine(e.Data); |
204 | | - }; |
205 | | - |
206 | | - Console.WriteLine($"Converting extracted sample {sampleName}.snr to wave..."); |
207 | | - process.Start(); |
208 | | - process.BeginOutputReadLine(); |
209 | | - process.BeginErrorReadLine(); |
210 | | - process.WaitForExit(); |
211 | | - } |
212 | | - } |
213 | | - } |
214 | | - } |
215 | | - Console.WriteLine($"Imported {Path.GetFileName(ImportPath)} as {Path.GetFullPath(filePath)}."); |
| 188 | + convertedSamplePathName = Path.Combine(convertedSamplePathName, sampleName + ".wav"); |
| 189 | + |
| 190 | + if (!File.Exists(convertedSamplePathName) || Overwrite) |
| 191 | + { |
| 192 | + ProcessStartInfo start = new ProcessStartInfo |
| 193 | + { |
| 194 | + FileName = sxPath, |
| 195 | + Arguments = $"-wave -s16l_int -v0 \"{samplePathName}.snr\" -=\"{convertedSamplePathName}\"", |
| 196 | + RedirectStandardOutput = true, |
| 197 | + RedirectStandardError = true, |
| 198 | + UseShellExecute = false, |
| 199 | + CreateNoWindow = true |
| 200 | + }; |
| 201 | + |
| 202 | + using (Process process = new Process()) |
| 203 | + { |
| 204 | + process.StartInfo = start; |
| 205 | + process.OutputDataReceived += (sender, e) => |
| 206 | + { |
| 207 | + if (!string.IsNullOrEmpty(e.Data)) Console.WriteLine(e.Data); |
| 208 | + }; |
| 209 | + |
| 210 | + process.ErrorDataReceived += (sender, e) => |
| 211 | + { |
| 212 | + if (!string.IsNullOrEmpty(e.Data)) Console.WriteLine(e.Data); |
| 213 | + }; |
| 214 | + |
| 215 | + Console.WriteLine($"Converting extracted sample {sampleName}.snr to wave..."); |
| 216 | + process.Start(); |
| 217 | + process.BeginOutputReadLine(); |
| 218 | + process.BeginErrorReadLine(); |
| 219 | + process.WaitForExit(); |
| 220 | + } |
| 221 | + } |
| 222 | + else |
| 223 | + { |
| 224 | + Console.WriteLine($"Converted sample {Path.GetFileName(convertedSamplePathName)} already exists, skipping..."); |
| 225 | + } |
| 226 | + } |
| 227 | + } |
| 228 | + } |
| 229 | + Console.WriteLine($"Imported {Path.GetFileName(sourceFile)} as {Path.GetFullPath(filePath)}."); |
216 | 230 | })); |
217 | 231 | } |
218 | 232 | await Task.WhenAll(tasks); |
|
0 commit comments