Example #1
0
        /*********
        ** Public methods
        *********/
        /// <summary>When overridden in a derived class, executes the task.</summary>
        /// <returns>true if the task successfully executed; otherwise, false.</returns>
        public override bool Execute()
        {
            // log build settings
            {
                var properties = this
                                 .GetPropertiesToLog()
                                 .Select(p => $"{p.Key}: {p.Value}");
                this.Log.LogMessage(MessageImportance.High, $"[mod build package] Handling build with options {string.Join(", ", properties)}");
            }

            if (!this.EnableModDeploy && !this.EnableModZip)
            {
                return(true); // nothing to do
            }
            try
            {
                // parse extra DLLs to bundle
                ExtraAssemblyTypes bundleAssemblyTypes = this.GetExtraAssembliesToBundleOption();

                // parse ignore patterns
                string[] ignoreFilePaths    = this.GetCustomIgnoreFilePaths().ToArray();
                Regex[]  ignoreFilePatterns = this.GetCustomIgnorePatterns().ToArray();

                // get mod info
                ModFileManager package = new ModFileManager(this.ProjectDir, this.TargetDir, ignoreFilePaths, ignoreFilePatterns, bundleAssemblyTypes, this.ModDllName, validateRequiredModFiles: this.EnableModDeploy || this.EnableModZip);

                // deploy mod files
                if (this.EnableModDeploy)
                {
                    string outputPath = Path.Combine(this.GameModsDir, this.EscapeInvalidFilenameCharacters(this.ModFolderName));
                    this.Log.LogMessage(MessageImportance.High, $"[mod build package] Copying the mod files to {outputPath}...");
                    this.CreateModFolder(package.GetFiles(), outputPath);
                }

                // create release zip
                if (this.EnableModZip)
                {
                    string zipName = this.EscapeInvalidFilenameCharacters($"{this.ModFolderName} {package.GetManifestVersion()}.zip");
                    string zipPath = Path.Combine(this.ModZipPath, zipName);

                    this.Log.LogMessage(MessageImportance.High, $"[mod build package] Generating the release zip at {zipPath}...");
                    this.CreateReleaseZip(package.GetFiles(), this.ModFolderName, zipPath);
                }

                return(true);
            }
            catch (UserErrorException ex)
            {
                this.Log.LogErrorFromException(ex);
                return(false);
            }
            catch (Exception ex)
            {
                this.Log.LogError($"[mod build package] Failed trying to deploy the mod.\n{ex}");
                return(false);
            }
        }
Example #2
0
        /*********
        ** Public methods
        *********/
        /// <summary>When overridden in a derived class, executes the task.</summary>
        /// <returns>true if the task successfully executed; otherwise, false.</returns>
        public override bool Execute()
        {
            if (!this.EnableModDeploy && !this.EnableModZip)
            {
                return(true); // nothing to do
            }
            try
            {
                // validate context
                if (!this.ValidPlatforms.Contains(this.Platform))
                {
                    throw new UserErrorException($"The mod build package doesn't recognise OS type '{this.Platform}'.");
                }
                if (!Directory.Exists(this.GameDir))
                {
                    throw new UserErrorException("The mod build package can't find your game path. See https://github.com/Pathoschild/SMAPI/blob/develop/docs/mod-build-config.md for help specifying it.");
                }
                if (!File.Exists(Path.Combine(this.GameDir, this.GameExeName)))
                {
                    throw new UserErrorException($"The mod build package found a game folder at {this.GameDir}, but it doesn't contain the {this.GameExeName} file. If this folder is invalid, delete it and the package will autodetect another game install path.");
                }
                if (!File.Exists(Path.Combine(this.GameDir, this.SmapiExeName)))
                {
                    throw new UserErrorException($"The mod build package found a game folder at {this.GameDir}, but it doesn't contain SMAPI. You need to install SMAPI before building the mod.");
                }

                // get mod info
                ModFileManager package = new ModFileManager(this.ProjectDir, this.TargetDir);

                // deploy mod files
                if (this.EnableModDeploy)
                {
                    string outputPath = Path.Combine(this.GameDir, "Mods", this.EscapeInvalidFilenameCharacters(this.ModFolderName));
                    this.Log.LogMessage(MessageImportance.High, $"The mod build package is copying the mod files to {outputPath}...");
                    this.CreateModFolder(package.GetFiles(), outputPath);
                }

                // create release zip
                if (this.EnableModZip)
                {
                    this.Log.LogMessage(MessageImportance.High, $"The mod build package is generating a release zip at {this.ModZipPath} for {this.ModFolderName}...");
                    this.CreateReleaseZip(package.GetFiles(), this.ModFolderName, package.GetManifestVersion(), this.ModZipPath);
                }

                return(true);
            }
            catch (UserErrorException ex)
            {
                this.Log.LogErrorFromException(ex);
                return(false);
            }
            catch (Exception ex)
            {
                this.Log.LogError($"The mod build package failed trying to deploy the mod.\n{ex}");
                return(false);
            }
        }
Example #3
0
        /*********
        ** Public methods
        *********/
        /// <summary>When overridden in a derived class, executes the task.</summary>
        /// <returns>true if the task successfully executed; otherwise, false.</returns>
        public override bool Execute()
        {
            if (!this.EnableModDeploy && !this.EnableModZip)
            {
                return(true); // nothing to do
            }
            try
            {
                // parse ignore patterns
                Regex[] ignoreFilePatterns = this.GetCustomIgnorePatterns().ToArray();

                // get mod info
                ModFileManager package = new ModFileManager(this.ProjectDir, this.TargetDir, ignoreFilePatterns, validateRequiredModFiles: this.EnableModDeploy || this.EnableModZip);

                // deploy mod files
                if (this.EnableModDeploy)
                {
                    string outputPath = Path.Combine(this.GameDir, "Mods", this.EscapeInvalidFilenameCharacters(this.ModFolderName));
                    this.Log.LogMessage(MessageImportance.High, $"The mod build package is copying the mod files to {outputPath}...");
                    this.CreateModFolder(package.GetFiles(), outputPath);
                }

                // create release zip
                if (this.EnableModZip)
                {
                    this.Log.LogMessage(MessageImportance.High, $"The mod build package is generating a release zip at {this.ModZipPath} for {this.ModFolderName}...");
                    this.CreateReleaseZip(package.GetFiles(), this.ModFolderName, package.GetManifestVersion(), this.ModZipPath);
                }

                return(true);
            }
            catch (UserErrorException ex)
            {
                this.Log.LogErrorFromException(ex);
                return(false);
            }
            catch (Exception ex)
            {
                this.Log.LogError($"The mod build package failed trying to deploy the mod.\n{ex}");
                return(false);
            }
        }