1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . IO ;
3
4
using System . Linq ;
4
5
using System . Text ;
5
6
using System . Threading . Tasks ;
@@ -82,7 +83,8 @@ private void ExtractScripts()
82
83
PopulateStringHashCache ( ) ;
83
84
84
85
// Collect files to extract
85
- string [ ] files = Directory . Exists ( _config . FilePath ) ?
86
+ bool isDirectory = Directory . Exists ( _config . FilePath ) ;
87
+ string [ ] files = isDirectory ?
86
88
Directory . GetFiles ( _config . FilePath , "*.xq" , SearchOption . AllDirectories ) :
87
89
new [ ] { _config . FilePath } ;
88
90
@@ -97,7 +99,10 @@ private void ExtractScripts()
97
99
}
98
100
catch ( Exception e )
99
101
{
100
- Console . WriteLine ( $ "Error ({ e . Message } )") ;
102
+ string relativePath = isDirectory ?
103
+ Path . GetRelativePath ( _config . FilePath , file ) :
104
+ Path . GetFileName ( file ) ;
105
+ Console . WriteLine ( $ "Could not extract { relativePath } : { GetInnermostException ( e ) . Message } ") ;
101
106
}
102
107
}
103
108
}
@@ -128,7 +133,8 @@ private void ExtractScript(string filePath)
128
133
private void CreateScripts ( )
129
134
{
130
135
// Collect files to extract
131
- string [ ] files = Directory . Exists ( _config . FilePath ) ?
136
+ bool isDirectory = Directory . Exists ( _config . FilePath ) ;
137
+ string [ ] files = isDirectory ?
132
138
Directory . GetFiles ( _config . FilePath , "*.txt" , SearchOption . AllDirectories ) :
133
139
new [ ] { _config . FilePath } ;
134
140
@@ -143,7 +149,10 @@ private void CreateScripts()
143
149
}
144
150
catch ( Exception e )
145
151
{
146
- Console . WriteLine ( $ "Error ({ e . Message } )") ;
152
+ string relativePath = isDirectory ?
153
+ Path . GetRelativePath ( _config . FilePath , file ) :
154
+ Path . GetFileName ( file ) ;
155
+ Console . WriteLine ( $ "Could not compile { relativePath } : { GetInnermostException ( e ) . Message } ") ;
147
156
}
148
157
}
149
158
}
@@ -173,7 +182,8 @@ private void CreateScript(string filePath)
173
182
private void DecompressScripts ( )
174
183
{
175
184
// Collect files to extract
176
- string [ ] files = Directory . Exists ( _config . FilePath ) ?
185
+ bool isDirectory = Directory . Exists ( _config . FilePath ) ;
186
+ string [ ] files = isDirectory ?
177
187
Directory . GetFiles ( _config . FilePath , "*.xq" , SearchOption . AllDirectories ) :
178
188
new [ ] { _config . FilePath } ;
179
189
@@ -188,7 +198,10 @@ private void DecompressScripts()
188
198
}
189
199
catch ( Exception e )
190
200
{
191
- Console . WriteLine ( $ "Error ({ e . Message } )") ;
201
+ string relativePath = isDirectory ?
202
+ Path . GetRelativePath ( _config . FilePath , file ) :
203
+ Path . GetFileName ( file ) ;
204
+ Console . WriteLine ( $ "Could not decompress { relativePath } : { GetInnermostException ( e ) . Message } ") ;
192
205
}
193
206
}
194
207
}
@@ -266,5 +279,13 @@ private void PrintHelp()
266
279
Console . WriteLine ( $ "\t Extract any script to human readable text: { Environment . ProcessPath } -o e -f Path/To/File.xq") ;
267
280
Console . WriteLine ( $ "\t Create a xq32 script from human readable text: { Environment . ProcessPath } -o c -t xq32 -f Path/To/File.txt") ;
268
281
}
282
+
283
+ private Exception GetInnermostException ( Exception e )
284
+ {
285
+ while ( e . InnerException != null )
286
+ e = e . InnerException ;
287
+
288
+ return e ;
289
+ }
269
290
}
270
291
}
0 commit comments