OSDN Git Service

AppliStation-GUI,インストール除外リストの設定を設定ダイアログに追加
[applistation/AppliStation.git] / AppliStation / UserPrefForm.cs
index 7342303..8005bf3 100644 (file)
@@ -27,6 +27,7 @@ namespace AppliStation
                        InitializeComponent();\r
                        \r
                        this.openInternetOptionLinkAdminLabel.Visible = ! NaGet.Utils.IsAdministrators();\r
+                       AppliStation.Util.NativeMethods.LinkLabel_SetElevationRequiredState(this.openInternetOptionLinkAdminLabel, true);\r
                        \r
                        loadCurrentPref();\r
                }\r
@@ -42,6 +43,8 @@ namespace AppliStation
                        this.ProxyAddress = userPref.ProxyAddress;\r
                        this.EnableScanInstallerFile = userPref.EnableScanInstallerFile;\r
                        this.InstallOnBackground = userPref.InstallOnBackground;\r
+                       this.CacheFolder = userPref.CacheFolder;\r
+                       this.ExcludeUpdatePackageNames = userPref.ExcludeUpdatePackageNames;\r
                }\r
                \r
                #region レポジトリリスト設定関連\r
@@ -71,7 +74,7 @@ namespace AppliStation
                /// </summary>\r
                /// <param name="repo">対象レポジトリ</param>\r
                /// <returns>ListBoxに表示すべき文字列</returns>\r
-               private string repoListCheckedListBoxRenderer(RepositoryInfo repo) {\r
+               private static string repoListCheckedListBoxRenderer(RepositoryInfo repo) {\r
                        return string.Format("{0}[{1}]", repo.Name, repo.Url.Href);\r
                }\r
 \r
@@ -167,7 +170,7 @@ namespace AppliStation
                        }\r
                }\r
                \r
