@@ -7,84 +7,72 @@ using System.Threading.Tasks;
7
7
8
8
EnsureDataLoaded ( ) ;
9
9
10
- int maxCount ;
11
-
12
10
// Setup root export folder.
13
11
string winFolder = GetFolder ( FilePath ) ; // The folder data.win is located in.
14
- bool usesAGRP = ( Data . AudioGroups . Count > 0 ) ;
12
+ bool usesAGRP = ( Data . AudioGroups . Count > 0 ) ;
13
+ string exportedSoundsDir = Path . Combine ( winFolder , "Exported_Sounds" ) ;
15
14
16
15
//Overwrite Folder Check One
17
- if ( Directory . Exists ( winFolder + "Exported_Sounds \\ " ) )
16
+ if ( Directory . Exists ( exportedSoundsDir ) )
18
17
{
19
- bool overwriteCheckOne = ScriptQuestion ( @"A 'Exported_Sounds' folder already exists.
20
- Would you like to remove it? This may some time.
18
+ bool overwriteCheckOne = ScriptQuestion ( @"An 'Exported_Sounds' folder already exists.
19
+
20
+ Would you like to remove it? This may take some time.
21
21
22
22
Note: If an error window stating that 'the directory is not empty' appears, please try again or delete the folder manually.
23
23
" ) ;
24
- if ( overwriteCheckOne )
25
- Directory . Delete ( winFolder + "Exported_Sounds\\ " , true ) ;
26
24
if ( ! overwriteCheckOne )
27
25
{
28
- ScriptError ( "A 'Exported_Sounds' folder already exists. Please remove it." , "Error: Export already exists." ) ;
26
+ ScriptError ( "An 'Exported_Sounds' folder already exists. Please remove it." , "Error: Export already exists." ) ;
29
27
return ;
30
28
}
29
+ Directory . Delete ( exportedSoundsDir , true ) ;
31
30
}
32
31
33
- var externalOGG_Copy = 0 ;
34
-
35
32
// EXTERNAL OGG CHECK
36
- bool externalOGGs = ScriptQuestion ( @"This script exports embedded sounds.
33
+ bool externalOGG_Copy = ScriptQuestion ( @"This script exports embedded sounds.
37
34
However, it can also export the external OGGs to a separate folder.
38
35
If you would like to export both, select 'YES'.
39
36
If you just want the embedded sounds, select 'NO'.
40
37
" ) ;
41
38
42
- if ( externalOGGs )
43
- externalOGG_Copy = 1 ;
44
- if ( ! externalOGGs )
45
- externalOGG_Copy = 0 ;
46
-
47
39
// Overwrite Folder Check Two
48
- if ( Directory . Exists ( winFolder + "External_Sounds \\ " ) && externalOGG_Copy == 1 )
40
+ if ( Directory . Exists ( exportedSoundsDir ) && externalOGG_Copy )
49
41
{
50
42
bool overwriteCheckTwo = ScriptQuestion ( @"A 'External_Sounds' folder already exists.
51
43
Would you like to remove it? This may some time.
52
44
53
45
Note: If an error window stating that 'the directory is not empty' appears, please try again or delete the folder manually.
54
46
" ) ;
55
- if ( overwriteCheckTwo )
56
- Directory . Delete ( winFolder + "External_Sounds\\ " , true ) ;
57
47
if ( ! overwriteCheckTwo )
58
48
{
59
49
ScriptError ( "A 'External_Sounds' folder already exists. Please remove it." , "Error: Export already exists." ) ;
60
50
return ;
61
51
}
52
+
53
+ Directory . Delete ( exportedSoundsDir , true ) ;
62
54
}
63
55
64
56
// Group by audio group check
65
- var groupedExport = 0 ;
57
+ bool groupedExport ;
66
58
if ( usesAGRP )
67
59
{
68
- bool groupedCheck = ScriptQuestion ( @"Group sounds by audio group?
69
- " ) ;
70
- if ( groupedCheck )
71
- groupedExport = 1 ;
72
- if ( ! groupedCheck )
73
- groupedExport = 0 ;
60
+ groupedExport = ScriptQuestion ( "Group sounds by audio group?" ) ;
61
+
74
62
}
75
63
76
64
byte [ ] EMPTY_WAV_FILE_BYTES = System . Convert . FromBase64String ( "UklGRiQAAABXQVZFZm10IBAAAAABAAIAQB8AAAB9AAAEABAAZGF0YQAAAAA=" ) ;
77
65
string DEFAULT_AUDIOGROUP_NAME = "audiogroup_default" ;
78
66
79
- maxCount = Data . Sounds . Count ;
67
+ int maxCount = Data . Sounds . Count ;
80
68
SetProgressBar ( null , "Sound" , 0 , maxCount ) ;
81
69
StartProgressBarUpdater ( ) ;
82
70
83
71
await Task . Run ( DumpSounds ) ; // This runs sync, because it has to load audio groups.
84
72
85
73
await StopProgressBarUpdater ( ) ;
86
74
HideProgressBar ( ) ;
87
- if ( Directory . Exists ( winFolder + "External_Sounds \\ " ) )
75
+ if ( Directory . Exists ( exportedSoundsDir ) )
88
76
ScriptMessage ( "Sounds exported to " + winFolder + " in the 'Exported_Sounds' and 'External_Sounds' folders." ) ;
89
77
else
90
78
ScriptMessage ( "Sounds exported to " + winFolder + " in the 'Exported_Sounds' folder." ) ;
@@ -95,10 +83,10 @@ void IncProgressLocal()
95
83
IncrementProgress ( ) ;
96
84
}
97
85
98
- void MakeFolder ( String folderName )
86
+ void MakeFolder ( string folderName )
99
87
{
100
- if ( ! Directory . Exists ( winFolder + folderName + "/" ) )
101
- Directory . CreateDirectory ( winFolder + folderName + "/" ) ;
88
+ string fullPath = Path . Combine ( winFolder , folderName ) ;
89
+ Directory . CreateDirectory ( fullPath ) ;
102
90
}
103
91
104
92
string GetFolder ( string path )
@@ -109,14 +97,14 @@ string GetFolder(string path)
109
97
Dictionary < string , IList < UndertaleEmbeddedAudio > > loadedAudioGroups ;
110
98
IList < UndertaleEmbeddedAudio > GetAudioGroupData ( UndertaleSound sound )
111
99
{
112
- if ( loadedAudioGroups == null )
100
+ if ( loadedAudioGroups is null )
113
101
loadedAudioGroups = new Dictionary < string , IList < UndertaleEmbeddedAudio > > ( ) ;
114
102
115
- string audioGroupName = sound . AudioGroup != null ? sound . AudioGroup . Name . Content : DEFAULT_AUDIOGROUP_NAME ;
103
+ string audioGroupName = sound . AudioGroup is not null ? sound . AudioGroup . Name . Content : DEFAULT_AUDIOGROUP_NAME ;
116
104
if ( loadedAudioGroups . ContainsKey ( audioGroupName ) )
117
105
return loadedAudioGroups [ audioGroupName ] ;
118
106
119
- string groupFilePath = winFolder + "audiogroup" + sound . GroupID + ".dat" ;
107
+ string groupFilePath = Path . Combine ( winFolder , "audiogroup" + sound . GroupID + ".dat" ) ;
120
108
if ( ! File . Exists ( groupFilePath ) )
121
109
return null ; // Doesn't exist.
122
110
@@ -128,7 +116,8 @@ IList<UndertaleEmbeddedAudio> GetAudioGroupData(UndertaleSound sound)
128
116
129
117
loadedAudioGroups [ audioGroupName ] = data . EmbeddedAudio ;
130
118
return data . EmbeddedAudio ;
131
- } catch ( Exception e )
119
+ }
120
+ catch ( Exception e )
132
121
{
133
122
ScriptMessage ( "An error occured while trying to load " + audioGroupName + ":\n " + e . Message ) ;
134
123
return null ;
@@ -137,13 +126,13 @@ IList<UndertaleEmbeddedAudio> GetAudioGroupData(UndertaleSound sound)
137
126
138
127
byte [ ] GetSoundData ( UndertaleSound sound )
139
128
{
140
- if ( sound . AudioFile != null )
129
+ if ( sound . AudioFile is not null )
141
130
return sound . AudioFile . Data ;
142
131
143
132
if ( sound . GroupID > Data . GetBuiltinSoundGroupID ( ) )
144
133
{
145
134
IList < UndertaleEmbeddedAudio > audioGroup = GetAudioGroupData ( sound ) ;
146
- if ( audioGroup != null )
135
+ if ( audioGroup is not null )
147
136
return audioGroup [ sound . AudioID ] . Data ;
148
137
}
149
138
return EMPTY_WAV_FILE_BYTES ;
@@ -168,13 +157,14 @@ void DumpSound(UndertaleSound sound)
168
157
// 4 = 110 = Regular. '.ogg' type saved outside win.
169
158
string audioExt = ".ogg" ;
170
159
string soundFilePath ;
171
- if ( groupedExport == 1 )
172
- soundFilePath = winFolder + "Exported_Sounds \\ " + sound . AudioGroup . Name . Content + " \\ " + soundName ;
160
+ if ( groupedExport )
161
+ soundFilePath = Path . Combine ( exportedSoundsDir , sound . AudioGroup . Name . Content , soundName ) ;
173
162
else
174
- soundFilePath = winFolder + "Exported_Sounds \\ " + soundName ;
163
+ soundFilePath = Path . Combine ( exportedSoundsDir , soundName ) ;
175
164
MakeFolder ( "Exported_Sounds" ) ;
176
- if ( groupedExport == 1 )
177
- MakeFolder ( "Exported_Sounds\\ " + sound . AudioGroup . Name . Content ) ;
165
+ if ( groupedExport )
166
+ MakeFolder ( Path . Combine ( "Exported_Sounds" , sound . AudioGroup . Name . Content ) ) ;
167
+
178
168
bool process = true ;
179
169
if ( flagEmbedded && ! flagCompressed ) // 1.
180
170
audioExt = ".wav" ;
@@ -186,17 +176,18 @@ void DumpSound(UndertaleSound sound)
186
176
{
187
177
process = false ;
188
178
audioExt = ".ogg" ;
189
- string source = winFolder + soundName + audioExt ;
190
- string dest = winFolder + "External_Sounds\\ " + soundName + audioExt ;
191
- if ( externalOGG_Copy == 1 )
179
+ string source = Path . Combine ( winFolder , soundName + audioExt ) ;
180
+ string dest = Path . Combine ( winFolder , "External_Sounds" , soundName + audioExt ) ;
181
+ if ( externalOGG_Copy )
192
182
{
193
- if ( groupedExport == 1 )
183
+ if ( groupedExport )
194
184
{
195
- dest = winFolder + "External_Sounds\\ " + sound . AudioGroup . Name . Content + "\\ " + soundName + audioExt ;
196
- MakeFolder ( "External_Sounds\\ " + sound . AudioGroup . Name . Content ) ;
185
+ dest = Path . Combine ( winFolder , "External_Sounds" , sound . AudioGroup . Name . Content , soundName + audioExt ) ;
186
+
187
+ MakeFolder ( Path . Combine ( "External_Sounds" , sound . AudioGroup . Name . Content ) ) ;
197
188
}
198
- MakeFolder ( "External_Sounds\\ " ) ;
199
- System . IO . File . Copy ( source , dest , false ) ;
189
+ MakeFolder ( "External_Sounds" ) ;
190
+ File . Copy ( source , dest , false ) ;
200
191
}
201
192
}
202
193
if ( process && ! File . Exists ( soundFilePath + audioExt ) )
0 commit comments