@@ -13,32 +13,33 @@ public class SongConvertManager
13
13
public enum SongType {
14
14
Psarc , Midi
15
15
}
16
- public static async Task < bool > ConvertFile ( SongType type , string location , bool reconvert , bool copySource , Action < string > output ) {
17
- bool success = false ;
16
+ public static async Task < DirectoryInfo > ConvertFile ( SongType type , string location , bool reconvert , bool copySource , Action < string > output ) {
17
+ DirectoryInfo outputFolder = null ;
18
18
19
19
try {
20
20
if ( type == SongType . Midi )
21
- success = ExportMidi ( new DirectoryInfo ( location ) , output ) ;
21
+ outputFolder = ExportMidi ( new DirectoryInfo ( location ) , output ) ;
22
22
if ( type == SongType . Psarc )
23
- success = await ExportPsarc ( new FileInfo ( location ) , reconvert , copySource , output ) ;
23
+ outputFolder = await ExportPsarc ( new FileInfo ( location ) , reconvert , copySource , output ) ;
24
24
} catch ( Exception e ) {
25
25
Console . WriteLine ( e ) ;
26
26
Console . WriteLine ( $ "Failed to convert file '{ location } '") ;
27
- return false ;
27
+ return null ;
28
28
}
29
29
30
- return success ;
30
+ return outputFolder ;
31
31
}
32
32
33
- private static async Task < bool > ExportPsarc ( FileInfo file , bool reconvert , bool copySource , Action < string > output ) {
33
+ private static async Task < DirectoryInfo > ExportPsarc ( FileInfo file , bool reconvert , bool copySource , Action < string > output ) {
34
34
PsarcFile p = null ;
35
+ DirectoryInfo outputFolder = null ;
35
36
try {
36
37
output ( "Converting: " + file . FullName ) ;
37
38
p = new PsarcFile ( file . FullName ) ;
38
39
39
40
var songNames = p . ExtractArrangementManifests ( ) . Select ( x => x . Attributes . BlockAsset ) . Distinct ( ) ;
40
41
if ( songNames . Count ( ) <= 1 ) {
41
- var outputFolder = await ExportSinglePsarc ( p , null , reconvert , output ) ;
42
+ outputFolder = await ExportSinglePsarc ( p , null , reconvert , output ) ;
42
43
if ( copySource )
43
44
File . Copy ( file . FullName , Path . Combine ( outputFolder . FullName , file . Name ) , true ) ;
44
45
}
@@ -48,7 +49,7 @@ private static async Task<bool> ExportPsarc(FileInfo file, bool reconvert, bool
48
49
49
50
foreach ( var name in songNames ) {
50
51
try {
51
- var outputFolder = await ExportSinglePsarc ( p , name . Split ( ':' ) . Last ( ) , reconvert , output ) ;
52
+ outputFolder = await ExportSinglePsarc ( p , name . Split ( ':' ) . Last ( ) , reconvert , output ) ;
52
53
if ( copySource ) {
53
54
if ( sourceOfSongBatch == null ) {
54
55
sourceOfSongBatch = Path . Combine ( outputFolder . FullName , file . Name ) ;
@@ -71,18 +72,18 @@ await File.WriteAllTextAsync(Path.Combine(outputFolder.FullName, file.Name + ".t
71
72
output ( "Failed to convert file, see last error in log" ) ;
72
73
Console . WriteLine ( ef ) ;
73
74
Console . WriteLine ( $ "File format was weird for { file . FullName } ") ;
74
- return false ;
75
+ return null ;
75
76
} catch ( Exception e ) {
76
77
output ( "Failed to convert file, see last error in log" ) ;
77
78
Console . WriteLine ( e ) ;
78
79
Console . WriteLine ( $ "Failed to convert file: { file . FullName } ") ;
79
- return false ;
80
+ return null ;
80
81
} finally {
81
82
Console . WriteLine ( $ "Converted { file . FullName } ") ;
82
83
p ? . Dispose ( ) ;
83
84
}
84
85
85
- return true ;
86
+ return outputFolder ;
86
87
}
87
88
88
89
private static async Task < DirectoryInfo > ExportSinglePsarc ( PsarcFile p , string songFilter , bool reconvert , Action < string > output )
@@ -130,7 +131,7 @@ await File.WriteAllTextAsync(jsonFile, JsonConvert.SerializeObject(info, Newtons
130
131
return jsonFile ;
131
132
}
132
133
133
- private static bool ExportMidi ( DirectoryInfo f , Action < string > output ) {
134
+ private static DirectoryInfo ExportMidi ( DirectoryInfo f , Action < string > output ) {
134
135
throw new Exception ( "Midi not supported, here for reference" ) ;
135
136
}
136
137
}
0 commit comments