2 using System.Collections.Generic;
\r
3 using System.Drawing;
\r
4 using System.Windows.Forms;
\r
5 using System.Diagnostics;
\r
7 using NaGet.Packages;
\r
9 namespace AppliStation
\r
14 public partial class UserPrefForm : Form
\r
16 private List<RepositoryInfo> repos;
\r
18 private bool isRepoListChanged;
\r
23 public UserPrefForm()
\r
25 repos = new List<RepositoryInfo>();
\r
27 InitializeComponent();
\r
29 this.openInternetOptionLinkAdminLabel.Visible = ! NaGet.Utils.IsAdministrators();
\r
37 public void loadCurrentPref()
\r
39 this.RepositoriesListSetting = NaGet.Utils.GetDeserializedObject<RepositoriesList>(NaGet.Env.RepositoriesListFile);
\r
41 NaGet.NaGetLibPref userPref = NaGet.Env.Pref;
\r
42 this.ProxyAddress = userPref.ProxyAddress;
\r
43 this.EnableScanInstallerFile = userPref.EnableScanInstallerFile;
\r
44 this.InstallOnBackground = userPref.InstallOnBackground;
\r
47 #region レポジトリリスト設定関連
\r
50 /// レポジトリリストの設定を読み書きする
\r
52 public RepositoriesList RepositoriesListSetting {
\r
54 RepositoriesList repoList = new RepositoriesList();
\r
55 repoList.Repositories = repos.ToArray();
\r
60 repos.AddRange(value.Repositories);
\r
65 isRepoListChanged = false;
\r
70 /// ListBoxへ表示するレポジトリ表現文字列を返す
\r
72 /// <param name="repo">対象レポジトリ</param>
\r
73 /// <returns>ListBoxに表示すべき文字列</returns>
\r
74 private static string repoListCheckedListBoxRenderer(RepositoryInfo repo) {
\r
75 return string.Format("{0}[{1}]", repo.Name, repo.Url.Href);
\r
79 /// ListBoxの内容を更新(再構築)する。
\r
81 private void updateRepos()
\r
83 repoListCheckedListBox.Items.Clear();
\r
85 foreach (RepositoryInfo repo in repos) {
\r
86 string label = repoListCheckedListBoxRenderer(repo);
\r
87 repoListCheckedListBox.Items.Add(label, repo.Enabled);
\r
91 void RepoListCheckedListBoxSelectedIndexChanged(object sender, EventArgs e)
\r
93 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
94 bool selected = (selectedIndex >= 0);
\r
96 removeRepoButton.Enabled = selected;
\r
97 upRepoButton.Enabled = selected && ((1 <= selectedIndex) && (selectedIndex < repos.Count));
\r
98 downRepoButton.Enabled = selected && ((0 <= selectedIndex) && (selectedIndex < (repos.Count-1)));
\r
99 repoUrlLabel.Enabled = selected;
\r
100 repoUrlTextBox.Enabled = selected;
\r
102 repoUrlTextBox.Text = repos[repoListCheckedListBox.SelectedIndex].Url.Href;
\r
103 repoUrlTextBox.SelectAll();
\r
105 repoUrlTextBox.Clear();
\r
109 void AddRepoButtonClick(object sender, EventArgs e)
\r
111 RepositoryInfo repo = new RepositoryInfo();
\r
112 repo.Name = string.Format("新しいレポジトリ");
\r
113 repo.Url = new LocationEntry();
\r
114 repo.Enabled = true;
\r
119 repoListCheckedListBox.SelectedIndex = repos.Count - 1;
\r
121 isRepoListChanged = true;
\r
124 void RepoListCheckedListBoxItemCheck(object sender, ItemCheckEventArgs e)
\r
126 repos[e.Index].Enabled = (e.NewValue == CheckState.Checked);
\r
128 isRepoListChanged = true;
\r
131 void RemoveRepoButtonClick(object sender, EventArgs e)
\r
133 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
134 if ((0 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
135 string text = string.Format("本当にレポジトリ「{0}」を消去しますか?", repos[selectedIndex].Name);
\r
136 DialogResult result = MessageBox.Show(text, "レポジトリの削除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
\r
137 if (result == DialogResult.OK) {
\r
138 repos.RemoveAt(selectedIndex);
\r
139 repoListCheckedListBox.Items.RemoveAt(selectedIndex);
\r
141 isRepoListChanged = true;
\r
146 void UpRepoButtonClick(object sender, EventArgs e)
\r
148 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
149 if ((1 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
150 NaGet.Utils.ListSwap(repos, selectedIndex-1, selectedIndex);
\r
151 AppliStation.Util.GUIUtils.CheckedListBox_SwapItems(repoListCheckedListBox, selectedIndex-1, selectedIndex);
\r
152 repoListCheckedListBox.SelectedIndex --;
\r
154 isRepoListChanged = true;
\r
158 void DownRepoButtonClick(object sender, EventArgs e)
\r
160 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
161 if ((0 <= selectedIndex) && (selectedIndex < (repos.Count-1))) {
\r
162 NaGet.Utils.ListSwap(repos, selectedIndex, selectedIndex+1);
\r
163 AppliStation.Util.GUIUtils.CheckedListBox_SwapItems(repoListCheckedListBox, selectedIndex, selectedIndex+1);
\r
164 repoListCheckedListBox.SelectedIndex ++;
\r
166 isRepoListChanged = true;
\r
170 void RepoUrlTextBoxLeave(object sender, EventArgs e)
\r
172 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
173 if ((0 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
174 if (repoUrlTextBox.Text != repos[selectedIndex].Url.Href) {
\r
175 repos[selectedIndex].Url = new LocationEntry(repoUrlTextBox.Text);
\r
176 repoListCheckedListBox.Items[selectedIndex] = repoListCheckedListBoxRenderer(repos[selectedIndex]);
\r
178 isRepoListChanged = true;
\r
184 /// レポジトリリストが編集されたか否かのフラグ
\r
186 /// <remarks>ソフトリストの再読み込みが必要か否かの判断に使われる</remarks>
\r
187 public bool IsRepositoryListSettingChanged {
\r
188 get { return isRepoListChanged; }
\r
192 /// レポジトリリストの設定を反映する
\r
194 private void commitRepositoryListSetting()
\r
196 if (isRepoListChanged) {
\r
197 NaGet.Utils.PutSerializeObject<RepositoriesList>(NaGet.Env.RepositoriesListFile, this.RepositoriesListSetting);
\r
203 #region プロキシサーバ設定関連
\r
206 /// プロキシアドレスを設定あるいは取得する
\r
208 public string ProxyAddress {
\r
210 if (proxySameAsIERadioButton.Checked) {
\r
211 return string.Empty;
\r
212 } else if (directConnRadioButton.Checked) {
\r
215 return proxyURLTextBox.Text;
\r
219 if (string.IsNullOrEmpty(value)) {
\r
220 proxySameAsIERadioButton.Checked = true;
\r
221 } else if ("-" == value) {
\r
222 directConnRadioButton.Checked = true;
\r
224 specifyProxyRadioButton.Checked = true;
\r
225 proxyURLTextBox.Text = value;
\r
228 updateProxyURLEnability();
\r
233 /// ProxyURLのテキストボックス領域の有効状態を切り替える
\r
235 private void updateProxyURLEnability()
\r
237 bool isSpecifiedProxy = specifyProxyRadioButton.Checked;
\r
239 proxyURLLabel.Enabled = isSpecifiedProxy;
\r
240 proxyURLTextBox.Enabled = isSpecifiedProxy;
\r
243 void ProxyRadioButtonsCheckedChanged(object sender, EventArgs e)
\r
245 updateProxyURLEnability();
\r
248 void OpenInternetOptionLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
250 string verb = "open";
\r
252 if (sender == openInternetOptionLinkAdminLabel) {
\r
257 ProcessStartInfo procInfo = new ProcessStartInfo("control.exe");
\r
258 procInfo.Arguments = "inetcpl.cpl,,4";
\r
259 procInfo.UseShellExecute = true;
\r
260 procInfo.Verb = verb;
\r
262 Process.Start(procInfo);
\r
263 } catch (System.ComponentModel.Win32Exception ex) {
\r
264 MessageBox.Show(ex.Message, "インターネットオプション", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
265 } catch (Exception) {
\r
266 MessageBox.Show("インターネットオプションが開けませんでした", "インターネットオプション", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
271 /// プロキシ設定を、指定された設定オブジェクトに設定する。
\r
273 /// <param name="pref">設定オブジェクト</param>
\r
274 private void commitProxySetting(NaGet.NaGetLibPref pref)
\r
276 pref.ProxyAddress = this.ProxyAddress;
\r
284 /// インストーラーファイルをウイルススキャンするかを設定あるいは取得する
\r
286 public bool EnableScanInstallerFile {
\r
287 set { this.installScanInstallerFileCheckbox.Checked = value; }
\r
288 get { return this.installScanInstallerFileCheckbox.Checked; }
\r
292 /// インストール・アンインストールを優先度を下げて実行するかを設定あるいは取得する
\r
294 public bool InstallOnBackground {
\r
295 set { this.installOnBackgroundCheckBox.Checked = value; }
\r
296 get { return this.installOnBackgroundCheckBox.Checked; }
\r
300 /// インストール関連設定を、指定された設定オブジェクトに設定する。
\r
302 /// <param name="pref">設定オブジェクト</param>
\r
303 private void commitInstallSetting(NaGet.NaGetLibPref pref)
\r
305 pref.EnableScanInstallerFile = this.EnableScanInstallerFile;
\r
306 pref.InstallOnBackground = this.InstallOnBackground;
\r
312 /// 指定された設定オブジェクトをファイルとして保存する
\r
314 /// <param name="pref">設定ファイル</param>
\r
315 private static void commitNaGetLibPref(NaGet.NaGetLibPref pref)
\r
318 string path = NaGet.Env.PrefPath;
\r
319 NaGet.Utils.PutSerializeObject<NaGet.NaGetLibPref>(path, pref);
\r
321 // 設定についてファイルから設定を再読み込みさせる
\r
322 NaGet.Env.LoadPref();
\r
325 void OkButtonClick(object sender, EventArgs e)
\r
327 NaGet.NaGetLibPref pref = NaGet.Env.Pref;
\r
329 commitRepositoryListSetting();
\r
330 commitProxySetting(pref);
\r
331 commitInstallSetting(pref);
\r
333 commitNaGetLibPref(pref);
\r
336 void CancelButtonClick(object sender, EventArgs e)
\r
340 void RepoUrlTextBoxValidating(object sender, System.ComponentModel.CancelEventArgs e)
\r
342 string urlText = repoUrlTextBox.Text;
\r
344 if (string.IsNullOrEmpty(urlText)) {
\r
345 return; // special case.
\r
346 } if (Uri.IsWellFormedUriString(urlText, UriKind.Absolute) == false) {
\r
347 repoUrlTextBoxErrorProvider.SetError(repoUrlLabel, "URLの記述が不正です");
\r
350 Uri uri = new Uri(urlText);
\r
351 if ((uri.Scheme != Uri.UriSchemeFile) &&
\r
352 (uri.Scheme != Uri.UriSchemeFtp) &&
\r
353 (uri.Scheme != Uri.UriSchemeHttp) &&
\r
354 (uri.Scheme != Uri.UriSchemeHttps)){
\r
355 repoUrlTextBoxErrorProvider.SetError(repoUrlLabel, "URLの記述が不正です");
\r
358 repoUrlTextBoxErrorProvider.Clear();
\r