protected override bool DoTask(DoWorkArgs args) { string file = Installer.GetPath(); if (!File.Exists(file)) { MessageBox.Show("The file " + file + " does not exist.", "Restore Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } string backupFile = "Resources" + Path.DirectorySeparatorChar + "Backups"; if (!File.Exists(backupFile)) { MessageBox.Show("Either tModLoader has not been installed or the backups resource file is missing.", "Restore Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } ZipFile backups = ZipFile.Read(backupFile); string fetchFile = vanilla ? "Vanilla" : "tModLoader"; if (!backups.HasFile(fetchFile)) { MessageBox.Show("Missing " + file + " from Backups resources", "Installation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } File.WriteAllBytes(file, backups[fetchFile]); MessageBox.Show("Success!", "Restore", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); }
private bool ChoosePath() { if (Installer.platform == Platform.MAC || Installer.platform == Platform.LINUX) { MessageBox.Show("Please drag and drop the Terraria executable you wish to mod onto the installer window.", "Choose File", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Executable (.exe)|*.exe"; string initial = Path.GetDirectoryName(Installer.GetPath()); if (Directory.Exists(initial)) { dialog.InitialDirectory = initial; } dialog.Title = "Select Terraria executable"; if (dialog.ShowDialog() != DialogResult.OK) { return(false); } string file = dialog.FileName; if (!File.Exists(file)) { MessageBox.Show(file + " does not exist", "Choose File", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } Installer.SetTerrariaPath(file); return(true); }
protected override bool DoTask(DoWorkArgs args) { string file = Installer.GetPath(); if (!File.Exists(file)) { MessageBox.Show("The file " + file + " does not exist.", "Installation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } ProgressChangedArgs pass = new ProgressChangedArgs(); pass.main = args.main; pass.header = ""; pass.maxProgress = 6; if (Installer.platform == Platform.WINDOWS) { pass.maxProgress += 5; } else { pass.maxProgress += 10; } pass.message = "Backing up Terraria"; ReportProgress(args.background, 0, pass); string directory = Path.GetDirectoryName(file) + Path.DirectorySeparatorChar; string backupFile = directory + "Terraria_" + Installer.version + ".exe"; if (!File.Exists(backupFile)) { File.Copy(file, backupFile); } pass.message = "Backing up Terraria even more"; ReportProgress(args.background, -1, pass); Directory.CreateDirectory("Resources"); ZipFile zip = new ZipFile("Resources" + Path.DirectorySeparatorChar + "Backups"); zip["Vanilla"] = File.ReadAllBytes(file); pass.header = "Reading Install resources"; string resourceFile = "Resources" + Path.DirectorySeparatorChar + "Install"; if (!File.Exists(resourceFile)) { MessageBox.Show("Could not find installation resource file", "Installation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } ZipFile resources = ZipFile.Read(resourceFile, this, args, pass); pass.header = " "; pass.message = "Installing..."; ReportProgress(args.background, -1, pass); if (!HasAllFiles(Installer.platform, resources)) { return(false); } string contentFolder = directory + "Content" + Path.DirectorySeparatorChar + "ModLoader"; Directory.CreateDirectory(contentFolder); contentFolder += Path.DirectorySeparatorChar; if (Installer.platform == Platform.WINDOWS) { File.WriteAllBytes(file, resources["Windows.exe"]); ReportProgress(args.background, -1, pass); File.WriteAllBytes(contentFolder + "MysteryItem.png", resources["Content/MysteryItem.png"]); } else if (Installer.platform == Platform.MAC) { File.WriteAllBytes(file, resources["Mac.exe"]); ReportProgress(args.background, -1, pass); File.WriteAllBytes(directory, resources["MP3Sharp.dll"]); ReportProgress(args.background, -1, pass); File.WriteAllBytes(contentFolder + "MysteryItem.png", resources["Content/MysteryItem.png"]); } else if (Installer.platform == Platform.LINUX) { File.WriteAllBytes(file, resources["Linux.exe"]); ReportProgress(args.background, -1, pass); File.WriteAllBytes(directory, resources["MP3Sharp.dll"]); ReportProgress(args.background, -1, pass); File.WriteAllBytes(contentFolder + "MysteryItem.png", resources["Content/MysteryItem.png"]); } pass.message = "Backing up tModLoader"; ReportProgress(args.background, -1, pass); pass.header = "Saving backups"; zip["tModLoader"] = File.ReadAllBytes(file); zip.Write(this, args, pass); MessageBox.Show("Success!", "Install", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); }
protected override bool DoTask(DoWorkArgs args) { string file = Installer.GetPath(); if (!File.Exists(file)) { MessageBox.Show("The file " + file + " does not exist.", "Installation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } ProgressChangedArgs pass = new ProgressChangedArgs(); pass.main = args.main; pass.header = "Reading Install resources"; pass.maxProgress = 2; if (Installer.platform == Platform.WINDOWS) { pass.maxProgress += 5; } else { pass.maxProgress += 12; } pass.message = ""; ReportProgress(args.background, 0, pass); string resourceFile = "Resources" + Path.DirectorySeparatorChar + "Install"; if (!File.Exists(resourceFile)) { MessageBox.Show("Could not find installation resource file", "Installation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } ZipFile resources = ZipFile.Read(resourceFile, this, args, pass); pass.header = " "; pass.message = "Installing"; ReportProgress(args.background, -1, pass); if (!HasAllFiles(Installer.platform, resources)) { return(false); } string directory = Path.GetDirectoryName(file) + Path.DirectorySeparatorChar; if (Installer.platform == Platform.WINDOWS) { File.WriteAllBytes(directory + "TerrariaMac.exe", resources["Mac.exe"]); ReportProgress(args.background, -1, pass); File.WriteAllBytes(directory + "FNA.dll", resources["FNA.dll"]); } else { File.WriteAllBytes(directory + "TerrariaWindows.exe", resources["Windows.exe"]); ReportProgress(args.background, -1, pass); string fileToWrite = "Microsoft.Xna.Framework.dll"; File.WriteAllBytes(directory + fileToWrite, resources[fileToWrite]); ReportProgress(args.background, -1, pass); fileToWrite = "Microsoft.Xna.Framework.Game.dll"; File.WriteAllBytes(directory + fileToWrite, resources[fileToWrite]); ReportProgress(args.background, -1, pass); fileToWrite = "Microsoft.Xna.Framework.Graphics.dll"; File.WriteAllBytes(directory + fileToWrite, resources[fileToWrite]); ReportProgress(args.background, -1, pass); fileToWrite = "Microsoft.Xna.Framework.Xact.dll"; File.WriteAllBytes(directory + fileToWrite, resources[fileToWrite]); } pass.message = "Done"; ReportProgress(args.background, -1, pass); MessageBox.Show("Success!", "Install", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); }