Beispiel #1
0
 public void InsertWzFileUnsafe(WzFile f, HaRepackerMainPanel panel)
 {
     wzFiles.Add(f);
     WzNode node = new WzNode(f);
     panel.DataTree.Nodes.Add(node);
     SortNodesRecursively(node);
 }
Beispiel #2
0
        public void startExtractCharacters()
        {
            WzFile file = new WzFile(wzDir + @"\Character.wz", Version);
            //WzFile file = new WzFile(wzDir + @"\Data - kopie.wz", Version);
            file.ParseWzFile();
            //Console.WriteLine("Version: {0}", file.);
            
            string tempDir = currentDir;
            WzDirectory loldir = file.WzDirectory.GetDirectoryByName("Character");
            if (loldir == null)
            {
                loldir = file.WzDirectory;
            }
            loldir.ParseImages();

            foreach (WzImage img in loldir.WzImages)
            {
                currentDir += img.Name + "\\";
                parseImage(img);
                currentDir = tempDir;
            }

            foreach (WzDirectory dir in loldir.WzDirectories)
            {
                currentDir += dir.Name + "\\";
                parseDir(dir);
                currentDir = tempDir;
            }

        }
 public WzPatcherEntry(string wzname, string path, string value)
 {
     wzFile = null;
     wzFileName = wzname;
     nodePath = path;
     newValue = value;
 }
 public WzPatcherEntry(WzFile wz, string path, string value)
 {
     wzFile = wz;
     nodePath = path;
     newValue = value;
     wzFileName = wz.Name;
 }
Beispiel #5
0
 public SaveForm(HaRepackerMainPanel panel, WzNode wzNode)
 {
     InitializeComponent();
     this.wzNode = wzNode;
     this.wzf = (WzFile)wzNode.Tag;
     this.panel = panel;
 }
Beispiel #6
0
 /// <summary>
 /// Creates a WzDirectory
 /// </summary>
 /// <param name="reader">The BinaryReader that is currently reading the wz file</param>
 /// <param name="blockStart">The start of the data block</param>
 /// <param name="parentname">The name of the directory</param>
 /// <param name="wzFile">The parent Wz File</param>
 internal WzDirectory(WzBinaryReader reader, string dirName, uint verHash, byte[] WzIv, WzFile wzFile)
 {
     this.reader = reader;
     this.name = dirName;
     this.hash = verHash;
     this.WzIv = WzIv;
     this.wzFile = wzFile;
 }
Beispiel #7
0
 public void ReloadWzFile(WzFile file, HaRepackerMainPanel panel)
 {
     WzMapleVersion encVersion = file.MapleVersion;
     string path = file.FilePath;
     short version = ((WzFile)file).Version;
     ((WzNode)file.HRTag).Delete();
     wzFiles.Remove(file);
     LoadWzFile(path, encVersion, (short)-1, panel);
 }
Beispiel #8
0
 public SaveForm(HaRepackerMainPanel panel, WzNode wzNode)
 {
     InitializeComponent();
     encryptionBox.Items.Add(HaRepacker.Properties.Resources.EncTypeGMS);
     encryptionBox.Items.Add(HaRepacker.Properties.Resources.EncTypeMSEA);
     encryptionBox.Items.Add(HaRepacker.Properties.Resources.EncTypeNone);
     this.wzNode = wzNode;
     this.wzf = (WzFile)wzNode.Tag;
     this.panel = panel;
 }
 /// <summary>
 /// Applies all patches to the given WZ file.
 /// </summary>
 /// <param name="wz">The WZFile to patch.  Assumed to have already been parsed.</param>
 public static void applyPatches(WzFile wz)
 {
     foreach (WzPatcherEntry wpe in customPatches) {
         if (wpe.WzFileName.Equals(wz.Name)) {
             WzPatcherEntry localPatch = new WzPatcherEntry(wz, wpe.NodePath, wpe.NewValue);
             if (!checkSingleNode(localPatch)) {
                 modifySingleNode(localPatch);
             }
             localPatch.wzFile = null;
         }
     }
 }
Beispiel #10
0
 private void okButton_Click(object sender, EventArgs e)
 {
     if (regBox.Checked)
     {
         WzFile file = new WzFile((short)versionBox.Value, (WzMapleVersion)encryptionBox.SelectedIndex);
         file.Header.Copyright = copyrightBox.Text;
         file.Header.RecalculateFileStart();
         file.Name = nameBox.Text + ".wz";
         file.WzDirectory.Name = nameBox.Text + ".wz";
         panel.DataTree.Nodes.Add(new WzNode(file));
     }
     else
         new ListEditor(null, (WzMapleVersion)encryptionBox.SelectedIndex).Show();
     Close();
 }
        public void Save()
        {
            bool   settingsExist = File.Exists(wzPath);
            WzFile wzFile;

            if (settingsExist)
            {
                wzFile = new WzFile(wzPath, 1337, WzMapleVersion.CLASSIC);

                string parseErrorMessage = string.Empty;
                bool   success           = wzFile.ParseWzFile(out parseErrorMessage);
            }
            else
            {
                wzFile = new WzFile(1337, WzMapleVersion.CLASSIC);
                wzFile.Header.Copyright = "Wz settings file generated by MapleLib's WzSettings module created by haha01haha01";
                wzFile.Header.RecalculateFileStart();
                WzImage US = new WzImage("UserSettings.img")
                {
                    Changed = true,
                    Parsed  = true
                };
                WzImage AS = new WzImage("ApplicationSettings.img")
                {
                    Changed = true,
                    Parsed  = true
                };
                wzFile.WzDirectory.WzImages.Add(US);
                wzFile.WzDirectory.WzImages.Add(AS);
            }
            SaveSettingsImage((WzImage)wzFile["UserSettings.img"], userSettingsType);
            SaveSettingsImage((WzImage)wzFile["ApplicationSettings.img"], appSettingsType);
            if (settingsExist)
            {
                string tempFile     = Path.GetTempFileName();
                string settingsPath = wzFile.FilePath;

                wzFile.SaveToDisk(tempFile);
                wzFile.Dispose();
                File.Delete(settingsPath);
                File.Move(tempFile, settingsPath);
            }
            else
            {
                wzFile.SaveToDisk(wzPath);
            }
        }
