Esempio n. 1
0
        /// <summary>
        /// Converts a mod archive (zip) into a NuGet package.
        /// </summary>
        /// <returns>The location of the newly created package.</returns>
        public static string FromArchiveFile(string archivePath, string outputDirectory)
        {
            var archiveFile = new ArchiveFile(archivePath);
            var modConfig   = JsonSerializer.Deserialize <ModConfig>(archiveFile.ExtractModConfig());

            SetNullPropertyValues(modConfig);

            // Create output directories.
            var directory = GetDirectory;

            if (Directory.Exists(directory))
            {
                Directory.Delete(directory, true);
            }

            var contentDirectory = $"{directory}\\{NugetContentDirectory}";

            Directory.CreateDirectory(contentDirectory);

            // Extract
            archiveFile.ExtractToDirectory(contentDirectory);
            var nugetPackageOutput = FromModDirectory(contentDirectory, outputDirectory, modConfig);

            Directory.Delete(directory, true);
            return(nugetPackageOutput);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a NuGet package given the directory of a mod.
        /// </summary>
        /// <param name="modDirectory">Full path to the directory containing the mod.</param>
        /// <param name="outputDirectory">The path to the folder where the NuGet package should be output.</param>
        /// <param name="modConfig">The mod configuration for which to create the NuGet package.</param>
        /// <returns>The path of the generated .nupkg file.</returns>
        public static string FromModDirectory(string modDirectory, string outputDirectory, IModConfig modConfig)
        {
            var xmlSerializer = new XmlSerializer(typeof(Package), "http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd");

            // Write .nuspec
            using (TextWriter writer = new StreamWriter($"{modDirectory}\\{modConfig.ModId}.nuspec"))
            {
                xmlSerializer.Serialize(writer, FromModConfig(modConfig));
            }

            // Compress
            string nupkgPath = Path.Combine(outputDirectory, $"{modConfig.ModId}.nupkg");

            ArchiveFile.CompressDirectory(modDirectory, nupkgPath);
            return(nupkgPath);
        }