Esempio n. 1
0
        /// <summary>
        ///     Template the given string.
        /// </summary>
        /// <param name="text">The string to template.</param>
        /// <param name="resourceName">The name of the resource being created.</param>
        /// <param name="darkriftVersion">The version of DarkRift being used.</param>
        /// <param name="tier">The tier of DarkRift being used.</param>
        /// <param name="platform">The platform the DarkRift being used was built for.</param>
        private static string TemplateString(string text, string resourceName, string darkriftVersion, ServerTier tier, ServerPlatform platform)
        {
            // Keep files containing __k__
            if (text.Contains("__k__"))
            {
                text = text.Replace("__k__", "");
            }

            // Template __n__ to the resource name
            if (text.Contains("__n__"))
            {
                text = text.Replace("__n__", resourceName);
            }

            // Template __v__ to the darkrift version
            if (text.Contains("__v__"))
            {
                text = text.Replace("__v__", darkriftVersion);
            }

            // Template __t__ to 'Pro' or 'Free'
            if (text.Contains("__t__"))
            {
                text = text.Replace("__t__", tier.ToString());
            }

            // Template __p__ to 'Standard' or 'Framework'
            if (text.Contains("__p__"))
            {
                text = text.Replace("__p__", platform.ToString());
            }

            return(text);
        }
        /// <summary>
        /// Gets a list of versions installed with specific tier and platform
        /// </summary>
        /// <param name="tier">The tier</param>
        /// <param name="platform">The platform</param>
        /// <returns>A list of installed versions</returns>
        public List <DarkRiftInstallation> GetVersions(ServerTier tier, ServerPlatform platform)
        {
            string searchPath = Path.Combine(installationDirectory, tier.ToString().ToLower(), platform.ToString().ToLower());

            if (!fileUtility.DirectoryExists(searchPath))
            {
                return(new List <DarkRiftInstallation>());
            }
            else
            {
                return(fileUtility.GetDirectories(searchPath)
                       .Select(path => new DarkRiftInstallation(path, tier, platform, Path.Combine(searchPath, path)))
                       .ToList());
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets a list of versions installed with specific tier and platform
        /// </summary>
        /// <param name="tier">The tier</param>
        /// <returns>A list of installed versions</returns>
        public List <DarkRiftInstallation> GetVersions(ServerTier tier)
        {
            string searchPath = Path.Combine(installationDirectory, tier.ToString().ToLower());

            if (!fileUtility.DirectoryExists(searchPath))
            {
                return(new List <DarkRiftInstallation>());
            }
            else
            {
                return(fileUtility.GetDirectories(searchPath)
                       .SelectMany(path => fileUtility.GetDirectories(Path.Combine(searchPath, path))
                                   .Select(subPath => new DarkRiftInstallation(
                                               subPath,
                                               tier,
                                               path switch { "core" => "Core", "framework" => "Framework", _ => path },
Esempio n. 4
0
        /// <summary>
        /// Gets the path to a specified installation, downloading it if required.
        /// </summary>
        /// <param name="version">The version number required.</param>
        /// <param name="pro">Whether the pro version should be used.</param>
        /// <param name="netStandard">Whether the .NET Standard build should be used.</param>
        /// <returns>The path to the installation, or null, if it cannot be provided.</returns>
        public static string GetInstallationPath(string version, ServerTier tier, ServerPlatform platform)
        {
            string fullPath = Path.Combine(USER_DR_DIR, "installed", tier.ToString().ToLower(), platform.ToString().ToLower(), version);

            if (!Directory.Exists(fullPath))
            {
                Console.WriteLine($"DarkRift {version} - {tier} (.NET {platform}) not installed! Downloading package...");

                string stagingPath = Path.Combine(USER_DR_DIR, "Download.zip");

                string uri = $"https://www.darkriftnetworking.com/DarkRift2/Releases/{version}/{tier}/{platform}/";
                if (tier == ServerTier.Pro)
                {
                    string invoiceNumber = GetInvoiceNumber();
                    if (invoiceNumber == null)
                    {
                        Console.WriteLine(Output.Red($"You must provide an invoice number in order to download Pro DarkRift releases."));
                        return(null);
                    }

                    uri += $"?invoice={invoiceNumber}";
                }

                try
                {
                    using (WebClient myWebClient = new WebClient())
                    {
                        myWebClient.DownloadFile(uri, stagingPath);
                    }
                }
                catch (WebException e)
                {
                    Console.WriteLine(Output.Red($"Could not download DarkRift {version} - {tier} (.NET {platform}):\n\t{e.Message}"));
                    return(null);
                }

                Console.WriteLine($"Extracting package...");

                Directory.CreateDirectory(fullPath);

                ZipFile.ExtractToDirectory(stagingPath, fullPath, true);

                Console.WriteLine(Output.Green($"Successfully downloaded package."));
            }

            return(fullPath);
        }
 /// <summary>
 /// Gets the path to a specified installation, or null if it is not installed.
 /// </summary>
 /// <param name="version">The version number required.</param>
 /// <param name="pro">Whether the pro version should be used.</param>
 /// <param name="platform">Whether the .NET Standard build should be used.</param>
 /// <returns>The path to the installation, or null, if it is not installed.</returns>
 private string GetInstallationPath(string version, ServerTier tier, ServerPlatform platform)
 {
     return(Path.Combine(installationDirectory, tier.ToString().ToLower(), platform.ToString().ToLower(), version));
 }
Esempio n. 6
0
 /// <summary>
 /// Gets the path to a specified installation, downloading it if required.
 /// </summary>
 /// <param name="version">The version number required.</param>
 /// <param name="pro">Whether the pro version should be used.</param>
 /// <param name="platform">Whether the .NET Standard build should be used.</param>
 /// <returns>The path to the installation, or null, if it cannot be provided.</returns>
 public static string GetInstallationPath(string version, ServerTier tier, ServerPlatform platform)
 {
     return(Path.Combine(Config.USER_DR_DIR, "installed", tier.ToString().ToLower(), platform.ToString().ToLower(), version));
 }