Example #1
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;
		}
Example #2
0
		private bool HasAllFiles(Platform platform, ZipFile zip)
		{
			string[] files;
			if (platform == Platform.WINDOWS)
			{
				files = new string[] { "Mac.exe", "FNA.dll" };
			}
			else
			{
				files = new string[]
				{ "Windows.exe", "Microsoft.Xna.Framework.dll", "Microsoft.Xna.Framework.Game.dll",
					"Microsoft.Xna.Framework.Graphics.dll", "Microsoft.Xna.Framework.Xact.dll"
				};
			}
			foreach (string file in files)
			{
				if (!zip.HasFile(file))
				{
					MessageBox.Show("Missing " + file + " from Install resources", "Installation Error",
						MessageBoxButtons.OK, MessageBoxIcon.Error);
					return false;
				}
			}
			return true;
		}
Example #3
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;
 }
Example #4
0
 public static ZipFile Read(string name)
 {
     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();
                     byte[] buffer = reader.ReadBytes(reader.ReadInt32());
                     zip[fileName] = buffer;
                 }
             }
         }
     }
     return zip;
 }
Example #5
0
		private bool HasAllFiles(Platform platform, ZipFile zip)
		{
			string[] files;
			if (platform == Platform.WINDOWS)
			{
				files = new string[] { "Windows.exe", "Content/MysteryItem.png" };
			}
			else if (platform == Platform.MAC)
			{
				files = new string[] { "Mac.exe", "MP3Sharp.dll", "Content/MysteryItem.png" };
			}
			else if (platform == Platform.LINUX)
			{
				files = new string[] { "Linux.exe", "MP3Sharp.dll", "Content/MysteryItem.png" };
			}
			else
			{
				return false;
			}
			foreach (string file in files)
			{
				if (!zip.HasFile(file))
				{
					MessageBox.Show("Missing " + file + " from Install resources", "Installation Error",
						MessageBoxButtons.OK, MessageBoxIcon.Error);
					return false;
				}
			}
			return true;
		}
Example #6
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;
		}