Example #1
0
		/// <summary>
		/// Saves a wz file to the disk, AKA repacking.
		/// </summary>
		/// <param name="path">Path to the output wz file</param>
		public void SaveToDisk(string path)
		{
			CreateVersionHash();
			wzDir.SetHash(versionHash);
			string tempFile = Path.GetFileNameWithoutExtension(path) + ".TEMP";
			File.Create(tempFile).Close();
			wzDir.GenerateDataFile(tempFile);
			WzTool.StringCache.Clear();
			uint totalLen = wzDir.GetImgOffsets(wzDir.GetOffsets(Header.FStart + 2));
			WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), WzIv);
			wzWriter.Hash = (uint)versionHash;
			Header.FSize = totalLen - Header.FStart;
			for (int i = 0; i < 4; i++)
				wzWriter.Write((byte)Header.Ident[i]);
			wzWriter.Write((long)Header.FSize);
			wzWriter.Write(Header.FStart);
			wzWriter.WriteNullTerminatedString(Header.Copyright);
			long extraHeaderLength = Header.FStart - wzWriter.BaseStream.Position;
			if (extraHeaderLength > 0)
			{
				wzWriter.Write(new byte[(int)extraHeaderLength]);
			}
			wzWriter.Write(version);
			wzWriter.Header = Header;
			wzDir.SaveDirectory(wzWriter);
			wzWriter.StringCache.Clear();
			FileStream fs = File.OpenRead(tempFile);
			wzDir.SaveImages(wzWriter, fs);
			fs.Close();
			File.Delete(tempFile);
			wzWriter.StringCache.Clear();
			wzWriter.Close();
		}
Example #2
0
		/// <summary>
		/// Saves a wz file to the disk, AKA repacking.
		/// </summary>
		/// <param name="path">Path to the output wz file</param>
        /// <param name="progressBar">Progressbar, optional. (Set to null if not in use)</param>
		public void SaveToDisk(string path, ProgressBar progressBar)
		{
            WzIv = WzTool.GetIvByMapleVersion(mapleVersion);
			CreateVersionHash();
			wzDir.SetHash(versionHash);
            if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //30%
			string tempFile = Path.GetFileNameWithoutExtension(path) + ".TEMP";
			File.Create(tempFile).Close();
			wzDir.GenerateDataFile(tempFile);
			WzTool.StringCache.Clear();
            if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //40%
			uint totalLen = wzDir.GetImgOffsets(wzDir.GetOffsets(Header.FStart + 2));
			WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), WzIv);
			wzWriter.Hash = (uint)versionHash;
			Header.FSize = totalLen - Header.FStart;
			for (int i = 0; i < 4; i++)
				wzWriter.Write((byte)Header.Ident[i]);
            if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //50%
			wzWriter.Write((long)Header.FSize);
			wzWriter.Write(Header.FStart);
			wzWriter.WriteNullTerminatedString(Header.Copyright);
            if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //60%
			long extraHeaderLength = Header.FStart - wzWriter.BaseStream.Position;
			if (extraHeaderLength > 0)
			{
				wzWriter.Write(new byte[(int)extraHeaderLength]);
			}
            if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //70%
			wzWriter.Write(version);
			wzWriter.Header = Header;
			wzDir.SaveDirectory(wzWriter);
			wzWriter.StringCache.Clear();
			FileStream fs = File.OpenRead(tempFile);
			wzDir.SaveImages(wzWriter, fs);
			fs.Close();
            if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //80%
			File.Delete(tempFile);
			wzWriter.StringCache.Clear();
			wzWriter.Close();
            if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //90%
            GC.Collect();
            GC.WaitForPendingFinalizers();
		}