Esempio n. 1
0
        /// <summary>
        /// Expands a template.
        /// </summary>
        /// <param name="type">The template to expand</param>
        /// <param name="targetDirectory">The directory to exapand into.</param>
        /// <param name="version">The DarkRift version to template with.</param>
        /// <param name="tier">The DarkRift tier to template with.</param>
        /// <param name="platform">The DarkRift platform to template with.</param>
        /// <param name="force">Whether to force expansion on a non-empty directory.</param>
        public void Template(string type, string targetDirectory, string version, ServerTier tier, ServerPlatform platform, bool force)
        {
            string templatePath = Path.Combine(templatesPath, type + ".zip");

            Directory.CreateDirectory(targetDirectory);

            if (Directory.GetFiles(targetDirectory).Length > 0 && !force)
            {
                throw new DirectoryNotEmptyException();
            }

            if (!File.Exists(templatePath))
            {
                throw new ArgumentException("Cannot create from template, no template with that name exists.", nameof(type));
            }

            Console.WriteLine($"Creating new {type} '{Path.GetFileName(targetDirectory)}' from template...");

            ZipFile.ExtractToDirectory(templatePath, targetDirectory, true);

            Console.WriteLine($"Cleaning up extracted artifacts...");

            foreach (string path in Directory.GetFiles(targetDirectory, "*.*", SearchOption.AllDirectories))
            {
                FileTemplater.TemplateFileAndPath(path, Path.GetFileName(targetDirectory), version, tier, platform);
            }

            Console.WriteLine(Output.Green($"Created '{Path.GetFileName(targetDirectory)}'"));
        }
Esempio n. 2
0
        public void TestIsSpecialChar(char input, bool expectedOutput)
        {
            // WHEN the character is tested
            bool result = FileTemplater.IsSpecialChar(input);

            // THEN the result as expected
            Assert.AreEqual(expectedOutput, result);
        }
Esempio n. 3
0
        public void TestNormalize(string input, string expectedOutput)
        {
            // WHEN the string is normalized
            string result = FileTemplater.Normalize(input);

            // THEN the string is normalized correctly
            Assert.AreEqual(expectedOutput, result);
        }