Пример #1
0
        static bool RecursivelyCheckDependencies(string DatabaseItem, string DestinationFilename, Module mod)
        {
            MpqManager manager;

            byte[] file = null;

            if (File.Exists(mod.FileName))
            {
                manager = new MpqManager(mod.FileName);
                if (manager.MpqArchive.FileExists(mod.SubPath + "Base.SC2Assets\\" + DatabaseItem))
                {
                    file = manager.read(mod.SubPath + "Base.SC2Assets\\" + DatabaseItem);
                }
                else if (manager.MpqArchive.FileExists("Base.SC2Assets\\" + DatabaseItem))
                {
                    file = manager.read("Base.SC2Assets\\" + DatabaseItem);
                }

                if (file != null)
                {
                    using (FileStream fs = File.Create(DestinationFilename))
                    {
                        fs.Write(file, 0, file.Length);
                        fs.Close();
                    }
                    manager.Close();
                    return(true);
                }
                manager.Close();
            }
            else if (File.Exists(mod.FileName + "\\Base.SC2Assets"))
            {
                manager = new MpqManager(mod.FileName + "\\Base.SC2Assets");
                if (manager.MpqArchive.FileExists(DatabaseItem))
                {
                    file = manager.read(DatabaseItem);

                    using (FileStream fs = File.Create(DestinationFilename))
                    {
                        fs.Write(file, 0, file.Length);
                        fs.Close();
                    }
                    manager.Close();
                    return(true);
                }
                manager.Close();
            }

            for (int i = mod.Dependencies.Count - 1; i >= 0; i--)
            {
                if (RecursivelyCheckDependencies(DatabaseItem, DestinationFilename, mod.Dependencies[i]))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        public void Parse(string fileName)
        {
            try
            {
                if (fileName == null)
                {
                    fileName = string.Empty;
                }

                MpqManager manager = null;

                if (File.Exists(fileName))
                {
                    manager   = new MpqManager(fileName);
                    _FileName = fileName;
                }
                else if (Directory.Exists(fileName))
                {
                    _FileName = fileName;
                }
                else
                {
                    if (fileName.StartsWith("Mods\\") || fileName.StartsWith("Campaigns\\"))
                    {
                        fileName = GameData.SC2FilePath.Remove(GameData.SC2FilePath.LastIndexOf("Versions")) + fileName;
                        if (File.Exists(fileName))
                        {
                            manager   = new MpqManager(fileName);
                            _FileName = fileName;
                        }
                        else if (Directory.Exists(fileName))
                        {
                            _FileName = fileName;
                        }
                    }
                    if (fileName.Contains("Maps\\"))
                    {
                        string Folder = fileName.Remove(fileName.IndexOf("Maps")) + "Campaigns";
                        string Path   = fileName.Remove(0, fileName.IndexOf("Maps\\")).Replace('/', '\\') + "\\";
                        foreach (string s in Directory.GetFiles(Folder, "*.SC2Maps", SearchOption.AllDirectories))
                        {
                            manager = new MpqManager(s);
                            if (manager.MpqArchive.FileExists(Path + "DocumentInfo"))
                            {
                                _FileName = s;
                                _SubPath  = Path;
                                break;
                            }
                            else
                            {
                                manager.Close();
                                manager = null;
                            }
                        }
                    }
                }

                if (manager != null)
                {
                    string   DocumentInfo = System.Text.Encoding.UTF8.GetString(manager.read(_SubPath + "DocumentInfo"));
                    XElement DocInfo      = XElement.Parse(DocumentInfo);

                    foreach (XElement dependency in DocInfo.Element("Dependencies").Elements("Value"))
                    {
                        string Value = dependency.Value;
                        _Dependencies.Add(new Module(Value.Remove(0, Value.IndexOf("file:") + 5).Replace('/', '\\')));
                    }
                }
                else if (_FileName.Contains("Swarm") && (File.Exists(_FileName.Replace("Swarm", "Liberty")) || Directory.Exists(_FileName.Replace("Swarm", "Liberty"))))
                {
                    _Dependencies.Add(new Module(_FileName.Replace("Swarm", "Liberty")));
                }

                string GameDataPath = _SubPath + "Base.SC2Data\\GameData\\";
                if (manager == null && File.Exists(_FileName + "\\Base.SC2Data"))
                {
                    manager      = new MpqManager(_FileName + "\\Base.SC2Data");
                    GameDataPath = _SubPath + "GameData\\";
                }

                if (manager != null)
                {
                    foreach (MpqEntry entry in manager.MpqArchive)
                    {
                        if (entry.Filename != null && entry.Filename.StartsWith(GameDataPath) && entry.Filename.EndsWith(".xml"))
                        {
                            string Name     = entry.Filename.Replace(GameDataPath, "").Replace(".xml", "");
                            string DataFile = System.Text.Encoding.UTF8.GetString(manager.read(entry.Filename));
                            _DataFiles.Add(Name, new DataFile(Name, DataFile));
                        }
                    }

                    manager.Close();
                }
            }
            catch (Exception ex)
            { }
        }