Ejemplo n.º 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);
						}
					}
				}
			}
		}
Ejemplo n.º 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;
		}
Ejemplo n.º 3
0
 protected internal void ReportProgress(BackgroundWorker background, int progress, ProgressChangedArgs args)
 {
     updating = true;
     background.ReportProgress(progress, args);
     while (updating)
         ;
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 protected void ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     if (e.UserState is ProgressChangedArgs)
     {
         ProgressChangedArgs args = (ProgressChangedArgs)e.UserState;
         args.main.SetMaxProgress(args.maxProgress);
         if (args.header.Length > 0)
         {
             args.main.SetHeader(args.header);
         }
         if (args.message.Length > 0)
         {
             args.main.SetMessage(args.message);
         }
         if (e.ProgressPercentage < 0)
         {
             args.main.IncrementProgress();
         }
         else
         {
             args.main.SetProgress(e.ProgressPercentage);
         }
     }
     else if (e.UserState is Installer)
     {
         (e.UserState as Installer).IncrementProgress();
     }
     updating = false;
 }
Ejemplo n.º 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);
                 }
             }
         }
     }
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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;
		}
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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;
		}
Ejemplo n.º 12
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;
		}
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
 protected internal void ReportProgress(BackgroundWorker background, int progress, ProgressChangedArgs args)
 {
     updating = true;
     background.ReportProgress(progress, args);
     while (updating)
     {
         ;
     }
 }