@@ -6,51 +6,54 @@ namespace XLua
6
6
{
7
7
public class FilesSignature
8
8
{
9
- static void useage ( )
9
+ static void usage ( )
10
10
{
11
11
Console . WriteLine ( "FilesSignature from_path to_path" ) ;
12
12
}
13
13
14
14
static void doSignature ( string from , string to , SHA1 sha , RSACryptoServiceProvider rsa )
15
15
{
16
- if ( ! Directory . Exists ( to ) )
16
+ if ( ! Directory . Exists ( to ) )
17
17
{
18
18
Directory . CreateDirectory ( to ) ;
19
19
}
20
- foreach ( var filename in Directory . GetFiles ( from , "*.lua" ) )
20
+ foreach ( var filename in Directory . GetFiles ( from , "*.lua" ) )
21
21
{
22
22
byte [ ] filecontent = File . ReadAllBytes ( filename ) ;
23
23
byte [ ] sig = rsa . SignData ( filecontent , sha ) ;
24
- FileStream fs = new FileStream ( to + "/" + Path . GetFileName ( filename ) , FileMode . Create ) ;
25
- fs . Write ( sig , 0 , sig . Length ) ;
26
- fs . Write ( filecontent , 0 , filecontent . Length ) ;
27
- fs . Close ( ) ;
24
+ string sigFilePath = Path . Combine ( to , Path . GetFileName ( filename ) ) ;
25
+ using ( FileStream fs = new FileStream ( sigFilePath , FileMode . Create ) )
26
+ {
27
+ fs . Write ( sig , 0 , sig . Length ) ;
28
+ fs . Write ( filecontent , 0 , filecontent . Length ) ;
29
+ fs . Flush ( ) ;
30
+ }
28
31
}
29
- foreach ( var dir in Directory . GetDirectories ( from ) )
32
+ foreach ( var dir in Directory . GetDirectories ( from ) )
30
33
{
31
-
32
- doSignature ( dir , to + "/" + new DirectoryInfo ( dir ) . Name , sha , rsa ) ;
34
+ string newDir = Path . Combine ( to , new DirectoryInfo ( dir ) . Name ) ;
35
+ doSignature ( dir , newDir , sha , rsa ) ;
33
36
}
34
37
}
35
38
36
39
public static void Main ( string [ ] args )
37
40
{
38
- if ( ! File . Exists ( "key_ras " ) )
41
+ if ( ! File . Exists ( "key_rsa " ) )
39
42
{
40
- Console . WriteLine ( "no key_ras !" ) ;
43
+ Console . WriteLine ( "No key_rsa file found !" ) ;
41
44
return ;
42
45
}
43
46
44
47
if ( args . Length != 2 )
45
48
{
46
- useage ( ) ;
49
+ usage ( ) ;
47
50
return ;
48
51
}
49
52
50
53
SHA1 sha = new SHA1CryptoServiceProvider ( ) ;
51
54
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider ( ) ;
52
- rsa . FromXmlString ( File . ReadAllText ( "key_ras " ) ) ;
55
+ rsa . FromXmlString ( File . ReadAllText ( "key_rsa " ) ) ;
53
56
doSignature ( args [ 0 ] , args [ 1 ] , sha , rsa ) ;
54
57
}
55
58
}
56
- }
59
+ }
0 commit comments