private void tvFileData_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.lbIndexList.SuspendLayout();
            this.lbIndexList.SelectedIndexChanged -= lbIndexList_SelectedIndexChanged;

            this.lbIndexList.Items.Clear();
            if ((e.Node != null) && (e.Node.Parent != null))
            {
                UOPFile uopToParse = UopManager.getIstance().UopFile;
                for (int iLabel = 0; iLabel < uopToParse.m_Content[(int)e.Node.Tag].m_ListData.Count; iLabel++)
                {
                    this.lbIndexList.Items.Add(String.Format("Index {0}", iLabel));
                }

                SetPanel(ShowPanels.DataNode, UopManager.getIstance().UopFile.m_Content[(int)e.Node.Tag]);
            }
            else if ((e.Node != null) && (e.Node.Parent == null))
            {
                SetPanel(ShowPanels.RootNode, UopManager.getIstance().UopFile);
            }
            this.lbIndexList.SelectedItem = null;

            this.lbIndexList.SelectedIndexChanged += new EventHandler(lbIndexList_SelectedIndexChanged);
            this.lbIndexList.ResumeLayout(true);
        }
        private void lbIndexList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((this.tvFileData.SelectedNode == null) || (this.tvFileData.SelectedNode.Parent == null))
            {
                return;
            }

            ListBox lbSender = (ListBox)sender;

            switch (lbSender.SelectedIndices.Count)
            {
            case 1:
            {
                SetPanel(ShowPanels.SingleHeader,
                         UopManager.getIstance().UopFile.m_Content[(int)(this.tvFileData.SelectedNode.Tag)].m_ListData[lbSender.SelectedIndex]
                         );
            } break;

            case 0:
            default:
            {
                SetPanel(ShowPanels.Nothing, null);
            } break;
            }
        }
        private void toolBtnDump_Click(object sender, EventArgs e)
        {
            if (DoingSomeJob.Working)
            {
                MessageBox.Show("Please wait... Still working in background!", "UO:KR Uop Dumper", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                ThreadArgs.MyThreadDelegate mtdParse = delegate(object args)
                {
                    ThreadArgs      theArgs = (ThreadArgs)args;
                    StupidInterface theForm = (StupidInterface)theArgs.Args[0];
                    string          thePath = (string)theArgs.Args[1];
                    string          theFile = (string)theArgs.Args[2];

                    UopManager upIstance = UopManager.getIstance();

                    try
                    {
                        string pathandfile = thePath + @"\" + theFile;

                        if (!Directory.Exists(thePath))
                        {
                            Directory.CreateDirectory(thePath);
                        }

                        using (StreamWriter swFile = new StreamWriter(pathandfile, false))
                        {
                            swFile.Write(UopManager.getIstance().UopFile.ToString());
                        }

                        theForm.SetTextArea("Completed information dump.");
                    }
                    catch
                    {
                        theForm.SetTextArea("ERROR while writing information dump.");
                    }
                    finally
                    {
                        theForm.DisableOtherIcon(false);
                        theForm.SetLoadIcon(true);
                        DoingSomeJob.Working = false;
                    }
                };

                DoingSomeJob.Working = true;

                string sPath = Application.StartupPath + StaticData.DUMPINFO_DIR;
                string sFile = Utility.GetFileName(UopManager.getIstance().UopPath) + ".txt";

                SetTextArea("Dumping UOP file to \"" + sPath + "\\" + sFile + "\" ...");
                this.SetDisableIcon(true);
                this.SetLoadIcon(false);

                System.Threading.Thread tRun = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(mtdParse));
                tRun.Start(new ThreadArgs(new object[] { this, sPath, sFile }));
            }
        }
        private void toolBtnSaveAs_Click(object sender, EventArgs e)
        {
            this.oFileDlgUopsave.FileName = UopManager.getIstance().UopPath;

            if (this.oFileDlgUopsave.ShowDialog(this) == DialogResult.OK)
            {
                CommonSave(this.oFileDlgUopsave.FileName, !this.toolBtnDontFix.Checked);
            }
        }
