Example #1
0
        /// <summary>
        /// Downloads and installs a DarkRift version.
        /// </summary>
        /// <param name="version">The version to be installed</param>
        /// <param name="tier">The tier</param>
        /// <param name="platform">The platform</param>
        /// <param name="downloadDirectory">The directory to download the release to</param>
        /// <returns>True if installed successfully otherwise false</returns>
        public bool DownloadVersionTo(string version, ServerTier tier, string platform, string downloadDirectory)
        {
            string stagingPath = fileUtility.GetTempFileName();

            string uri = $"/DarkRift2/Releases/{version}/{tier}/{platform}/";

            if (tier == ServerTier.Pro)
            {
                string invoiceNumber = invoiceManager.GetInvoiceNumber();
                if (invoiceNumber == null)
                {
                    Console.Error.WriteLine(Output.Red($"You must provide an invoice number in order to download Pro DarkRift releases."));
                    return(false);
                }

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

            try
            {
                webClientUtility.DownloadFile(uri, stagingPath);
            }
            catch (WebException e)
            {
                Console.Error.WriteLine(Output.Red($"Could not download DarkRift {version} - {tier} (.NET {platform}):\n\t{e.Message}"));
                return(false);
            }

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

            try
            {
                fileUtility.ExtractZipTo(stagingPath, downloadDirectory);
            }
            catch (Exception)
            {
                // Make sure we don't leave a partial install
                if (fileUtility.DirectoryExists(downloadDirectory))
                {
                    fileUtility.Delete(downloadDirectory);
                }

                throw;
            }
            finally
            {
                fileUtility.Delete(stagingPath);
            }

            Console.WriteLine(Output.Green($"Successfully downloaded DarkRift {version} - {tier} (.NET {platform})."));

            return(true);
        }