OSDN Git Service

AppliStation,キャッシュフォルダ一旦ひらいて消すのが面倒になったから、キャッシュフォルダをクリーンアップする機能を設定画面に追加
[applistation/AppliStation.git] / AppliStation / UserPrefForm.cs
index 3f6ff2b..712222e 100644 (file)
@@ -477,5 +477,33 @@ namespace AppliStation
                                MessageBox.Show(string.Format("フォルダーパス\"{0}\"は存在しませんでした。", folderPath), "キャッシュフォルダー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
                        }\r
                }\r
+               \r
+               void CacheFolderClearLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
+               {\r
+                       string folderPath;\r
+                       \r
+                       if (cacheFolderCustomCheckBox.Checked) {\r
+                               folderPath = cacheFolderTextBox.Text;\r
+                       } else {\r
+                               // デフォルトは AppDataFolderPath/Cache。\r
+                               folderPath = System.IO.Path.Combine(NaGet.Env.AppDataFolderPath, "Cache");\r
+                       }\r
+                       \r
+                       if (System.IO.Directory.Exists(folderPath)) {\r
+                               DialogResult result = MessageBox.Show(string.Format("フォルダーパス\"{0}\"のファイルを削除して構いませんか?", folderPath), "キャッシュフォルダー", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);\r
+                               if (result == DialogResult.OK) {\r
+                                       foreach (string targetDir in System.IO.Directory.GetDirectories(folderPath)) {\r
+                                               try {\r
+                                                       NaGet.Utils.SetAttributeRecursive(targetDir, System.IO.FileAttributes.Normal);\r
+                                                       System.IO.Directory.Delete(targetDir, true);\r
+                                               } catch {\r
+                                                       // 何もせずに静かに先に進む\r
+                                               }\r
+                                       }\r
+                               }\r
+                       } else {\r
+                               MessageBox.Show(string.Format("フォルダーパス\"{0}\"は存在しませんでした。", folderPath), "キャッシュフォルダー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                       }\r
+               }\r
        }\r
 }\r