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
45 #region レポジトリリスト設定関連
\r
48 /// レポジトリリストの設定を読み書きする
\r
50 public RepositoriesList RepositoriesListSetting {
\r
52 RepositoriesList repoList = new RepositoriesList();
\r
53 repoList.Repositories = repos.ToArray();
\r
58 repos.AddRange(value.Repositories);
\r
63 isRepoListChanged = false;
\r
68 /// ListBoxへ表示するレポジトリ表現文字列を返す
\r
70 /// <param name="repo">対象レポジトリ</param>
\r
71 /// <returns>ListBoxに表示すべき文字列</returns>
\r
72 private string repoListCheckedListBoxRenderer(RepositoryInfo repo) {
\r
73 return string.Format("{0}[{1}]", repo.Name, repo.Url.Href);
\r
77 /// ListBoxの内容を更新(再構築)する。
\r
79 private void updateRepos()
\r
81 repoListCheckedListBox.Items.Clear();
\r
83 foreach (RepositoryInfo repo in repos) {
\r
84 string label = repoListCheckedListBoxRenderer(repo);
\r
85 repoListCheckedListBox.Items.Add(label, repo.Enabled);
\r
89 void RepoListCheckedListBoxSelectedIndexChanged(object sender, EventArgs e)
\r
91 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
92 bool selected = (selectedIndex >= 0);
\r
94 removeRepoButton.Enabled = selected;
\r
95 upRepoButton.Enabled = selected && ((1 <= selectedIndex) && (selectedIndex < repos.Count));
\r
96 downRepoButton.Enabled = selected && ((0 <= selectedIndex) && (selectedIndex < (repos.Count-1)));
\r
97 repoUrlLabel.Enabled = selected;
\r
98 repoUrlTextBox.Enabled = selected;
\r
100 repoUrlTextBox.Text = repos[repoListCheckedListBox.SelectedIndex].Url.Href;
\r
101 repoUrlTextBox.SelectAll();
\r
103 repoUrlTextBox.Clear();
\r
107 void AddRepoButtonClick(object sender, EventArgs e)
\r
109 RepositoryInfo repo = new RepositoryInfo();
\r
110 repo.Name = string.Format("新しいレポジトリ");
\r
111 repo.Url = new LocationEntry();
\r
112 repo.Enabled = true;
\r
117 repoListCheckedListBox.SelectedIndex = repos.Count - 1;
\r
119 isRepoListChanged = true;
\r
122 void RepoListCheckedListBoxItemCheck(object sender, ItemCheckEventArgs e)
\r
124 repos[e.Index].Enabled = (e.NewValue == CheckState.Checked);
\r
126 isRepoListChanged = true;
\r
129 void RemoveRepoButtonClick(object sender, EventArgs e)
\r
131 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
132 if ((0 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
133 string text = string.Format("本当にレポジトリ「{0}」を消去しますか?", repos[selectedIndex].Name);
\r
134 DialogResult result = MessageBox.Show(text, "レポジトリの削除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
\r
135 if (result == DialogResult.OK) {
\r
136 repos.RemoveAt(selectedIndex);
\r
137 repoListCheckedListBox.Items.RemoveAt(selectedIndex);
\r
139 isRepoListChanged = true;
\r
144 void UpRepoButtonClick(object sender, EventArgs e)
\r
146 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
147 if ((1 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
148 NaGet.Utils.ListSwap(repos, selectedIndex-1, selectedIndex);
\r
149 AppliStation.Util.GUIUtils.CheckedListBox_SwapItems(repoListCheckedListBox, selectedIndex-1, selectedIndex);
\r
150 repoListCheckedListBox.SelectedIndex --;
\r
152 isRepoListChanged = true;
\r
156 void DownRepoButtonClick(object sender, EventArgs e)
\r
158 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
159 if ((0 <= selectedIndex) && (selectedIndex < (repos.Count-1))) {
\r
160 NaGet.Utils.ListSwap(repos, selectedIndex, selectedIndex+1);
\r
161 AppliStation.Util.GUIUtils.CheckedListBox_SwapItems(repoListCheckedListBox, selectedIndex, selectedIndex+1);
\r
162 repoListCheckedListBox.SelectedIndex ++;
\r
164 isRepoListChanged = true;
\r
168 void RepoUrlTextBoxLeave(object sender, EventArgs e)
\r
170 int selectedIndex = repoListCheckedListBox.SelectedIndex;
\r
171 if ((0 <= selectedIndex) && (selectedIndex < repos.Count)) {
\r
172 if (repoUrlTextBox.Text != repos[selectedIndex].Url.Href) {
\r
173 repos[selectedIndex].Url = new LocationEntry(repoUrlTextBox.Text);
\r
174 repoListCheckedListBox.Items[selectedIndex] = repoListCheckedListBoxRenderer(repos[selectedIndex]);
\r
176 isRepoListChanged = true;
\r
182 /// レポジトリリストが編集されたか否かのフラグ
\r
184 /// <remarks>ソフトリストの再読み込みが必要か否かの判断に使われる</remarks>
\r
185 public bool IsRepositoryListSettingChanged {
\r
186 get { return isRepoListChanged; }
\r
190 /// レポジトリリストの設定を反映する
\r
192 private void commitRepositoryListSetting()
\r
194 if (isRepoListChanged) {
\r
195 NaGet.Utils.PutSerializeObject<RepositoriesList>(NaGet.Env.RepositoriesListFile, this.RepositoriesListSetting);
\r
201 #region プロキシサーバ設定関連
\r
204 /// プロキシアドレスを設定あるいは取得する
\r
206 public string ProxyAddress {
\r
208 if (proxySameAsIERadioButton.Checked) {
\r
209 return string.Empty;
\r
210 } else if (directConnRadioButton.Checked) {
\r
213 return proxyURLTextBox.Text;
\r
217 if (string.IsNullOrEmpty(value)) {
\r
218 proxySameAsIERadioButton.Checked = true;
\r
219 } else if ("-" == value) {
\r
220 directConnRadioButton.Checked = true;
\r
222 specifyProxyRadioButton.Checked = true;
\r
223 proxyURLTextBox.Text = value;
\r
226 updateProxyURLEnability();
\r
231 /// ProxyURLのテキストボックス領域の有効状態を切り替える
\r
233 private void updateProxyURLEnability()
\r
235 bool isSpecifiedProxy = specifyProxyRadioButton.Checked;
\r
237 proxyURLLabel.Enabled = isSpecifiedProxy;
\r
238 proxyURLTextBox.Enabled = isSpecifiedProxy;
\r
241 void ProxyRadioButtonsCheckedChanged(object sender, EventArgs e)
\r
243 updateProxyURLEnability();
\r
246 void OpenInternetOptionLinkLabelLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
248 string verb = "open";
\r
250 if (sender == openInternetOptionLinkAdminLabel) {
\r
255 ProcessStartInfo procInfo = new ProcessStartInfo("control.exe");
\r
256 procInfo.Arguments = "inetcpl.cpl,,4";
\r
257 procInfo.UseShellExecute = true;
\r
258 procInfo.Verb = verb;
\r
260 Process.Start(procInfo);
\r
261 } catch (System.ComponentModel.Win32Exception ex) {
\r
262 MessageBox.Show(ex.Message, "インターネットオプション", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
263 } catch (Exception) {
\r
264 MessageBox.Show("インターネットオプションが開けませんでした", "インターネットオプション", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
269 /// プロキシ設定を、指定された設定オブジェクトに設定する。
\r
271 /// <param name="pref">設定オブジェクト</param>
\r
272 private void commitProxySetting(NaGet.NaGetLibPref pref)
\r
274 pref.ProxyAddress = this.ProxyAddress;
\r
280 /// 指定された設定オブジェクトをファイルとして保存する
\r
282 /// <param name="pref">設定ファイル</param>
\r
283 private void commitNaGetLibPref(NaGet.NaGetLibPref pref)
\r
286 string path = NaGet.Env.PrefPath;
\r
287 NaGet.Utils.PutSerializeObject<NaGet.NaGetLibPref>(path, pref);
\r
289 // 設定についてファイルから設定を再読み込みさせる
\r
290 NaGet.Env.LoadPref();
\r
293 void OkButtonClick(object sender, EventArgs e)
\r
295 NaGet.NaGetLibPref pref = NaGet.Env.Pref;
\r
297 commitRepositoryListSetting();
\r
298 commitProxySetting(pref);
\r
300 commitNaGetLibPref(pref);
\r
303 void CancelButtonClick(object sender, EventArgs e)
\r