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
30 AppliStation.Util.NativeMethods.LinkLabel_SetElevationRequiredState(this.openInternetOptionLinkAdminLabel, true);
\r
38 public void loadCurrentPref()
\r
41 this.RepositoriesListSetting = NaGet.Utils.GetDeserializedObject<RepositoriesList>(NaGet.Env.RepositoriesListFile);
\r
43 this.RepositoriesListSetting = new RepositoriesList();
\r
46 NaGet.NaGetLibPref userPref = NaGet.Env.Pref;
\r
47 this.ProxyAddress = userPref.ProxyAddress;
\r
48 this.EnableScanInstallerFile = userPref.EnableScanInstallerFile;
\r
49 this.InstallOnBackground = userPref.InstallOnBackground;
\r
50 this.CacheFolder = userPref.CacheFolder;
\r
51 this.ExcludeUpdatePackageNames = userPref.ExcludeUpdatePackageNames;
\r
54 #region レポジトリリスト設定関連
\r
57 /// レポジトリリストの設定を読み書きする
\r
59 public RepositoriesList RepositoriesListSetting {
\r
61 RepositoriesList repoList = new RepositoriesList();
\r
62 repoList.Repositories = repos.ToArray();
\r
67 repos.AddRange(value.Repositories);
\r
72 isRepoListChanged = false;
\r
77 /// ListBoxへ表示するレポジトリ表現文字列を返す
\r
79 /// <param name="repo">対象レポジトリ</param>
\r
80 /// <returns>ListBoxに表示すべき文字列</returns>
\r
81 private static string repoListCheckedListBoxRenderer(RepositoryInfo repo) {
\r
82 return string.Format("{0}[{1}]", repo.Name, repo.Url.Href);
\r
86 /// ListBoxの内容を更新(再構築)する。
\r
88 private void updateRepos()
\r
90 repoListCheckedListBox.Items.Clear();
\r
92 foreach (RepositoryInfo repo in repos) {
\r
93 string label = repoListCheckedListBoxRenderer(repo);
\r
94 repoListCheckedListBox.Items.Add(label, repo.Enabled);
\r
98 void RepoListCheckedListBoxSelectedIndexChanged(object sender, EventArgs e)
\r
100 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
101 bool selected = (selectedIndex >= 0);
\r
103 removeRepoButton.Enabled = selected;
\r
104 upRepoButton.Enabled = selected && ((1 <= selectedIndex) && (selectedIndex < repos.Count));
\r
105 downRepoButton.Enabled = selected && ((0 <= selectedIndex) && (selectedIndex < (repos.Count-1)));
\r
106 repoUrlLabel.Enabled = selected;
\r
107 repoUrlTextBox.Enabled = selected;
\r
109 repoUrlTextBox.Text = repos[repoListCheckedListBox.SelectedIndex].Url.Href;
\r
110 repoUrlTextBox.SelectAll();
\r
112 repoUrlTextBox.Clear();
\r
116 void AddRepoButtonClick(object sender, EventArgs e)
\r
118 RepositoryInfo repo = new RepositoryInfo();
\r
119 repo.Name = string.Format("新しいレポジトリ");
\r
120 repo.Url = new LocationEntry();
\r
121 repo.Enabled = true;
\r
126 repoListCheckedListBox.SelectedIndex = repos.Count - 1;
\r
128 isRepoListChanged = true;
\r
131 void RepoListCheckedListBoxItemCheck(object sender, ItemCheckEventArgs e)
\r
133 repos[e.Index].Enabled = (e.NewValue == CheckState.Checked);
\r
135 isRepoListChanged = true;
\r
138 void RemoveRepoButtonClick(object sender, EventArgs e)
\r
140 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
141 if ((0 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
142 string text = string.Format("本当にレポジトリ「{0}」を消去しますか?", repos[selectedIndex].Name);
\r
143 DialogResult result = MessageBox.Show(text, "レポジトリの削除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
\r
144 if (result == DialogResult.OK) {
\r
145 repos.RemoveAt(selectedIndex);
\r
146 repoListCheckedListBox.Items.RemoveAt(selectedIndex);
\r
148 isRepoListChanged = true;
\r
153 void UpRepoButtonClick(object sender, EventArgs e)
\r
155 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
156 if ((1 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
157 NaGet.Utils.ListSwap(repos, selectedIndex-1, selectedIndex);
\r
158 AppliStation.Util.GUIUtils.CheckedListBox_SwapItems(repoListCheckedListBox, selectedIndex-1, selectedIndex);
\r
159 repoListCheckedListBox.SelectedIndex --;
\r
161 isRepoListChanged = true;
\r
165 void DownRepoButtonClick(object sender, EventArgs e)
\r
167 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
168 if ((0 <= selectedIndex) && (selectedIndex < (repos.Count-1))) {
\r
169 NaGet.Utils.ListSwap(repos, selectedIndex, selectedIndex+1);
\r
170 AppliStation.Util.GUIUtils.CheckedListBox_SwapItems(repoListCheckedListBox, selectedIndex, selectedIndex+1);
\r
171 repoListCheckedListBox.SelectedIndex ++;
\r
173 isRepoListChanged = true;
\r
177 void RepoUrlTextBoxValidated(object sender, EventArgs e)
\r
179 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
180 if ((0 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
181 if (repoUrlTextBox.Text != repos[selectedIndex].Url.Href) {
\r
182 repos[selectedIndex].Url = new LocationEntry(repoUrlTextBox.Text);
\r
183 repoListCheckedListBox.Items[selectedIndex] = repoListCheckedListBoxRenderer(repos[selectedIndex]);
\r
185 isRepoListChanged = true;
\r
191 /// レポジトリリストが編集されたか否かのフラグ
\r
193 /// <remarks>ソフトリストの再読み込みが必要か否かの判断に使われる</remarks>
\r
194 public bool IsRepositoryListSettingChanged {
\r
195 get { return isRepoListChanged; }
\r
199 /// レポジトリリストの設定を反映する
\r
201 private void commitRepositoryListSetting()
\r
203 if (isRepoListChanged) {
\r
204 NaGet.Utils.PutSerializeObject<RepositoriesList>(NaGet.Env.RepositoriesListFile, this.RepositoriesListSetting);
\r
210 #region プロキシサーバ設定関連
\r
213 /// プロキシアドレスを設定あるいは取得する
\r
215 public string ProxyAddress {
\r
217 if (proxySameAsIERadioButton.Checked) {
\r
218 return string.Empty;
\r
219 } else if (directConnRadioButton.Checked) {
\r
222 return proxyURLTextBox.Text;
\r
226 if (string.IsNullOrEmpty(value)) {
\r
227 proxySameAsIERadioButton.Checked = true;
\r
228 } else if ("-" == value) {
\r
229 directConnRadioButton.Checked = true;
\r
231 specifyProxyRadioButton.Checked = true;
\r
232 proxyURLTextBox.Text = value;
\r
235 updateProxyURLEnability();
\r
240 /// ProxyURLのテキストボックス領域の有効状態を切り替える
\r
242 private void updateProxyURLEnability()
\r
244 bool isSpecifiedProxy = specifyProxyRadioButton.Checked;
\r
246 proxyURLLabel.Enabled = isSpecifiedProxy;
\r
247 proxyURLTextBox.Enabled = isSpecifiedProxy;
\r
250 void ProxyRadioButtonsCheckedChanged(object sender, EventArgs e)
\r
252 updateProxyURLEnability();
\r
255 void OpenInternetOptionLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
257 string verb = "open";
\r
259 if (sender == openInternetOptionLinkAdminLabel) {
\r
264 ProcessStartInfo procInfo = new ProcessStartInfo("control.exe");
\r
265 procInfo.Arguments = "inetcpl.cpl,,4";
\r
266 procInfo.UseShellExecute = true;
\r
267 procInfo.Verb = verb;
\r
269 Process.Start(procInfo);
\r
270 } catch (System.ComponentModel.Win32Exception ex) {
\r
271 MessageBox.Show(ex.Message, "インターネットオプション", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
272 } catch (Exception) {
\r
273 MessageBox.Show("インターネットオプションが開けませんでした", "インターネットオプション", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
278 /// プロキシ設定を、指定された設定オブジェクトに設定する。
\r
280 /// <param name="pref">設定オブジェクト</param>
\r
281 private void commitProxySetting(NaGet.NaGetLibPref pref)
\r
283 pref.ProxyAddress = this.ProxyAddress;
\r
291 /// インストーラーファイルをウイルススキャンするかを設定あるいは取得する
\r
293 public bool EnableScanInstallerFile {
\r
294 set { this.installScanInstallerFileCheckbox.Checked = value; }
\r
295 get { return this.installScanInstallerFileCheckbox.Checked; }
\r
299 /// インストール・アンインストールを優先度を下げて実行するかを設定あるいは取得する
\r
301 public bool InstallOnBackground {
\r
302 set { this.installOnBackgroundCheckBox.Checked = value; }
\r
303 get { return this.installOnBackgroundCheckBox.Checked; }
\r
306 public string CacheFolder {
\r
308 if (string.IsNullOrEmpty(value)) {
\r
309 this.cacheFolderCustomCheckBox.Checked = false;
\r
310 this.cacheFolderTextBox.Text = string.Empty;
\r
312 this.cacheFolderCustomCheckBox.Checked = true;
\r
313 this.cacheFolderTextBox.Text = value;
\r
317 if (this.cacheFolderCustomCheckBox.Checked) {
\r
318 return this.cacheFolderTextBox.Text;
\r
326 /// インストール関連設定を、指定された設定オブジェクトに設定する。
\r
328 /// <param name="pref">設定オブジェクト</param>
\r
329 private void commitInstallSetting(NaGet.NaGetLibPref pref)
\r
331 pref.EnableScanInstallerFile = this.EnableScanInstallerFile;
\r
332 pref.InstallOnBackground = this.InstallOnBackground;
\r
333 pref.CacheFolder = this.CacheFolder;
\r
341 public string[] ExcludeUpdatePackageNames {
\r
343 this.upgradeExcludeTextBox.Lines = value;
\r
346 List<string> list = new List<string>();
\r
348 foreach (string line in this.upgradeExcludeTextBox.Lines) {
\r
349 if (!string.IsNullOrEmpty(line)) {
\r
354 return list.ToArray();
\r
359 /// ソフト更新関連設定を、指定された設定オブジェクトに設定する。
\r
361 /// <param name="pref">設定オブジェクト</param>
\r
362 private void commitUpgradeSetting(NaGet.NaGetLibPref pref)
\r
364 pref.ExcludeUpdatePackageNames = this.ExcludeUpdatePackageNames;
\r
370 /// 指定された設定オブジェクトをファイルとして保存する
\r
372 /// <param name="pref">設定ファイル</param>
\r
373 private static void commitNaGetLibPref(NaGet.NaGetLibPref pref)
\r
376 string path = NaGet.Env.PrefPath;
\r
377 NaGet.Utils.PutSerializeObject<NaGet.NaGetLibPref>(path, pref);
\r
379 // 設定についてファイルから設定を再読み込みさせる
\r
380 NaGet.Env.LoadPref();
\r
383 void OkButtonClick(object sender, EventArgs e)
\r
385 NaGet.NaGetLibPref pref = NaGet.Env.Pref;
\r
387 commitRepositoryListSetting();
\r
388 commitProxySetting(pref);
\r
389 commitInstallSetting(pref);
\r
390 commitUpgradeSetting(pref);
\r
392 commitNaGetLibPref(pref);
\r
395 void CancelButtonClick(object sender, EventArgs e)
\r
399 void RepoUrlTextBoxValidating(object sender, System.ComponentModel.CancelEventArgs e)
\r
401 string urlText = repoUrlTextBox.Text;
\r
403 if (string.IsNullOrEmpty(urlText)) {
\r
404 return; // special case.
\r
405 } if (Uri.IsWellFormedUriString(urlText, UriKind.Absolute) == false) {
\r
406 errorProvider.SetError(repoUrlLabel, "URLの記述が不正です");
\r
409 Uri uri = new Uri(urlText);
\r
410 if ((uri.Scheme != Uri.UriSchemeFile) &&
\r
411 (uri.Scheme != Uri.UriSchemeFtp) &&
\r
412 (uri.Scheme != Uri.UriSchemeHttp) &&
\r
413 (uri.Scheme != Uri.UriSchemeHttps)){
\r
414 errorProvider.SetError(repoUrlLabel, "URLの記述が不正です");
\r
417 errorProvider.Clear();
\r
423 void CacheFolderCustomCheckBoxCheckedChanged(object sender, EventArgs e)
\r
425 cacheFolderTextBox.Enabled = cacheFolderCustomCheckBox.Checked;
\r
426 cacheFolderBrowseButton.Enabled = cacheFolderCustomCheckBox.Checked;
\r
429 void CacheFolderBrowseButtonClick(object sender, EventArgs e)
\r
431 string pwd = System.IO.Directory.GetCurrentDirectory();
\r
432 FolderBrowserDialog fd = new FolderBrowserDialog();
\r
433 fd.Description = "キャッシュフォルダーを指定してください。";
\r
434 fd.SelectedPath = cacheFolderTextBox.Text;
\r
435 fd.ShowNewFolderButton = true;
\r
437 if (fd.ShowDialog(this) == DialogResult.OK) {
\r
438 cacheFolderTextBox.Text = fd.SelectedPath;
\r
441 System.IO.Directory.SetCurrentDirectory(pwd); // ダイアログで変わったカレントディレクトリを元に戻す
\r
444 void CacheFolderTextBoxValidating(object sender, System.ComponentModel.CancelEventArgs e)
\r
446 string folderPath = cacheFolderTextBox.Text;
\r
448 if (string.IsNullOrEmpty(folderPath)) {
\r
449 errorProvider.Clear();
\r
450 return; // special case
\r
451 } else if (! System.IO.Directory.Exists(folderPath)) {
\r
452 errorProvider.SetError(cacheFolderTextBox, "存在しないフォルダーパスを指定しています。");
\r
455 errorProvider.Clear();
\r
459 void CacheFolderOpenLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
463 if (cacheFolderCustomCheckBox.Checked) {
\r
464 folderPath = cacheFolderTextBox.Text;
\r
466 // デフォルトは AppDataFolderPath/Cache。
\r
467 folderPath = System.IO.Path.Combine(NaGet.Env.AppDataFolderPath, "Cache");
\r
470 if (System.IO.Directory.Exists(folderPath)) {
\r
472 Process.Start(folderPath);
\r
473 } catch (Exception ex) {
\r
474 MessageBox.Show(ex.Message, "キャッシュフォルダー", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
477 MessageBox.Show(string.Format("フォルダーパス\"{0}\"は存在しませんでした。", folderPath), "キャッシュフォルダー", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
481 void CacheFolderClearLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
485 if (cacheFolderCustomCheckBox.Checked) {
\r
486 folderPath = cacheFolderTextBox.Text;
\r
488 // デフォルトは AppDataFolderPath/Cache。
\r
489 folderPath = System.IO.Path.Combine(NaGet.Env.AppDataFolderPath, "Cache");
\r
492 if (System.IO.Directory.Exists(folderPath)) {
\r
493 DialogResult result = MessageBox.Show(string.Format("フォルダーパス\"{0}\"のファイルを削除して構いませんか?", folderPath), "キャッシュフォルダー", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
\r
494 if (result == DialogResult.OK) {
\r
495 foreach (string targetDir in System.IO.Directory.GetDirectories(folderPath)) {
\r
497 NaGet.Utils.SetAttributeRecursive(targetDir, System.IO.FileAttributes.Normal);
\r
498 System.IO.Directory.Delete(targetDir, true);
\r
505 MessageBox.Show(string.Format("フォルダーパス\"{0}\"は存在しませんでした。", folderPath), "キャッシュフォルダー", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r