Ejemplo n.º 1
0
 public ModMetadata(ModProject project)
 {
     Title             = project.Title;
     Description       = project.Description;
     SteamPublishId    = project.SteamPublishId;
     RequiresExpansion = project.Edition.IsExpansion;
 }
Ejemplo n.º 2
0
        private static void NewGuid(List <string> args, XCom2Edition edition)
        {
            if (!LocateMod(args, out ModInfo modInfo) || args.Count > 0)
            {
                HelpNewGuid();
                return;
            }

            var project = ModProject.Load(modInfo, edition);

            project.Id = Guid.NewGuid();
            project.Save(modInfo.ProjectPath);
        }
Ejemplo n.º 3
0
        public static ModProject Load(ModInfo modInfo, XCom2Edition edition)
        {
            if (PathHelper.IsRelative(modInfo.ProjectPath))
            {
                throw new InvalidOperationException($"The project path is a relative path");
            }

            var document   = XDocument.Parse(File.ReadAllText(modInfo.ProjectPath));
            var properties = document.Root.GetElementsByLocalName(XmlPropertyGroup).First();

            var folderPath = Path.GetDirectoryName(modInfo.ProjectPath);
            var itemGroups = document.Root.GetElementsByLocalName(XmlItemGroup);

            var folders = itemGroups.SelectMany(x => x.GetElementsByLocalName(XmlFolder))
                          .Select(x => x.GetAttributeByLocalName(XmlInclude).Value)
                          .Select(x => PathHelper.MakeAbsolute(x, folderPath))
                          .Select(x => DirectoryHelper.GetExactPathName(x));

            var content = itemGroups.SelectMany(x => x.GetElementsByLocalName(XmlContent))
                          .Select(x => x.GetAttributeByLocalName(XmlInclude).Value)
                          .Select(x => PathHelper.MakeAbsolute(x, folderPath))
                          .Select(x => DirectoryHelper.GetExactPathName(x));

            var project = new ModProject
            {
                ModInfo        = modInfo,
                Edition        = edition,
                Id             = Guid.Parse(properties.GetElementByLocalName(XmlGuid).Value),
                Title          = properties.GetElementByLocalName(XmlTitle).Value,
                Description    = properties.GetElementByLocalName(XmlDescription).Value,
                AssemblyName   = properties.GetElementByLocalName(XmlAssemblyName).Value,
                RootNamespace  = properties.GetElementByLocalName(XmlRootNamespace).Value,
                SteamPublishId = ulong.Parse(properties.GetElementByLocalName(XmlSteamPublishId).Value, NumberStyles.None, CultureInfo.InvariantCulture),
                Folders        = folders.ToArray(),
                Content        = content.ToArray()
            };

            return(project);
        }
Ejemplo n.º 4
0
        public void Build(ModBuildType buildType)
        {
            Report.Verbose($"{buildType} build of {modInfo.ModName}");

            // Load project first, to check folder structure is as we expect before we start moving files.
            Report.Verbose("Loading project");
            modProject = ModProject.Load(modInfo, edition);

            if (!string.Equals(modProject.Title, modInfo.ModName, StringComparison.Ordinal))
            {
                Report.Warning($"Mod name {modInfo.ModName} does not match title '{modProject.Title}' in project {modInfo.ProjectName}");
            }

            // Switching between building with/without the highlander requires a full build.
            if (IsSdkBuiltWithHighlander() != Settings.Default.Highlander)
            {
                var highlander = Settings.Default.Highlander;
                Report.Warning($"This is a {(highlander ? "" : "non-")}highlander build, but {KeyStandardPackageCompiledScriptFileName} was {(highlander ? "not " : "")}built with the highlander; switching to full build");
                buildType = ModBuildType.Full;
            }
            else
            {
                var highlander = Settings.Default.Highlander;
                Report.Verbose($"This is a {(highlander ? "" : "non-")}highlander build, as is {KeyStandardPackageCompiledScriptFileName}");
            }

            CleanModStaging();
            ThrowIfCancelled();

            CleanSdkMods();
            Directory.CreateDirectory(modStagingPath);
            StageModFolder(ModInfo.SourceCodeFolder);
            StageModFolder(ModInfo.ConfigFolder);
            StageModFolder(ModInfo.LocalizationFolder);
            StageModFolder(ModInfo.ContentFolder);
            StageModMetadata();
            ThrowIfCancelled();

            if (modHasSourceCode)
            {
                switch (buildType)
                {
                case ModBuildType.Full:
                    CleanSdkSourceCode();
                    RestoreSdkSourceCode();
                    CopyModSourceCodeToSdk();
                    CleanSdkCompiledScripts();
                    CompileGame();
                    break;

                case ModBuildType.Fast:
                    CleanSdkSourceCode();
                    RestoreSdkSourceCode();
                    CopyModSourceCodeToSdk();
                    CleanModSdkCompiledScripts();
                    CompileGame();
                    break;

                case ModBuildType.Smart:
                    var flags = GetBuiltStandardPackageFlags();
                    if (!flags.HasValue)
                    {
                        Report.Verbose($"{KeyStandardPackageCompiledScriptFileName} invalid or not found, switching to full build");
                        goto case ModBuildType.Full;
                    }
                    if (Settings.Default.Debug != flags.Value.HasFlag(PackageFlags.Debug))
                    {
                        Settings.Default.Debug = !Settings.Default.Debug;
                        Report.Verbose($"Detected {(Settings.Default.Debug ? "debug" : "release")} build of {KeyStandardPackageCompiledScriptFileName}");
                    }
                    SmartCleanSdkSourceCode();
                    CopyModSourceCodeToSdk();
                    SmartCleanSdkCompiledScripts();
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(buildType));
                }

                CompileMod();
                if (modHasShaderContent)
                {
                    switch (buildType)
                    {
                    case ModBuildType.Full:
                    case ModBuildType.Fast:
                        CompileShaders();
                        break;

                    case ModBuildType.Smart:
                        if (IsDeployedShaderCacheUpToDate())
                        {
                            CopyDeployedShaderCacheToStaging();
                        }
                        else
                        {
                            CompileShaders();
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(buildType));
                    }
                }
                StageModCompiledScripts();
                SmartCleanSdkSourceCode();
            }

            DeployMod();
        }
Ejemplo n.º 5
0
 public static void Save(ModProject project, string path) => new ModMetadata(project).Save(path);