OSDN Git Service

AppliStation-GUI,リソースファイルの画像の破損を修正
[applistation/AppliStation.git] / AppliStation / UserPrefForm.cs
index 555bfa1..b9c3ba2 100644 (file)
@@ -2,6 +2,7 @@
 using System.Collections.Generic;\r
 using System.Drawing;\r
 using System.Windows.Forms;\r
+using System.Diagnostics;\r
 \r
 using NaGet.Packages;\r
 \r
@@ -16,12 +17,17 @@ namespace AppliStation
                \r
                private bool isRepoListChanged;\r
                \r
+               /// <summary>\r
+               /// コンストラクタ\r
+               /// </summary>\r
                public UserPrefForm()\r
                {\r
                        repos = new List<RepositoryInfo>();\r
                        \r
                        InitializeComponent();\r
                        \r
+                       this.openInternetOptionLinkAdminLabel.Visible = ! NaGet.Utils.IsAdministrators();\r
+                       \r
                        loadCurrentPref();\r
                }\r
                \r
@@ -34,10 +40,15 @@ namespace AppliStation
                        \r
                        NaGet.NaGetLibPref userPref = NaGet.Env.Pref;\r
                        this.ProxyAddress = userPref.ProxyAddress;\r
+                       this.EnableScanInstallerFile = userPref.EnableScanInstallerFile;\r
+                       this.InstallOnBackground = userPref.InstallOnBackground;\r
                }\r
                \r
                #region レポジトリリスト設定関連\r
                \r
+               /// <summary>\r
+               /// レポジトリリストの設定を読み書きする\r
+               /// </summary>\r
                public RepositoriesList RepositoriesListSetting {\r
                        get {\r
                                RepositoriesList repoList = new RepositoriesList();\r
@@ -55,10 +66,18 @@ namespace AppliStation
                        }\r
                }\r
                \r
-               private string repoListCheckedListBoxRenderer(RepositoryInfo repo) {\r
+               /// <summary>\r
+               /// ListBoxへ表示するレポジトリ表現文字列を返す\r
+               /// </summary>\r
+               /// <param name="repo">対象レポジトリ</param>\r
+               /// <returns>ListBoxに表示すべき文字列</returns>\r
+               private static string repoListCheckedListBoxRenderer(RepositoryInfo repo) {\r
                        return string.Format("{0}[{1}]", repo.Name, repo.Url.Href);\r
                }\r
-               \r
+\r
+               /// <summary>\r
+               /// ListBoxの内容を更新(再構築)する。\r
+               /// </summary>\r
                private void updateRepos()\r
                {\r
                        repoListCheckedListBox.Items.Clear();\r
@@ -69,7 +88,6 @@ namespace AppliStation
                        }\r
                }\r
                \r
-               \r
                void RepoListCheckedListBoxSelectedIndexChanged(object sender, EventArgs e)\r
                {\r
                        int selectedIndex = repoListCheckedListBox.SelectedIndex;\r
@@ -162,10 +180,17 @@ namespace AppliStation
                        }\r
                }\r
                \r
+               /// <summary>\r
+               /// レポジトリリストが編集されたか否かのフラグ\r
+               /// </summary>\r
+               /// <remarks>ソフトリストの再読み込みが必要か否かの判断に使われる</remarks>\r
                public bool IsRepositoryListSettingChanged {\r
                        get { return isRepoListChanged; }\r
                }\r
                \r
