/BlueVex2/Settings/SettingsForm.cs

https://github.com/killerbonzai/BlueVex2 · C# · 305 lines · 265 code · 37 blank · 3 comment · 40 complexity · 49b7bb2536b66110890a802eeb049a3f MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using BlueVex2.Settings;
  10. namespace BlueVex2
  11. {
  12. public partial class SettingsForm : Form
  13. {
  14. public SettingsForm()
  15. {
  16. InitializeComponent();
  17. if (BlueVex2.Properties.Settings.Default.Accounts == null)
  18. {
  19. BlueVex2.Properties.Settings.Default.Accounts = new System.Collections.Specialized.StringCollection();
  20. }
  21. if (BlueVex2.Properties.Settings.Default.Installations == null)
  22. {
  23. BlueVex2.Properties.Settings.Default.Installations = new System.Collections.Specialized.StringCollection();
  24. }
  25. if (BlueVex2.Properties.Settings.Default.Games == null)
  26. {
  27. BlueVex2.Properties.Settings.Default.Games = new System.Collections.Specialized.StringCollection();
  28. }
  29. }
  30. #region General Form Stuff
  31. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  32. {
  33. switch (this.listBox1.SelectedItem.ToString())
  34. {
  35. case "Installations" :
  36. HideAllPanels();
  37. this.InstallationsPanel.Visible = true;
  38. break;
  39. case "Accounts" :
  40. HideAllPanels();
  41. this.AccountsPanel.Visible = true;
  42. break;
  43. case "Games":
  44. HideAllPanels();
  45. this.GamesPanel.Visible = true;
  46. break;
  47. case "Core" :
  48. HideAllPanels();
  49. this.CorePanel.Visible = true;
  50. break;
  51. }
  52. }
  53. private void HideAllPanels()
  54. {
  55. this.InstallationsPanel.Visible = false;
  56. this.AccountsPanel.Visible = false;
  57. this.GamesPanel.Visible = false;
  58. this.CorePanel.Visible = false;
  59. }
  60. private void SettingsForm_Load(object sender, EventArgs e)
  61. {
  62. PopulateInstallationsListView();
  63. PopulateAccountsListView();
  64. PopulateGamesListView();
  65. }
  66. private void OKButton_Click(object sender, EventArgs e)
  67. {
  68. BlueVex2.Properties.Settings.Default.Save();
  69. this.Close();
  70. }
  71. private void CancelButton_Click(object sender, EventArgs e)
  72. {
  73. BlueVex2.Properties.Settings.Default.Reload();
  74. this.Close();
  75. }
  76. #endregion
  77. #region Installations
  78. private void PopulateInstallationsListView()
  79. {
  80. this.InstallationsListView.Items.Clear();
  81. // Populate the installations list view
  82. foreach (string installationString in BlueVex2.Properties.Settings.Default.Installations)
  83. {
  84. string[] parts = installationString.Split(',');
  85. if (parts.Length == 3)
  86. {
  87. ListViewItem item = new ListViewItem(parts[0]);
  88. item.SubItems.Add(parts[1]);
  89. item.SubItems.Add(parts[2]);
  90. this.InstallationsListView.Items.Add(item);
  91. }
  92. }
  93. }
  94. private void AddInstallButton_Click(object sender, EventArgs e)
  95. {
  96. InstallationForm newInstallation = new InstallationForm(""); //<------------------
  97. if (newInstallation.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  98. {
  99. BlueVex2.Properties.Settings.Default.Installations.Add(newInstallation.KeyName + "," + newInstallation.Account + "," + newInstallation.Path);
  100. PopulateInstallationsListView();
  101. }
  102. }
  103. private void RemoveInstallButton_Click(object sender, EventArgs e)
  104. {
  105. if (this.InstallationsListView.SelectedItems.Count > 0)
  106. {
  107. string itemString = this.InstallationsListView.SelectedItems[0].Text + "," + this.InstallationsListView.SelectedItems[0].SubItems[1].Text + "," + this.InstallationsListView.SelectedItems[0].SubItems[2].Text;
  108. BlueVex2.Properties.Settings.Default.Installations.Remove(itemString);
  109. PopulateInstallationsListView();
  110. }
  111. }
  112. private void EditInstallButton_Click(object sender, EventArgs e)
  113. {
  114. if (this.InstallationsListView.SelectedItems.Count > 0)
  115. {
  116. string itemString = this.InstallationsListView.SelectedItems[0].Text + "," + this.InstallationsListView.SelectedItems[0].SubItems[1].Text + "," + this.InstallationsListView.SelectedItems[0].SubItems[2].Text;
  117. InstallationForm newInstallation = new InstallationForm(itemString);
  118. if (newInstallation.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  119. {
  120. BlueVex2.Properties.Settings.Default.Installations.Remove(itemString);
  121. BlueVex2.Properties.Settings.Default.Installations.Add(newInstallation.KeyName + "," + newInstallation.Account + "," + newInstallation.Path);
  122. PopulateInstallationsListView();
  123. }
  124. }
  125. }
  126. private void InstallationsListView_KeyDown(object sender, KeyEventArgs e)
  127. {
  128. if (this.InstallationsListView.SelectedItems.Count > 0)
  129. {
  130. if (e.KeyCode == Keys.Delete)
  131. {
  132. string itemString = this.InstallationsListView.SelectedItems[0].Text + "," + this.InstallationsListView.SelectedItems[0].SubItems[1].Text + "," + this.InstallationsListView.SelectedItems[0].SubItems[2].Text;
  133. BlueVex2.Properties.Settings.Default.Installations.Remove(itemString);
  134. PopulateInstallationsListView();
  135. }
  136. }
  137. }
  138. #endregion
  139. #region Accounts
  140. private void PopulateAccountsListView()
  141. {
  142. this.AccountsListView.Items.Clear();
  143. // Populate the accounts list view
  144. foreach (string accountString in BlueVex2.Properties.Settings.Default.Accounts)
  145. {
  146. string[] parts = accountString.Split(',');
  147. if (parts.Length == 5)
  148. {
  149. ListViewItem item = new ListViewItem(parts[0]);
  150. item.SubItems.Add(parts[1]);
  151. item.SubItems.Add(parts[2]);
  152. item.SubItems.Add(parts[3]);
  153. item.SubItems.Add(parts[4]);
  154. this.AccountsListView.Items.Add(item);
  155. }
  156. }
  157. }
  158. private void AddAccountButton_Click(object sender, EventArgs e)
  159. {
  160. AccountForm newAccount = new AccountForm("");
  161. if (newAccount.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  162. {
  163. BlueVex2.Properties.Settings.Default.Accounts.Add(newAccount.Username + "," + newAccount.Password + "," + newAccount.CharSlot + "," + newAccount.Master + "," + newAccount.Realm);
  164. PopulateAccountsListView();
  165. }
  166. }
  167. private void RemoveAccountButton_Click(object sender, EventArgs e)
  168. {
  169. if (this.AccountsListView.SelectedItems.Count > 0)
  170. {
  171. string itemString = this.AccountsListView.SelectedItems[0].Text + "," + this.AccountsListView.SelectedItems[0].SubItems[1].Text + "," + this.AccountsListView.SelectedItems[0].SubItems[2].Text + "," + this.AccountsListView.SelectedItems[0].SubItems[3].Text + "," + this.AccountsListView.SelectedItems[0].SubItems[4].Text;
  172. BlueVex2.Properties.Settings.Default.Accounts.Remove(itemString);
  173. PopulateAccountsListView();
  174. }
  175. }
  176. private void EditAccountButton_Click(object sender, EventArgs e)
  177. {
  178. if (this.AccountsListView.SelectedItems.Count > 0)
  179. {
  180. string itemString = this.AccountsListView.SelectedItems[0].Text + "," + this.AccountsListView.SelectedItems[0].SubItems[1].Text + "," + this.AccountsListView.SelectedItems[0].SubItems[2].Text + "," + this.AccountsListView.SelectedItems[0].SubItems[3].Text + "," + this.AccountsListView.SelectedItems[0].SubItems[4].Text;
  181. AccountForm newAccount = new AccountForm(itemString);
  182. if (newAccount.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  183. {
  184. BlueVex2.Properties.Settings.Default.Accounts.Remove(itemString);
  185. BlueVex2.Properties.Settings.Default.Accounts.Add(newAccount.Username + "," + newAccount.Password + "," + newAccount.CharSlot + "," + newAccount.Master + "," + newAccount.Realm);
  186. PopulateAccountsListView();
  187. }
  188. }
  189. }
  190. private void AccountsListView_KeyDown(object sender, KeyEventArgs e)
  191. {
  192. if (e.KeyCode == Keys.Delete)
  193. {
  194. if (this.AccountsListView.SelectedItems.Count > 0)
  195. {
  196. string itemString = this.AccountsListView.SelectedItems[0].Text + "," + this.AccountsListView.SelectedItems[0].SubItems[1].Text + "," + this.AccountsListView.SelectedItems[0].SubItems[2].Text + "," + this.AccountsListView.SelectedItems[0].SubItems[3].Text + "," + this.AccountsListView.SelectedItems[0].SubItems[4].Text;
  197. BlueVex2.Properties.Settings.Default.Accounts.Remove(itemString);
  198. PopulateAccountsListView();
  199. }
  200. }
  201. }
  202. #endregion
  203. #region Games
  204. private void PopulateGamesListView()
  205. {
  206. this.GamesListView.Items.Clear();
  207. // Populate the games list view
  208. foreach (string gameString in BlueVex2.Properties.Settings.Default.Games)
  209. {
  210. string[] parts = gameString.Split(',');
  211. if (parts.Length == 2)
  212. {
  213. ListViewItem item = new ListViewItem(parts[0]);
  214. item.SubItems.Add(parts[1]);
  215. this.GamesListView.Items.Add(item);
  216. }
  217. }
  218. }
  219. private void AddGamesButton_Click(object sender, EventArgs e)
  220. {
  221. GamesForm newGames = new GamesForm("");
  222. if (newGames.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  223. {
  224. BlueVex2.Properties.Settings.Default.Games.Add(newGames.GameName + "," + newGames.GamePW);
  225. PopulateGamesListView();
  226. }
  227. }
  228. private void RemoveGamesButton_Click(object sender, EventArgs e)
  229. {
  230. if (this.GamesListView.SelectedItems.Count > 0)
  231. {
  232. string itemString = this.GamesListView.SelectedItems[0].Text + "," + this.GamesListView.SelectedItems[0].SubItems[1].Text;
  233. BlueVex2.Properties.Settings.Default.Games.Remove(itemString);
  234. PopulateGamesListView();
  235. }
  236. }
  237. private void EditGamesButton_Click(object sender, EventArgs e)
  238. {
  239. if (this.GamesListView.SelectedItems.Count > 0)
  240. {
  241. string itemString = this.GamesListView.SelectedItems[0].Text + "," + this.GamesListView.SelectedItems[0].SubItems[1].Text;
  242. GamesForm newGames = new GamesForm(itemString);
  243. if (newGames.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  244. {
  245. BlueVex2.Properties.Settings.Default.Games.Remove(itemString);
  246. BlueVex2.Properties.Settings.Default.Games.Add(newGames.GameName + "," + newGames.GamePW);
  247. PopulateGamesListView();
  248. }
  249. }
  250. }
  251. private void GamesListView_KeyDown(object sender, KeyEventArgs e)
  252. {
  253. if (e.KeyCode == Keys.Delete)
  254. {
  255. if (this.GamesListView.SelectedItems.Count > 0)
  256. {
  257. string itemString = this.GamesListView.SelectedItems[0].Text + "," + this.GamesListView.SelectedItems[0].SubItems[1].Text;
  258. BlueVex2.Properties.Settings.Default.Games.Remove(itemString);
  259. PopulateGamesListView();
  260. }
  261. }
  262. }
  263. #endregion
  264. private void InstallationsListView_SelectedIndexChanged(object sender, EventArgs e)
  265. {
  266. }
  267. }
  268. }