Exemple #1
0
 internal void Write(Task task, DoWorkArgs progress, ProgressChangedArgs args)
 {
     using (FileStream fileStream = File.Create(this.name))
     {
         using (DeflateStream compress = new DeflateStream(fileStream, CompressionMode.Compress))
         {
             using (BinaryWriter writer = new BinaryWriter(compress))
             {
                 writer.Write((byte)this.files.Count);
                 foreach (string file in this.files.Keys)
                 {
                     if (task != null)
                     {
                         args.message = "Saving " + file + "...";
                         task.ReportProgress(progress.background, -1, args);
                     }
                     writer.Write(file);
                     writer.Write(this.files[file].Length);
                     writer.Write(this.files[file]);
                 }
                 if (task != null)
                 {
                     args.message = "Done";
                     task.ReportProgress(progress.background, -1, args);
                 }
             }
         }
     }
 }
Exemple #2
0
		internal static ZipFile Read(string name, Task task, DoWorkArgs progress, ProgressChangedArgs args)
		{
			ZipFile zip = new ZipFile(name);
			using (FileStream fileStream = File.OpenRead(name))
			{
				using (DeflateStream decompress = new DeflateStream(fileStream, CompressionMode.Decompress))
				{
					using (BinaryReader reader = new BinaryReader(decompress))
					{
						int count = reader.ReadByte();
						for (int k = 0; k < count; k++)
						{
							string fileName = reader.ReadString();
							if (task != null)
							{
								args.message = "Reading " + fileName + "...";
								task.ReportProgress(progress.background, -1, args);
							}
							byte[] buffer = reader.ReadBytes(reader.ReadInt32());
							zip[fileName] = buffer;
						}
					}
				}
			}
			return zip;
		}
Exemple #3
0
		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;
		}
Exemple #4
0
 protected internal void ReportProgress(DoWorkArgs args)
 {
     updating = true;
     args.background.ReportProgress(-1, args.main);
     while (updating)
         ;
 }
Exemple #5
0
        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);
        }
Exemple #6
0
		internal void Write(Task task, DoWorkArgs progress, ProgressChangedArgs args)
		{
			using (FileStream fileStream = File.Create(this.name))
			{
				using (DeflateStream compress = new DeflateStream(fileStream, CompressionMode.Compress))
				{
					using (BinaryWriter writer = new BinaryWriter(compress))
					{
						writer.Write((byte)this.files.Count);
						foreach (string file in this.files.Keys)
						{
							if (task != null)
							{
								args.message = "Saving " + file + "...";
								task.ReportProgress(progress.background, -1, args);
							}
							writer.Write(file);
							writer.Write(this.files[file].Length);
							writer.Write(this.files[file]);
						}
						if (task != null)
						{
							args.message = "Done";
							task.ReportProgress(progress.background, -1, args);
						}
					}
				}
			}
		}
Exemple #7
0
        public void Run(Installer main)
        {
            main.DisableButtons();
            main.SetProgress(0);
            main.SetProgressVisible(true);
            result = null;
            BackgroundWorker background = new BackgroundWorker();

            background.WorkerReportsProgress = true;
            background.DoWork             += DoWork;
            background.ProgressChanged    += ProgressChanged;
            background.RunWorkerCompleted += RunWorkerCompleted;
            DoWorkArgs args = new DoWorkArgs();

            args.background = background;
            args.main       = main;
            background.RunWorkerAsync(args);
            while (!result.HasValue)
            {
                Application.DoEvents();
            }
            main.SetProgressVisible(false);
            main.SetHeader("");
            main.SetMessage("");
            main.ReenableButtons();
        }
Exemple #8
0
        internal static ZipFile Read(string name, Task task, DoWorkArgs progress, ProgressChangedArgs args)
        {
            ZipFile zip = new ZipFile(name);

            using (FileStream fileStream = File.OpenRead(name))
            {
                using (DeflateStream decompress = new DeflateStream(fileStream, CompressionMode.Decompress))
                {
                    using (BinaryReader reader = new BinaryReader(decompress))
                    {
                        int count = reader.ReadByte();
                        for (int k = 0; k < count; k++)
                        {
                            string fileName = reader.ReadString();
                            if (task != null)
                            {
                                args.message = "Reading " + fileName + "...";
                                task.ReportProgress(progress.background, -1, args);
                            }
                            byte[] buffer = reader.ReadBytes(reader.ReadInt32());
                            zip[fileName] = buffer;
                        }
                    }
                }
            }
            return(zip);
        }