+               /// <summary>\r
+               /// レポジトリリストの設定を反映する\r
+               /// </summary>\r
                private void commitRepositoryListSetting()\r
                {\r
                        if (isRepoListChanged) {\r
@@ -177,6 +202,9 @@ namespace AppliStation
                \r
                #region プロキシサーバ設定関連\r
 \r
+               /// <summary>\r
+               /// プロキシアドレスを設定あるいは取得する\r
+               /// </summary>\r
                public string ProxyAddress {\r
                        get {\r
                                if (proxySameAsIERadioButton.Checked) {\r
@@ -201,6 +229,9 @@ namespace AppliStation
                        }\r
                }\r
                \r
+               /// <summary>\r
+               /// ProxyURLのテキストボックス領域の有効状態を切り替える\r
+               /// </summary>\r
                private void updateProxyURLEnability()\r
                {\r
                        bool isSpecifiedProxy = specifyProxyRadioButton.Checked;\r
@@ -214,16 +245,74 @@ namespace AppliStation
                        updateProxyURLEnability();\r
                }\r
                \r
+               void OpenInternetOptionLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
+               {\r
+                       string verb = "open";\r
+                       \r
+                       if (sender == openInternetOptionLinkAdminLabel) {\r
+                               verb = "runas"; \r
+                       }\r
+                       \r
+                       try {\r
+                               ProcessStartInfo procInfo = new ProcessStartInfo("control.exe");\r
+                               procInfo.Arguments = "inetcpl.cpl,,4";\r
+                               procInfo.UseShellExecute = true;\r
+                               procInfo.Verb = verb;\r
+                               \r
+                               Process.Start(procInfo);\r
+                       } catch (System.ComponentModel.Win32Exception ex) {\r
+                               MessageBox.Show(ex.Message, "インターネットオプション", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                       } catch (Exception) {\r
+                               MessageBox.Show("インターネットオプションが開けませんでした", "インターネットオプション", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                       }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// プロキシ設定を、指定された設定オブジェクトに設定する。\r
+               /// </summary>\r
+               /// <param name="pref">設定オブジェクト</param>\r
                private void commitProxySetting(NaGet.NaGetLibPref pref)\r
                {\r
                        pref.ProxyAddress = this.ProxyAddress;\r
-                       \r
-                       NaGet.Utils.PutSerializeObject<NaGet.NaGetLibPref>(NaGet.Env.PrefPath, pref);\r
                }\r
                \r
                #endregion\r
                \r
-               private void commitNaGetLibPref(NaGet.NaGetLibPref pref)\r
+               #region インストール設定関連\r
+               \r
+               /// <summary>\r
+               /// インストーラーファイルをウイルススキャンするかを設定あるいは取得する\r
+               /// </summary>\r
+               public bool EnableScanInstallerFile {\r
+                       set {   this.installScanInstallerFileCheckbox.Checked = value;  }\r
+                       get {   return this.installScanInstallerFileCheckbox.Checked;   }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// インストール・アンインストールを優先度を下げて実行するかを設定あるいは取得する\r
+               /// </summary>\r
+               public bool InstallOnBackground {\r
+                       set {   this.installOnBackgroundCheckBox.Checked = value;       }\r
+                       get {   return this.installOnBackgroundCheckBox.Checked;        }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// インストール関連設定を、指定された設定オブジェクトに設定する。\r
+               /// </summary>\r
+               /// <param name="pref">設定オブジェクト</param>\r
+               private void commitInstallSetting(NaGet.NaGetLibPref pref)\r
+               {\r
+                       pref.EnableScanInstallerFile = this.EnableScanInstallerFile;\r
+                       pref.InstallOnBackground = this.InstallOnBackground;\r
+               }\r
+               \r
+               #endregion\r
+               \r
+               /// <summary>\r
+               /// 指定された設定オブジェクトをファイルとして保存する\r
+               /// </summary>\r
+               /// <param name="pref">設定ファイル</param>\r
+               private static void commitNaGetLibPref(NaGet.NaGetLibPref pref)\r
                {\r
                        // ファイルに書き込む\r
                        string path = NaGet.Env.PrefPath;\r
@@ -239,6 +328,7 @@ namespace AppliStation
                        \r
                        commitRepositoryListSetting();\r
                        commitProxySetting(pref);\r
+                       commitInstallSetting(pref);\r
                        \r
                        commitNaGetLibPref(pref);\r
                }\r
@@ -246,5 +336,28 @@ namespace AppliStation
                void CancelButtonClick(object sender, EventArgs e)\r
                {\r
                }\r
+               \r
+               void RepoUrlTextBoxValidating(object sender, System.ComponentModel.CancelEventArgs e)\r
+               {\r
+                       string urlText = repoUrlTextBox.Text;\r
+                       \r
+                       if (string.IsNullOrEmpty(urlText)) {\r
+                               return; // special case.\r
+                       } if (Uri.IsWellFormedUriString(urlText, UriKind.Absolute) == false) {\r
+                               repoUrlTextBoxErrorProvider.SetError(repoUrlLabel, "URLの記述が不正です");\r
+                               e.Cancel = true;\r
+                       } else {\r
+                               Uri uri = new Uri(urlText);\r
+                               if ((uri.Scheme != Uri.UriSchemeFile) &&\r
+                                   (uri.Scheme != Uri.UriSchemeFtp) &&\r
+                                   (uri.Scheme != Uri.UriSchemeHttp) &&\r
+                                   (uri.Scheme != Uri.UriSchemeHttps)){\r
+                                       repoUrlTextBoxErrorProvider.SetError(repoUrlLabel, "URLの記述が不正です");\r
+                                       e.Cancel = true;\r
+                               } else {\r
+                                       repoUrlTextBoxErrorProvider.Clear();\r
+                               }\r
+                       }\r
+               }\r
        }\r
 }\r