OSDN Git Service

OpenTweenを書き込みに制限のあるフォルダ内で起動した場合には設定ファイルの配置先を変更する
authorKimura Youichi <kim.upsilon@bucyou.net>
Fri, 17 Mar 2017 19:49:24 +0000 (04:49 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Fri, 17 Mar 2017 19:49:24 +0000 (04:49 +0900)
Program Files 内に OpenTween を配置するユーザーのための対策
変更先は通常であれば C:\Users\ユーザー名\Roaming\OpenTween\ 以下となる

OpenTween/ApplicationEvents.cs
OpenTween/Properties/Resources.Designer.cs
OpenTween/Properties/Resources.en.resx
OpenTween/Properties/Resources.resx
OpenTween/Resources/ChangeLog.txt
OpenTween/Setting/SettingManager.cs

index a67f892..82fc983 100644 (file)
@@ -229,13 +229,45 @@ namespace OpenTween
             }
             else
             {
-                if (File.Exists(Path.Combine(Application.StartupPath, "roaming")))
+                // OpenTween.exe と同じディレクトリに設定ファイルを配置する
+                MyCommon.settingPath = Application.StartupPath;
+
+                SettingManager.LoadAll();
+
+                try
                 {
-                    MyCommon.settingPath = MySpecialPath.UserAppDataPath();
+                    // 設定ファイルが書き込み可能な状態であるかテストする
+                    SettingManager.SaveAll();
                 }
-                else
+                catch (UnauthorizedAccessException)
                 {
-                    MyCommon.settingPath = Application.StartupPath;
+                    // 書き込みに失敗した場合 (Program Files 以下に配置されている場合など)
+
+                    // 通常は C:\Users\ユーザー名\AppData\Roaming\OpenTween\ となる
+                    MyCommon.settingPath = Path.Combine(new[]
+                    {
+                        Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
+                        Application.ProductName,
+                    });
+                    Directory.CreateDirectory(MyCommon.settingPath);
+
+                    if (File.Exists(Path.Combine(MyCommon.settingPath, "SettingCommon.xml")))
+                    {
+                        // 既に Roaming に設定ファイルが存在する場合
+                        SettingManager.LoadAll();
+                    }
+                    else
+                    {
+                        if (File.Exists(Path.Combine(Application.StartupPath, "SettingCommon.xml")))
+                        {
+                            // StartupPath に設定ファイルが存在し、かつ書き込みができない場合のみ警告を表示する
+                            var message = string.Format(Properties.Resources.SettingPath_Relocation, Application.StartupPath, MyCommon.settingPath);
+                            MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
+                        }
+
+                        // Roaming に設定ファイルを作成 (StartupPath に読み込みに成功した設定ファイルがあれば内容がコピーされる)
+                        SettingManager.SaveAll();
+                    }
                 }
             }
 
index 726eaaf..1b335ab 100644 (file)
@@ -2531,6 +2531,18 @@ namespace OpenTween.Properties {
         }
         
         /// <summary>
+        ///   {0} での設定の書き込みに失敗しました。
+        ///
+        ///既存の設定ファイルは {1} にコピーされます。
+        ///(次回起動時は {1} の設定ファイルが優先されます) に類似しているローカライズされた文字列を検索します。
+        /// </summary>
+        internal static string SettingPath_Relocation {
+            get {
+                return ResourceManager.GetString("SettingPath_Relocation", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   IDとAPIキーの組み合わせが違います。IDと同時に設定するのはパスワードではなくAPIキーです。ご確認ください。 に類似しているローカライズされた文字列を検索します。
         /// </summary>
         internal static string SettingSave_ClickText1 {
index 14e9da6..a1ee30f 100644 (file)
@@ -1142,4 +1142,10 @@ Available service: {1}</value>
 "{1}"
 Do you retry to update status?</value>
   </data>
+  <data name="SettingPath_Relocation" xml:space="preserve">
+    <value>Failed to write settings to {0}.
+
+Existing setting files are copied to {1}.
+(The setting files in {1} will be used at next startup)</value>
+  </data>
 </root>
\ No newline at end of file
index af6338e..d776872 100644 (file)
 "{1}"
 もう一度投稿を試みますか?</value>
   </data>
+  <data name="SettingPath_Relocation" xml:space="preserve">
+    <value>{0} での設定の書き込みに失敗しました。
+
+既存の設定ファイルは {1} にコピーされます。
+(次回起動時は {1} の設定ファイルが優先されます)</value>
+  </data>
 </root>
\ No newline at end of file
index 061182c..a101736 100644 (file)
@@ -6,6 +6,9 @@
   - 削除されたのはメニューやメッセージの簡体字中国語訳であり、ツイートの翻訳に使用する Bing 翻訳機能は引き続き使用できます
   - UIの翻訳 (l10n) について継続的にサポートできる体制になく、現状の簡体字中国語の翻訳も古いままメンテナンスできていないため当面の間は英語以外の翻訳を提供しません
   - 簡体字中国語を使用しているユーザーは、本バージョンからは英語を使用して下さい (用户使用简体中文,请使用英语作为此版本的显示语言)
+ * CHG: OpenTweenを書き込みに制限のあるフォルダ (Program Files など) に配置した場合、設定ファイルを C:\Users\ユーザー名\Roaming\OpenTween\ 以下に保存します
+  - 書き込み可能なフォルダ内に配置した場合は、今まで通り OpenTween.exe と同じ場所に保存します
+  - OpenTweenを Program Files 内に配置した状態での使用は現時点ではあくまで非推奨です
  * FIX: OSの設定で小数点にピリオド以外の記号を用いている環境で、Foursquareのサムネイル表示時にエラーが発生する不具合を修正 (thx @Xiatian!)
  * FIX: 「前データを取得」の後に通常の更新が行われると、次に「前データを取得」した際に1件も取得されない不具合を修正
  * FIX: 発言一覧の更新時にエラーが発生する不具合を回避
index 9f2077c..a37ae76 100644 (file)
@@ -76,6 +76,14 @@ namespace OpenTween.Setting
         public static void LoadAtIdList()
             => SettingManager.AtIdList = SettingAtIdList.Load();
 
+        public static void SaveAll()
+        {
+            SaveCommon();
+            SaveLocal();
+            SaveTabs();
+            SaveAtIdList();
+        }
+
         public static void SaveCommon()
             => SettingManager.Common.Save();