@@ -36,10 +36,25 @@ select a
3636 ;
3737 }
3838
39- internal static string UpdateIfNeeded ( string name , string sourceFilename , string targetFilename )
39+ internal struct UpdateData
4040 {
41- sourceFilename = System . IO . Path . Combine ( SanityLib . CalcGameData ( ) , sourceFilename ) ;
42- targetFilename = System . IO . Path . Combine ( SanityLib . CalcGameData ( ) , targetFilename ) ;
41+ public readonly string name ;
42+ public readonly string sourceFilename ;
43+ public readonly string targetFilename ;
44+
45+ internal UpdateData ( string name , string sourceFilename , string targetFilename )
46+ {
47+ this . name = name ;
48+ this . sourceFilename = sourceFilename ;
49+ this . targetFilename = targetFilename ;
50+ }
51+ }
52+ internal static string UpdateIfNeeded ( UpdateData ud )
53+ {
54+ string sourceFilename = System . IO . Path . Combine ( SanityLib . CalcGameData ( ) , ud . sourceFilename ) ;
55+ string targetFilename = System . IO . Path . Combine ( SanityLib . CalcGameData ( ) , ud . targetFilename ) ;
56+
57+ Log . dbg ( "UpdateIfNeeded from {0} to {1}" , sourceFilename , targetFilename ) ;
4358 if ( System . IO . File . Exists ( sourceFilename ) )
4459 {
4560 if ( System . IO . File . Exists ( targetFilename ) )
@@ -55,19 +70,19 @@ internal static string UpdateIfNeeded(string name, string sourceFilename, string
5570
5671 if ( ! sane )
5772 {
58- Log . info ( "File {0} is not compatible with {1}. This is going to cause trouble, replacing it!" , targetFilename , name ) ;
73+ Log . info ( "File {0} is not compatible with {1}. This is going to cause trouble, replacing it!" , targetFilename , ud . name ) ;
5974 Delete ( targetFilename ) ; // Remove the file and update it no matter what!
60- return Update ( name , sourceFilename , targetFilename ) ;
75+ return Update ( ud . name , sourceFilename , targetFilename ) ;
6176 }
6277 }
6378 {
6479 System . Reflection . Assembly sourceAsm = System . Reflection . Assembly . LoadFile ( sourceFilename ) ;
6580 System . Reflection . Assembly targetAsm = System . Reflection . Assembly . LoadFile ( targetFilename ) ;
6681 if ( ! sourceAsm . GetName ( ) . Version . Equals ( targetAsm . GetName ( ) . Version ) )
6782 {
68- Log . info ( "File {0} is older then {1}. This is going to cause trouble, updating it!" , targetFilename , name ) ;
83+ Log . info ( "File {0} is older then {1}. This is going to cause trouble, updating it!" , targetFilename , ud . name ) ;
6984 Delete ( targetFilename ) ; // Remove the file or the update will not work.
70- return Update ( name , sourceFilename , targetFilename ) ;
85+ return Update ( ud . name , sourceFilename , targetFilename ) ;
7186 }
7287 else
7388 {
@@ -76,18 +91,18 @@ internal static string UpdateIfNeeded(string name, string sourceFilename, string
7691 }
7792 }
7893 }
79- else return SanityLib . Update ( name , sourceFilename , targetFilename ) ;
94+ else return SanityLib . Update ( ud . name , sourceFilename , targetFilename ) ;
8095 }
8196 // Nothing to do. If this is an error, someone else will yell about.
8297 return null ;
8398 }
8499
85100 private static string Update ( string name , string sourceFilename , string targetFilename )
86101 {
102+ Log . dbg ( "Update from {0} to {1}" , sourceFilename , targetFilename ) ;
87103 try
88104 {
89105 Copy ( sourceFilename , targetFilename ) ;
90- Log . dbg ( "Deleting {0}" , sourceFilename ) ;
91106 Delete ( sourceFilename ) ;
92107 return string . Format ( "{0} was updated." , name ) ;
93108 }
@@ -107,7 +122,8 @@ private static void Copy(string sourceFilename, string targetFilename)
107122 private static void Delete ( string filename )
108123 {
109124 Log . dbg ( "Deleting {0}" , filename ) ;
110- System . IO . File . Delete ( filename ) ;
125+ if ( System . IO . File . Exists ( filename ) )
126+ System . IO . File . Delete ( filename ) ;
111127 }
112128
113129 private static string GAMEDATA = null ;
0 commit comments