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
45 this.CacheFolder = userPref.CacheFolder;
\r
48 #region レポジトリリスト設定関連
\r
51 /// レポジトリリストの設定を読み書きする
\r
53 public RepositoriesList RepositoriesListSetting {
\r
55 RepositoriesList repoList = new RepositoriesList();
\r
56 repoList.Repositories = repos.ToArray();
\r
61 repos.AddRange(value.Repositories);
\r
66 isRepoListChanged = false;
\r
71 /// ListBoxへ表示するレポジトリ表現文字列を返す
\r
73 /// <param name="repo">対象レポジトリ</param>
\r
74 /// <returns>ListBoxに表示すべき文字列</returns>
\r
75 private static string repoListCheckedListBoxRenderer(RepositoryInfo repo) {
\r
76 return string.Format("{0}[{1}]", repo.Name, repo.Url.Href);
\r
80 /// ListBoxの内容を更新(再構築)する。
\r
82 private void updateRepos()
\r
84 repoListCheckedListBox.Items.Clear();
\r
86 foreach (RepositoryInfo repo in repos) {
\r
87 string label = repoListCheckedListBoxRenderer(repo);
\r
88 repoListCheckedListBox.Items.Add(label, repo.Enabled);
\r
92 void RepoListCheckedListBoxSelectedIndexChanged(object sender, EventArgs e)
\r
94 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
95 bool selected = (selectedIndex >= 0);
\r
97 removeRepoButton.Enabled = selected;
\r
98 upRepoButton.Enabled = selected && ((1 <= selectedIndex) && (selectedIndex < repos.Count));
\r
99 downRepoButton.Enabled = selected && ((0 <= selectedIndex) && (selectedIndex < (repos.Count-1)));
\r
100 repoUrlLabel.Enabled = selected;
\r
101 repoUrlTextBox.Enabled = selected;
\r
103 repoUrlTextBox.Text = repos[repoListCheckedListBox.SelectedIndex].Url.Href;
\r
104 repoUrlTextBox.SelectAll();
\r
106 repoUrlTextBox.Clear();
\r
110 void AddRepoButtonClick(object sender, EventArgs e)
\r
112 RepositoryInfo repo = new RepositoryInfo();
\r
113 repo.Name = string.Format("新しいレポジトリ");
\r
114 repo.Url = new LocationEntry();
\r
115 repo.Enabled = true;
\r
120 repoListCheckedListBox.SelectedIndex = repos.Count - 1;
\r
122 isRepoListChanged = true;
\r
125 void RepoListCheckedListBoxItemCheck(object sender, ItemCheckEventArgs e)
\r
127 repos[e.Index].Enabled = (e.NewValue == CheckState.Checked);
\r
129 isRepoListChanged = true;
\r
132 void RemoveRepoButtonClick(object sender, EventArgs e)
\r
134 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
135 if ((0 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
136 string text = string.Format("本当にレポジトリ「{0}」を消去しますか?", repos[selectedIndex].Name);
\r
137 DialogResult result = MessageBox.Show(text, "レポジトリの削除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
\r
138 if (result == DialogResult.OK) {
\r
139 repos.RemoveAt(selectedIndex);
\r
140 repoListCheckedListBox.Items.RemoveAt(selectedIndex);
\r
142 isRepoListChanged = true;
\r
147 void UpRepoButtonClick(object sender, EventArgs e)
\r
149 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
150 if ((1 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
151 NaGet.Utils.ListSwap(repos, selectedIndex-1, selectedIndex);
\r
152 AppliStation.Util.GUIUtils.CheckedListBox_SwapItems(repoListCheckedListBox, selectedIndex-1, selectedIndex);
\r
153 repoListCheckedListBox.SelectedIndex --;
\r
155 isRepoListChanged = true;
\r
159 void DownRepoButtonClick(object sender, EventArgs e)
\r
161 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
162 if ((0 <= selectedIndex) && (selectedIndex < (repos.Count-1))) {
\r
163 NaGet.Utils.ListSwap(repos, selectedIndex, selectedIndex+1);
\r
164 AppliStation.Util.GUIUtils.CheckedListBox_SwapItems(repoListCheckedListBox, selectedIndex, selectedIndex+1);
\r
165 repoListCheckedListBox.SelectedIndex ++;
\r
167 isRepoListChanged = true;
\r
171 void RepoUrlTextBoxLeave(object sender, EventArgs e)
\r
173 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
174 if ((0 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
175 if (repoUrlTextBox.Text != repos[selectedIndex].Url.Href) {
\r
176 repos[selectedIndex].Url = new LocationEntry(repoUrlTextBox.Text);
\r
177 repoListCheckedListBox.Items[selectedIndex] = repoListCheckedListBoxRenderer(repos[selectedIndex]);
\r
179 isRepoListChanged = true;
\r
185 /// レポジトリリストが編集されたか否かのフラグ
\r
187 /// <remarks>ソフトリストの再読み込みが必要か否かの判断に使われる</remarks>
\r
188 public bool IsRepositoryListSettingChanged {
\r
189 get { return isRepoListChanged; }
\r
193 /// レポジトリリストの設定を反映する
\r
195 private void commitRepositoryListSetting()
\r
197 if (isRepoListChanged) {
\r
198 NaGet.Utils.PutSerializeObject<RepositoriesList>(NaGet.Env.RepositoriesListFile, this.RepositoriesListSetting);
\r
204 #region プロキシサーバ設定関連
\r
207 /// プロキシアドレスを設定あるいは取得する
\r
209 public string ProxyAddress {
\r
211 if (proxySameAsIERadioButton.Checked) {
\r
212 return string.Empty;
\r
213 } else if (directConnRadioButton.Checked) {
\r
216 return proxyURLTextBox.Text;
\r
220 if (string.IsNullOrEmpty(value)) {
\r
221 proxySameAsIERadioButton.Checked = true;
\r
222 } else if ("-" == value) {
\r
223 directConnRadioButton.Checked = true;
\r
225 specifyProxyRadioButton.Checked = true;
\r
226 proxyURLTextBox.Text = value;
\r
229 updateProxyURLEnability();
\r
234 /// ProxyURLのテキストボックス領域の有効状態を切り替える
\r
236 private void updateProxyURLEnability()
\r
238 bool isSpecifiedProxy = specifyProxyRadioButton.Checked;
\r
240 proxyURLLabel.Enabled = isSpecifiedProxy;
\r
241 proxyURLTextBox.Enabled = isSpecifiedProxy;
\r
244 void ProxyRadioButtonsCheckedChanged(object sender, EventArgs e)
\r
246 updateProxyURLEnability();
\r
249 void OpenInternetOptionLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
251 string verb = "open";
\r
253 if (sender == openInternetOptionLinkAdminLabel) {
\r
258 ProcessStartInfo procInfo = new ProcessStartInfo("control.exe");
\r
259 procInfo.Arguments = "inetcpl.cpl,,4";
\r
260 procInfo.UseShellExecute = true;
\r
261 procInfo.Verb = verb;
\r
263 Process.Start(procInfo);
\r
264 } catch (System.ComponentModel.Win32Exception ex) {
\r
265 MessageBox.Show(ex.Message, "インターネットオプション", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
266 } catch (Exception) {
\r
267 MessageBox.Show("インターネットオプションが開けませんでした", "インターネットオプション", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
272 /// プロキシ設定を、指定された設定オブジェクトに設定する。
\r
274 /// <param name="pref">設定オブジェクト</param>
\r
275 private void commitProxySetting(NaGet.NaGetLibPref pref)
\r
277 pref.ProxyAddress = this.ProxyAddress;
\r
285 /// インストーラーファイルをウイルススキャンするかを設定あるいは取得する
\r
287 public bool EnableScanInstallerFile {
\r
288 set { this.installScanInstallerFileCheckbox.Checked = value; }
\r
289 get { return this.installScanInstallerFileCheckbox.Checked; }
\r
293 /// インストール・アンインストールを優先度を下げて実行するかを設定あるいは取得する
\r
295 public bool InstallOnBackground {
\r
296 set { this.installOnBackgroundCheckBox.Checked = value; }
\r
297 get { return this.installOnBackgroundCheckBox.Checked; }
\r
300 public string CacheFolder {
\r
302 if (string.IsNullOrEmpty(value)) {
\r
303 this.cacheFolderCustomCheckBox.Checked = false;
\r
304 this.cacheFolderTextBox.Text = string.Empty;
\r
306 this.cacheFolderCustomCheckBox.Checked = true;
\r
307 this.cacheFolderTextBox.Text = value;
\r
311 if (this.cacheFolderCustomCheckBox.Checked) {
\r
312 return this.cacheFolderTextBox.Text;
\r
320 /// インストール関連設定を、指定された設定オブジェクトに設定する。
\r
322 /// <param name="pref">設定オブジェクト</param>
\r
323 private void commitInstallSetting(NaGet.NaGetLibPref pref)
\r
325 pref.EnableScanInstallerFile = this.EnableScanInstallerFile;
\r
326 pref.InstallOnBackground = this.InstallOnBackground;
\r
327 pref.CacheFolder = this.CacheFolder;
\r
333 /// 指定された設定オブジェクトをファイルとして保存する
\r
335 /// <param name="pref">設定ファイル</param>
\r
336 private static void commitNaGetLibPref(NaGet.NaGetLibPref pref)
\r
339 string path = NaGet.Env.PrefPath;
\r
340 NaGet.Utils.PutSerializeObject<NaGet.NaGetLibPref>(path, pref);
\r
342 // 設定についてファイルから設定を再読み込みさせる
\r
343 NaGet.Env.LoadPref();
\r
346 void OkButtonClick(object sender, EventArgs e)
\r
348 NaGet.NaGetLibPref pref = NaGet.Env.Pref;
\r
350 commitRepositoryListSetting();
\r
351 commitProxySetting(pref);
\r
352 commitInstallSetting(pref);
\r
354 commitNaGetLibPref(pref);
\r
357 void CancelButtonClick(object sender, EventArgs e)
\r
361 void RepoUrlTextBoxValidating(object sender, System.ComponentModel.CancelEventArgs e)
\r
363 string urlText = repoUrlTextBox.Text;
\r
365 if (string.IsNullOrEmpty(urlText)) {
\r
366 return; // special case.
\r
367 } if (Uri.IsWellFormedUriString(urlText, UriKind.Absolute) == false) {
\r
368 errorProvider.SetError(repoUrlLabel, "URLの記述が不正です");
\r
371 Uri uri = new Uri(urlText);
\r
372 if ((uri.Scheme != Uri.UriSchemeFile) &&
\r
373 (uri.Scheme != Uri.UriSchemeFtp) &&
\r
374 (uri.Scheme != Uri.UriSchemeHttp) &&
\r
375 (uri.Scheme != Uri.UriSchemeHttps)){
\r
376 errorProvider.SetError(repoUrlLabel, "URLの記述が不正です");
\r
379 errorProvider.Clear();
\r
385 void CacheFolderCustomCheckBoxCheckedChanged(object sender, EventArgs e)
\r
387 cacheFolderTextBox.Enabled = cacheFolderCustomCheckBox.Checked;
\r
388 cacheFolderBrowseButton.Enabled = cacheFolderCustomCheckBox.Checked;
\r
391 void CacheFolderBrowseButtonClick(object sender, EventArgs e)
\r
393 FolderBrowserDialog fd = new FolderBrowserDialog();
\r
394 fd.Description = "キャッシュフォルダーを指定してください。";
\r
395 fd.SelectedPath = cacheFolderTextBox.Text;
\r
396 fd.ShowNewFolderButton = true;
\r
398 if (fd.ShowDialog(this) == DialogResult.OK) {
\r
399 cacheFolderTextBox.Text = fd.SelectedPath;
\r
403 void CacheFolderTextBoxValidating(object sender, System.ComponentModel.CancelEventArgs e)
\r
405 string folderPath = cacheFolderTextBox.Text;
\r
407 if (string.IsNullOrEmpty(folderPath)) {
\r
408 errorProvider.Clear();
\r
409 return; // special case
\r
410 } else if (! System.IO.Directory.Exists(folderPath)) {
\r
411 errorProvider.SetError(cacheFolderTextBox, "存在しないフォルダーパスを指定しています。");
\r
414 errorProvider.Clear();
\r
418 void CacheFolderOpenLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
422 if (cacheFolderCustomCheckBox.Checked) {
\r
423 folderPath = cacheFolderTextBox.Text;
\r
425 // デフォルトは AppDataFolderPath/Cache。
\r
426 folderPath = System.IO.Path.Combine(NaGet.Env.AppDataFolderPath, "Cache");
\r
429 if (System.IO.Directory.Exists(folderPath)) {
\r
431 Process.Start(folderPath);
\r
432 } catch (Exception ex) {
\r
433 MessageBox.Show(ex.Message, "キャッシュフォルダー", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
436 MessageBox.Show(string.Format("フォルダーパス\"{0}\"は存在しませんでした。", folderPath), "キャッシュフォルダー", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r