Beispiel #12
0
 private bool OpenWzFile(string path, WzMapleVersion encVersion, short version, out WzFile file)
 {
     try
     {
         WzFile f = new WzFile(path, version, encVersion);
         wzFiles.Add(f);
         f.ParseWzFile();
         file = f;
         return true;
     }
     catch (Exception e)
     {
         Warning.Error("Error initializing " + Path.GetFileName(path) + " (" + e.Message + ").\r\nCheck that the directory is valid and the file is not in use.");
         file = null;
         return false;
     }
 }
 public void Load()
 {
     if (File.Exists(wzPath))
     {
         WzFile wzFile = new WzFile(wzPath, 1337, WzMapleVersion.CLASSIC);
         try
         {
             wzFile.ParseWzFile();
             ExtractSettingsImage((WzImage)wzFile["UserSettings.img"], userSettingsType);
             ExtractSettingsImage((WzImage)wzFile["ApplicationSettings.img"], appSettingsType);
             wzFile.Dispose();
         }
         catch
         {
             wzFile.Dispose();
             throw;
         }
     }
 }
Beispiel #14
0
 public void Load()
 {
     if (File.Exists(wzPath))
     {
         WzFile wzFile = new WzFile(wzPath, 1337, WzMapleVersion.CLASSIC);
         try
         {
             wzFile.ParseWzFile();
             ExtractSettingsImage((WzImage)wzFile["UserSettings.img"], userSettingsType);
             ExtractSettingsImage((WzImage)wzFile["ApplicationSettings.img"], appSettingsType);
             wzFile.Dispose();
         }
         catch
         {
             wzFile.Dispose();
             throw;
         }
     }
 }
Beispiel #15
0
        /// <summary>
        /// Load UserSettings and ApplicationSettings
        /// </summary>
        public void LoadSettings()
        {
            if (File.Exists(wzPath))
            {
                using (WzFile wzFile = new WzFile(wzPath, 1337, WzMapleVersion.CLASSIC))
                {
                    try
                    {
                        WzFileParseStatus parseStatus = wzFile.ParseWzFile();

                        ExtractSettingsImage((WzImage)wzFile["UserSettings.img"], userSettingsType);
                        ExtractSettingsImage((WzImage)wzFile["ApplicationSettings.img"], appSettingsType);
                    }
                    catch
                    {
                        throw;
                    }
                }
            }
        }
        /// <summary>
        /// Load UserSettings and ApplicationSettings
        /// </summary>
        public void LoadSettings()
        {
            if (File.Exists(wzPath))
            {
                using (WzFile wzFile = new WzFile(wzPath, 1337, WzMapleVersion.CLASSIC))
                {
                    try
                    {
                        string parseErrorMessage = string.Empty;
                        bool   success           = wzFile.ParseWzFile(out parseErrorMessage);

                        ExtractSettingsImage((WzImage)wzFile["UserSettings.img"], userSettingsType);
                        ExtractSettingsImage((WzImage)wzFile["ApplicationSettings.img"], appSettingsType);
                    }
                    catch
                    {
                        throw;
                    }
                }
            }
        }
 public void Save()
 {
     bool settingsExist = File.Exists(wzPath);
     WzFile wzFile;
     if (settingsExist)
     {
         wzFile = new WzFile(wzPath, 1337, WzMapleVersion.CLASSIC);
         wzFile.ParseWzFile();
     }
     else
     {
         wzFile = new WzFile(1337, WzMapleVersion.CLASSIC);
         wzFile.Header.Copyright = "Wz settings file generated by MapleLib's WzSettings module created by haha01haha01";
         wzFile.Header.RecalculateFileStart();
         WzImage US = new WzImage("UserSettings.img") { Changed = true, Parsed = true };
         WzImage AS = new WzImage("ApplicationSettings.img") { Changed = true, Parsed = true };
         wzFile.WzDirectory.WzImages.Add(US);
         wzFile.WzDirectory.WzImages.Add(AS);
     }
     SaveSettingsImage((WzImage)wzFile["UserSettings.img"], userSettingsType);
     SaveSettingsImage((WzImage)wzFile["ApplicationSettings.img"], appSettingsType);
     if (settingsExist)
     {
         string tempFile = Path.GetTempFileName();
         string settingsPath = wzFile.FilePath;
         wzFile.SaveToDisk(tempFile);
         wzFile.Dispose();
         File.Delete(settingsPath);
         File.Move(tempFile, settingsPath);
     }
     else
         wzFile.SaveToDisk(wzPath);
 }
