示例#1
0
        public static void LoadAllMLIFiles()
        {
            const String root = @"D:\Games\Hellgate London\data\background\";
            List<String> mliFiles = new List<String>(Directory.GetFiles(root, "*.mli", SearchOption.AllDirectories));

            foreach (String mliFilePath in mliFiles)
            {
                String path = mliFilePath;
                //path = @"D:\Games\Hellgate London\data\background\city\charactercreate.rom";
                //path = "D:\\Games\\Hellgate London\\data\\background\\props\\vehicles\\ambulance_a.rom";

                byte[] mliFileBytes = File.ReadAllBytes(path);
                MLIFile roomDefinitionFile = new MLIFile();

                String fileName = path.Replace(@"D:\Games\Hellgate London\data\background\", "");
                String xmlPath = path.Replace(MLIFile.Extension, MLIFile.ExtensionDeserialised);
                Console.WriteLine("Loading: " + fileName);
                try
                {
                    roomDefinitionFile.ParseFileBytes(mliFileBytes);
                    byte[] xmlBytes = roomDefinitionFile.ExportAsDocument();
                    File.WriteAllBytes(xmlPath, xmlBytes);

                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(xmlPath);
                    MLIFile mliFile2 = new MLIFile();
                    mliFile2.ParseXmlDocument(xmlDocument);
                    byte[] bytes = mliFile2.ToByteArray();

                    if (!mliFileBytes.SequenceEqual(bytes))
                    {
                        File.WriteAllBytes(path + "2", bytes);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to load file!\n" + e);
                    continue;
                }
            }
        }
示例#2
0
        /// <summary>
        /// User-friendly uncooking of Tree Node list.
        /// </summary>
        /// <param name="progressForm">A progress form to update.</param>
        /// <param name="param">The Tree Node List.</param>
        private void _DoUnooking(ProgressForm progressForm, Object param)
        {
            List<TreeNode> uncookingNodes = (List<TreeNode>)param;
            const int progressUpdateFreq = 20;
            if (progressForm != null)
            {
                progressForm.ConfigBar(1, uncookingNodes.Count, progressUpdateFreq);
            }

            int i = 0;
            foreach (TreeNode treeNode in uncookingNodes)
            {
                NodeObject nodeObject = (NodeObject)treeNode.Tag;
                PackFileEntry fileEntry = nodeObject.FileEntry;

                // update progress if applicable
                if (i % progressUpdateFreq == 0 && progressForm != null)
                {
                    progressForm.SetCurrentItemText(fileEntry.Path);
                }
                i++;

                // get the file bytes
                String relativePath = fileEntry.Path;
                byte[] fileBytes;
                try
                {
                    fileBytes = _fileManager.GetFileBytes(fileEntry, true);
                    if (fileBytes == null) continue;
                }
                catch (Exception e)
                {
                    ExceptionLogger.LogException(e);
                    continue;
                }

                // determine file type
                HellgateFile hellgateFile;
                if (relativePath.EndsWith(XmlCookedFile.Extension))
                {
                    hellgateFile = new XmlCookedFile(_fileManager);
                }
                else if (relativePath.EndsWith(RoomDefinitionFile.Extension))
                {
                    hellgateFile = new RoomDefinitionFile(relativePath);
                }
                else if (relativePath.EndsWith(MLIFile.Extension))
                {
                    hellgateFile = new MLIFile();
                }
                else
                {
                    Debug.Assert(false, "wtf");
                    continue;
                }

                // deserialise file
                DialogResult dr = DialogResult.Retry;
                bool uncooked = false;
                while (dr == DialogResult.Retry && !uncooked)
                {
                    try
                    {
                        hellgateFile.ParseFileBytes(fileBytes);
                        uncooked = true;
                    }
                    catch (Exception e)
                    {
                        ExceptionLogger.LogException(e, true);

                        String errorMsg = String.Format("Failed to uncooked file!\n{0}\n\n{1}", relativePath, e);
                        dr = MessageBox.Show(errorMsg, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);
                        if (dr == DialogResult.Abort) return;
                        if (dr == DialogResult.Ignore) break;
                    }
                }
                if (!uncooked) continue;

                // save file
                String relativeSavePath = relativePath.Replace(HellgateFile.Extension, HellgateFile.ExtensionDeserialised);
                String savePath = Path.Combine(Config.HglDir, relativeSavePath);

                dr = DialogResult.Retry;
                bool saved = false;
                byte[] documentBytes = null;
                while (dr == DialogResult.Retry && !saved)
                {
                    try
                    {
                        if (documentBytes == null) documentBytes = hellgateFile.ExportAsDocument();
                        File.WriteAllBytes(savePath, documentBytes);
                        saved = true;
                    }
                    catch (Exception e)
                    {
                        ExceptionLogger.LogException(e, true);

                        String errorMsg = String.Format("Failed to save file!\n{0}\n\n{1}", relativePath, e);
                        dr = MessageBox.Show(errorMsg, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);
                        if (dr == DialogResult.Abort) return;
                        if (dr == DialogResult.Ignore) break;
                    }
                }

                // update tree view
                TreeNode newTreeNode = new TreeNode();
                NodeObject newNodeObject = new NodeObject
                {
                    CanEdit = true,
                    IsUncookedVersion = true
                };
                newTreeNode.Tag = newNodeObject;
                treeNode.Nodes.Add(newTreeNode);
            }
        }