Пример #1
0
        public void LoadMeta(YmfFile ymf)
        {
            string fn;

            Xml      = MetaXml.GetXml(ymf, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = ymf;
            rpfFileEntry = ymf?.FileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (ymf != null)
            {
                if (ymf.Meta != null)
                {
                    metaFormat = MetaFormat.RSC;
                }
                if (ymf.Pso != null)
                {
                    metaFormat = MetaFormat.PSO;
                }
                if (ymf.Rbf != null)
                {
                    metaFormat = MetaFormat.RBF;
                }
            }
        }
Пример #2
0
        public void LoadMeta(YtypFile ytyp)
        {
            string fn;

            Xml      = MetaXml.GetXml(ytyp, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = ytyp;
            rpfFileEntry = ytyp?.RpfFileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (ytyp != null)
            {
                if (ytyp.Meta != null)
                {
                    metaFormat = MetaFormat.RSC;
                }
                if (ytyp.Pso != null)
                {
                    metaFormat = MetaFormat.PSO;
                }
                if (ytyp.Rbf != null)
                {
                    metaFormat = MetaFormat.RBF;
                }
            }
        }
Пример #3
0
        public void LoadMeta(JPsoFile jpso)
        {
            string fn;

            Xml      = MetaXml.GetXml(jpso, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = jpso;
            modified = false;
        }
Пример #4
0
        public void LoadMeta(CutFile cut)
        {
            string fn;

            Xml      = MetaXml.GetXml(cut, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = cut;
            modified = false;
        }
Пример #5
0
        public void LoadMeta(YtypFile ytyp)
        {
            string fn;

            Xml      = MetaXml.GetXml(ytyp, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = ytyp;
            modified = false;
        }
Пример #6
0
        public void LoadMeta(YmfFile ymf)
        {
            string fn;

            Xml      = MetaXml.GetXml(ymf, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = ymf;
            modified = false;
        }
Пример #7
0
        public void LoadMeta(CacheDatFile cachedat)
        {
            var fn = ((cachedat?.FileEntry?.Name) ?? "") + ".xml";

            Xml      = MetaXml.GetXml(cachedat, out fn, "");
            FileName = fn;
            RawPropertyGrid.SelectedObject = cachedat;
            rpfFileEntry = cachedat?.FileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (cachedat?.FileEntry != null)
            {
                metaFormat = MetaFormat.CacheFile;
            }
        }
Пример #8
0
        public void LoadMeta(YndFile ynd)
        {
            var fn = ((ynd?.RpfFileEntry?.Name) ?? "") + ".xml";

            Xml      = MetaXml.GetXml(ynd, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = ynd;
            rpfFileEntry = ynd?.RpfFileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (ynd?.RpfFileEntry != null)
            {
                metaFormat = MetaFormat.Ynd;
            }
        }
Пример #9
0
        private void ConvertResourceToXml()
        {
            string inputFileName  = arguments[0];
            string outputFileName = inputFileName + ".xml";

            var res = new ResourceFile_GTA5_pc <MetaFile>();

            res.Load(inputFileName);

            AddHashForStrings("MetaTool.Lists.FileNames.txt");
            AddHashForStrings("MetaTool.Lists.MetaNames.txt");

            var xml = MetaXml.GetXml(res.ResourceData);

            File.WriteAllText(outputFileName, xml);
        }
Пример #10
0
        public void LoadMeta(JPsoFile jpso)
        {
            string fn;

            Xml      = MetaXml.GetXml(jpso, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = jpso;
            rpfFileEntry = jpso?.FileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (jpso != null)
            {
                if (jpso.Pso != null)
                {
                    metaFormat = MetaFormat.PSO;
                }
            }
        }
Пример #11
0
        public void LoadMeta(CutFile cut)
        {
            string fn;

            Xml      = MetaXml.GetXml(cut, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = cut;
            rpfFileEntry = cut?.FileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (cut != null)
            {
                if (cut.Pso != null)
                {
                    metaFormat = MetaFormat.PSO;
                }
            }
        }
Пример #12
0
        static void HandleImportMetaOptions(string[] args)
        {
            CommandLine.Parse <ImportMetaOptions>(args, (opts, gOpts) =>
            {
                if (opts.Metadata)
                {
                    Init(args);
                }
                else
                {
                    EnsurePath();
                    EnsureKeys();
                    EnsureCache();
                }

                if (opts.InputFiles == null)
                {
                    Console.WriteLine("Please provide input files with -i --input");
                    return;
                }
                else
                {
                    var inputFiles = Utils.Expand(opts.InputFiles);

                    for (int i = 0; i < inputFiles.Length; i++)
                    {
                        var fileInfo = inputFiles[i];

                        Console.WriteLine(fileInfo.FullName);

                        var strings = MetaUtilities.GetAllStringsFromXml(fileInfo.FullName);

                        foreach (var str in strings)
                        {
                            Utils.Hash(str.ToLowerInvariant());
                        }

                        var doc = new XmlDocument();

                        doc.Load(fileInfo.FullName);

                        var res          = new ResourceFile_GTA5_pc <MetaFile>();
                        res.Version      = 2;
                        res.ResourceData = XmlMeta.GetMeta(doc);

                        if (fileInfo.Name.EndsWith(".ymap.xml") && opts.Metadata)
                        {
                            var toDelete = opts.Delete?.Select(e => Convert.ToUInt32(e)).ToList() ?? new List <uint>();

                            var mappings   = new Dictionary <uint, Dictionary <uint, JObject> >();
                            var basePath   = Path.GetDirectoryName(fileInfo.FullName);
                            var ymaps      = new List <YmapFile>();
                            var ymap       = new YmapFile();
                            var nameHashes = new Dictionary <uint, string>();

                            ymap.ResourceFile = res;

                            ymap.Parse();

                            var topParent     = ImportMeta_GetTopYmapParent((uint)ymap.CMapData.Name);
                            var topParentHash = (uint)topParent["hash"];
                            var topParentName = (string)topParent["name"];
                            var topParentPath = (string)topParent["path"];
                            var topParentYmap = new YmapFile();

                            Console.WriteLine("Top parent is " + topParentName);

                            var entries = new List <JObject>()
                            {
                                topParent
                            };

                            entries.AddRange(ImportMeta_GetYmapChildrens(topParent));

                            for (int j = 0; j < entries.Count; j++)
                            {
                                var entry        = entries[j];
                                var entryHash    = (uint)entry["hash"];
                                var entryName    = (string)entry["name"];
                                var entryPath    = (string)entry["path"];
                                var ymapPath     = basePath + "\\" + entryName + ".ymap";
                                var metadataPath = ymapPath + ".json";

                                nameHashes.Add(entryHash, entryName);

                                if (!File.Exists(ymapPath))
                                {
                                    Console.WriteLine("ERROR => File not found : " + entryName + ".ymap");
                                    return;
                                }

                                if (!File.Exists(metadataPath))
                                {
                                    Console.WriteLine("ERROR => Metadata not found for " + entryName);
                                    return;
                                }

                                var metadataMapping = (JArray)JObject.Parse(File.ReadAllText(metadataPath))["mapping"];
                                var mapping         = new Dictionary <uint, JObject>();

                                for (int k = 0; k < metadataMapping.Count; k++)
                                {
                                    mapping.Add((uint)metadataMapping[k]["guid"], (JObject)metadataMapping[k]);
                                }

                                mappings.Add(entryHash, mapping);

                                if (entryHash == (uint)ymap.CMapData.Name)
                                {
                                    ymaps.Add(ymap);
                                }
                                else
                                {
                                    var ymap2 = new YmapFile();
                                    ymap2.Load(ymapPath);
                                    ymaps.Add(ymap2);
                                }
                            }

                            for (int j = 0; j < ymaps.Count; j++)
                            {
                                var ymap2 = ymaps[j];

                                if (ymap2.CMapData.Parent != 0)
                                {
                                    ymap2.CMapData.ParentMapData = ymaps.Find(e => e.CMapData.Name == ymap2.CMapData.Parent).CMapData;
                                }
                            }

                            bool modified;

                            do
                            {
                                modified = false;

                                for (int j = 0; j < ymaps.Count; j++)
                                {
                                    var ymap2 = ymaps[j];

                                    Console.WriteLine(nameHashes[(uint)ymap2.CMapData.Name]);

                                    var toRemove      = new List <MCEntityDef>();
                                    var toSet         = new List <Tuple <MCEntityDef, MCEntityDef> >();
                                    bool currModified = false;

                                    for (int k = 0; k < ymap2.CMapData.Entities.Count; k++)
                                    {
                                        var entity        = ymap2.CMapData.Entities[k];
                                        var oldHasParent  = (bool)mappings[(uint)ymap2.CMapData.Name][entity.Guid]["hasParent"];
                                        var currHasParent = entity.ParentIndex != -1;

                                        if (oldHasParent)
                                        {
                                            var oldParent         = (uint)mappings[(uint)ymap2.CMapData.Name][entity.Guid]["parent"];
                                            var oldParentYmapName = (string)mappings[(uint)ymap2.CMapData.Name][entity.Guid]["parentYmap"];
                                            var oldParentYmap     = Utils.Hash(oldParentYmapName);

                                            if (currHasParent)
                                            {
                                                if (entity.ParentEntity == null || entity.ParentEntity.Guid != oldParent)
                                                {
                                                    var parentYmap = ymaps.Find(e => (uint)e.CMapData.Name == oldParentYmap);
                                                    var parentIdx  = parentYmap.CMapData.Entities.FindIndex(e => e.Guid == oldParent);

                                                    if (parentIdx == -1)
                                                    {
                                                        Console.WriteLine("DELETE " + entity.Guid + " => Missing parent (" + oldParentYmapName + ")");
                                                        toRemove.Add(entity);
                                                        modified     = true;
                                                        currModified = true;
                                                    }
                                                    else
                                                    {
                                                        Console.WriteLine("ASSIGN parent " + oldParent + " to " + entity.Guid);
                                                        var parent = parentYmap.CMapData.Entities[parentIdx];
                                                        toSet.Add(new Tuple <MCEntityDef, MCEntityDef>(entity, parent));
                                                        modified     = true;
                                                        currModified = true;
                                                    }
                                                }
                                                else
                                                {
                                                    if (toDelete.IndexOf(oldParent) != -1 || (opts.DeleteScope == "full" && toDelete.IndexOf(entity.Guid) != -1))
                                                    {
                                                        Console.WriteLine("DELETE " + entity.Guid + " => Marked for deletion @" + opts.DeleteMode);
                                                        toRemove.Add(entity);
                                                        modified     = true;
                                                        currModified = true;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (opts.DeleteMode == "dummy")
                                    {
                                        for (int k = 0; k < toRemove.Count; k++)
                                        {
                                            toRemove[k].ArchetypeName = Utils.Hash("gtautil_dummy");
                                        }
                                    }
                                    else
                                    {
                                        ymap2.CMapData.RemoveEntities(toRemove);
                                    }

                                    for (int k = 0; k < toSet.Count; k++)
                                    {
                                        toSet[k].Item1.ParentEntity = toSet[k].Item2;
                                    }

                                    if (currModified)
                                    {
                                        Console.WriteLine("MODIFIED");
                                    }
                                }
                            } while (modified && opts.DeleteMode != "dummy");

                            for (int j = 0; j < ymaps.Count; j++)
                            {
                                var ymap2   = ymaps[j];
                                var mapping = new Dictionary <uint, int>();
                                var name    = nameHashes[(uint)ymap2.CMapData.Name];

                                ymap2.Save(basePath + "\\" + name + ".ymap");

                                var data = new JObject
                                {
                                    ["mapping"] = new JArray()
                                };

                                var dataMapping = (JArray)(data["mapping"]);

                                for (int k = 0; k < ymap2.CMapData.Entities.Count; k++)
                                {
                                    var entity = ymap2.CMapData.Entities[k];

                                    if (mapping.ContainsKey(entity.Guid))
                                    {
                                        Console.WriteLine("Duplicate GUID found => " + entity.Guid + " at index " + j + " ABORTING");
                                        return;
                                    }
                                    else
                                    {
                                        mapping.Add(entity.Guid, k);

                                        var entry = new JObject()
                                        {
                                            ["guid"]      = entity.Guid,
                                            ["hasParent"] = entity.ParentIndex != -1,
                                        };

                                        if (entity.ParentIndex != -1)
                                        {
                                            entry["parent"]     = entity.ParentEntity.Guid;
                                            entry["parentName"] = MetaXml.HashString((MetaName)entity.ParentEntity.Guid);
                                            entry["parentYmap"] = nameHashes[(uint)entity.ParentEntity.Parent.Name];
                                        }

                                        dataMapping.Add(entry);
                                    }
                                }

                                var jsonString = JsonConvert.SerializeObject(data, new JsonSerializerSettings()
                                {
                                    Formatting = Newtonsoft.Json.Formatting.Indented
                                });

                                File.WriteAllText(basePath + "\\" + name + ".ymap.json", jsonString);
                            }
                        }
                        else
                        {
                            string fileName = fileInfo.FullName.Replace(".xml", "");
                            res.Save(fileName);
                        }
                    }

                    using (StreamWriter writer = new StreamWriter(AssemblyDirectory + "\\strings.txt"))
                    {
                        foreach (var kvp in Jenkins.Index)
                        {
                            writer.Write(kvp.Value + "\n");
                        }
                    }
                }
            });
        }
Пример #13
0
        public void ToXml(RIRecordModel record)
        {
            try
            {
                //Record转xml描述文件
                WrapXml obj = new WrapXml();
                obj.filename = record.EntityID + "_" + record.Version;
                obj.filepath = "crcd";
                obj._head    = new head()
                {
                    documentID    = record.DocID,
                    contentFormat = "doc",
                    contentType   = "JP3_RI",
                    documentType  = "crcd",
                    effectiveDate = DateTime.Now.ToString("yyyy-MM-dd"),
                    elementID     = "1",
                    entityID      = record.EntityID,
                    expiredDate   = "9999-12-31"
                    ,
                    subContentFormat = "snapshotFullDocument"
                };

                List <paragraph> _p = new List <paragraph>();
                foreach (var item in record.CheckItem)
                {
                    _p.Add(new paragraph()
                    {
                        Attr_type = "checkitem", checkitemID = item.DocID
                    });
                }
                obj._wrapbody = new WrapBody()
                {
                    _paragraph = _p
                };
                RIRecordXMLService.Instance.Toxml(obj);

                // //Record转xml数据文件
                MetaXml obj2 = new MetaXml();
                obj2.filename = record.EntityID + "_" + record.Version + "_META";
                obj2.filepath = "crcd";
                obj2._head    = new head()
                {
                    documentID       = record.DocID + "_META",
                    contentFormat    = "doc",
                    contentType      = "JP3_RI",
                    documentType     = "crcd",
                    effectiveDate    = DateTime.Now.ToString("yyyy-MM-dd"),
                    elementID        = "1",
                    entityID         = record.EntityID,
                    expiredDate      = "9999-12-31",
                    subContentFormat = "snapshotFullDocument"
                };

                List <Metadata> _p2  = new List <Metadata>();
                Metadata_Main   meta = new Metadata_Main();
                _p2.Add(new Metadata()
                {
                    Attr_type = "packageID", ObjSub = new Metadata_Sub()
                    {
                        text = StringHelper.XMLSpecialCharToConvert(record.PackageID)
                    }
                });
                _p2.Add(new Metadata()
                {
                    Attr_type = "class", ObjSub = new Metadata_Sub()
                    {
                        text = StringHelper.XMLSpecialCharToConvert(record.Topic)
                    }
                });
                _p2.Add(new Metadata()
                {
                    Attr_type = "subclass", ObjSub = new Metadata_Sub()
                    {
                        text = StringHelper.XMLSpecialCharToConvert(record.SubTopic)
                    }
                });
                _p2.Add(new Metadata()
                {
                    Attr_type = "packageIDwithSuffix", ObjSub = new Metadata_Sub()
                    {
                        text = record.PackageID + ";riallmodule"
                    }
                });
                _p2.Add(new Metadata()
                {
                    Attr_type = "documentTitle", ObjSub = new Metadata_Sub()
                    {
                        text = StringHelper.XMLSpecialCharToConvert(record.Title)
                    }
                });
                _p2.Add(new Metadata()
                {
                    Attr_type = "documentNumber", ObjSub = new Metadata_Sub()
                    {
                        text = "30001010010010"
                    }
                });
                _p2.Add(new Metadata()
                {
                    Attr_type = "abstract", ObjSub = new Metadata_Sub()
                    {
                        text = StringHelper.XMLSpecialCharToConvert(record.Summary)
                    }
                });
                _p2.Add(new Metadata()
                {
                    Attr_type = "riskAbstract", ObjSub = new Metadata_Sub()
                    {
                        text = StringHelper.XMLSpecialCharToConvert(record.Risk)
                    }
                });
                _p2.Add(new Metadata()
                {
                    Attr_type = "author", ObjSub = new Metadata_Sub()
                    {
                        text = StringHelper.XMLSpecialCharToConvert(record.Author)
                    }
                });
                foreach (var item in record.CheckItem)
                {
                    _p2.Add(new Metadata()
                    {
                        Attr_type = "importance", Attr_citm_id = item.DocID, ObjSub = new Metadata_Sub()
                        {
                            text = item.Importance.ToString()
                        }
                    });
                    _p2.Add(new Metadata()
                    {
                        Attr_type = "hasMeta", Attr_citm_id = item.DocID, ObjSub = new Metadata_Sub()
                        {
                            text = item.HasMeta
                        }
                    });
                    _p2.Add(new Metadata()
                    {
                        Attr_type = "body", Attr_citm_id = item.DocID, Attr_hasMeta = "Y", ObjMain = new Metadata_Main()
                        {
                            _paragraph = new Metadata_paragraph()
                            {
                                Attr_num = "1", markupText = StringHelper.XMLSpecialCharToConvert(item.CheckItemContent), Attr_type = "body"
                            }
                        }
                    });
                    _p2.Add(new Metadata()
                    {
                        Attr_type = "penalty", Attr_citm_id = item.DocID, ObjSub = new Metadata_Sub()
                        {
                            text = StringHelper.XMLSpecialCharToConvert(item.Penalty)
                        }
                    });
                    _p2.Add(new Metadata()
                    {
                        Attr_type = "reasonCode", Attr_citm_id = item.DocID, ObjSub = new Metadata_Sub()
                        {
                            text = StringHelper.XMLSpecialCharToConvert(item.ReasonCodes)
                        }
                    });
                }
                var _listFile = _fileService.GetFilesById(record.DocID);
                foreach (var temp in _listFile)
                {
                    if (temp.MimeType.Equals("url"))
                    {
                        _p2.Add(new Metadata()
                        {
                            Attr_type = "referenceDocuments", Attr_citm_id = record.CheckItem[0].DocID, Attr_doc_id = temp.DocID, Attr_url = temp.Path, Attr_content = "URL", ObjSub = new Metadata_Sub()
                            {
                                text = StringHelper.XMLSpecialCharToConvert(temp.Path)
                            }
                        });
                    }
                    if (temp.MimeType.Contains("application"))
                    {
                        var _spt      = temp.MimeType.Split('/');
                        var _mimeType = _spt[_spt.Length - 1].ToUpper();
                        _p2.Add(new Metadata()
                        {
                            Attr_type = "referenceDocuments", Attr_citm_id = record.CheckItem[0].DocID, Attr_doc_id = temp.DocID, Attr_content = _mimeType, ObjSub = new Metadata_Sub()
                            {
                                text = StringHelper.XMLSpecialCharToConvert(temp.Title)
                            }
                        });
                    }
                }

                obj2._meta = new Meta()
                {
                    _metadata = _p2
                };
                RIRecordXMLService.Instance.Toxml_Meta(obj2);
                var _userName     = new HttpContextWrapper(HttpContext.Current).User.Identity.Name;
                var _listFileZero = _fileService.GetFilesById("-1", _userName);
                if (_listFileZero != null && _listFileZero.Count > 0)
                {
                    _iRlFileDataProvider.DelFileByDocmentIdForZero(_userName);
                }
                //CheckItem转xml
                foreach (var item in record.CheckItem)
                {
                    //CheckItem描述文件
                    Sub_Xml obj1 = new Sub_Xml();
                    obj1.filename = (Convert.ToInt64(item.EntityID)).ToString() + "_" + item.Version;
                    obj1.filepath = "citm";
                    obj1._head    = new head()
                    {
                        documentID       = item.DocID,
                        contentFormat    = "doc",
                        contentType      = "JP3_RI",
                        documentType     = "citm",
                        effectiveDate    = DateTime.Now.ToString("yyyy-MM-dd"),
                        elementID        = "1",
                        entityID         = (Convert.ToInt64(item.EntityID)).ToString(),
                        expiredDate      = "9999-12-31",
                        subContentFormat = "snapshotFullDocument"
                    };

                    obj1._sub_body = new sub_body()
                    {
                        Attr_type  = "body",
                        Attr_num   = "1",
                        markupText = item.CheckItemContent
                    };

                    RIRecordXMLService.Instance.Toxml_Sub(obj1);

                    //CheckItem数据文件
                    MetaXml obj3 = new MetaXml();
                    obj3.filename = (Convert.ToInt64(item.EntityID)).ToString() + "_" + item.Version + "_META";
                    obj3.filepath = "citm";
                    obj3._head    = new head()
                    {
                        documentID       = item.DocID,
                        contentFormat    = "doc",
                        contentType      = "JP3_RI",
                        documentType     = "citm",
                        effectiveDate    = DateTime.Now.ToString("yyyy-MM-dd"),
                        elementID        = "1",
                        entityID         = (Convert.ToInt64(item.EntityID)).ToString(),
                        expiredDate      = "9999-12-31",
                        subContentFormat = "snapshotFullDocument"
                    };
                    List <Metadata> _p3 = new List <Metadata>();
                    _p3.Add(new Metadata()
                    {
                        Attr_type = "importance", ObjSub = new Metadata_Sub()
                        {
                            text = item.Importance.ToString()
                        }
                    });
                    _p3.Add(new Metadata()
                    {
                        Attr_type = "hasMeta", ObjSub = new Metadata_Sub()
                        {
                            text = item.HasMeta
                        }
                    });
                    _p3.Add(new Metadata()
                    {
                        Attr_type = "penalty", ObjSub = new Metadata_Sub()
                        {
                            text = StringHelper.XMLSpecialCharToConvert(item.Penalty)
                        }
                    });
                    _p3.Add(new Metadata()
                    {
                        Attr_type = "reasonCode", ObjSub = new Metadata_Sub()
                        {
                            text = StringHelper.XMLSpecialCharToConvert(item.ReasonCodes)
                        }
                    });
                    obj3._meta = new Meta()
                    {
                        _metadata = _p3
                    };
                    RIRecordXMLService.Instance.Toxml_Meta(obj3);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error <lnRIRecordService>("XML Convert Failed! \n", ex);
                throw new RequestErrorException("Model to XMl is failed__" + ex.Message);
            }
        }
Пример #14
0
        static void HandleGenPedDefsOptions(string[] args)
        {
            CommandLine.Parse <GenPedDefsOptions>(args, (opts, gOpts) =>
            {
                var ymtRegex  = new Regex("mp_(m|f)_freemode_01.*\\.ymt$");
                var cYddRegex = new Regex("(head|berd|hair|uppr|lowr|hand|feet|teef|accs|task|decl|jbib)_(\\d\\d\\d)_u.ydd$");
                var pYddRegex = new Regex("p_(head|ears|mouth|lhand|rhand|lwrist|rwrist|hip|lfoot|rfoot)_(\\d\\d\\d).ydd$");

                var fileDlcLevels = new Dictionary <string, int>();
                var overrides     = new Dictionary <string, List <string> >();

                if (opts.CreateMode)
                {
                    if (opts.OutputDirectory == null)
                    {
                        Console.WriteLine("Please provide input directory with --output");
                        return;
                    }

                    if (!Directory.Exists(opts.OutputDirectory))
                    {
                        Directory.CreateDirectory(opts.OutputDirectory);
                    }

                    Init(args);

                    int maxDLCLevel = (Array.IndexOf(DLCList, opts.DLCLevel) == -1) ? DLCList.Length - 1 : Array.IndexOf(DLCList, opts.DLCLevel);

                    var targets   = opts.Targets?.ToList() ?? new List <string>();
                    var dlcpaths  = new Dictionary <string, int>();
                    var dlcdirs   = new Dictionary <string, int>();
                    var processed = new List <string>();

                    ArchiveUtilities.ForEachFile(Settings.Default.GTAFolder, (fullFileName, file, encryption) =>
                    {
                        string[] path   = fullFileName.Split('\\');
                        string folder   = path[path.Length - 2];
                        string fileName = path[path.Length - 1];
                        string name     = fileName.Split('.').First();
                        string outPath;
                        bool isOverride = false;

                        var ymtMatch  = ymtRegex.Match(fileName);
                        var cYddMatch = cYddRegex.Match(fileName);
                        var pYddMatch = pYddRegex.Match(fileName);

                        int dlcLevel = GetDLCLevel(fullFileName);

                        if (dlcLevel > maxDLCLevel)
                        {
                            return;
                        }

                        if (targets.Count > 0 && opts.Targets.Where(e => e == name || (e + "_p") == name || e == folder || (e + "_p") == folder).ToArray().Length == 0)
                        {
                            return;
                        }

                        // Found interesting entry
                        if (ymtMatch.Success || cYddMatch.Success || pYddMatch.Success)
                        {
                            string pathPart;

                            // Found definition file (.ymt)
                            if (ymtMatch.Success)
                            {
                                if (!path[path.Length - 1].Contains("_freemode_01"))
                                {
                                    return;
                                }

                                outPath  = opts.OutputDirectory;
                                pathPart = path[path.Length - 1];

                                if (!dlcpaths.ContainsKey(pathPart))
                                {
                                    dlcpaths[pathPart] = dlcLevel;
                                    isOverride         = true;
                                }
                                else if (dlcLevel > dlcpaths[pathPart])
                                {
                                    dlcpaths[pathPart] = dlcLevel;
                                    isOverride         = true;
                                }
                            }
                            else  // Found model file (component or prop)
                            {
                                if (!path[path.Length - 2].Contains("_freemode_01"))
                                {
                                    return;
                                }

                                outPath    = opts.OutputDirectory + "\\" + path[path.Length - 2];
                                pathPart   = path[path.Length - 2] + "\\" + path[path.Length - 1];
                                string dir = path[path.Length - 2];
                                dlcLevel   = GetDLCLevel(fullFileName);

                                // Console.WriteLine(pathPart);

                                if (!dlcpaths.ContainsKey(pathPart))
                                {
                                    dlcpaths[pathPart] = dlcLevel;

                                    Console.WriteLine(DLCList[dlcLevel] + " [" + dlcLevel + "] => " + pathPart);
                                    dlcdirs[dir] = dlcLevel;
                                    isOverride   = true;
                                }
                                else if (dlcLevel > dlcdirs[dir])
                                {
                                    Console.WriteLine(DLCList[dlcLevel] + " [" + dlcLevel + "] => " + pathPart);
                                    dlcpaths[pathPart] = dlcLevel;
                                    dlcdirs[dir]       = dlcLevel;
                                    isOverride         = true;
                                }
                            }

                            Directory.CreateDirectory(outPath);

                            // If dlc level of this directory is superior to current matching one
                            if (isOverride)
                            {
                                // Write higher level ymt
                                if (ymtMatch.Success)
                                {
                                    using (var ms = new MemoryStream())
                                    {
                                        file.Export(ms);

                                        var rMeta = new ResourceFile_GTA5_pc <MetaFile>();

                                        rMeta.Load(ms);

                                        string xml = MetaXml.GetXml(rMeta.ResourceData);

                                        File.WriteAllText(outPath + "\\" + fileName + ".xml", xml);
                                    }
                                }
                                else if (cYddMatch.Success)
                                {
                                    foreach (var entry in ComponentFilePrefix)
                                    {
                                        Directory.CreateDirectory(outPath + "\\components\\" + entry.Value);
                                    }
                                }
                                else if (pYddMatch.Success)
                                {
                                    foreach (var entry in AnchorFilePrefix)
                                    {
                                        Directory.CreateDirectory(outPath + "\\props\\" + entry.Value);
                                    }
                                }

                                if (cYddMatch.Success || pYddMatch.Success)
                                {
                                    dynamic directoryInfos = new JObject();

                                    string dlc = DLCList[dlcLevel];

                                    directoryInfos["dlc"]  = dlc;
                                    directoryInfos["path"] = Directory.GetParent(fullFileName);

                                    var jsonString = JsonConvert.SerializeObject(directoryInfos, new JsonSerializerSettings()
                                    {
                                        Formatting = Newtonsoft.Json.Formatting.Indented
                                    });

                                    File.WriteAllText(outPath + "\\directory.json", jsonString);
                                }
                            }
                        }
                    });
                }
                else
                {
                    if (opts.InputDirectory == null)
                    {
                        Console.WriteLine("Please provide input directory with --input");
                        return;
                    }

                    if (opts.OutputDirectory == null)
                    {
                        Console.WriteLine("Please provide input directory with --output");
                        return;
                    }

                    Init(args);

                    int maxDLCLevel = (Array.IndexOf(DLCList, opts.DLCLevel) == -1) ? DLCList.Length - 1 : Array.IndexOf(DLCList, opts.DLCLevel);

                    string[] files = Directory.GetFiles(opts.InputDirectory).Where(e => e.EndsWith("ymt.xml")).ToArray();
                    string[] dirs  = Directory.GetDirectories(opts.InputDirectory);
                    var addonDirs  = new List <string>();

                    var ymts = new Dictionary <string, YmtPedDefinitionFile>();

                    var processedYmts = new Dictionary <string, Tuple <
                                                            Dictionary <string, Tuple <string, int, int, int, string, string> >,
                                                            Dictionary <string, int>,
                                                            Dictionary <string, Tuple <string, int, int, int, string, string> >,
                                                            Dictionary <string, int>
                                                            > >();

                    for (int j = 0; j < files.Length; j++)
                    {
                        string targetMetaXml       = files[j];
                        string targetName          = targetMetaXml.Split('\\').Last().Replace(".ymt.xml", "");
                        string parentDirectoryPath = Directory.GetParent(targetMetaXml).FullName;
                        string parentDirectoryName = parentDirectoryPath.Split('\\').Last();

                        // Parse .ymt.xml
                        string xml = File.ReadAllText(targetMetaXml);
                        var doc    = new XmlDocument();
                        doc.LoadXml(xml);
                        var meta = XmlMeta.GetMeta(doc);
                        var ymt  = new YmtPedDefinitionFile();
                        ymt.ResourceFile.ResourceData = meta;
                        ymt.Parse();

                        ymts[targetName] = ymt;
                    }

                    if (opts.FiveMFormat)
                    {
                        Directory.CreateDirectory(opts.OutputDirectory + "\\stream");
                        File.Create(opts.OutputDirectory + "\\__resource.lua");
                    }
                    else
                    {
                        Directory.CreateDirectory(opts.OutputDirectory + "\\x64\\models\\cdimages\\streamedpeds_mp.rpf");
                        Directory.CreateDirectory(opts.OutputDirectory + "\\x64\\models\\cdimages\\streamedpedprops.rpf");

                        string contentXml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<CDataFileMgr__ContentsOfDataFileXml>
    <disabledFiles />
    <includedXmlFiles />
    <includedDataFiles />
    <dataFiles>
        <Item>
            <filename>dlc_gtauclothes:/%PLATFORM%/models/cdimages/streamedpeds_mp.rpf</filename>
            <fileType>RPF_FILE</fileType>
            <overlay value=""true"" />
            <disabled value=""true"" />
            <persistent value=""true"" />
        </Item>
        <Item>
            <filename>dlc_gtauclothes:/%PLATFORM%/models/cdimages/streamedpedprops.rpf</filename>
            <fileType>RPF_FILE</fileType>
            <overlay value=""true"" />
            <disabled value=""true"" />
            <persistent value=""true"" />
        </Item>
    </dataFiles>
    <contentChangeSets>
        <Item>
            <changeSetName>gtauclothes_AUTOGEN</changeSetName>
            <filesToDisable />
            <filesToEnable>
                <Item>dlc_gtauclothes:/%PLATFORM%/models/cdimages/streamedpeds_mp.rpf</Item>
                <Item>dlc_gtauclothes:/%PLATFORM%/models/cdimages/streamedpedprops.rpf</Item>
            </filesToEnable>
            <txdToLoad />
            <txdToUnload />
            <residentResources />
            <unregisterResources />
        </Item>
    </contentChangeSets>
    <patchFiles />
</CDataFileMgr__ContentsOfDataFileXml>";

                        string setup2Xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<SSetupData>
    <deviceName>dlc_gtauclothes</deviceName>
    <datFile>content.xml</datFile>
    <timeStamp>03/30/2018 17:26:39</timeStamp>
    <nameHash>gtauclothes</nameHash>
    <contentChangeSetGroups>
        <Item>
            <NameHash>GROUP_STARTUP</NameHash>
            <ContentChangeSets>
                <Item>gtauclothes_AUTOGEN</Item>
            </ContentChangeSets>
        </Item>
    </contentChangeSetGroups>
</SSetupData>";

                        File.WriteAllText(opts.OutputDirectory + "\\content.xml", contentXml);
                        File.WriteAllText(opts.OutputDirectory + "\\setup2.xml", setup2Xml);
                    }

                    foreach (var ymtEntry in ymts)
                    {
                        var targetName = ymtEntry.Key;
                        var ymt        = ymtEntry.Value;

                        // Components
                        var cCount        = new Dictionary <Unk_884254308, int>();
                        var cYddMapping   = new Dictionary <string, Tuple <string, int, int, int, string, string> >(); // sourceYddPath => prefix, origPos, pos, count, folder, yddFileName
                        var cTextureCount = new Dictionary <string, int>();

                        // Props
                        var pCount        = new Dictionary <Unk_2834549053, int>();
                        var pYddMapping   = new Dictionary <string, Tuple <string, int, int, int, string, string> >(); // sourceYddPath => prefix, origPos, pos, count, folder, yddFileName
                        var pTextureCount = new Dictionary <string, int>();

                        // Set component base count
                        Unk_884254308[] cValues = (Unk_884254308[])Enum.GetValues(typeof(Unk_884254308));

                        foreach (Unk_884254308 component in cValues)
                        {
                            if (component == Unk_884254308.PV_COMP_INVALID || component == Unk_884254308.PV_COMP_MAX)
                            {
                                continue;
                            }

                            cCount[component] = (ymt.Unk_376833625.Components[component] ?? new MUnk_3538495220()).Unk_1756136273.Count;
                        }

                        // Set prop base count
                        Unk_2834549053[] pValues = (Unk_2834549053[])Enum.GetValues(typeof(Unk_2834549053));

                        foreach (Unk_2834549053 anchor in pValues)
                        {
                            if (anchor == Unk_2834549053.NUM_ANCHORS)
                            {
                                continue;
                            }

                            int max = (opts.ReservePropEntries > ymt.Unk_376833625.PropInfo.Props[anchor].Count) ? opts.ReservePropEntries : ymt.Unk_376833625.PropInfo.Props[anchor].Count;

                            pCount[anchor] = (ymt.Unk_376833625.PropInfo.Props[anchor] ?? new List <MUnk_94549140>()).Count;
                        }

                        foreach (var entry in ComponentFilePrefix)
                        {
                            Unk_884254308 component = entry.Key;
                            string prefix           = entry.Value;
                            string targetDirectory  = opts.InputDirectory + "\\" + targetName + "\\components\\" + prefix;

                            if (Directory.Exists(targetDirectory))
                            {
                                IEnumerable <string> addonFilesUnordered = Directory.GetFiles(targetDirectory).Where(e => e.EndsWith(".ydd"));

                                int padLen = 0;

                                if (addonFilesUnordered.Count() > 0)
                                {
                                    padLen = addonFilesUnordered.Max(e => e.Length);
                                }

                                string[] addonFiles = addonFilesUnordered.OrderBy(e => e.PadLeft(padLen, '0')).ToArray();

                                var addons = new List <int>();

                                for (int k = 0; k < addonFiles.Length; k++)
                                {
                                    addons.Add(k);
                                }

                                if (addons.Count > 0)
                                {
                                    // Create addon component entries
                                    var def = ymt.Unk_376833625.Components[component] ?? new MUnk_3538495220();

                                    for (int k = 0; k < addons.Count; k++)
                                    {
                                        int addonPos            = def.Unk_1756136273.Count();
                                        string textureDirectory = targetDirectory + "\\" + addons[k];
                                        var addonTextures       = new List <int>();
                                        var item = new MUnk_1535046754();
                                        IEnumerable <string> texturesUnordered = Directory.GetFiles(textureDirectory).Where(e => e.EndsWith(".ytd"));
                                        int padLen1 = 0;

                                        if (texturesUnordered.Count() > 0)
                                        {
                                            padLen1 = texturesUnordered.Max(e => e.Length);
                                        }

                                        string[] textures  = texturesUnordered.OrderBy(e => e.PadLeft(padLen1, '0')).ToArray();
                                        string yddFileName = prefix + "_" + addonPos.ToString().PadLeft(3, '0') + "_u.ydd";

                                        cYddMapping[addonFiles[k]] = new Tuple <string, int, int, int, string, string>(prefix, addons[k], addonPos, addons.Count, targetDirectory, yddFileName);

                                        // Create addon texture entries
                                        for (int l = 0; l < textures.Length; l++)
                                        {
                                            addonTextures.Add(l);
                                        }

                                        cTextureCount[addonFiles[k]] = addonTextures.Count;

                                        for (int l = 0; l < addonTextures.Count; l++)
                                        {
                                            var texture = new MUnk_1036962405();
                                            item.ATexData.Add(texture);

                                            // Create componentinfo
                                            var cInfo = new MCComponentInfo();

                                            cInfo.Unk_2114993291 = 0;
                                            cInfo.Unk_3509540765 = (byte)component;
                                            cInfo.Unk_4196345791 = (byte)l;

                                            ymt.Unk_376833625.CompInfos.Add(cInfo);
                                        }

                                        if (File.Exists(addonFiles[k].Replace(".ydd", ".yld")))
                                        {
                                            item.ClothData.Unk_2828247905 = 1;
                                        }

                                        def.Unk_1756136273.Add(item);

                                        cCount[component]++;
                                    }

                                    ymt.Unk_376833625.Components[component] = def;
                                }
                            }
                        }

                        foreach (var entry in AnchorFilePrefix)
                        {
                            Unk_2834549053 anchor  = entry.Key;
                            string prefix          = entry.Value;
                            string targetDirectory = opts.InputDirectory + "\\" + targetName + "_p" + "\\props\\" + prefix;

                            if (Directory.Exists(targetDirectory))
                            {
                                IEnumerable <string> addonFilesUnordered = Directory.GetFiles(targetDirectory).Where(e => e.EndsWith(".ydd"));

                                int padLen = 0;

                                if (addonFilesUnordered.Count() > 0)
                                {
                                    padLen = addonFilesUnordered.Max(e => e.Length);
                                }

                                string[] addonFiles = addonFilesUnordered.OrderBy(e => e.PadLeft(padLen, '0')).ToArray();

                                var addons = new List <int>();

                                for (int k = 0; k < addonFiles.Length; k++)
                                {
                                    addons.Add(k);
                                }

                                if (addons.Count > 0)
                                {
                                    // Create addon prop entries
                                    var defs = ymt.Unk_376833625.PropInfo.Props[anchor] ?? new List <MUnk_94549140>();

                                    for (int k = 0; k < addons.Count; k++)
                                    {
                                        int addonPos            = defs.Count();
                                        string textureDirectory = targetDirectory + "\\" + addons[k];
                                        var addonTextures       = new List <int>();
                                        var item = new MUnk_94549140(ymt.Unk_376833625.PropInfo);
                                        IEnumerable <string> texturesUnordered = Directory.GetFiles(textureDirectory).Where(e => e.EndsWith(".ytd"));
                                        int padLen2 = 0;

                                        if (texturesUnordered.Count() > 0)
                                        {
                                            padLen2 = texturesUnordered.Max(e => e.Length);
                                        }

                                        string[] textures  = texturesUnordered.OrderBy(e => e.PadLeft(padLen2, '0')).ToArray();
                                        string yddFileName = "p_" + prefix + "_" + addonPos.ToString().PadLeft(3, '0') + ".ydd";

                                        item.AnchorId = (byte)anchor;

                                        pYddMapping[addonFiles[k]] = new Tuple <string, int, int, int, string, string>(prefix, addons[k], addonPos, addons.Count, targetDirectory, yddFileName);

                                        // Create addon texture entries
                                        for (int l = 0; l < textures.Length; l++)
                                        {
                                            addonTextures.Add(l);
                                        }

                                        pTextureCount[addonFiles[k]] = addonTextures.Count;

                                        for (int l = 0; l < addonTextures.Count; l++)
                                        {
                                            var texture = new MUnk_254518642();
                                            item.TexData.Add(texture);
                                        }

                                        // Get or create linked anchor
                                        var aanchor = ymt.Unk_376833625.PropInfo.AAnchors.Find(e => e.Anchor == anchor);

                                        if (aanchor == null)
                                        {
                                            aanchor = new MCAnchorProps(ymt.Unk_376833625.PropInfo);
                                            aanchor.PropsMap[item] = (byte)item.TexData.Count;
                                            ymt.Unk_376833625.PropInfo.AAnchors.Add(aanchor);
                                        }
                                        else
                                        {
                                            aanchor.PropsMap[item] = (byte)item.TexData.Count;
                                        }

                                        defs.Add(item);
                                        pCount[anchor]++;
                                    }

                                    ymt.Unk_376833625.PropInfo.Props[anchor] = defs;
                                }
                            }
                        }

                        // Create reserved component entries
                        foreach (Unk_884254308 component in cValues)
                        {
                            if (component == Unk_884254308.PV_COMP_INVALID || component == Unk_884254308.PV_COMP_MAX)
                            {
                                continue;
                            }

                            int count = cCount[component];
                            int max   = (opts.ReservePropEntries > count) ? opts.ReservePropEntries : count;
                            var def   = ymt.Unk_376833625.Components[component] ?? new MUnk_3538495220();

                            for (int i = count; i < max; i++)
                            {
                                var item    = new MUnk_1535046754();
                                var texture = new MUnk_1036962405();
                                item.ATexData.Add(texture);

                                // Create componentinfo
                                var cInfo = new MCComponentInfo();

                                cInfo.Unk_2114993291 = 0;
                                cInfo.Unk_3509540765 = (byte)component;
                                cInfo.Unk_4196345791 = (byte)i;

                                ymt.Unk_376833625.CompInfos.Add(cInfo);

                                def.Unk_1756136273.Add(item);
                            }

                            if (def.Unk_1756136273.Count > 0)
                            {
                                ymt.Unk_376833625.Components[component] = def;
                            }
                        }

                        // Create reserved prop entries
                        foreach (Unk_2834549053 anchor in pValues)
                        {
                            if (anchor == Unk_2834549053.NUM_ANCHORS)
                            {
                                continue;
                            }

                            int count = pCount[anchor];
                            int max   = (opts.ReservePropEntries > count) ? opts.ReservePropEntries : count;
                            var defs  = ymt.Unk_376833625.PropInfo.Props[anchor] ?? new List <MUnk_94549140>();

                            for (int i = count; i < max; i++)
                            {
                                var item      = new MUnk_94549140(ymt.Unk_376833625.PropInfo);
                                item.AnchorId = (byte)anchor;
                                var texture   = new MUnk_254518642();
                                item.TexData.Add(texture);

                                var aanchor = ymt.Unk_376833625.PropInfo.AAnchors.Find(e => e.Anchor == anchor);

                                if (aanchor == null)
                                {
                                    aanchor                = new MCAnchorProps(ymt.Unk_376833625.PropInfo);
                                    aanchor.Anchor         = anchor;
                                    aanchor.PropsMap[item] = 1;
                                    ymt.Unk_376833625.PropInfo.AAnchors.Add(aanchor);
                                }
                                else
                                {
                                    aanchor.PropsMap[item] = 1;
                                }


                                defs.Add(item);
                            }

                            if (defs.Count > 0)
                            {
                                ymt.Unk_376833625.PropInfo.Props[anchor] = defs;
                            }
                        }

                        processedYmts[targetName] = new Tuple <
                            Dictionary <string, Tuple <string, int, int, int, string, string> >,
                            Dictionary <string, int>,
                            Dictionary <string, Tuple <string, int, int, int, string, string> >,
                            Dictionary <string, int>
                            >(cYddMapping, cTextureCount, pYddMapping, pTextureCount);

                        if (opts.FiveMFormat)
                        {
                            ymt.Save(opts.OutputDirectory + "\\stream\\" + targetName + ".ymt");

                            // var xml2 = MetaXml.GetXml(ymt.ResourceFile.ResourceData);
                            // File.WriteAllText(opts.OutputDirectory + "\\stream\\" + targetMetaYmtFileName + ".xml", xml2);
                        }
                        else
                        {
                            ymt.Save(opts.OutputDirectory + "\\x64\\models\\cdimages\\streamedpeds_mp.rpf\\" + targetName + ".ymt");
                        }

                        dynamic overrideInfos = new JObject();

                        overrideInfos["components"] = new JObject();
                        overrideInfos["props"]      = new JObject();

                        foreach (Unk_884254308 component in cValues)
                        {
                            if (component == Unk_884254308.PV_COMP_INVALID || component == Unk_884254308.PV_COMP_MAX)
                            {
                                continue;
                            }

                            int count = ymt.Unk_376833625.Components[component]?.Unk_1756136273.Count ?? 0;
                            int max   = (opts.ReserveEntries > count) ? opts.ReserveEntries : count;

                            overrideInfos["components"][ComponentFilePrefix[component]] = new JObject()
                            {
                                ["start"] = cCount[component], ["end"] = max
                            };
                        }

                        foreach (Unk_2834549053 anchor in pValues)
                        {
                            if (anchor == Unk_2834549053.NUM_ANCHORS)
                            {
                                continue;
                            }

                            int count = ymt.Unk_376833625.PropInfo.Props[anchor]?.Count ?? 0;
                            int max   = (opts.ReservePropEntries > count) ? opts.ReservePropEntries : count;

                            overrideInfos["props"][AnchorFilePrefix[anchor]] = new JObject()
                            {
                                ["start"] = pCount[anchor], ["end"] = max
                            };
                        }

                        var jsonString = JsonConvert.SerializeObject(overrideInfos, new JsonSerializerSettings()
                        {
                            Formatting = Newtonsoft.Json.Formatting.Indented
                        });

                        File.WriteAllText(opts.OutputDirectory + "\\" + targetName + ".override.json", jsonString);
                    }

                    // Check which directories contains addon component / props
                    for (int i = 0; i < dirs.Length; i++)
                    {
                        bool found = false;

                        foreach (var entry in ComponentFilePrefix)
                        {
                            string prefix = entry.Value;


                            if (Directory.Exists(dirs[i] + "\\components\\" + prefix) && Directory.GetFiles(dirs[i] + "\\components\\" + prefix).Where(e => e.EndsWith(".ydd")).Count() > 0)
                            {
                                found = true;
                                break;
                            }

                            if (Directory.Exists(dirs[i] + "\\props\\" + prefix) && Directory.GetFiles(dirs[i] + "\\props\\" + prefix).Where(e => e.EndsWith(".ydd")).Count() > 0)
                            {
                                found = true;
                                break;
                            }

                            if (found)
                            {
                                break;
                            }
                        }

                        if (found)
                        {
                            addonDirs.Add(dirs[i]);
                        }
                    }

                    for (int i = 0; i < addonDirs.Count; i++)
                    {
                        Console.WriteLine(addonDirs[i]);

                        string directory  = addonDirs[i];
                        string[] path     = directory.Split('\\');
                        string name       = path[path.Length - 1];
                        string ymtDirName = name;

                        if (ymtDirName.EndsWith("_p"))
                        {
                            ymtDirName = ymtDirName.Substring(0, ymtDirName.Length - 2);
                        }

                        Tuple <
                            Dictionary <string, Tuple <string, int, int, int, string, string> >,
                            Dictionary <string, int>,
                            Dictionary <string, Tuple <string, int, int, int, string, string> >,
                            Dictionary <string, int>
                            > processedYmtData = null;

                        // Copy models / textures with resolved names to build directory
                        if (processedYmts.TryGetValue(ymtDirName, out processedYmtData))
                        {
                            foreach (var entry in processedYmtData.Item1)
                            {
                                if (opts.FiveMFormat)
                                {
                                    GenPedDefs_CreateComponentFiles_FiveM(opts, ymtDirName, entry, processedYmtData.Item2[entry.Key]);
                                }
                                else
                                {
                                    GenPedDefs_CreateComponentFiles(opts, ymtDirName, entry, processedYmtData.Item2[entry.Key]);
                                }
                            }

                            foreach (var entry in processedYmtData.Item3)
                            {
                                if (opts.FiveMFormat)
                                {
                                    GenPedDefs_CreatePropFiles_FiveM(opts, ymtDirName, entry, processedYmtData.Item4[entry.Key]);
                                }
                                else
                                {
                                    GenPedDefs_CreatePropFiles(opts, ymtDirName, entry, processedYmtData.Item4[entry.Key]);
                                }
                            }
                        }
                    }
                }
            });
        }
Пример #15
0
        static void Main(string[] args)
        {
            EnsurePath();
            EnsureKeys();
            EnsureCache();

            CommandLine.Parse <GenPropDefsOptions>(args, opts =>
            {
                if (opts.InputFiles != null)
                {
                    var inputFiles = Utils.Expand(opts.InputFiles);
                    var ytyp       = new YtypFile();

                    for (int i = 0; i < inputFiles.Length; i++)
                    {
                        var fileInfo = inputFiles[i];

                        string name = "";
                        var split   = fileInfo.Name.Split('.');

                        for (int j = 0; j < split.Length; j++)
                        {
                            if (j < split.Length - 1)
                            {
                                if (j > 0)
                                {
                                    name += ".";
                                }

                                name += split[j];
                            }
                        }

                        Console.WriteLine(name);

                        try
                        {
                            switch (fileInfo.Extension)
                            {
                            case ".ydr":
                                {
                                    var ydr      = new YdrFile();
                                    var arch     = new RageLib.GTA5.ResourceWrappers.PC.Meta.Structures.CBaseArchetypeDef();
                                    var nameHash = (MetaName)Jenkins.Hash(name);

                                    ydr.Load(fileInfo.FullName);

                                    arch.Name              = nameHash;
                                    arch.AssetName         = nameHash;
                                    arch.TextureDictionary = nameHash;
                                    arch.PhysicsDictionary = (MetaName)Jenkins.Hash("prop_" + name);
                                    arch.Flags             = 32;
                                    arch.AssetType         = Unk_1991964615.ASSET_TYPE_DRAWABLE;
                                    arch.BbMin             = (Vector3)(Vector4)ydr.Drawable.BoundingBoxMin;
                                    arch.BbMax             = (Vector3)(Vector4)ydr.Drawable.BoundingBoxMax;
                                    arch.BsCentre          = (Vector3)ydr.Drawable.BoundingCenter;
                                    arch.BsRadius          = ydr.Drawable.BoundingSphereRadius;
                                    arch.LodDist           = 500f;
                                    arch.HdTextureDist     = 5;

                                    ytyp.CMapTypes.Archetypes.Add(arch);

                                    break;
                                }

                            case ".ydd":     // TODO
                                {
                                    break;
                                }

                            default: break;
                            }
                        }
                        catch (Exception e)
                        {
                            Console.Error.WriteLine("ERROR => " + e.Message);
                        }
                    }

                    string path = (opts.Directory == null) ? @".\props.ytyp" : opts.Directory + @"\props.ytyp";

                    ytyp.Save(path);
                }
            });

            CommandLine.Parse <ImportMetaOptions>(args, opts =>
            {
                if (opts.InputFiles != null && opts.Directory != null)
                {
                    var inputFiles = Utils.Expand(opts.InputFiles);

                    for (int i = 0; i < inputFiles.Length; i++)
                    {
                        var fileInfo = inputFiles[i];

                        Console.WriteLine(fileInfo.FullName);

                        var doc = new XmlDocument();

                        doc.Load(fileInfo.FullName);

                        var res          = new ResourceFile_GTA5_pc <MetaFile>();
                        res.Version      = 2;
                        res.ResourceData = XmlMeta.GetMeta(doc);;

                        string fileName = fileInfo.FullName.Replace(".xml", "");

                        res.Save(fileName);
                    }
                }
            });

            CommandLine.Parse <ExportMetaOptions>(args, opts =>
            {
                if (opts.InputFiles != null && opts.Directory != null)
                {
                    var inputFiles = Utils.Expand(opts.InputFiles);

                    for (int i = 0; i < inputFiles.Length; i++)
                    {
                        var fileInfo = inputFiles[i];

                        Console.WriteLine(fileInfo.FullName);

                        var res = new ResourceFile_GTA5_pc <MetaFile>();
                        res.Load(fileInfo.FullName);

                        var xml = MetaXml.GetXml(res.ResourceData);

                        File.WriteAllText(opts.Directory + "\\" + fileInfo.Name + ".xml", xml);
                    }
                }
            });

            CommandLine.Parse <InjectEntitiesOptions>(args, opts =>
            {
                if (opts.Ymap == null)
                {
                    Console.WriteLine("Please provide source ymap file with --ymap");
                    return;
                }

                if (opts.Ytyp == null)
                {
                    Console.WriteLine("Please provide source ytyp file with --ytyp");
                    return;
                }

                if (opts.Room == null)
                {
                    Console.WriteLine("Please provide mlo room name with --room");
                    return;
                }

                if (opts.Position == null || opts.Position.Count() != 3)
                {
                    Console.WriteLine("Please provide a correct position ex: --position 120.5,1370.312,769.2");
                    return;
                }

                if (opts.Rotation == null || opts.Rotation.Count() != 4)
                {
                    Console.WriteLine("Plase provide a correct rotation ex: --rotation 0,0,0,1");
                    return;
                }

                if (opts.Name == null)
                {
                    Console.WriteLine("Plase provide new generated ytyp name with --name");
                    return;
                }

                var position = new Vector3(opts.Position.ElementAt(0), opts.Position.ElementAt(1), opts.Position.ElementAt(2));
                var rotation = new Quaternion(opts.Rotation.ElementAt(0), opts.Rotation.ElementAt(1), opts.Rotation.ElementAt(2), opts.Rotation.ElementAt(3));

                var ymap = new YmapFile();
                var ytyp = new YtypFile();

                ymap.Load(opts.Ymap);
                ytyp.Load(opts.Ytyp);

                RageLib.GTA5.ResourceWrappers.PC.Meta.Structures.CMloArchetypeDef mlo = null;

                for (int i = 0; i < ytyp.CMapTypes.MloArchetypes.Count; i++)
                {
                    mlo = ytyp.CMapTypes.MloArchetypes[i];
                    break;
                }

                if (mlo == null)
                {
                    Console.WriteLine("MLO archetype not found");
                    return;
                }

                RageLib.GTA5.ResourceWrappers.PC.Meta.Structures.CMloRoomDef room = null;

                for (int i = 0; i < mlo.Rooms.Count; i++)
                {
                    if (mlo.Rooms[i].Name == opts.Room)
                    {
                        room = mlo.Rooms[i];
                        break;
                    }
                }

                if (room == null)
                {
                    Console.WriteLine("MLO room not found");
                    return;
                }

                var mloEntities     = new List <RageLib.GTA5.ResourceWrappers.PC.Meta.Structures.CEntityDef>();
                var attachedObjects = new List <uint>();

                mloEntities.AddRange(mlo.Entities);
                attachedObjects.AddRange(room.AttachedObjects);

                for (int i = 0; i < ymap.CMapData.Entities.Count; i++)
                {
                    var entity       = ymap.CMapData.Entities[i];
                    var mloRot       = rotation;
                    var objRot       = new Quaternion(entity.Rotation.X, entity.Rotation.Y, entity.Rotation.Z, entity.Rotation.W);
                    var rotationDiff = objRot * mloRot;                                                                    // Multiply initial entity rotation by mlo rotation

                    entity.Position -= position;                                                                           // Substract mlo world coords from entity world coords
                    entity.Position  = Utils.RotateTransform(Quaternion.Conjugate(mloRot), entity.Position, Vector3.Zero); // Rotate entity around center of mlo instance (mlo entities rotations in space are inverted)
                    entity.Rotation  = new Vector4(rotationDiff.X, rotationDiff.Y, rotationDiff.Z, rotationDiff.W);

                    mloEntities.Add(entity);
                    attachedObjects.Add((uint)mloEntities.IndexOf(entity));
                }

                mlo.Entities         = mloEntities;
                room.AttachedObjects = attachedObjects;

                ytyp.Save(opts.Name.EndsWith(".ytyp") ? opts.Name : opts.Name + ".ytyp");
            });

            CommandLine.Parse <FindOptions>(args, opts =>
            {
                if (opts.Position == null || opts.Position.Count != 3)
                {
                    Console.Error.WriteLine("Please specify position with -p --position");
                    return;
                }

                if (Cache == null)
                {
                    Console.Error.WriteLine("Please build cache first with buildcache");
                    return;
                }

                var c = CultureInfo.InvariantCulture;

                for (int i = 0; i < Cache["ymap"].Count; i++)
                {
                    var cYmap = Cache["ymap"][i];

                    var entitiesExtentsMin = new Vector3((float)cYmap["entitiesExtentsMin"]["x"], (float)cYmap["entitiesExtentsMin"]["y"], (float)cYmap["entitiesExtentsMin"]["z"]);
                    var entitiesExtentsMax = new Vector3((float)cYmap["entitiesExtentsMax"]["x"], (float)cYmap["entitiesExtentsMax"]["y"], (float)cYmap["entitiesExtentsMax"]["z"]);

                    if (
                        opts.Position[0] >= entitiesExtentsMin.X && opts.Position[0] <= entitiesExtentsMax.X &&
                        opts.Position[1] >= entitiesExtentsMin.Y && opts.Position[1] <= entitiesExtentsMax.Y &&
                        opts.Position[2] >= entitiesExtentsMin.Z && opts.Position[2] <= entitiesExtentsMax.Z
                        )
                    {
                        Console.WriteLine("ymap: " + ((string)cYmap["path"]).Split('\\').Last());

                        for (int j = 0; j < cYmap["mloInstances"].Count; j++)
                        {
                            var cMloInstance     = cYmap["mloInstances"][j];
                            var cMloInstanceHash = (uint)cMloInstance["name"];

                            var instancePos = new Vector3((float)cMloInstance["position"]["x"], (float)cMloInstance["position"]["y"], (float)cMloInstance["position"]["z"]);
                            var instanceRot = new Quaternion((float)cMloInstance["rotation"]["x"], (float)cMloInstance["rotation"]["y"], (float)cMloInstance["rotation"]["z"], (float)cMloInstance["rotation"]["w"]);

                            for (int k = 0; k < Cache["ytyp"].Count; k++)
                            {
                                var cYtyp     = Cache["ytyp"][k];
                                var cYtypHash = (uint)cYtyp["hash"];

                                for (int l = 0; l < cYtyp["mloArchetypes"].Count; l++)
                                {
                                    var cMloArch     = cYtyp["mloArchetypes"][l];
                                    var cMloArchHash = (uint)cMloArch["name"];

                                    if (cMloInstanceHash == cMloArchHash)
                                    {
                                        Console.WriteLine("  ytyp => " + ((string)cYtyp["path"]).Split('\\').Last());
                                        Console.WriteLine("    mlo => " + Jenkins.GetString(cMloArchHash));
                                        Console.WriteLine("    position => " + instancePos.X.ToString(c) + "," + instancePos.Y.ToString(c) + "," + instancePos.Z.ToString(c));
                                        Console.WriteLine("    rotation => " + instanceRot.X.ToString(c) + "," + instanceRot.Y.ToString(c) + "," + instanceRot.Z.ToString(c) + "," + instanceRot.W.ToString(c));

                                        for (int m = 0; m < cMloArch["rooms"].Count; m++)
                                        {
                                            var cMloRoom = cMloArch["rooms"][m];

                                            var roomBbMin = new Vector3((float)cMloRoom["bbMin"]["x"], (float)cMloRoom["bbMin"]["y"], (float)cMloRoom["bbMin"]["z"]);
                                            var roomBbMax = new Vector3((float)cMloRoom["bbMax"]["x"], (float)cMloRoom["bbMax"]["y"], (float)cMloRoom["bbMax"]["z"]);

                                            var roomBbMinWorld = instancePos + roomBbMin;
                                            var roomBbMaxWorld = instancePos + roomBbMax;

                                            roomBbMinWorld = Utils.RotateTransform(Quaternion.Conjugate(instanceRot), roomBbMinWorld, Vector3.Zero);
                                            roomBbMaxWorld = Utils.RotateTransform(Quaternion.Conjugate(instanceRot), roomBbMaxWorld, Vector3.Zero);

                                            if (
                                                opts.Position[0] >= roomBbMinWorld.X && opts.Position[0] <= roomBbMaxWorld.X &&
                                                opts.Position[1] >= roomBbMinWorld.Y && opts.Position[1] <= roomBbMaxWorld.Y &&
                                                opts.Position[2] >= roomBbMinWorld.Z && opts.Position[2] <= roomBbMaxWorld.Z
                                                )
                                            {
                                                Console.WriteLine("      room => " + cMloRoom["name"]);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        Console.WriteLine("");
                    }
                }
            });

            CommandLine.Parse <BuildCacheOptions>(args, opts =>
            {
                dynamic cache = new JObject();

                cache["ymap"] = new JArray();
                cache["ytyp"] = new JArray();

                ArchiveUtilities.ForEachFile(Settings.Default.GTAFolder, (fullFileName, file, encryption) =>
                {
                    Console.WriteLine(fullFileName);

                    string fileNameWithoutExtension = file.Name.Split('.').First();

                    Jenkins.Ensure(fileNameWithoutExtension);

                    if (file.Name.EndsWith(".ymap"))
                    {
                        var ymap = new YmapFile();

                        using (MemoryStream ms = new MemoryStream())
                        {
                            file.Export(ms);
                            ymap.Load(ms);
                        }

                        dynamic entry = new JObject()
                        {
                            ["name"] = fileNameWithoutExtension,
                            ["path"] = fullFileName,
                            ["hash"] = Jenkins.Hash(fileNameWithoutExtension),
                            ["entitiesExtentsMin"] = new JObject()
                            {
                                ["x"] = ymap.CMapData.EntitiesExtentsMin.X,
                                ["y"] = ymap.CMapData.EntitiesExtentsMin.Y,
                                ["z"] = ymap.CMapData.EntitiesExtentsMin.Z,
                            },
                            ["entitiesExtentsMax"] = new JObject()
                            {
                                ["x"] = ymap.CMapData.EntitiesExtentsMax.X,
                                ["y"] = ymap.CMapData.EntitiesExtentsMax.Y,
                                ["z"] = ymap.CMapData.EntitiesExtentsMax.Z,
                            },
                            ["mloInstances"] = new JArray(),
                        };

                        if (ymap.CMapData.MloInstances != null)
                        {
                            for (int i = 0; i < ymap.CMapData.MloInstances.Count; i++)
                            {
                                var mloInstance = ymap.CMapData.MloInstances[i];

                                var mloInstanceEntry = new JObject()
                                {
                                    ["name"]     = ymap.CMapData.MloInstances[i].ArchetypeName,
                                    ["position"] = new JObject()
                                    {
                                        ["x"] = mloInstance.Position.X,
                                        ["y"] = mloInstance.Position.Y,
                                        ["z"] = mloInstance.Position.Z,
                                    },
                                    ["rotation"] = new JObject()
                                    {
                                        ["x"] = mloInstance.Rotation.X,
                                        ["y"] = mloInstance.Rotation.Y,
                                        ["z"] = mloInstance.Rotation.Z,
                                        ["w"] = mloInstance.Rotation.W,
                                    }
                                };

                                entry["mloInstances"].Add(mloInstanceEntry);
                            }
                        }

                        cache["ymap"].Add(entry);
                    }
                    else if (file.Name.EndsWith(".ytyp"))
                    {
                        var ytyp = new YtypFile();

                        using (MemoryStream ms = new MemoryStream())
                        {
                            file.Export(ms);
                            ytyp.Load(ms);
                        }

                        dynamic entry = new JObject()
                        {
                            ["name"]          = fileNameWithoutExtension,
                            ["path"]          = fullFileName,
                            ["hash"]          = Jenkins.Hash(fileNameWithoutExtension),
                            ["mloArchetypes"] = new JArray(),
                        };

                        if (ytyp.CMapTypes.MloArchetypes != null)
                        {
                            for (int i = 0; i < ytyp.CMapTypes.MloArchetypes.Count; i++)
                            {
                                var archetype = ytyp.CMapTypes.MloArchetypes[i];
                                var mloEntry  = new JObject
                                {
                                    ["name"]  = archetype.Name,
                                    ["rooms"] = new JArray(),
                                };

                                if (archetype.Rooms != null)
                                {
                                    for (int j = 0; j < archetype.Rooms.Count; j++)
                                    {
                                        var room      = archetype.Rooms[j];
                                        var roomEntry = new JObject
                                        {
                                            ["name"]  = room.Name,
                                            ["bbMin"] = new JObject()
                                            {
                                                ["x"] = room.BbMin.X,
                                                ["y"] = room.BbMin.Y,
                                                ["z"] = room.BbMin.Z,
                                            },
                                            ["bbMax"] = new JObject()
                                            {
                                                ["x"] = room.BbMax.X,
                                                ["y"] = room.BbMax.Y,
                                                ["z"] = room.BbMax.Z,
                                            }
                                        };

                                        ((JArray)mloEntry["rooms"]).Add(roomEntry);
                                    }
                                }

                                entry["mloArchetypes"].Add(mloEntry);
                            }
                        }

                        cache["ytyp"].Add(entry);
                    }
                });

                var jsonString = JsonConvert.SerializeObject(cache, new JsonSerializerSettings()
                {
                    Formatting = Newtonsoft.Json.Formatting.None
                });

                File.WriteAllText(AssemblyDirectory + "\\cache.json", jsonString);

                using (StreamWriter writer = new StreamWriter(AssemblyDirectory + "\\strings.txt"))
                {
                    foreach (var kvp in Jenkins.Index)
                    {
                        writer.Write(kvp.Value + "\n");
                    }
                }
            });

            if (args.Length == 0 || args[0] == "help")
            {
                Console.Error.Write(CommandLine.GenHelp());
                return;
            }
        }
Пример #16
0
        static void HandleExportMetaOptions(string[] args)
        {
            CommandLine.Parse <ExportMetaOptions>(args, (opts, gOpts) =>
            {
                if (opts.Metadata)
                {
                    Init(args);
                }
                else
                {
                    EnsurePath();
                    EnsureKeys();
                    EnsureCache();
                }

                if (opts.InputFiles == null)
                {
                    Console.WriteLine("Please provide input files with -i --input");
                    return;
                }
                else
                {
                    var inputFiles = Utils.Expand(opts.InputFiles);

                    for (int i = 0; i < inputFiles.Length; i++)
                    {
                        var fileInfo = inputFiles[i];

                        Console.WriteLine(fileInfo.FullName);

                        MetaFile meta = null;

                        if (fileInfo.Name.EndsWith(".ymap") && opts.Metadata)
                        {
                            var ymap = new YmapFile();

                            ymap.Load(fileInfo.FullName);

                            meta = ymap.ResourceFile.ResourceData;

                            var basePath      = Path.GetDirectoryName(fileInfo.FullName);
                            var topParent     = ImportMeta_GetTopYmapParent((uint)ymap.CMapData.Name);
                            var topParentHash = (uint)topParent["hash"];
                            var topParentName = (string)topParent["name"];
                            var topParentPath = (string)topParent["path"];
                            var topParentYmap = new YmapFile();

                            Console.WriteLine("Top parent is " + topParentName);

                            if (File.Exists(basePath + "\\" + topParentName + ".ymap"))
                            {
                                topParentYmap.Load(basePath + "\\" + topParentName + ".ymap");
                            }
                            else
                            {
                                ArchiveUtilities.ForEachResourceFile(Settings.Default.GTAFolder, (fullFileName, file, encryption) =>
                                {
                                    if (fullFileName == topParentPath)
                                    {
                                        var ms = new MemoryStream();
                                        file.Export(ms);
                                        topParentYmap.Load(ms);
                                    }
                                });
                            }

                            var children = ImportMeta_GetYmapChildrens(topParent);
                            var ymaps    = new List <YmapFile>()
                            {
                                topParentYmap
                            };
                            var nameHashes = new Dictionary <uint, string>();

                            nameHashes.Add((uint)topParent["hash"], (string)topParent["name"]);

                            for (int j = 0; j < children.Count; j++)
                            {
                                var cYmap = new YmapFile();
                                var child = children[j];
                                var hash  = (uint)child["hash"];
                                var name  = (string)child["name"];
                                var path  = (string)child["path"];

                                nameHashes.Add(hash, name);

                                if (File.Exists(basePath + "\\" + name + ".ymap"))
                                {
                                    cYmap.Load(basePath + "\\" + name + ".ymap");
                                }
                                else
                                {
                                    Console.WriteLine("Grabbing missing " + name + " from install directory (very slowly, needs optimization)");

                                    ArchiveUtilities.ForEachResourceFile(Settings.Default.GTAFolder, (fullFileName, file, encryption) =>
                                    {
                                        if (fullFileName == path)
                                        {
                                            var ms = new MemoryStream();

                                            file.Export(ms);

                                            cYmap.Load(ms);
                                        }
                                    });
                                }

                                ymaps.Add(cYmap);
                            }

                            ymaps[ymaps.FindIndex(e => e.CMapData.Name == ymap.CMapData.Name)] = ymap;

                            for (int j = 0; j < ymaps.Count; j++)
                            {
                                ymaps[j].CMapData.ParentMapData = ymaps.Find(e => e.CMapData.Name == ymaps[j].CMapData.Parent)?.CMapData;
                            }

                            for (int j = 0; j < ymaps.Count; j++)
                            {
                                var ymap2   = ymaps[j];
                                var mapping = new Dictionary <uint, int>();
                                var name    = nameHashes[(uint)ymap2.CMapData.Name];

                                ymap2.Save(basePath + "\\" + name + ".ymap");

                                var data = new JObject
                                {
                                    ["mapping"] = new JArray()
                                };

                                var dataMapping = (JArray)(data["mapping"]);

                                for (int k = 0; k < ymap2.CMapData.Entities.Count; k++)
                                {
                                    var entity = ymap2.CMapData.Entities[k];

                                    if (mapping.ContainsKey(entity.Guid))
                                    {
                                        Console.WriteLine("Duplicate GUID found => " + entity.Guid + " at index " + j + " ABORTING");
                                        return;
                                    }
                                    else
                                    {
                                        mapping.Add(entity.Guid, k);

                                        var entry = new JObject()
                                        {
                                            ["guid"]      = entity.Guid,
                                            ["hasParent"] = entity.ParentIndex != -1,
                                        };

                                        if (entity.ParentIndex != -1)
                                        {
                                            entry["parent"]     = entity.ParentEntity.Guid;
                                            entry["parentName"] = MetaXml.HashString((MetaName)entity.ParentEntity.Guid);
                                            entry["parentYmap"] = nameHashes[(uint)entity.ParentEntity.Parent.Name];
                                        }

                                        dataMapping.Add(entry);
                                    }
                                }

                                var jsonString = JsonConvert.SerializeObject(data, new JsonSerializerSettings()
                                {
                                    Formatting = Newtonsoft.Json.Formatting.Indented
                                });

                                File.WriteAllText(basePath + "\\" + name + ".ymap.json", jsonString);
                            }
                        }
                        else
                        {
                            var res = new ResourceFile_GTA5_pc <MetaFile>();
                            res.Load(fileInfo.FullName);
                            meta = res.ResourceData;
                        }

                        var xml = MetaXml.GetXml(meta);

                        string fileName = fileInfo.FullName + ".xml";

                        File.WriteAllText(fileName, xml);
                    }
                }
            });
        }
Пример #17
0
 public void LoadMeta(Meta meta)
 {
     Xml      = MetaXml.GetXml(meta);
     modified = false;
 }
Пример #18
0
 /// <summary>
 /// 主文件 子文件 的公用 Meta
 /// </summary>
 /// <param name="obj"></param>
 public void Toxml_Meta(MetaXml obj)
 {
     try
     {
         string        fileName = GetFileName(obj);
         XmlDocument   xmldoc   = new XmlDocument();
         StringBuilder sb       = new StringBuilder();
         sb.Append(@"<?xml version='1.0' encoding='UTF-8' ?>");
         sb.Append(@"<snapshotResource>");
         sb.Append(GenerHead(obj._head));
         sb.Append(@"<meta>");
         if (obj != null)
         {
             if (obj._meta != null)
             {
                 if (obj._meta._metadata != null && obj._meta._metadata.Count > 0)
                 {
                     for (int i = 0; i < obj._meta._metadata.Count; i++)
                     {
                         if (obj._meta._metadata[i].ObjSub != null && obj._meta._metadata[i].ObjSub.text != null)
                         {
                             if (obj._meta._metadata[i].Attr_citm_id != null && obj._meta._metadata[i].Attr_citm_id != "")
                             {
                                 if (!string.IsNullOrEmpty(obj._meta._metadata[i].Attr_doc_id) && !string.IsNullOrEmpty(obj._meta._metadata[i].Attr_content))
                                 {
                                     if (!string.IsNullOrEmpty(obj._meta._metadata[i].Attr_url))
                                     {
                                         sb.Append(@"<metadata type='" + obj._meta._metadata[i].Attr_type + "' citm_id= '" + obj._meta._metadata[i].Attr_citm_id + "' doc_id= '" + obj._meta._metadata[i].Attr_doc_id + "' url= '" + obj._meta._metadata[i].Attr_url + "' content= '" + obj._meta._metadata[i].Attr_content + "'><title>" + obj._meta._metadata[i].ObjSub.text + "</title></metadata>");
                                     }
                                     else
                                     {
                                         sb.Append(@"<metadata type='" + obj._meta._metadata[i].Attr_type + "' citm_id= '" + obj._meta._metadata[i].Attr_citm_id + "' doc_id= '" + obj._meta._metadata[i].Attr_doc_id + "' content= '" + obj._meta._metadata[i].Attr_content + "'><title>" + obj._meta._metadata[i].ObjSub.text + "</title></metadata>");
                                     }
                                 }
                                 else
                                 {
                                     sb.Append(@"<metadata type='" + obj._meta._metadata[i].Attr_type + "' citm_id= '" + obj._meta._metadata[i].Attr_citm_id + "'><text>" + obj._meta._metadata[i].ObjSub.text + "</text></metadata>");
                                 }
                             }
                             else
                             {
                                 sb.Append(@"<metadata type='" + obj._meta._metadata[i].Attr_type + "'><text>" + obj._meta._metadata[i].ObjSub.text + "</text></metadata>");
                             }
                         }
                         if (obj._meta._metadata[i].ObjMain != null && obj._meta._metadata[i].ObjMain._paragraph != null)
                         {
                             sb.Append(@"<metadata type='" + obj._meta._metadata[i].Attr_type + "' citm_id= '" + obj._meta._metadata[i].Attr_citm_id + "' hasMeta='" + obj._meta._metadata[i].Attr_hasMeta + "'><text><paragraph type='" + obj._meta._metadata[i].ObjMain._paragraph.Attr_type + "' num='" + obj._meta._metadata[i].ObjMain._paragraph.Attr_num + "'><markupText>" + obj._meta._metadata[i].ObjMain._paragraph.markupText + "</markupText></paragraph></text></metadata>");
                         }
                     }
                 }
             }
         }
         sb.Append(@"</meta>");
         sb.Append(@"</snapshotResource>");
         xmldoc.LoadXml(sb.ToString());
         xmldoc.Save(fileName + ".xml");
     }
     catch (Exception ex)
     {
         throw;
     }
 }