OSDN Git Service

設定ファイル保存時に Setting*.xml.tmp ファイルが適切に削除されない場合がある問題の修正
authorKimura Youichi <kim.upsilon@bucyou.net>
Tue, 7 Jan 2014 09:45:53 +0000 (18:45 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Thu, 9 Jan 2014 10:05:46 +0000 (19:05 +0900)
OpenTween/Resources/ChangeLog.txt
OpenTween/Setting/SettingBase.cs

index fc474a7..6c51c83 100644 (file)
@@ -1,6 +1,7 @@
 更新履歴
 
 ==== Ver 1.1.7-beta1(201x/xx/xx)
+ * FIX: 設定ファイルの保存時に Setting*.xml.tmp ファイルが残ったまま設定が保存できなくなる問題の修正
 
 ==== Ver 1.1.6(2013/12/12)
  * UriFormatException のエラーが多数報告されたため修正版をリリースしました
index ca51435..130fc3b 100644 (file)
@@ -146,21 +146,7 @@ namespace OpenTween
                         if (fileInfo.Length != 0)
                         {
                             // 成功
-
-                            // 上書き保存時の動作:
-                            //   1. Settingなんとか.xml を Settingなんとか.xml.tmp にリネーム
-                            //   2. 一時ファイル (tmpfilePath) を Settingなんとか.xml にリネーム
-                            //   3. Settingなんとか.xml.tmp を削除
-                            var overwrite = File.Exists(filePath);
-
-                            if (overwrite)
-                                File.Move(filePath, filePath + ".tmp");
-
-                            File.Move(tmpfilePath, filePath);
-
-                            if (overwrite)
-                                File.Delete(filePath + ".tmp");
-
+                            File.Copy(tmpfilePath, filePath, true);
                             return;
                         }
                     }
@@ -169,12 +155,14 @@ namespace OpenTween
                 {
                     lastException = e;
                 }
+                finally
+                {
+                    if (File.Exists(tmpfilePath))
+                        File.Delete(tmpfilePath);
+                }
 
                 // リトライ
                 retryCount++;
-                if (File.Exists(tmpfilePath))
-                    File.Delete(tmpfilePath);
-
                 Thread.Sleep(1000);
 
             } while (retryCount <= SaveRetryMax);