-               void RepoUrlTextBoxLeave(object sender, EventArgs e)\r
+               void RepoUrlTextBoxValidated(object sender, EventArgs e)\r
                {\r
                        int selectedIndex = repoListCheckedListBox.SelectedIndex;\r
                        if ((0 <= selectedIndex) && (selectedIndex < repos.Count)) {\r
@@ -281,7 +284,7 @@ namespace AppliStation
                #region インストール設定関連\r
                \r
                /// <summary>\r
-               /// インストーラファイルをウイルススキャンするかを設定あるいは取得する\r
+               /// ã\82¤ã\83³ã\82¹ã\83\88ã\83¼ã\83©ã\83¼ã\83\95ã\82¡ã\82¤ã\83«ã\82\92ã\82¦ã\82¤ã\83«ã\82¹ã\82¹ã\82­ã\83£ã\83³ã\81\99ã\82\8bã\81\8bã\82\92設å®\9aã\81\82ã\82\8bã\81\84ã\81¯å\8f\96å¾\97ã\81\99ã\82\8b\r
                /// </summary>\r
                public bool EnableScanInstallerFile {\r
                        set {   this.installScanInstallerFileCheckbox.Checked = value;  }\r
@@ -296,6 +299,25 @@ namespace AppliStation
                        get {   return this.installOnBackgroundCheckBox.Checked;        }\r
                }\r
                \r
+               public string CacheFolder {\r
+                       set {\r
+                               if (string.IsNullOrEmpty(value)) {\r
+                                       this.cacheFolderCustomCheckBox.Checked = false;\r
+                                       this.cacheFolderTextBox.Text = string.Empty;\r
+                               } else {\r
+                                       this.cacheFolderCustomCheckBox.Checked = true;\r
+                                       this.cacheFolderTextBox.Text = value;\r
+                               }\r
+                       }\r
+                       get {\r
+                               if (this.cacheFolderCustomCheckBox.Checked) {\r
+                                       return this.cacheFolderTextBox.Text;\r
+                               } else {\r
+                                       return null;\r
+                               }\r
+                       }\r
+               }\r
+               \r
                /// <summary>\r
                /// インストール関連設定を、指定された設定オブジェクトに設定する。\r
                /// </summary>\r
@@ -304,6 +326,38 @@ namespace AppliStation
                {\r
                        pref.EnableScanInstallerFile = this.EnableScanInstallerFile;\r
                        pref.InstallOnBackground = this.InstallOnBackground;\r
+                       pref.CacheFolder = this.CacheFolder;\r
+               }\r
+               \r
+               #endregion\r
+               \r
+               #region ソフト更新設定関連\r
+               \r
+               \r
+               public string[] ExcludeUpdatePackageNames {\r
+                       set {\r
+                               this.upgradeExcludeTextBox.Lines = value;\r
+                       }\r
+                       get {\r
+                               List<string> list = new List<string>();\r
+                               \r
+                               foreach (string line in this.upgradeExcludeTextBox.Lines) {\r
+                                       if (!string.IsNullOrEmpty(line)) {\r
+                                               list.Add(line);\r
+                                       }\r
+                               }\r
+                               \r
+                               return list.ToArray();\r
+                       }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// ソフト更新関連設定を、指定された設定オブジェクトに設定する。\r
+               /// </summary>\r
+               /// <param name="pref">設定オブジェクト</param>\r
+               private void commitUpgradeSetting(NaGet.NaGetLibPref pref)\r
+               {\r
+                       pref.ExcludeUpdatePackageNames = this.ExcludeUpdatePackageNames;\r
                }\r
                \r
                #endregion\r
@@ -312,7 +366,7 @@ namespace AppliStation
                /// 指定された設定オブジェクトをファイルとして保存する\r
                /// </summary>\r
                /// <param name="pref">設定ファイル</param>\r
-               private void commitNaGetLibPref(NaGet.NaGetLibPref pref)\r
+               private static void commitNaGetLibPref(NaGet.NaGetLibPref pref)\r
                {\r
                        // ファイルに書き込む\r
                        string path = NaGet.Env.PrefPath;\r
@@ -329,6 +383,7 @@ namespace AppliStation
                        commitRepositoryListSetting();\r
                        commitProxySetting(pref);\r
                        commitInstallSetting(pref);\r
+                       commitUpgradeSetting(pref);\r
                        \r
                        commitNaGetLibPref(pref);\r
                }\r
@@ -344,7 +399,7 @@ namespace AppliStation
                        if (string.IsNullOrEmpty(urlText)) {\r
                                return; // special case.\r
                        } if (Uri.IsWellFormedUriString(urlText, UriKind.Absolute) == false) {\r
-                               repoUrlTextBoxErrorProvider.SetError(repoUrlLabel, "URLの記述が不正です");\r
+                               errorProvider.SetError(repoUrlLabel, "URLの記述が不正です");\r
                                e.Cancel = true;\r
                        } else {\r
                                Uri uri = new Uri(urlText);\r
@@ -352,11 +407,70 @@ namespace AppliStation
                                    (uri.Scheme != Uri.UriSchemeFtp) &&\r
                                    (uri.Scheme != Uri.UriSchemeHttp) &&\r
                                    (uri.Scheme != Uri.UriSchemeHttps)){\r
-                                       repoUrlTextBoxErrorProvider.SetError(repoUrlLabel, "URLの記述が不正です");\r
+                                       errorProvider.SetError(repoUrlLabel, "URLの記述が不正です");\r
                                        e.Cancel = true;\r
                                } else {\r
-                                       repoUrlTextBoxErrorProvider.Clear();\r
+                                       errorProvider.Clear();\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               \r
+               void CacheFolderCustomCheckBoxCheckedChanged(object sender, EventArgs e)\r
+               {\r
+                       cacheFolderTextBox.Enabled = cacheFolderCustomCheckBox.Checked;\r
+                       cacheFolderBrowseButton.Enabled = cacheFolderCustomCheckBox.Checked;\r
+               }\r
+               \r
+               void CacheFolderBrowseButtonClick(object sender, EventArgs e)\r
+               {\r
+                       string pwd = System.IO.Directory.GetCurrentDirectory();\r
+                       FolderBrowserDialog fd = new FolderBrowserDialog();\r
+                       fd.Description = "キャッシュフォルダーを指定してください。";\r
+                       fd.SelectedPath = cacheFolderTextBox.Text;\r
+                       fd.ShowNewFolderButton = true;\r
+                       \r
+                       if (fd.ShowDialog(this) == DialogResult.OK) {\r
+                               cacheFolderTextBox.Text = fd.SelectedPath;\r
+                       }\r
+                       \r
+                       System.IO.Directory.SetCurrentDirectory(pwd); // ダイアログで変わったカレントディレクトリを元に戻す\r
+               }\r
+               \r
+               void CacheFolderTextBoxValidating(object sender, System.ComponentModel.CancelEventArgs e)\r
+               {\r
+                       string folderPath = cacheFolderTextBox.Text;\r
+                       \r
+                       if (string.IsNullOrEmpty(folderPath)) {\r
+                               errorProvider.Clear();\r
+                               return; // special case\r
+                       } else if (! System.IO.Directory.Exists(folderPath)) {\r
+                               errorProvider.SetError(cacheFolderTextBox, "存在しないフォルダーパスを指定しています。");\r
+                               e.Cancel = true;\r
+                       } else {\r
+                               errorProvider.Clear();\r
+                       }\r
+               }\r
+               \r
+               void CacheFolderOpenLinkLabelLinkClicked(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
+                               try {\r
+                                       Process.Start(folderPath);\r
+                               } catch (Exception ex) {\r
+                                       MessageBox.Show(ex.Message, "キャッシュフォルダー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
                                }\r
+                       } else {\r
+                               MessageBox.Show(string.Format("フォルダーパス\"{0}\"は存在しませんでした。", folderPath), "キャッシュフォルダー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
                        }\r
                }\r
        }\r