예제 #1
0
        public void Init()
        {
            var backup = Application.StartupPath + "/Backups/";

            Instance.BackupFolder = backup;

            Mods.Clear();
            if (Directory.Exists(Instance.ModFolder))
            {
                var dirs = Directory.GetDirectories(Instance.ModFolder);
                foreach (var d in dirs)
                {
                    var mod = ModInfo.Create(d);
                    if (mod == null)
                    {
                        continue;
                    }

                    mod.Enabled = BuildSettings.EnableAllMods || EnabledMods == null || EnabledMods.Contains(mod.Name);
                    Mods.Add(mod);
                }
            }
        }
예제 #2
0
        public static ModInfo Create(string directory)
        {
            var ret = new ModInfo();

            //ret.Location = directory;
            ret.FolderName  = new DirectoryInfo(directory).Name;
            ret.Enabled     = true;
            ret.Name        = "Unknown";
            ret.Author      = "Unknown";
            ret.Description = "None";
            ret.ModVersion  = "0.0";
            ret.IsValid     = false;


            bool   hasModFile     = false;
            bool   hasModInfoFile = false;
            string modXmlPath     = Path.Combine(directory, "mod.xml");

            if (hasModFile = File.Exists(modXmlPath))
            {
                var configDoc = new XmlDocument();
                configDoc.Load(modXmlPath);
                ret.IsValid = ret.FromSdxModFileXml(modXmlPath, configDoc);
            }


            string modInfoPath = Path.Combine(directory, "ModInfo.xml");

            if (hasModFile && !File.Exists(modInfoPath))
            {
                File.WriteAllText(modInfoPath, $@"<?xml version=""1.0"" encoding=""UTF-8""?>
<xml>
  <ModInfo>
    <Name value=""{ret.Name}"" />
    <Description value=""{ret.Description}"" />
    <Author value=""{ret.Author}"" />
    <Version value=""{ret.ModVersion}"" />
    <Website value=""{ret.Website}"" />
  </ModInfo>
  <DMT>
    <dependencies />
    <conflicts />
  </DMT>
</xml>
");
            }

            if (hasModInfoFile = File.Exists(modInfoPath))
            {
                var configDoc = new XmlDocument();
                configDoc.Load(modInfoPath);
                ret.IsValid = ret.FromModInfoXml(modInfoPath, configDoc, hasModFile);
            }

            if (!hasModFile && !hasModInfoFile)
            {
                return(null);
            }

            return(ret);
        }