Example #5
0
        public static UopManager getIstance(bool bReset)
        {
            if (bReset && (sm_Istance != null))
            {
                sm_Istance.Dispose();
                sm_Istance = null;
            }

            return(sm_Istance = (sm_Istance == null) ? new UopManager() : sm_Istance);
        }
Example #6
0
        public static UopManager getIstance(bool bReset)
        {
            if (bReset && (sm_Istance != null))
            {
                sm_Istance.Dispose();
                sm_Istance = null;
            }

            return (sm_Istance = (sm_Istance == null) ? new UopManager() : sm_Istance);
        }
        private void CommonSave(string sFile, bool bFix)
        {
            if (DoingSomeJob.Working)
            {
                MessageBox.Show("Please wait... Still working in background!", "UO:KR Uop Dumper", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                ThreadArgs.MyThreadDelegate mtdParse = delegate(object args)
                {
                    ThreadArgs      theArgs = (ThreadArgs)args;
                    StupidInterface theForm = (StupidInterface)theArgs.Args[0];
                    string          theFile = (string)theArgs.Args[1];
                    bool            theFix  = (bool)theArgs.Args[2];

                    UopManager upIstance = UopManager.getIstance();

                    if (theFix)
                    {
                        upIstance.FixOffsets(0, 0);
                    }

                    bool bResult = upIstance.Write(theFile);

                    if (bResult)
                    {
                        theForm.SetTextArea("Done saving UOP file.");

                        if (!upIstance.UopPath.Equals(theFile, StringComparison.OrdinalIgnoreCase))
                        {
                            upIstance.UopPath = theFile;
                        }
                    }
                    else
                    {
                        theForm.SetTextArea("ERROR while saving file \"" + theFile + "\" !!!");
                    }

                    theForm.DisableOtherIcon(false);
                    theForm.SetLoadIcon(true);
                    DoingSomeJob.Working = false;
                };

                DoingSomeJob.Working = true;
                SetTextArea("Saving UOP file to \"" + sFile + "\" ...");
                this.SetDisableIcon(true);
                this.SetLoadIcon(false);

                System.Threading.Thread tRun = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(mtdParse));
                tRun.Start(new ThreadArgs(new object[] { this, sFile, bFix }));
            }
        }
        private void btnDetailsDelete_Click(object sender, EventArgs e)
        {
            if (DoingSomeJob.Working)
            {
                MessageBox.Show("Please wait... Still working in background!", "UO:KR Uop Dumper", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            DoingSomeJob.Working = true;

            if (this.pnUopfile.Enabled)
            {
                SetPanel(ShowPanels.RootNode, this.gbSelectedData.Tag);

                MessageBox.Show("You cannot delete the UOP file that way!", "UO:KR Uop Dumper - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (this.pnUopDatafile.Enabled)
            {
                SetTextArea("Deleting selected header block ...");
                SetPanel(ShowPanels.DataNode, this.gbSelectedData.Tag);

                UopManager.getIstance().Delete((UOPIndexBlockHeader)(this.gbSelectedData.Tag));

                RefreshData();
                SetTextArea("Deleted selected header block.");
            }
            else if (this.pnUopHeaderAndData.Enabled)
            {
                SetTextArea("Deleting selected index ...");
                SetPanel(ShowPanels.SingleHeader, this.gbSelectedData.Tag);

                UopManager.getIstance().Delete((UOPPairData)(this.gbSelectedData.Tag));

                RefreshData();
                SetTextArea("Deleted selected index.");
            }
            else
            {
                SetPanel(ShowPanels.Nothing, null);
            }

            SetTextArea("");
            DoingSomeJob.Working = false;
        }
        private void genericToolStripMenuItem(ToolStripMenuButtons tsmbClick, int iNode)
        {
            if (iNode == -1)
            {
                return;
            }

            UOPFile uopToParse = UopManager.getIstance().UopFile;

            switch (tsmbClick)
            {
            case ToolStripMenuButtons.Delete:
            {
                uopToParse.m_Content.RemoveAt(iNode);
                RefreshData();
                SetTextArea("Deleted selected header block.");
            } break;

            case ToolStripMenuButtons.MoveUp:
            {
                if (iNode != 0)
                {
                    UOPIndexBlockHeader uBack = uopToParse.m_Content[iNode - 1];
                    uopToParse.m_Content[iNode - 1] = uopToParse.m_Content[iNode];
                    uopToParse.m_Content[iNode]     = uBack;
                    RefreshData();
                    SetTextArea("Moved Up selected header block.");
                }
            } break;

            case ToolStripMenuButtons.MoveDown:
            {
                if (iNode != (uopToParse.m_Content.Count - 1))
                {
                    UOPIndexBlockHeader uFront = uopToParse.m_Content[iNode + 1];
                    uopToParse.m_Content[iNode + 1] = uopToParse.m_Content[iNode];
                    uopToParse.m_Content[iNode]     = uFront;
                    RefreshData();
                    SetTextArea("Moved Down selected header block.");
                }
            } break;
            }
        }
        private void LoadUOP(string theNewFile)
        {
            ThreadArgs.MyThreadDelegate mtdParse = delegate(object args)
            {
                ThreadArgs      theArgs = (ThreadArgs)args;
                StupidInterface theForm = (StupidInterface)theArgs.Args[0];
                string          theFile = (string)theArgs.Args[1];

                UopManager upIstance = UopManager.getIstance(true);
                upIstance.UopPath = theFile;

                bool bResult = upIstance.Load();

                if (bResult)
                {
                    theForm.SetTextArea("Done parsing.");
                }
                else
                {
                    theForm.SetTextArea("ERROR while parsing file \"" + theFile + "\" !!!");
                }

                if (bResult)
                {
                    theForm.SetNodes();
                    theForm.DisableOtherIcon(false);
                }

                theForm.SetLoadIcon(true);
                DoingSomeJob.Working = false;
            };

            DoingSomeJob.Working = true;
            this.SetTextArea("Parsing file \"" + theNewFile + "\" ...");

            this.SetDisableIcon(true);
            this.SetLoadIcon(false);

            System.Threading.Thread tRun = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(mtdParse));
            tRun.Start(new ThreadArgs(new object[] { this, theNewFile }));
        }
        private void Parse()
        {
            UOPFile uopToParse = UopManager.getIstance().UopFile;

            this.tvFileData.SuspendLayout();
            this.tvFileData.Nodes.Clear();

            TreeNodeCollection tncCurrent = this.tvFileData.Nodes;
            TreeNode           tnRoot     = new TreeNode(Utility.GetFileName(UopManager.getIstance().UopPath));

            tnRoot.Tag = -1; tncCurrent.Add(tnRoot);

            for (int iNode = 0; iNode < uopToParse.m_Content.Count; iNode++)
            {
                TreeNode tnCurrent = new TreeNode(String.Format("Header Block {0}", iNode));
                tnCurrent.ContextMenuStrip = this.ctxMenuNode;
                tnCurrent.Tag = iNode;
                tnRoot.Nodes.Add(tnCurrent);
            }

            tnRoot.Expand();
            this.tvFileData.ResumeLayout(true);
        }
 private void toolBtnUnpack_Click(object sender, EventArgs e)
 {
     CommonDump(ShowPanels.RootNode, UopManager.getIstance().UopFile);
 }
 private void toolBtnSave_Click(object sender, EventArgs e)
 {
     CommonSave(UopManager.getIstance().UopPath, !this.toolBtnDontFix.Checked);
 }
        private void btnDetailsApply_Click(object sender, EventArgs e)
        {
            if (DoingSomeJob.Working)
            {
                MessageBox.Show("Please wait... Still working in background!", "UO:KR Uop Dumper", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            DoingSomeJob.Working = true;

            if (this.pnUopfile.Enabled)
            {
                try
                {
                    UOPFile uppeCurrent = (UOPFile)this.gbSelectedData.Tag;

                    byte[] bHeader1 = Utility.StringToByteArray(this.txt_pnlUopFile_Header1.Text, Utility.HashStringStyle.HexWithSeparator, 24);
                    byte[] bHeader2 = Utility.StringToByteArray(this.txt_pnlUopFile_Header2.Text, Utility.HashStringStyle.HexWithSeparator, 12);
                    uint   uCount   = Decimal.ToUInt32(this.num_pnlUopFile_Files.Value);

                    if ((bHeader1 == null) || (bHeader1 == null))
                    {
                        throw new Exception();
                    }
                    else
                    {
                        uppeCurrent.m_Header.m_variousData = bHeader1;
                        uppeCurrent.m_Header.m_totalIndex  = uCount;
                        uppeCurrent.m_Header.m_Unknown     = bHeader2;
                    }
                }
                catch
                {
                    MessageBox.Show("Error while parsing the data!", "UO:KR Uop Dumper - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                SetPanel(ShowPanels.RootNode, this.gbSelectedData.Tag);
            }
            else if (this.pnUopDatafile.Enabled)
            {
                try
                {
                    UOPIndexBlockHeader uppeCurrent = (UOPIndexBlockHeader)this.gbSelectedData.Tag;

                    ulong ulOffset = UInt64.Parse(this.txt_pnUopDatafile_Offset.Text, System.Globalization.NumberStyles.AllowHexSpecifier);
                    uint  uCount   = Decimal.ToUInt32(this.nud_pnUopDatafile_Files.Value);

                    uppeCurrent.m_Files           = uCount;
                    uppeCurrent.m_OffsetNextIndex = ulOffset;
                }
                catch
                {
                    MessageBox.Show("Error while parsing the data!", "UO:KR Uop Dumper - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                SetPanel(ShowPanels.DataNode, this.gbSelectedData.Tag);
            }
            else if (this.pnUopHeaderAndData.Enabled)
            {
                try
                {
                    UOPPairData uppeCurrent = (UOPPairData)this.gbSelectedData.Tag;

                    // Header block
                    ulong  ulOffset = UInt64.Parse(this.txt_pnUopHeaderAndData_Offset.Text, System.Globalization.NumberStyles.AllowHexSpecifier);
                    uint   uiUnk1 = UInt32.Parse(this.txt_pnUopHeaderAndData_Unk1.Text, System.Globalization.NumberStyles.AllowHexSpecifier);
                    uint   uiUnk2 = UInt32.Parse(this.txt_pnUopHeaderAndData_Unk2.Text, System.Globalization.NumberStyles.AllowHexSpecifier);
                    uint   uiUnk3 = UInt32.Parse(this.txt_pnUopHeaderAndData_Unk3.Text, System.Globalization.NumberStyles.AllowHexSpecifier);
                    string sNewFile = null; bool bUncompressed = false;
                    if (this.txt_pnUopHeaderAndData_Data.Tag != null)
                    {
                        sNewFile      = (string)(((System.Collections.Hashtable) this.txt_pnUopHeaderAndData_Data.Tag)["file"]);
                        bUncompressed = (bool)(((System.Collections.Hashtable) this.txt_pnUopHeaderAndData_Data.Tag)["uncompressed"]);
                    }
                    ulong ulUnkData = UInt64.Parse(this.txt_pnUopHeaderAndData_DataUnk1.Text, System.Globalization.NumberStyles.AllowHexSpecifier);

                    if (sNewFile != null)
                    {
                        if (UopManager.getIstance().Replace(sNewFile, uppeCurrent, bUncompressed) != UopManager.UopPatchError.Okay)
                        {
                            throw new Exception();
                        }
                    }

                    uppeCurrent.First.m_OffsetOfDataBlock = ulOffset;
                    uppeCurrent.First.m_Unknown1          = uiUnk1;
                    uppeCurrent.First.m_Unknown2          = uiUnk2;
                    uppeCurrent.First.m_Unknown3          = uiUnk2;
                }
                catch
                {
                    MessageBox.Show("Error while parsing the data!", "UO:KR Uop Dumper - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                SetPanel(ShowPanels.SingleHeader, this.gbSelectedData.Tag);
            }
            else
            {
                SetPanel(ShowPanels.Nothing, null);
            }

            DoingSomeJob.Working = false;
        }
        private void CommonDump(ShowPanels spType, object oCast)
        {
            if (DoingSomeJob.Working)
            {
                MessageBox.Show("Please wait... Still working in background!", "UO:KR Uop Dumper", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                ThreadArgs.MyThreadDelegate mtdParse = delegate(object args)
                {
                    ThreadArgs      theArgs   = (ThreadArgs)args;
                    StupidInterface theForm   = (StupidInterface)theArgs.Args[0];
                    string          thePath   = (string)theArgs.Args[1];
                    ShowPanels      theType   = (ShowPanels)theArgs.Args[2];
                    object          theObject = theArgs.Args[3];

                    UopManager upIstance  = UopManager.getIstance();
                    string     baseName   = Path.GetFileNameWithoutExtension(upIstance.UopPath);
                    string     resultName = "";

                    try
                    {
                        if (!Directory.Exists(thePath))
                        {
                            Directory.CreateDirectory(thePath);
                        }

                        int i = 0, j = 0;

                        switch (spType)
                        {
                        case ShowPanels.RootNode:
                        {
                            UOPFile toDump = (UOPFile)theObject;
                            foreach (UOPIndexBlockHeader dumpTemp1 in toDump.m_Content)
                            {
                                foreach (UOPPairData dumpTemp2 in dumpTemp1.m_ListData)
                                {
                                    using (FileStream fsWrite = File.Create(thePath + @"\" + String.Format(StaticData.UNPACK_NAMEPATTERN, baseName, i, j, dumpTemp2.First.IsCompressed ? StaticData.UNPACK_EXT_COMP : StaticData.UNPACK_EXT_UCOMP)))
                                    {
                                        using (BinaryWriter bwWrite = new BinaryWriter(fsWrite))
                                        {
                                            bwWrite.Write(dumpTemp2.Second.Extract(dumpTemp2.First.IsCompressed, dumpTemp2.First.m_LenghtUncompressed));
                                        }
                                    }

                                    j++;
                                }

                                i++;
                                j = 0;
                            }

                            resultName = "the UOP file.";
                        } break;

                        case ShowPanels.DataNode:
                        {
                            UOPIndexBlockHeader toDump = (UOPIndexBlockHeader)theObject;
                            foreach (UOPIndexBlockHeader dumpTemp1 in upIstance.UopFile.m_Content)
                            {
                                if (dumpTemp1.Equals(toDump))
                                {
                                    break;
                                }

                                i++;
                            }

                            foreach (UOPPairData dumpTemp2 in toDump.m_ListData)
                            {
                                using (FileStream fsWrite = File.Create(thePath + @"\" + String.Format(StaticData.UNPACK_NAMEPATTERN, baseName, i, j, dumpTemp2.First.IsCompressed ? StaticData.UNPACK_EXT_COMP : StaticData.UNPACK_EXT_UCOMP)))
                                {
                                    using (BinaryWriter bwWrite = new BinaryWriter(fsWrite))
                                    {
                                        bwWrite.Write(dumpTemp2.Second.Extract(dumpTemp2.First.IsCompressed, dumpTemp2.First.m_LenghtUncompressed));
                                    }
                                }

                                j++;
                            }

                            resultName = "the Header Block " + i.ToString() + ".";
                        } break;

                        case ShowPanels.SingleHeader:
                        {
                            UOPPairData toDump = (UOPPairData)theObject; bool bBreakLoop = false;
                            foreach (UOPIndexBlockHeader dumpTemp1 in upIstance.UopFile.m_Content)
                            {
                                foreach (UOPPairData dumpTemp2 in dumpTemp1.m_ListData)
                                {
                                    bBreakLoop = dumpTemp2.Equals(toDump);
                                    if (bBreakLoop)
                                    {
                                        break;
                                    }

                                    j++;
                                }

                                if (bBreakLoop)
                                {
                                    break;
                                }

                                i++;
                                j = 0;
                            }

                            using (FileStream fsWrite = File.Create(thePath + @"\" + String.Format(StaticData.UNPACK_NAMEPATTERN, baseName, i, j, toDump.First.IsCompressed ? StaticData.UNPACK_EXT_COMP : StaticData.UNPACK_EXT_UCOMP)))
                            {
                                using (BinaryWriter bwWrite = new BinaryWriter(fsWrite))
                                {
                                    bwWrite.Write(toDump.Second.Extract(toDump.First.IsCompressed, toDump.First.m_LenghtUncompressed));
                                }
                            }

                            resultName = "the Index " + j.ToString() + ".";
                        } break;
                        }

                        GC.Collect();
                        theForm.SetTextArea("Completed unpacking for " + resultName);
                    }
                    catch
                    {
                        theForm.SetTextArea("ERROR while unpacking selected data.");
                    }
                    finally
                    {
                        theForm.DisableOtherIcon(false);
                        theForm.SetLoadIcon(true);
                        DoingSomeJob.Working = false;
                    }
                };

                DoingSomeJob.Working = true;
                SetTextArea("Unpacking seleceted data to \"" + Application.StartupPath + StaticData.UNPACK_DIR + "\" ...");
                this.SetDisableIcon(true);
                this.SetLoadIcon(false);

                System.Threading.Thread tRun = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(mtdParse));
                tRun.Start(new ThreadArgs(new object[] { this, Application.StartupPath + StaticData.UNPACK_DIR, spType, oCast }));
            }
        }
Example #16
0
        public static bool DoCommandLine(string[] args)
        {
            if (args.Length <= 1)
            {
                return(true);
            }

            patchList.Clear();
            System.Text.StringBuilder errorOutput = new System.Text.StringBuilder();
            errorOutput.AppendLine("-- ERROR LOG --");

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].Equals(CMD_HELP, StringComparison.OrdinalIgnoreCase))
                {
                    bHelp = true;
                    break;
                }
                else if ((!bEnablelog) && args[i].Equals(CMD_LOG, StringComparison.OrdinalIgnoreCase))
                {
                    bEnablelog = true;
                }
                else if ((!bInputfile) && args[i].Equals(CMD_INPUT, StringComparison.OrdinalIgnoreCase))
                {
                    if ((i + 1) < args.Length)
                    {
                        sInputpath = args[i + 1];
                        sInputpath = sInputpath.Trim();

                        if (sInputpath.Length > 0)
                        {
                            bInputfile = true;
                        }
                    }
                    else
                    {
                        errorOutput.AppendLine(CMD_INPUT + " switch without argument");
                    }
                }
                else if ((!bOutputfile) && args[i].Equals(CMD_OUTPUT, StringComparison.OrdinalIgnoreCase))
                {
                    if ((i + 1) < args.Length)
                    {
                        sOutputpath = args[i + 1];
                        sOutputpath = sOutputpath.Trim();

                        if (sOutputpath.Length > 0)
                        {
                            bOutputfile = true;
                        }
                    }
                    else
                    {
                        errorOutput.AppendLine(CMD_OUTPUT + " switch without argument");
                    }
                }
                else if ((!bUnpack) && args[i].Equals(CMD_UNPACK, StringComparison.OrdinalIgnoreCase))
                {
                    bUnpack = true;
                }
                else if ((!bDontfix) && args[i].Equals(CMD_DONTFIX, StringComparison.OrdinalIgnoreCase))
                {
                    bDontfix = true;
                }
                else if (args[i].Equals(CMD_PATCH, StringComparison.OrdinalIgnoreCase))
                {
                    if ((i + 1) < args.Length)
                    {
                        try
                        {
                            string[]   patchParams = args[i + 1].Split(new char[] { ',' }, 4);
                            PatchFiles pfTemp      = new PatchFiles();
                            pfTemp.file     = patchParams[0];
                            pfTemp.index    = Int32.Parse(patchParams[1]);
                            pfTemp.subindex = Int32.Parse(patchParams[2]);
                            pfTemp.compress = Int32.Parse(patchParams[3]);
                            patchList.Push(pfTemp);
                            bPatch = true;
                        }
                        catch
                        {
                            errorOutput.AppendLine(CMD_PATCH + " switch with incorrect argument (\"" + args[i + 1] + "\")");
                        }
                    }
                    else
                    {
                        errorOutput.AppendLine(CMD_PATCH + " switch without argument");
                    }
                }
                else if ((!bFullpatch) && args[i].Equals(CMD_FULLPATCH, StringComparison.OrdinalIgnoreCase))
                {
                    if ((i + 1) < args.Length)
                    {
                        sFullpatchPath = args[i + 1];
                        sFullpatchPath = sFullpatchPath.Trim();

                        if (sFullpatchPath.Length > 0)
                        {
                            bFullpatch = true;
                        }
                    }
                    else
                    {
                        errorOutput.AppendLine(CMD_FULLPATCH + " switch without argument");
                    }
                }
            }

            if (bHelp)
            {
                MessageBox.Show(MESSAGEBOX_HELP, "UO:KR Uop Dumper - Patch Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (bInputfile)
            {
                if (UopManager.getIstance().Load(sInputpath))
                {
                    if (bUnpack)
                    {
                        string thePath = Application.StartupPath + StaticData.UNPACK_DIR;;
                        if (!Directory.Exists(thePath))
                        {
                            Directory.CreateDirectory(thePath);
                        }

                        if (!UopManager.getIstance().UnPack(thePath))
                        {
                            errorOutput.AppendLine("Error while unpacking the uop file to (\"" + thePath + "\")");
                        }
                    }
                    else if (bFullpatch)
                    {
                        UopManager.UopPatchError upeError = UopManager.UopPatchError.Okay;

                        if (Directory.Exists(sFullpatchPath))
                        {
                            try
                            {
                                string   uopName    = Path.GetFileNameWithoutExtension(UopManager.getIstance().UopPath);
                                string[] filesFound = Directory.GetFiles(sFullpatchPath, uopName + "*.*", SearchOption.TopDirectoryOnly);
                                foreach (string currentFile in filesFound)
                                {
                                    string strippedName = Path.GetFileName(currentFile);
                                    if (!strippedName.StartsWith(uopName + "-", StringComparison.OrdinalIgnoreCase))
                                    {
                                        errorOutput.AppendLine("Error while patching \"" + strippedName + "\".");
                                        continue;
                                    }

                                    string parseName = strippedName.Substring(uopName.Length + 1);
                                    if (parseName.IndexOf('_') == -1)
                                    {
                                        errorOutput.AppendLine("Error while patching \"" + strippedName + "\".");
                                        continue;
                                    }

                                    int indexA = -1, indexB = -1;
                                    if (!Int32.TryParse(parseName.Substring(0, parseName.IndexOf('_')), out indexA))
                                    {
                                        errorOutput.AppendLine("Error while patching \"" + strippedName + "\".");
                                        continue;
                                    }

                                    parseName = parseName.Substring(parseName.IndexOf('_') + 1);
                                    if (!Int32.TryParse(parseName.Substring(0, parseName.IndexOf('.')), out indexB))
                                    {
                                        errorOutput.AppendLine("Error while patching \"" + strippedName + "\".");
                                        continue;
                                    }

                                    if ((indexA == -1) || (indexB == -1))
                                    {
                                        errorOutput.AppendLine("Error while patching \"" + strippedName + "\".");
                                        continue;
                                    }

                                    if (parseName.EndsWith("." + StaticData.UNPACK_EXT_COMP))
                                    {
                                        upeError = UopManager.getIstance().Replace(currentFile, indexA, indexB, false);
                                    }
                                    else if (parseName.EndsWith("." + StaticData.UNPACK_EXT_UCOMP))
                                    {
                                        upeError = UopManager.getIstance().Replace(currentFile, indexA, indexB, true);
                                    }
                                    else
                                    {
                                        errorOutput.AppendLine("Error while patching \"" + strippedName + "\".");
                                        continue;
                                    }

                                    if (upeError != UopManager.UopPatchError.Okay)
                                    {
                                        errorOutput.AppendLine("Error while patching \"" + strippedName + "\" (" + upeError.ToString() + ").");
                                        continue;
                                    }
                                }

                                if (!bOutputfile)
                                {
                                    sOutputpath = Utility.GetPathForSave(UopManager.getIstance().UopPath);
                                }

                                if (!bDontfix)
                                {
                                    UopManager.getIstance().FixOffsets(0, 0);
                                }

                                if (!UopManager.getIstance().Write(sOutputpath))
                                {
                                    errorOutput.AppendLine("Error while writing the new uop file (\"" + sOutputpath + "\")");
                                }
                            }
                            catch
                            {
                                errorOutput.AppendLine("Error while full-patching \"" + UopManager.getIstance().UopPath + "\" from \"" + sFullpatchPath + "\".");
                            }
                        }
                        else
                        {
                            errorOutput.AppendLine("Error while opening non-accessible directory \"" + sFullpatchPath + "\"");
                        }
                    }
                    else if (bPatch)
                    {
                        UopManager.UopPatchError upeError = UopManager.UopPatchError.Okay;
                        int iMinIndex = Int32.MaxValue, iMinSubindex = Int32.MaxValue;

                        foreach (PatchFiles pfCurrent in patchList)
                        {
                            iMinIndex    = Math.Min(iMinIndex, pfCurrent.index);
                            iMinSubindex = Math.Min(iMinSubindex, pfCurrent.subindex);
                            upeError     = UopManager.getIstance().Replace(pfCurrent.file, pfCurrent.index, pfCurrent.subindex, pfCurrent.compress > 0);

                            if (upeError != UopManager.UopPatchError.Okay)
                            {
                                errorOutput.AppendLine("Error (" + upeError.ToString() + ") while patching file \"" + pfCurrent.file + "\" to " + pfCurrent.index.ToString() + "," + pfCurrent.subindex.ToString() + " (" + ((pfCurrent.compress > 0) ? "UN" : "") + "compressed)");
                                break;
                            }
                        }

                        if (upeError == UopManager.UopPatchError.Okay)
                        {
                            if (!bOutputfile)
                            {
                                sOutputpath = Utility.GetPathForSave(UopManager.getIstance().UopPath);
                            }

                            if (bDontfix)
                            {
                                UopManager.getIstance().FixOffsets(iMinIndex, iMinSubindex);
                            }

                            if (!UopManager.getIstance().Write(sOutputpath))
                            {
                                errorOutput.AppendLine("Error while writing the new uop file (\"" + sOutputpath + "\")");
                            }
                        }
                    }
                }
                else
                {
                    errorOutput.AppendLine("Error while opening the uop file (\"" + UopManager.getIstance().UopPath + "\")");
                }
            }
            else
            {
                errorOutput.AppendLine("ERROR: No action defined.");
            }

            if (bEnablelog)
            {
                try
                {
                    File.WriteAllText(Application.StartupPath + @"\error.log", errorOutput.ToString());
                }
                catch { }
            }

            return(false);
        }