Esempio n. 1
0
		private void btnSet_Click(object sender, EventArgs e) {
			if(dgvServers.SelectedRows.Count > 0) {
				try {
					Profile profile = Globals.profiles.SingleOrDefault(item => item.ProfileName == cmbProfiles.Text);

					if(profile != null) {
						string fileUS = profile.ProfilePath + "\\Data\\enUS\\realmlist.wtf",
							fileGB = profile.ProfilePath + "\\Data\\enGB\\realmlist.wtf",
							exec32 = profile.ProfilePath + "\\Wow.exe",
							exec64 = profile.ProfilePath + "\\Wow-64.exe",
							file = "",
							text = "";

						// If realmlist.wtf does not exist
						if(!File.Exists(fileUS) && !File.Exists(fileGB)) {
							frmCreateRealmlist.ShowDialog();
						}
						// If realmlist.wtf and WoW executables exist
						else {
							// If realmlist.wtf is in the US folder
							if(File.Exists(fileUS)) {
								file = fileUS;
							}
							// If realmlist.wtf is in the GB folder
							else if(File.Exists(fileGB)) {
								file = fileGB;
							}

							// Read from the file and replace text
							text = File.ReadAllText(file);
							text = text.Remove(14, text.Substring(14, text.IndexOf(Environment.NewLine) - 14).Length);
							text = text.Insert(14, dgvServers.SelectedRows[0].Cells[2].Value.ToString());

							// Write the replaced text to a local file
							File.WriteAllText(Application.StartupPath + "\\realmlist.wtf", text);

							// And move it to the correct directory
							string[] args = { "true", Application.StartupPath + "\\realmlist.wtf", file };
							int fileAction = Globals.RunActionsExecutable(Globals.FileAction.CopyFile, args);

							if(fileAction == 0) {
								// If they want to open WoW after setting a server
								if(Properties.Settings.Default.openWow) {
									OpenWow();
								}
								else {
									MessageBox.Show("Server changed successfully.", "Success");
								}

								ToolstripInfo(false);
							}
							else if(fileAction != 5) {
								MessageBox.Show("Could not set server.", "Error");
							}
						}
					}
					else {
						MessageBox.Show("Cannot find a World of Warcraft installation with your current profile.", "Error");
					}
				}
				catch(Exception ex) {
					if(!ex.Message.Contains("canceled by the user")) {
						Globals.frmError.ShowDialog(ex);
					}
				}
			}
			else {
				MessageBox.Show("There is no row selected.", "Error");
			}
		}