Beispiel #18
0
        public void patch(Dictionary<String, List<String>> patches, string dir, int patchNum)
        {
            WzMapleVersion vrs = WzMapleVersion.GMS;
            foreach (String wzName in patches.Keys)
            {
                WzFile wzFile = null;
                foreach (WzFile patching in toPatch)
                {
                    if (patching.Name == wzName)
                    {
                        Console.WriteLine("Currently patching: {0}, nextToPatch: {1}", patching.Name, wzName);
                        wzFile = patching;
                        break;
                    }
                }
                if (wzFile == null)
                {
                    wzFile = new WzFile(wzName, vrs);
                    wzFile.ParseWzFile();
                }
                foreach (string img in patches[wzName])
                {
                    WzImage patchedImg = null;
                    string[] subdirs = img.Split(new char[] { '/' });
                    WzDirectory targetDir = wzFile.WzDirectory;
                    string targetImgName = null;
                    foreach (string subdir in subdirs)
                    {
                        Console.WriteLine("subdir: {0}", subdir);
                        if (!subdir.EndsWith(".img")) // if this isn't the img
                        {
                            targetDir = targetDir.GetDirectoryByName(subdir);
                            if (targetDir == null)
                            {
                                Console.WriteLine("ERROR: {0} is not a valid directory.", subdir);
                                return;
                            }
                        }
                        else
                        {
                            targetImgName = subdir;
                        }

                    }
                    patchedImg = new WzImage(targetImgName, File.OpenRead(dir + "-" + patchNum + targetImgName), vrs);
                    patchedImg.ParseImage();
                    WzImage targetImg = targetDir.GetImageByName(targetImgName);
                    if (targetImg != null) // patching an existing .img
                    {
                        targetDir.RemoveImage(targetImg);
                        targetDir.AddImage(patchedImg);
                        patchedImg.changed = true;
                        Console.WriteLine("Existing wz img found for name: {0} and successfully applied patch.", img);
                    }
                    else
                    {
                        targetDir.AddImage(patchedImg);
                        patchedImg.changed = true;
                        Console.WriteLine("Added new wz img with name: {0} in dir: {1} and sucessfully applied patch.", patchedImg.Name, targetDir.Name);
                    }
                }
                if (!toPatch.Contains(wzFile))
                {
                    toPatch.Add(wzFile);
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// Parses the WzDirectory
        /// </summary>
        internal void ParseDirectory(WzFile parent = null)
        {
            //Array.Copy(mReader.WzKey, keyCopy, mReader.WzKey.Length);
            int entryCount = mReader.ReadCompressedInt();

            for (int i = 0; i < entryCount; i++)
            {
                byte   type  = mReader.ReadByte();
                string fname = null;
                int    fsize;
                int    checksum;
                uint   offset;
                long   rememberPos = 0;
                switch (type)
                {
                case 1: {
                    mReader.ReadInt32();
                    mReader.ReadInt16();
                    mReader.ReadOffset();
                    continue;
                }

                case 2: {
                    int stringOffset = mReader.ReadInt32();
                    rememberPos = mReader.BaseStream.Position;
                    mReader.BaseStream.Position = mReader.Header.FStart + stringOffset;
                    type  = mReader.ReadByte();
                    fname = mReader.ReadString().Trim();
                }
                break;

                case 3:
                case 4:
                    fname       = mReader.ReadString().Trim();
                    rememberPos = mReader.BaseStream.Position;
                    break;
                }
                mReader.BaseStream.Position = rememberPos;
                fsize    = mReader.ReadCompressedInt();
                checksum = mReader.ReadCompressedInt();
                offset   = mReader.ReadOffset();
                if (type == 3)
                {
                    WzDirectory subDir = new WzDirectory(mReader, fname, mHash, mWzIv)
                    {
                        BlockSize = fsize, Checksum = checksum, Offset = offset, Parent = parent ?? this
                    };
                    if (parent != null)
                    {
                        parent.mSubDirs.Add(subDir);
                    }
                    mSubDirs.Add(subDir);
                }
                else
                {
                    WzImage img = new WzImage(fname, mReader)
                    {
                        BlockSize = fsize, Checksum = checksum, Offset = offset, Parent = parent ?? this
                    };
                    if (parent != null)
                    {
                        parent.mImages.Add(img);
                    }
                    mImages.Add(img);
                }
            }
            foreach (WzDirectory subdir in mSubDirs)
            {
                mReader.BaseStream.Position = subdir.mOffset;
                subdir.ParseDirectory();
            }
        }
Beispiel #20
0
 void loadDifferences()
 {
     // here we would query a website for latest patch rev.
     WzMapleVersion vrs = WzMapleVersion.GMS; // is classic old GMS??
     string imgPath = textBox1.Text;
     string wzPath = textBox2.Text;
     Console.WriteLine("imgPath: " + imgPath + ", wzPath: " + wzPath);
     WzFile affected = new WzFile(wzPath, vrs);
     affected.ParseWzFile();
     char[] split = { '\\', '/'};
     string imgName = imgPath.Split(split)[imgPath.Split(split).Length - 1].Trim();
     Console.WriteLine("imgName: " + imgName);
     WzImage toPatch = affected.WzDirectory.GetImageByName(imgName);
     FileStream stream = File.OpenRead(imgPath);
     WzImage img = new WzImage("-" + imgName, stream, vrs);
     img.ParseImage();
     toPatch.ParseImage();
     toPatch.ClearProperties();
     toPatch.AddProperties(img.WzProperties);
     affected.WzDirectory.GetImageByName(imgName).changed = true;
     affected.SaveToDisk(wzPath + ".new");
     affected.Dispose();
     stream.Close();
     while (!tryDelete(wzPath))
     {
         Thread.Sleep(1000); // ensure that we can rename the file
     }
     File.Move(wzPath + ".new", wzPath); // rewrite w/ patched file
     button1.Text = "Done!";
 }
Beispiel #21
0
 private void RunWzFilesExtraction(object param)
 {
     ChangeApplicationState(false);
     string[] wzFilesToDump = (string[])((object[])param)[0];
     string baseDir = (string)((object[])param)[1];
     WzMapleVersion version = (WzMapleVersion)((object[])param)[2];
     IWzFileSerializer serializer = (IWzFileSerializer)((object[])param)[3];
     UpdateProgressBar(MainPanel.mainProgressBar, 0, false, true);
     UpdateProgressBar(MainPanel.mainProgressBar, wzFilesToDump.Length, true, true);
     foreach (string wzpath in wzFilesToDump)
     {
         if (WzTool.IsListFile(wzpath))
         {
             Warning.Error("The file at " + wzpath + " is a List.wz file and will be skipped.");
             continue;
         }
         WzFile f = new WzFile(wzpath, version);
         f.ParseWzFile();
         serializer.SerializeFile(f, Path.Combine(baseDir, f.Name));
         f.Dispose();
         UpdateProgressBar(MainPanel.mainProgressBar, 1, false, false);
     }
     threadDone = true;
 }
Beispiel #22
0
        internal void ParseMainWzDirectory(WzFile parentFile = null)
        {
            if (mPath == null)
            {
                Console.WriteLine("[Error] Path is null");
                return;
            }
            byte[] key = WzKeyGenerator.GenerateWzKey(mWzIv);
            mReader = new WzBinaryReader(File.Open(mPath, FileMode.Open, FileAccess.Read, FileShare.Read), key, true);
            Header  = new WzHeader {
                Ident = mReader.ReadString(4), FSize = mReader.ReadUInt64(), FStart = mReader.ReadUInt32(), Copyright = mReader.ReadNullTerminatedString()
            };
            int bytesToRead = (int)(Header.FStart - mReader.BaseStream.Position);

            if (bytesToRead < 0)
            {
                throw new Exception("Unable to parse WZ file header");
            }
            mReader.ReadBytes(bytesToRead);
            mReader.Header = Header;
            mVersion       = mReader.ReadInt16();
            if (mFileVersion == -1)
            {
                for (int j = 0; j < short.MaxValue; j++)
                {
                    mFileVersion = (short)j;
                    if (parentFile != null)
                    {
                        mFileVersion = parentFile.mFileVersion;
                    }
                    mVersionHash = GetVersionHash(mVersion, mFileVersion);
                    if (mVersionHash == 0)
                    {
                        continue;
                    }
                    mReader.Hash = mVersionHash;
                    long        position = mReader.BaseStream.Position;
                    WzDirectory testDirectory;
                    try {
                        testDirectory = new WzDirectory(mReader, mName, mVersionHash, mWzIv);
                        testDirectory.ParseDirectory();
                    } catch {
                        mReader.BaseStream.Position = position;
                        continue;
                    }
                    foreach (WzImage s in testDirectory.GetChildImages())
                    {
                        if (s.Name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
                        {
                            testDirectory.Dispose();
                            throw new Exception("Invalid file names were detected. An invalid encryption may have been used.");
                        }
                    }
                    WzImage testImage = testDirectory.GetChildImages()[0];
                    try {
                        mReader.BaseStream.Position = testImage.Offset;
                        byte checkByte = mReader.ReadByte();
                        mReader.BaseStream.Position = position;
                        testDirectory.Dispose();
                        switch (checkByte)
                        {
                        case 0x73:
                        case 0x1b: {
                            mHash = mVersionHash;
                            ParseDirectory(parentFile);
                            return;
                        }
                        }
                        mReader.BaseStream.Position = position;
                    } catch {
                        mReader.BaseStream.Position = position;
                    }
                }
                throw new Exception("Error with game version hash : The specified game version is incorrect and WzLib was unable to determine the version itself");
            }
            mVersionHash = GetVersionHash(mVersion, mFileVersion);
            mReader.Hash = mVersionHash;
            mHash        = mVersionHash;
            ParseDirectory(parentFile);
        }
Beispiel #23
0
        static IWzImageProperty getNode(WzFile file, string fullPath)
        {
            List<string> subDirectories = new List<string>(fullPath.Split(new string[] { @"\" }, StringSplitOptions.None));
            //string nodeName = subDirectories[subDirectories.Count - 1];
            //subDirectories.RemoveAt(subDirectories.Count - 1); //The last element always contains the node; remove this, we only care about the directories

            WzDirectory targetDirectory = file.WzDirectory;
            WzImage targetImage;
            IWzImageProperty targetNode = null;

            int lastIndex;

            //First, navigate through the WzDirectory tree.
            for(lastIndex = 0; lastIndex < subDirectories.Count; lastIndex++){
                string subDirectory = subDirectories[lastIndex];
                if (targetDirectory.GetDirectoryByName(subDirectory) == null) {
                    break;
                } else if (targetDirectory.GetDirectoryByName(subDirectory) != null) {
                    targetDirectory = targetDirectory.GetDirectoryByName(subDirectory);
                }
            }

            targetImage = targetDirectory.GetImageByName(subDirectories[lastIndex]);
            targetImage.ParseImage();
            lastIndex++;

            //Reached the end of the WzImage tree, now go into the specific sub-node
            string subNode = subDirectories[lastIndex];
            foreach(IWzImageProperty prop in targetImage.WzProperties){
                if (subNode.Equals(prop.Name)) {
                    targetNode = prop;
                    break;
                }
            }
            lastIndex++;

            if (targetNode != null) {
                for (int i = lastIndex; i < subDirectories.Count; i++) {
                    string nextNode = subDirectories[i];
                    if(containsSubNode(targetNode, nextNode)) {
                        targetNode = getSubNode(targetNode, nextNode);
                    } else {
                        break;
                    }
                }
            }

            return targetNode;
        }
Beispiel #24
0
 /// <summary>
 /// Creates a WzDirectory
 /// </summary>
 /// <param name="reader">The BinaryReader that is currently reading the wz file</param>
 /// <param name="wzIv"></param>
 /// <param name="wzFile">The parent Wz File</param>
 /// <param name="dirName"></param>
 /// <param name="verHash"></param>
 internal WzDirectory(WzBinaryReader reader, string dirName, uint verHash, byte[] wzIv, WzFile wzFile)
 {
     _reader = reader;
     Name    = dirName;
     _hash   = verHash;
     WzIv    = wzIv;
     _wzFile = wzFile;
 }
Beispiel #25
0
 public WzMainDirectory(WzFile file, WzDirectory directory)
 {
     this.file = file;
     this.directory = directory;
 }
Beispiel #26
0
 static void ParseFile(string InputFileName,string OutputFileName)
 {
     JsonCreator Creator=new JsonCreator();
     WzFile File=new WzFile(InputFileName,WzMapleVersion.BMS);
     File.ParseWzFile();
     List<WzDirectory> RootDirectory=new List<WzDirectory>();
     RootDirectory.Add(File.WzDirectory);
     var Dirs=new Stack<DirObject>();
     var RootHash=new Dictionary<string,object>();
     Dirs.Push(new DirObject(RootDirectory.GetEnumerator(),RootHash));
     for(;Dirs.Count>0;){
         if(!Dirs.Peek().Dir.MoveNext()){
             Dirs.Pop();
             continue;
         }else{
             foreach(WzImage Image in Dirs.Peek().Dir.Current.WzImages){
                 var Props=new Stack<PropObject>();
                 var Temp1=new Dictionary<string,object>();
                 Dirs.Peek().Hash.Add(Image.Name,Temp1);
                 Props.Push(new PropObject(Image.WzProperties.GetEnumerator(),Temp1));
                 for(;Props.Count>0;){
                     if(!Props.Peek().Prop.MoveNext()){
                         Props.Pop();
                         continue;
                     }
                     var Obj=Props.Peek().Prop.Current;
                     switch(Props.Peek().Prop.Current.PropertyType){
                     case WzPropertyType.ByteFloat:
                         Props.Peek().Hash.Add(Obj.Name,(double)((WzByteFloatProperty)Obj).Value);
                         break;
                     case WzPropertyType.Canvas:
                         //Not Implemented
                         break;
                     case WzPropertyType.CompressedInt:
                         Props.Peek().Hash.Add(Obj.Name,(long)((WzCompressedIntProperty)Obj).Value);
                         break;
                     case WzPropertyType.Convex:
                         //Not Implemented
                         break;
                     case WzPropertyType.Double:
                         Props.Peek().Hash.Add(Obj.Name,((WzDoubleProperty)Obj).Value);
                         break;
                     case WzPropertyType.Null:
                         Props.Peek().Hash.Add(Obj.Name,null);
                         break;
                     case WzPropertyType.PNG:
                         var Temp2=((WzPngProperty)Obj).GetCompressedBytes(false).OfType<long>().ToList();
                         var Temp3=new Dictionary<string,object>();
                         Temp3.Add("Width",(long)((WzPngProperty)Obj).Width);
                         Temp3.Add("Height",(long)((WzPngProperty)Obj).Height);
                         Temp3.Add("Data",Temp2);
                         break;
                     case WzPropertyType.Sound:
                         var Temp4=((WzSoundProperty)Obj).GetBytes(false).OfType<long>().ToList();
                         var Temp5=new Dictionary<string,object>();
                         Temp5.Add("Frequency",(long)((WzSoundProperty)Obj).Frequency);
                         Temp5.Add("Length",(long)((WzSoundProperty)Obj).Length);
                         Temp5.Add("Data",Temp4);
                         Props.Peek().Hash.Add(Obj.Name,Temp5);
                         break;
                     case WzPropertyType.String:
                         Props.Peek().Hash.Add(Obj.Name,((WzStringProperty)Obj).Value);
                         break;
                     case WzPropertyType.SubProperty:
                         var Temp6=new Dictionary<string,object>();
                         Props.Peek().Hash.Add(Obj.Name,Temp6);
                         Props.Push(new PropObject(((WzSubProperty)Obj).WzProperties.GetEnumerator(),Temp6));
                         break;
                     case WzPropertyType.UnsignedShort:
                         Props.Peek().Hash.Add(Obj.Name,(long)((WzUnsignedShortProperty)Obj).Value);
                         break;
                     case WzPropertyType.UOL:
                         //Not Implemented
                         break;
                     case WzPropertyType.Vector:
                         var Temp7=new Dictionary<string,object>();
                         Temp7.Add("X",(long)((WzVectorProperty)Obj).X);
                         Temp7.Add("Y",(long)((WzVectorProperty)Obj).Y);
                         Props.Peek().Hash.Add(Obj.Name,Temp7);
                         break;
                     }
                 }
             }
             var Temp8=new Dictionary<string,object>();
             Dirs.Peek().Hash.Add(Dirs.Peek().Dir.Current.Name,Temp8);
             Dirs.Push(new DirObject(Dirs.Peek().Dir.Current.WzDirectories.GetEnumerator(),Temp8));
         }
     }
     var Json=Creator.Create(RootHash);
     System.IO.File.WriteAllText(OutputFileName,Json,Encoding.UTF8);
     return;
 }
Beispiel #27
0
 public WzMainDirectory(WzFile file)
 {
     this.file = file;
     this.directory = file.WzDirectory;
 }
Beispiel #28
0
        /// <summary>
        /// Checks if any current wz files are not set to the latest version number.
        /// </summary>
        /// <returns>
        /// Returns a List<Tuple<string, int>> array with the file name and detected version.
        /// </returns>
        protected List<Tuple<string, int>> outDatedFiles()
        {
            BinaryReader verificationWz;
            wzSignature vs;
            var outOfDateFiles = new List<Tuple<string, int>>();
            if (haveFiles())
            {
                for (int i = 0; i < wzFiles.Length; i++)
                {
                    try
                    {
                        verificationWz = new BinaryReader(new FileStream(wzFiles[i], FileMode.Open));
                        vs = new wzSignature(verificationWz, currentLauncherVersion);
                        if (!(vs.WzVersion == latestWZVersion) || !(vs.UIAdded && vs.EssenceAdded))
                            outOfDateFiles.Add(new Tuple<string, int>(wzFiles[i], vs.WzVersion));

                        verificationWz.Close();
                    }
                    catch (Exception)
                    {
                        updateLabel("Please close any program using " + wzFiles[0] + ".");
                        setStateWrapper(3);
                        backgroundWorker.ReportProgress(100);
                        //throw new Exception("Please close any program using " + wzFiles[0] + ".");
                    }
                }
            }

            List<string> toCheck = new List<string>();
            foreach (WzPatcherEntry patch in WzPatcher.customPatches) {
                if (!toCheck.Contains(patch.WzFileName)) {
                    toCheck.Add(patch.WzFileName);
                }
            }

            //Check for hardcoded changes.
            foreach (string i in toCheck) {
                WzFile wz = new WzFile(i, (short)mapleVersion, WzMapleVersion.BMS);
                wz.ParseWzFile();
                allWzFiles.Add(wz);
                foreach (WzPatcherEntry patch in WzPatcher.customPatches) {
                    WzPatcherEntry newPatch = patch;
                    newPatch.wzFile = wz;
                    if (newPatch.WzFileName.Equals(i)) {
                        if (!WzPatcher.checkSingleNode(newPatch)) {
                            bool found = false;
                            foreach (Tuple<string, int> toPatch in outOfDateFiles) {
                                if (toPatch.Item1.Equals(i)) {
                                    found = true;
                                }
                            }
                            if (!found) {
                                outOfDateFiles.Add(new Tuple<string, int>(i, latestWZVersion));
                            }
                        }
                    }
                }
            }
            return outOfDateFiles;
        }
Beispiel #29
0
 private void asdfToolStripMenuItem_Click(object sender, EventArgs e)
 {
     WzFile f = new WzFile(@"C:\Mob.wz", WzMapleVersion.BMS);
     //WzFile f = new WzFile(@"C:\Nexon\MapleStoryExt\Skill.wz", WzMapleVersion.BMS);
     f.ParseWzFile();
     foreach (WzImage mob in f.WzDirectory.WzImages)
     {
         mob.ParseImage();
         WzSubProperty info = (WzSubProperty)mob["info"];
         if (info != null)
         {
             WzCompressedIntProperty bodyatt = (WzCompressedIntProperty)info["bodyAttack"];
             if (bodyatt != null)
             {
                 bodyatt.Value = 0;
                 mob.Changed = true;
             }
         }
     }
     f.SaveToDisk(@"C:\Mob2.wz");
 }
Beispiel #30
0
 public void UnloadWzFile(WzFile file)
 {
     ((WzNode)file.HRTag).Delete();
     wzFiles.Remove(file);
 }
Beispiel #31
0
 public bool LoadWzFile(string name)
 {
     try
     {
         WzFile wzf = new WzFile(Path.Combine(baseDir, Capitalize(name) + ".wz"), version);
         wzf.ParseWzFile();
         name = name.ToLower();
         wzFiles[name] = wzf;
         wzFilesUpdated[wzf] = false;
         wzDirs[name] = new WzMainDirectory(wzf);
         return true;
     }
     catch (Exception e)
     {
         HaRepackerLib.Warning.Error("Error initializing " + name + ".wz (" + e.Message + ").\r\nCheck that the directory is valid and the file is not in use.");
         return false;
     }
 }
Beispiel #32
0
 private void RunWzFilesExtraction(object param)
 {
     ChangeApplicationState(false);
     string[] wzFilesToDump = (string[])((object[])param)[0];
     string baseDir = (string)((object[])param)[1];
     WzMapleVersion version = (WzMapleVersion)((object[])param)[2];
     IWzFileSerializer serializer = (IWzFileSerializer)((object[])param)[3];
     UpdateProgressBar(MainPanel.mainProgressBar, 0, false, true);
     UpdateProgressBar(MainPanel.mainProgressBar, wzFilesToDump.Length, true, true);
     foreach (string wzpath in wzFilesToDump)
     {
         if (WzTool.IsListFile(wzpath))
         {
             Warning.Error(string.Format(HaRepacker.Properties.Resources.MainListWzDetected, wzpath));
             continue;
         }
         WzFile f = new WzFile(wzpath, version);
         f.ParseWzFile();
         serializer.SerializeFile(f, Path.Combine(baseDir, f.Name));
         f.Dispose();
         UpdateProgressBar(MainPanel.mainProgressBar, 1, false, false);
     }
     threadDone = true;
 }
Beispiel #33
0
 public bool LoadDataWzFile(string name)
 {
     try
     {
         WzFile wzf = new WzFile(Path.Combine(baseDir, Capitalize(name) + ".wz"), version);
         wzf.ParseWzFile();
         name = name.ToLower();
         wzFiles[name] = wzf;
         wzFilesUpdated[wzf] = false;
         wzDirs[name] = new WzMainDirectory(wzf);
         foreach (WzDirectory mainDir in wzf.WzDirectory.WzDirectories)
         {
             wzDirs[mainDir.Name.ToLower()] = new WzMainDirectory(wzf, mainDir);
         }
         return true;
     }
     catch (Exception e)
     {
         MessageBox.Show("Error initializing " + name + ".wz (" + e.Message + ").\r\nCheck that the directory is valid and the file is not in use.");
         return false;
     }
 }
Beispiel #34
0
        public void Patch()
        {
            string curVTxt = "(Current V" + Patcher_UserSettings.CurrentVersion + ")";
            AppendStatus(curVTxt + " Checking for updates...");
            ProgressStyle(ProgressBarStyle.Marquee);
            WebClient download = new WebClient();
            //MessageBox.Show("hai");
            if (!CheckPath(Patcher_AppSettings.PatchURL)) //Check if the website directory actually exists. -DeathRight
            {
                download.Dispose();
                MessageBox.Show("The specified URL cannot be found, please contact the server owner or post in the help section of the server forum.", "Unreachable URL");
                Application.Exit();
            }

            //MessageBox.Show("hai2");

            if (!CheckPath(Patcher_AppSettings.PatchURL + "/" + (Patcher_UserSettings.CurrentVersion + 1).ToString()))
            {
                download.Dispose();
                Application.Exit(); //If there isn't a folder with a version 1 higher than the current, we can't update, so exit. -DeathRight
            }

            Dictionary<string, WzFile> WzFiles = new Dictionary<string, WzFile>();
            AppendStatus(curVTxt + " Downloading patch files...");
            ProgressValue(0);
            ProgressStyle(ProgressBarStyle.Marquee);
            RefreshStuff();
            Directory.CreateDirectory(Application.StartupPath + @"\Patches");
            foreach (string wzFile in WzTypes)
            {
                if (CheckFile(Patcher_AppSettings.PatchURL + "/" + (Patcher_UserSettings.CurrentVersion + 1).ToString() + "/" + wzFile))
                {
                    download.DownloadFile(Patcher_AppSettings.PatchURL + "/" + (Patcher_UserSettings.CurrentVersion + 1).ToString() + "/" + wzFile, Application.StartupPath + @"\Patches\" + wzFile);
                    short version = -1;
                    WzMapleVersion nWzFV = WzTool.DetectMapleVersion(Application.StartupPath + @"\Patches\" + wzFile, out version);
                    WzFile nWzF = new WzFile(Application.StartupPath + @"\Patches\" + wzFile, nWzFV);
                    nWzF.ParseWzFile();
                    nWzF.WzDirectory.ParseImages(); //Just to be safe -DeathRight
                    WzFiles.Add(wzFile, nWzF);
                }
            }
            download.Dispose();

            if (WzFiles.Count <= 0)
            {
                return;
            }

            string slTxt = curVTxt + " Patching files...";
            AppendStatus(slTxt);
            ProgressStyle(ProgressBarStyle.Continuous);
            //ProgressMax(WzFiles.Count);
            RefreshStuff();
            Directory.CreateDirectory(Application.StartupPath + @"\Patches\TEMP");
            foreach (WzFile wzFile in WzFiles.Values)
            {
                if (wzFile.WzDirectory["PatchInfo"] != null)
                    wzFile.WzDirectory["PatchInfo"].Remove();

                if (!File.Exists(Application.StartupPath + @"\" + wzFile.Name))
                {
                    MessageBox.Show("Unable to find WZ '" + wzFile.Name + "' in path '" + Application.StartupPath + "'","Unable to find WZ file");
                    Application.Exit();
                }

                ProgressValue(0);
                ProgressStyle(ProgressBarStyle.Marquee);
                RefreshStuff();
                AppendStatus(slTxt + " [" + wzFile.Name + "]");
                RefreshStuff();

                short version = -1;
                WzFile origWz = new WzFile(Application.StartupPath + @"\" + wzFile.Name, WzTool.DetectMapleVersion(Application.StartupPath + @"\" + wzFile.Name, out version));
                origWz.ParseWzFile();
                origWz.WzDirectory.ParseImages();
                try
                {
                    ReplaceDirs(wzFile.WzDirectory, origWz);
                    origWz.SaveToDisk(Application.StartupPath + @"\Patches\TEMP\" + wzFile.Name);
                }
                catch
                {
                    MessageBox.Show("Error while trying to save WZ file '" + wzFile.Name + "'", "Error saving WZ file");
                    wzFile.Dispose();
                    origWz.Dispose();
                    File.Delete(Application.StartupPath + @"\Patches\" + wzFile);
                    Application.Exit();
                }
                string wzName = wzFile.Name;
                wzFile.Dispose();
                origWz.Dispose();
                File.Delete(Application.StartupPath + @"\Patches\" + wzName);
                File.Delete(Application.StartupPath + @"\" + wzName);
                File.Move(Application.StartupPath + @"\Patches\TEMP\" + wzName, Application.StartupPath + @"\" + wzName);

                //ProgressValue();

                //RefreshStuff();
            }

            Patcher_UserSettings.CurrentVersion++;
            Patch();
        }
Beispiel #35
0
 public void Interop_AddLoadedWzFileToManager(WzFile f)
 {
     Program.WzMan.InsertWzFileUnsafe(f, MainPanel);
 }
Beispiel #36
0
 /// <summary>
 /// Creates a WzDirectory with the given name
 /// </summary>
 /// <param name="name">The name of the directory</param>
 public WzDirectory(string name, WzFile wzFile = null)
 {
     this.name   = name;
     this.wzFile = wzFile;
 }
Beispiel #37
0
        /*public void ReplaceObj(IWzObject obj, WzFile baseFile)
        {
            if (baseFile.GetObjectFromPath(obj.FullPath) == null)
                ReplaceObj(obj.Parent, baseFile);
            else
            {
                baseFile.GetObjectFromPath(obj.FullPath).Remove();
                baseFile.GetObjectFromPath(obj.Parent.FullPath)
            }
        }*/
        public void ReplaceDirs(WzDirectory parent, WzFile orignal)
        {
            string curVTxt = "(Current V" + Patcher_UserSettings.CurrentVersion + ")";
            string slTxt = curVTxt + " Patching files...";
            //AppendStatus("TEST");
            //RefreshStuff();
            foreach (WzDirectory dir in parent.WzDirectories)
            {
                if (orignal.GetObjectFromPath(dir.FullPath.Replace(@"\", "/")) == null)
                {
                    /*AppendStatus("TEST1");
                    RefreshStuff();
                    MessageBox.Show("TEST1");*/
                    ((WzDirectory)orignal.GetObjectFromPath(dir.FullPath.Replace(@"\", "/"))).AddDirectory(dir);
                }
                if ((dir.WzDirectories.Count != 0) || (dir.WzImages.Count != 0))
                {
                    /*AppendStatus("TEST2");
                    RefreshStuff();
                    MessageBox.Show("TEST2");*/
                    ReplaceDirs(dir, orignal);
                }

                AppendStatus(slTxt + " [" + orignal.Name + "]" + " [" + ((WzDirectory)dir).Name + "]");
                RefreshStuff();
            }
            //if (parent.WzImages.Count <= 0) { MessageBox.Show("TEST4"); }
            if ((parent.WzImages != null) && (parent.WzImages.Count > 0))
            {
                ProgressValue(0);
                ProgressStyle(ProgressBarStyle.Continuous);
                ProgressMax(parent.WzImages.Count);
                RefreshStuff();
            }
            foreach (WzImage img in parent.WzImages)
            {
                /*AppendStatus("TEST5"); //THIS HAPPENS ON STRING.WZ BUT NOT CHARACTER.WZ
                RefreshStuff();
                MessageBox.Show("TEST5");*/
                if (orignal.GetObjectFromPath(img.FullPath.Replace(@"\", "/")) != null)
                {
                    object Dir = orignal.GetObjectFromPath(img.FullPath.Replace(@"\", "/")).Parent; //is WzDirectory
                    AppendStatus(slTxt + " [" + orignal.Name + "]" + " [" + ((WzDirectory)Dir).Name + "]" + " [" + ((WzImage)img).Name + "]");
                    RefreshStuff();
                    ((WzImage)orignal.GetObjectFromPath(img.FullPath.Replace(@"\", "/"))).Remove();
                    if (Dir is WzDirectory)
                    {
                        ((WzDirectory)Dir).AddImage(img);
                        ((WzImage)((WzDirectory)Dir)[img.Name]).Changed = true;
                    }
                    else if (Dir is WzFile)
                    {
                        ((WzFile)Dir).WzDirectory.AddImage(img);
                        ((WzImage)((WzFile)Dir).WzDirectory[img.Name]).Changed = true;
                    }
                    ProgressValue();
                    RefreshStuff();
                }
                else
                {
                    string path = img.Parent.FullPath.Replace(@"\", "/");
                    object dir = orignal.GetObjectFromPath(path);
                    AppendStatus(slTxt + " [" + orignal.Name + "]" + " [" + ((WzDirectory)dir).Name + "]" + " [" + ((WzImage)img).Name + "]");
                    RefreshStuff();
                    if (dir is WzDirectory)
                    {
                        ((WzDirectory)dir).AddImage(img);
                        ((WzImage)((WzDirectory)dir)[img.Name]).Changed = true;
                    }
                    else if (dir is WzFile)
                    {
                        ((WzFile)dir).WzDirectory.AddImage(img);
                        ((WzImage)((WzFile)dir).WzDirectory[img.Name]).Changed = true;
                    }
                    ProgressValue();
                    RefreshStuff();
                }
            }
        }
Beispiel #38
0
 /// <summary>
 /// Creates a WzDirectory
 /// </summary>
 /// <param name="reader">The BinaryReader that is currently reading the wz file</param>
 /// <param name="blockStart">The start of the data block</param>
 /// <param name="parentname">The name of the directory</param>
 /// <param name="wzFile">The parent Wz File</param>
 internal WzDirectory(WzBinaryReader reader, string dirName, uint verHash, byte[] WzIv, WzFile wzFile)
 {
     this.reader = reader;
     this.name   = dirName;
     this.hash   = verHash;
     this.WzIv   = WzIv;
     this.wzFile = wzFile;
 }
Beispiel #39
0
        protected void downloadLatestVersion()
        {
            //oldversion_newversion.txt
                string updateFile = verificationSignature.WzVersion.ToString() + "_" + latestWZVersion.ToString() + ".txt";
            //Download and prepare the XML list for parsing.

            List<string> XMLsToUpdate = mergeFiles();
            List<Tuple<string, string>> XMLListing = new List<Tuple<string, string>>();
            WzXmlDeserializer xmlParser = new WzXmlDeserializer(true, new byte[] { 0, 0, 0, 0 });

            List<string> wzFilesNeedingPatch = new List<string>();

            updateLabel("(2/6) Receiving the update patch list."); //Removed the display here since it doesn't play well with merged files

            //splits the update log into <WzFile, WzNode>
            foreach (string XMLLine in XMLsToUpdate)
            {
                //Check for which files actually need patching first
                foreach (string wzName in wzFiles)
                {
                    if (!wzFilesNeedingPatch.Contains(wzName) && XMLLine.Contains(wzName))
                    {
                        wzFilesNeedingPatch.Add(wzName);
                    }
                }

                string[] splitted = XMLLine.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (!XMLListing.Contains(new Tuple<string, string>(splitted[0], splitted[1])))
                {
                    XMLListing.Add(new Tuple<string, string>(splitted[0], splitted[1]));
                }
            }

            //open the WZ files for patching
            foreach (string wzName in wzFilesNeedingPatch)
            {
                WzFile tmp = new WzFile(wzName, WzMapleVersion.BMS);
                tmp.ParseWzFile();
                allWzFiles.Add(tmp);
            }

            //Parse XML's and add the nodes to the WZ files.
            int counter = 0;
            foreach (WzFile wzFile in allWzFiles) //foreach (Tuple<string, string> XMLFile in XMLListing)
            {
                updateLabel("(3/6) Applying: " + wzFile.Name + " (Downloading and applying patch files)");

                foreach (Tuple<string, string> XMLFile in XMLListing) //foreach (WzFile wzFile in allWzFiles)
                {
                    if (wzFile.Name == XMLFile.Item1)
                    {
                        counter += 1;
                        string xmlContent = "";
                        try
                        {
                            xmlContent = readEntireWebFile(updateServer + @"wz/" + XMLFile.Item1 + "/" + XMLFile.Item2);
                        }
                        catch (Exception)
                        {
                            //Throw "Unable to connect to the update server" if unable to read any file from update server.
                            setStateWrapper(12);
                            backgroundWorker.ReportProgress(100);
                        }
                        try
                        {
                            WzImage imageToAdd = (WzImage)xmlParser.ParseXML(xmlContent)[0];
                            AddWzImage(wzFile, XMLFile.Item2, imageToAdd);
                            int percentage = (int)((double)counter * 100) / XMLListing.Count;
                            backgroundWorker.ReportProgress(percentage);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error on XML ("+ XMLFile.Item2 + ") " + e.ToString());
                        }
                    }
                }
                WzPatcher.applyPatches(wzFile);
            }

            //Done patching, save in temporary dir
            if (Directory.Exists(temporaryDirectory))
            {
                Directory.Delete(temporaryDirectory, true);
                Directory.CreateDirectory(temporaryDirectory);
            }
            else
            {
                Directory.CreateDirectory(temporaryDirectory);
            }

            updateLabel("(4/6) Adding custom content.");

            backgroundWorker.ReportProgress(0);

            WzFile CharacterWz = null;
            WzFile MapWz = null;
            WzFile UIWz = null;
            foreach (WzFile wzfile in allWzFiles)
            {
                if(wzfile.Name == "Character.wz")
                    CharacterWz = wzfile;
                if(wzfile.Name == "Map.wz")
                    MapWz = wzfile;
                if (wzfile.Name == "UI.wz")
                    UIWz = wzfile;
            }

            if (!verificationSignature.UIAdded)
            {
                if (MapWz == null)
                {
                    MapWz = new WzFile("Map.wz", WzMapleVersion.BMS);
                    MapWz.ParseWzFile();
                    allWzFiles.Add(MapWz);
                }
                AddCustomImages(MapWz, backgroundWorker);
                verificationSignature.UIAdded = true;
                backgroundWorker.ReportProgress(75);
            }
            if (!verificationSignature.EssenceAdded)
            {
                if (UIWz == null)
                {
                    UIWz = new WzFile("UI.wz", WzMapleVersion.BMS);
                    UIWz.ParseWzFile();
                    allWzFiles.Add(UIWz);
                }
                AddCustomImages(UIWz, backgroundWorker);
                verificationSignature.EssenceAdded = true;
                backgroundWorker.ReportProgress(100);
            }

            backgroundWorker.ReportProgress(100);

            //Generate the new signature
            wzSignature newSignature = verificationSignature;
            newSignature.LauncherVersion = currentLauncherVersion;
            newSignature.WzVersion = (ushort)latestWZVersion;

            counter = 0;
            backgroundWorker.ReportProgress(0);
            foreach (WzFile wzFile in allWzFiles)
            {
                    counter += 1;
                    updateLabel("(5/6) Creating: " + wzFile.Name + " (Saving files to disk)");

                    wzFile.SaveToDisk(temporaryDirectory + wzFile.Name);
                    wzFile.Dispose();

                    int percentage = (int)((double)counter * 100) / allWzFiles.Count;
                    backgroundWorker.ReportProgress(percentage);
            }

            counter = 0;
            backgroundWorker.ReportProgress(0);
            //Done patching, copy the patched files over to the game installation.
            foreach (FileInfo wzFile in new DirectoryInfo(temporaryDirectory).GetFiles())
            {
                counter += 1;
                updateLabel("(6/6) Finalizing: " + wzFile.Name + " (Replacing files with patched files)");
                File.Delete(Directory.GetCurrentDirectory() + "\\" + wzFile.Name);
                File.Copy(wzFile.FullName, Directory.GetCurrentDirectory() + "\\" + wzFile.Name);

                int percentage = (int)((double)counter * 100) / (new DirectoryInfo(temporaryDirectory).GetFiles().Length);
                backgroundWorker.ReportProgress(percentage);
            }

            allWzFiles.Clear();
            foreach (string wzName in wzFiles)
            {
                allWzFiles.Add(new WzFile(wzName, WzMapleVersion.BMS));
            }

            //Sign each WZ file
            foreach (WzFile wzFile in allWzFiles)
            {
                try
                {
                    string wzPath = wzFile.FilePath;
                    BinaryReader wzReaderStream = new BinaryReader(new FileStream(wzPath, FileMode.Open));
                    bool needsNewSignature = wzSignature.isSignedWzFile(wzReaderStream);
                    wzReaderStream.Close();

                    BinaryWriter wzWriterStream = new BinaryWriter(new FileStream(wzPath, FileMode.Open));
                    newSignature.writeSignature(wzWriterStream, !needsNewSignature);
                    wzWriterStream.Flush();
                    wzWriterStream.Close();
                }
                catch (Exception)
                {
                    updateLabel("Please close any program using " + wzFiles[0] + ".");
                    setStateWrapper(3);
                    backgroundWorker.ReportProgress(100);
                    //throw new Exception("Please close any program using " + wzFiles[0] + ".");
                }
            }

            Directory.Delete(temporaryDirectory, true);
            updateLabel("The patch is done.");
            backgroundWorker.ReportProgress(100);
            setStateWrapper(2);
        }