public static List<Server> readMultiple(string fileName) { List<Server> list = new List<Server>(); using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open))) { if (!verifyVersion(reader)) return null; int maxIterations = reader.ReadInt32(); for (int i = 0; i < maxIterations; i++) { Server server = new Server(); server.name = reader.ReadString(); server.website = reader.ReadString(); server.version = reader.ReadString(); server.patchesDirectory = reader.ReadString(); server.downloadDirectory = reader.ReadString(); server.realmlist = reader.ReadString(); server.clientDirectory = reader.ReadString(); server.locale = reader.ReadString(); server.status = string.Empty; list.Add(server); } } return list; }
public static void updateRealmlist(string directoryPath, Server server) { string realmlistPath = ClientHelper.realmlistPath(server); if (!File.Exists(realmlistPath)) return; File.Delete(realmlistPath); using (StreamWriter file = new StreamWriter(realmlistPath, true)) { file.WriteLine(server.realmlist); } }
public static void write(Server server, string fileName) { using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Append))) { writer.Write(server.name); writer.Write(server.website); writer.Write(server.version); writer.Write(server.patchesDirectory == null ? string.Empty : server.patchesDirectory); writer.Write(server.downloadDirectory == null ? string.Empty : server.downloadDirectory); writer.Write(server.realmlist); writer.Write(server.clientDirectory); writer.Write(server.locale); } }
public static Nullable<Server> readSingle(string fileName) { using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open))) { if (!verifyVersion(reader)) return null; Server server = new Server(); server.name = reader.ReadString(); server.website = reader.ReadString(); server.version = reader.ReadString(); server.patchesDirectory = reader.ReadString(); server.downloadDirectory = reader.ReadString(); server.realmlist = reader.ReadString(); server.clientDirectory = reader.ReadString(); server.locale = ClientHelper.localeVersion(server); return server; } }
public static void moveActive(Server server) { string serverDirectory = Path.Combine(server.clientDirectory, "ServerData", server.name); if (!Directory.Exists(serverDirectory)) return; string[] files = Directory.GetFiles(serverDirectory); for (int i = 0; i < files.Length; i++) { string filePath = files[i]; string destPath = Path.Combine(server.clientDirectory, "Data", Path.GetFileName(files[i])); try { File.Move(filePath, destPath); } catch (Exception e) { MessageBox.Show($"Error moving files - file already exists at destination\nPlease move/delete: {destPath}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static void delete(Server server) { string dataDirectory = Path.Combine(server.clientDirectory + "\\Data\\"); if (!Directory.Exists(dataDirectory)) return; string[] files = Directory.GetFiles(dataDirectory); string[] whiteList = { "patch.MPQ", "patch-2.MPQ", "patch-3.MPQ", "lichking.MPQ", "expansion.MPQ", "common.MPQ", "common-2.MPQ"}; for (int i = 0; i < files.Length; i++) { if (!Regex.IsMatch(files[i], ".MPQ") && !Regex.IsMatch(files[i], ".mpq")) continue; string fileName = Path.GetFileName(files[i]); if (shouldPass(fileName, whiteList)) continue; if (File.Exists(files[i])) File.Delete(files[i]); } }
public static void moveAway(Server server) { string dataDirectory = Path.Combine(server.clientDirectory + "\\Data\\"); if (!Directory.Exists(dataDirectory)) return; string[] files = Directory.GetFiles(dataDirectory); string[] whiteList = { "patch.MPQ", "patch-2.MPQ", "patch-3.MPQ", "lichking.MPQ", "expansion.MPQ", "common.MPQ", "common-2.MPQ"}; for (int i = 0; i < files.Length; i++) { if (!Regex.IsMatch(files[i], ".MPQ") && !Regex.IsMatch(files[i], ".mpq")) continue; string fileName = Path.GetFileName(files[i]); if (shouldPass(fileName, whiteList)) continue; string destination = Path.Combine(server.clientDirectory, "ServerData", server.name); if (!Directory.Exists(destination)) Directory.CreateDirectory(destination); string destinationFile = Path.Combine(destination, fileName); if (File.Exists(destinationFile)) { try { File.Delete(files[i]); } catch (System.IO.IOException e) { MessageBox.Show("Could not delete patch destination file!\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } continue; } try { File.Move(files[i], destinationFile); } catch (Exception e){ } } }
private void addButton_Click(object sender, EventArgs e) { if (nameField.Text == string.Empty) { MessageBox.Show("You must enter the server's name!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (websiteField.Text == string.Empty) { MessageBox.Show("You must enter a website!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (realmlistField.Text == string.Empty) { MessageBox.Show("You must enter a realmlist!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (directoryPath == string.Empty) { MessageBox.Show("You must select a directory!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Server server = new Server(); server.name = nameField.Text; server.website = websiteField.Text; server.version = VersionHelper.toVersion(((KeyValuePair<string, string>)versionCombo.SelectedItem).Value).ToString(); server.patchesDirectory = string.Empty; server.downloadDirectory = string.Empty; server.realmlist = realmlistField.Text; server.clientDirectory = directoryPath; server.locale = ClientHelper.localeVersion(server); form.addServer(server); addServerForm.Close(); }
private void saveChangesButton_Click(object sender, EventArgs e) { if (ApplicationStatus.downloading) { MessageBox.Show("You can't edit the server while downloading!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (nameField.Text == string.Empty) { MessageBox.Show("You must enter the server's name!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (websiteField.Text == string.Empty) { MessageBox.Show("You must enter a website!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (realmlistField.Text == string.Empty) { MessageBox.Show("You must enter a realmlist!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } directoryPath = clientDirField.Text; if (directoryPath == string.Empty) { MessageBox.Show("You must select a client directory!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Server server = new Server(); Server activeServer = (Server)ApplicationStatus.activeServer; server.name = nameField.Text; server.website = websiteField.Text; server.version = VersionHelper.toVersion(((KeyValuePair<string, string>)versionCombo.SelectedItem).Value).ToString(); server.patchesDirectory = activeServer.patchesDirectory; server.downloadDirectory = activeServer.downloadDirectory; server.realmlist = realmlistField.Text; server.clientDirectory = directoryPath; server.locale = ClientHelper.localeVersion(server); form.serverContainer.removeServer(activeServer.name); ApplicationStatus.activeServer = server; PatchDownloader.shouldMoveAway = false; form.addServer(server); form.updateServerList(); this.Close(); }
private int selectedIndex(Server server) { switch (server.version) { case "Vanilla": return 0; break; case "TBC": return 1; break; case "WOTLK": return 2; break; default: return -1; break; } }
public void patch(Server server) { serverToDownload = server; if (ApplicationStatus.oldServer != null && shouldMoveAway) PatchMover.moveAway((Server)ApplicationStatus.oldServer); else if (!shouldMoveAway) shouldMoveAway = true; using (WebClient webClient = new WebClient()) { string patchFileURL = URLFormatter.format($"{server.website}/{server.downloadDirectory}/patchfile.dat"); if (server.downloadDirectory == string.Empty || server.patchesDirectory == string.Empty || !ResourceHelper.resourceExists(patchFileURL)) { form.downloadStatusLabel.Text = "Status: Server does not support the launcher's patcher"; form.playButton.Text = "Play"; form.playButton.Enabled = true; ApplicationStatus.downloading = false; return; } ApplicationStatus.downloading = true; webClient.DownloadProgressChanged += downloadPatchProgressChanged; webClient.DownloadFileAsync(new System.Uri(patchFileURL), "patchfile.dat"); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(this.downloadPatchFileCompleted); } }
public void addServer(Server server) { serverContainer.addServer(server); patch(); }