Пример #1
0
        private static void ListFolders(XCom2Edition edition, string command)
        {
            Report.WriteLine("Names:");
            var folders = XCom2Browser.GetFolders();
            var length  = folders.Max(x => x.name.Length) + 2;

            foreach (var folder in folders)
            {
                var indent = new string(' ', length - folder.name.Length);
                Report.WriteLine($"  {folder.name}{indent}{folder.describe(edition)}");
                if (Report.Verbosity >= Verbosity.Verbose)
                {
                    indent = new string(' ', length);
                    string path;
                    try
                    {
                        path = folder.getPath(edition);
                    }
                    catch (Exception ex)
                    {
                        path = $"{ex.Message}";
                    }
                    Report.Verbose($"  {indent}{path}");
                    if (folder != folders.Last())
                    {
                        Report.WriteLine();
                    }
                }
            }
            if (Report.Verbosity < Verbosity.Verbose)
            {
                Report.WriteLine();
                Report.WriteLine($"Use '{Name} --verbose {command}' to see folder paths.");
            }
        }
Пример #2
0
 private static void HelpOpen(XCom2Edition edition)
 {
     Report.WriteLine("To open a specific XCOM 2 folder or program:");
     Report.WriteLine($"{Name} open \\<name>");
     Report.WriteLine();
     ListFolders(edition, "open");
 }
Пример #3
0
 private static void HelpClip(XCom2Edition edition)
 {
     Report.WriteLine("To copy a specific XCOM 2 path to the clipboard:");
     Report.WriteLine($"{Name} clip \\<name>");
     Report.WriteLine();
     ListFolders(edition, "clip");
 }
Пример #4
0
        private static void Help(XCom2Edition edition)
        {
            var indent = new string(' ', Name.Length);

            Report.WriteLine($"usage: <green>{Name}</green> [--version ] [ -v | --verbose ]");
            Report.WriteLine($"       {indent} [options]");
            Report.WriteLine($"       {indent} \\<command> [\\<args>]");
            Report.WriteLine();
            Report.WriteLine($"Options vary by command; see '{Name} help \\<command>'.");
            Report.WriteLine();
            Report.WriteLine($"Currently working on {edition.DisplayName}.");
            Report.WriteLine();
            Report.WriteLine("Commands:");
            Report.WriteLine("  <yellow>help</yellow>                  Display help on a command");
            Report.WriteLine($"  <yellow>wotc</yellow> | <yellow>base</yellow> | <yellow>legacy</yellow>  Switch between game editions");
            Report.WriteLine("  <yellow>create</yellow>                Create a mod");
            Report.WriteLine("  <yellow>rename</yellow>                Rename a mod");
            Report.WriteLine("  <yellow>build</yellow>                 Build a mod");
            Report.WriteLine("  <yellow>open</yellow>                  Open a specific game folder");
            Report.WriteLine("  <yellow>clip</yellow>                  Copy a specific game folder to the clipboard");
            Report.WriteLine("  <yellow>update-project</yellow>        Update a mod's project file");
            Report.WriteLine("  <yellow>new-guid</yellow>              Generate a new GUID for a mod");
            Report.WriteLine("  <yellow>package-info</yellow>          Display info on an Unreal package");
            Report.WriteLine("  <yellow>save-info</yellow>             Display info on a save file");
            Report.WriteLine();
            Paths();
        }
Пример #5
0
        private static void SetEdition(List <string> args, XCom2Edition edition)
        {
            if (args.Count != 0)
            {
                HelpSetEdition();
                return;
            }

            Settings.Default.Edition = edition;
        }
Пример #6
0
        private static void BuildClean(List <string> args, XCom2Edition edition, CancellationToken cancellation)
        {
            if (!LocateMod(args, out ModInfo modInfo) || args.Count > 0)
            {
                HelpBuild();
                return;
            }

            var builder = new ModBuilder(modInfo, edition, cancellation);

            builder.Clean();
        }
Пример #7
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);
        }
Пример #8
0
 public ModBuilder(ModInfo modInfo, XCom2Edition edition, CancellationToken cancellation)
 {
     this.modInfo                       = modInfo;
     this.edition                       = edition;
     this.cancellation                  = cancellation;
     compiler                           = new Compiler(edition);
     modStagingPath                     = edition.GetModStagingPath(modInfo);
     modInstallPath                     = edition.GetModInstallPath(modInfo);
     modShaderCacheStagingPath          = edition.GetModShaderCacheStagingPath(modInfo);
     modShaderCacheInstallPath          = edition.GetModShaderCacheInstallPath(modInfo);
     modHasSourceCode                   = modInfo.HasSourceCode();
     modHasShaderContent                = modInfo.HasShaderContent();
     modStagingCompiledScriptFolderPath = Path.Combine(modStagingPath, ScriptFolderName);
     modSdkCompiledScriptPath           = Path.Combine(edition.SdkXComGameCompiledScriptPath, modInfo.ModName + ScriptExtension);
     modStagingCompiledScriptFilePath   = Path.Combine(modStagingCompiledScriptFolderPath, modInfo.ModName + ScriptExtension);
     compiler.ReplacePaths.Add(edition.SdkSourceCodePath, modInfo.SourceCodePath);
 }
Пример #9
0
        private static void Clip(List <string> args, XCom2Edition edition)
        {
            if (args.Count != 1)
            {
                HelpClip(edition);
                return;
            }

            var folder = args[0];

            try
            {
                XCom2Browser.CopyToClipboard(folder, edition);
            }
            catch (ArgumentOutOfRangeException)
            {
                throw new InvalidOperationException($"'{folder}' is not a recognized folder. See '{Name} help clip'.");
            }
        }
Пример #10
0
        private static void Build(List <string> args, XCom2Edition edition, CancellationToken cancellation)
        {
            if (args.Count > 0 && args[0] == "clean")
            {
                args.RemoveAt(0);
                BuildClean(args, edition, cancellation);
                return;
            }

            var buildType = ModBuildType.Smart;

            while (args.Count > 0)
            {
                if (args[0] == "full")
                {
                    buildType = ModBuildType.Full;
                }
                else if (args[0] == "fast")
                {
                    buildType = ModBuildType.Fast;
                }
                else if (args[0] == "smart")
                {
                    buildType = ModBuildType.Smart;
                }
                else
                {
                    break;
                }
                args.RemoveAt(0);
            }

            if (!LocateMod(args, out ModInfo modInfo) || args.Count > 0)
            {
                HelpBuild();
                return;
            }

            var builder = new ModBuilder(modInfo, edition, cancellation);

            builder.Build(buildType);
        }
Пример #11
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);
        }
Пример #12
0
        private static void Help(List <string> args, XCom2Edition edition)
        {
            var command = args.Count > 0 ? args[0] : string.Empty;
            var help    = command switch
            {
                "wotc" => HelpSetEdition,
                "base" => HelpSetEdition,
                "legacy" => HelpSetEdition,
                "create" => HelpCreate,
                "rename" => HelpRename,
                "build" => HelpBuild,
                "open" => () => HelpOpen(edition),
                "clip" => () => HelpClip(edition),
                "update-project" => HelpUpdateProject,
                "new-guid" => HelpNewGuid,
                "package-info" => HelpPackageInfo,
                "save-info" => HelpSaveInfo,
                _ => new Action(() => Help(edition)),
            };

            help();
            return;
        }
Пример #13
0
 public Compiler(XCom2Edition edition)
 {
     this.edition = edition;
 }