Exemple #9
0
 protected internal void ReportProgress(DoWorkArgs args)
 {
     updating = true;
     args.background.ReportProgress(-1, args.main);
     while (updating)
     {
         ;
     }
 }
Exemple #10
0
        protected override bool DoTask(DoWorkArgs args)
        {
            ProgressChangedArgs pass = new ProgressChangedArgs();

            pass.maxProgress = 1;
            pass.header      = "";
            pass.message     = "";
            pass.main        = args.main;
            ReportProgress(args.background, 0, pass);
            Directory.CreateDirectory("Setup");
            if (!CreateResources(args, pass, "Windows", new string[]
            {
                "Windows.exe",
                "Mac.exe",
                "FNA.dll",
                "Content" + Path.DirectorySeparatorChar + "MysteryItem.png"
            }))
            {
                return(false);
            }
            if (!CreateResources(args, pass, "Mac", new string[]
            {
                "Windows.exe",
                "Mac.exe",
                "Microsoft.Xna.Framework.dll",
                "Microsoft.Xna.Framework.Game.dll",
                "Microsoft.Xna.Framework.Graphics.dll",
                "Microsoft.Xna.Framework.Xact.dll",
                "MP3Sharp.dll",
                "Content" + Path.DirectorySeparatorChar + "MysteryItem.png"
            }))
            {
                return(false);
            }
            if (!CreateResources(args, pass, "Linux", new string[]
            {
                "Windows.exe",
                "Linux.exe",
                "Microsoft.Xna.Framework.dll",
                "Microsoft.Xna.Framework.Game.dll",
                "Microsoft.Xna.Framework.Graphics.dll",
                "Microsoft.Xna.Framework.Xact.dll",
                "MP3Sharp.dll",
                "Content" + Path.DirectorySeparatorChar + "MysteryItem.png"
            }))
            {
                return(false);
            }
            MessageBox.Show("Success!", "Setup", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return(true);
        }
Exemple #11
0
		protected override bool DoTask(DoWorkArgs args)
		{
			ProgressChangedArgs pass = new ProgressChangedArgs();
			pass.maxProgress = 1;
			pass.header = "";
			pass.message = "";
			pass.main = args.main;
			ReportProgress(args.background, 0, pass);
			Directory.CreateDirectory("Setup");
			if (!CreateResources(args, pass, "Windows", new string[]
				{
					"Windows.exe",
					"Mac.exe",
					"FNA.dll",
					"Content" + Path.DirectorySeparatorChar + "MysteryItem.png"
				}))
			{
				return false;
			}
			if (!CreateResources(args, pass, "Mac", new string[]
				{
					"Windows.exe",
					"Mac.exe",
					"Microsoft.Xna.Framework.dll",
					"Microsoft.Xna.Framework.Game.dll",
					"Microsoft.Xna.Framework.Graphics.dll",
					"Microsoft.Xna.Framework.Xact.dll",
					"MP3Sharp.dll",
					"Content" + Path.DirectorySeparatorChar + "MysteryItem.png"
				}))
			{
				return false;
			}
			if (!CreateResources(args, pass, "Linux", new string[]
				{
					"Windows.exe",
					"Linux.exe",
					"Microsoft.Xna.Framework.dll",
					"Microsoft.Xna.Framework.Game.dll",
					"Microsoft.Xna.Framework.Graphics.dll",
					"Microsoft.Xna.Framework.Xact.dll",
					"MP3Sharp.dll",
					"Content" + Path.DirectorySeparatorChar + "MysteryItem.png"
				}))
			{
				return false;
			}
			MessageBox.Show("Success!", "Setup", MessageBoxButtons.OK, MessageBoxIcon.Information);
			return true;
		}
Exemple #12
0
 private bool CreateResources(DoWorkArgs args, ProgressChangedArgs pass, string platform, string[] files)
 {
     int progress = 0;
     pass.maxProgress = 2 * files.Length + 1;
     pass.header = "Creating " + platform + " installation resources";
     pass.message = "Finding files...";
     ReportProgress(args.background, progress, pass);
     string prefix = "Setup" + Path.DirectorySeparatorChar;
     for (int k = 0; k < files.Length; k++)
     {
         files[k] = prefix + files[k];
         if (!File.Exists(files[k]))
         {
             MessageBox.Show("The file " + files[k] + " does not exist.", "Setup Error",
                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             return false;
         }
     }
     Directory.CreateDirectory("Resources");
     try
     {
         ZipFile zip = new ZipFile("Resources" + Path.DirectorySeparatorChar + "Install_" + platform);
         foreach (string file in files)
         {
             string fileName = file.Substring(prefix.Length + 1);
             fileName = fileName.Replace(Path.DirectorySeparatorChar, '/');
             pass.message = "Packing " + fileName + "...";
             progress++;
             ReportProgress(args.background, progress, pass);
             zip[fileName] = File.ReadAllBytes(file);
         }
         pass.message = "Saving installation resources...";
         progress++;
         ReportProgress(args.background, progress, pass);
         zip.Write(this, args);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace, "Setup Error",
             MessageBoxButtons.OK, MessageBoxIcon.Error);
         return false;
     }
     return true;
 }
Exemple #13
0
        private bool CreateResources(DoWorkArgs args, ProgressChangedArgs pass, string platform, string[] files)
        {
            pass.maxProgress = 2 * files.Length + 1;
            pass.header      = "Creating " + platform + " installation resources";
            pass.message     = "Finding files...";
            ReportProgress(args.background, 0, pass);
            string prefix = "Setup" + Path.DirectorySeparatorChar;

            for (int k = 0; k < files.Length; k++)
            {
                files[k] = prefix + files[k];
                if (!File.Exists(files[k]))
                {
                    MessageBox.Show("The file " + files[k] + " does not exist.", "Setup Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }
            Directory.CreateDirectory("Resources");
            try
            {
                ZipFile zip = new ZipFile("Resources" + Path.DirectorySeparatorChar + "Install_" + platform);
                foreach (string file in files)
                {
                    string fileName = file.Substring(prefix.Length);
                    fileName     = fileName.Replace(Path.DirectorySeparatorChar, '/');
                    pass.message = "Packing " + fileName + "...";
                    ReportProgress(args.background, -1, pass);
                    zip[fileName] = File.ReadAllBytes(file);
                }
                zip.Write(this, args, pass);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace, "Setup Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
Exemple #14
0
 public void Write(Task task = null, DoWorkArgs progress = default(DoWorkArgs))
 {
     using (FileStream fileStream = File.Create(this.name))
     {
         using (DeflateStream compress = new DeflateStream(fileStream, CompressionMode.Compress))
         {
             using (BinaryWriter writer = new BinaryWriter(compress))
             {
                 writer.Write((byte)this.files.Count);
                 foreach (string file in this.files.Keys)
                 {
                     writer.Write(file);
                     writer.Write(this.files[file].Length);
                     writer.Write(this.files[file]);
                     if (task != null)
                     {
                         task.ReportProgress(progress);
                     }
                 }
             }
         }
     }
 }
Exemple #15
0
 public void Run(Installer main)
 {
     main.DisableButtons();
     main.SetProgress(0);
     main.SetProgressVisible(true);
     result = null;
     BackgroundWorker background = new BackgroundWorker();
     background.WorkerReportsProgress = true;
     background.DoWork += DoWork;
     background.ProgressChanged += ProgressChanged;
     background.RunWorkerCompleted += RunWorkerCompleted;
     DoWorkArgs args = new DoWorkArgs();
     args.background = background;
     args.main = main;
     background.RunWorkerAsync(args);
     while (!result.HasValue)
     {
         Application.DoEvents();
     }
     main.SetProgressVisible(false);
     main.SetHeader("");
     main.SetMessage("");
     main.ReenableButtons();
 }
Exemple #16
0
		protected override bool DoTask(DoWorkArgs args)
		{
			return (bool)args.main.Invoke((Func<bool>)ChoosePath);
		}
Exemple #17
0
 protected abstract bool DoTask(DoWorkArgs args);
Exemple #18
0
        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);
        }
Exemple #19
0
        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);
        }
Exemple #20
0
 protected abstract bool DoTask(DoWorkArgs args);
Exemple #21
0
		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;
		}
Exemple #22
0
		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;
		}
Exemple #23
0
 protected override bool DoTask(DoWorkArgs args)
 {
     return((bool)args.main.Invoke((Func <bool>)ChoosePath));
 }