/// <summary> /// </summary> /// <param name="product"></param> /// <exception cref="InvalidEnumArgumentException"></exception> private static void DownloadAndReplaceFiles(ProductToDownload product) { if (!Enum.IsDefined(typeof(ProductToDownload), product)) { throw new InvalidEnumArgumentException(nameof(product), (int)product, typeof(ProductToDownload)); } string downloadUrl; using (var client = new HttpClient { Timeout = TimeSpan.FromSeconds(30) }) { downloadUrl = GetDownloadUrlAsync(client).Result; } if (!string.IsNullOrEmpty(downloadUrl)) { ForegroundColor = ConsoleColor.Green; WriteLine($"Downloading LMP from: {downloadUrl} Please wait..."); try { CleanTempClientFiles(); CleanTempServerFiles(); using (var client = new WebClient()) { client.DownloadFile(downloadUrl, Path.Combine(Path.GetTempPath(), FileName)); WriteLine($"Downloading succeeded! Path: {Path.Combine(Path.GetTempPath(), FileName)}"); } WriteLine($"Decompressing file to {ClientFolderToDecompress}"); ZipFile.ExtractToDirectory(Path.Combine(Path.GetTempPath(), FileName), ClientFolderToDecompress); CopyClientFilesFromTempToDestination(); CopyServerFilesFromTempToDestination(); ForegroundColor = ConsoleColor.Green; WriteLine("-----------------===========FINISHED===========-----------------"); } catch (Exception e) { ForegroundColor = ConsoleColor.Red; WriteLine(e); ResetColor(); throw; } finally { CleanTempClientFiles(); CleanTempServerFiles(); } } }
private static string GetDownloadFileName(ProductToDownload product, string buildVersion) { switch (product) { case ProductToDownload.Client: return($"LunaMultiplayer-Client-{buildVersion}.zip"); case ProductToDownload.Server: return($"LunaMultiplayer-Server-{buildVersion}.zip"); default: throw new ArgumentOutOfRangeException(nameof(product), product, null); } }
private static string GetProductFolderName(ProductToDownload product) { switch (product) { case ProductToDownload.Client: return("LMPClient"); case ProductToDownload.Server: return("LMPServer"); default: throw new ArgumentOutOfRangeException(nameof(product), product, null); } }
private static void CopyFilesFromTempToDestination(ProductToDownload product) { var productFolderName = GetProductFolderName(product); foreach (var dirPath in Directory.GetDirectories(Path.Combine(FolderToDecompress, productFolderName), "*", SearchOption.AllDirectories)) { var destFolder = dirPath.Replace(Path.Combine(FolderToDecompress, productFolderName), Directory.GetCurrentDirectory()); Console.WriteLine($"Creating dest folder: {destFolder}"); Directory.CreateDirectory(destFolder); } foreach (var newPath in Directory.GetFiles(Path.Combine(FolderToDecompress, productFolderName), "*.*", SearchOption.AllDirectories)) { var destPath = newPath.Replace(Path.Combine(FolderToDecompress, productFolderName), Directory.GetCurrentDirectory()); Console.WriteLine($"Copying {Path.GetFileName(newPath)} to {destPath}"); File.Copy(newPath, destPath, true); } }
public static void DownloadAndReplaceFiles(ProductToDownload product, string buildVersion) { var downloadFileName = GetDownloadFileName(product, buildVersion); string downloadUrl; using (var client = new HttpClient { Timeout = TimeSpan.FromSeconds(30) }) { client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); downloadUrl = GetDownloadUrl(client, downloadFileName, buildVersion).Result; } if (!string.IsNullOrEmpty(downloadUrl)) { Console.WriteLine($"Downloading LMP from: {downloadUrl} Please wait..."); try { CleanTempFiles(downloadFileName); using (var client = new WebClient()) { client.DownloadFile(downloadUrl, Path.Combine(Path.GetTempPath(), downloadFileName)); Console.WriteLine($"Downloading succeeded! Path: {Path.Combine(Path.GetTempPath(), downloadFileName)}"); } Console.WriteLine($"Decompressing file to {FolderToDecompress}"); ZipFile.ExtractToDirectory(Path.Combine(Path.GetTempPath(), downloadFileName), FolderToDecompress); CopyFilesFromTempToDestination(product); Console.WriteLine("-----------------===========FINISHED===========-----------------"); } catch (Exception e) { Console.WriteLine(e); throw; } finally { CleanTempFiles(downloadFileName); } } }
public static void DownloadAndReplaceFiles(ProductToDownload product) { string downloadUrl; using (var client = new HttpClient { Timeout = TimeSpan.FromSeconds(30) }) { downloadUrl = GetDownloadUrl(client).Result; } if (!string.IsNullOrEmpty(downloadUrl)) { Console.WriteLine($"Downloading LMP from: {downloadUrl} Please wait..."); try { CleanTempFiles(); using (var client = new WebClient()) { client.DownloadFile(downloadUrl, Path.Combine(Path.GetTempPath(), FileName)); Console.WriteLine($"Downloading succeeded! Path: {Path.Combine(Path.GetTempPath(), FileName)}"); } Console.WriteLine($"Decompressing file to {FolderToDecompress}"); ZipFile.ExtractToDirectory(Path.Combine(Path.GetTempPath(), FileName), FolderToDecompress); CopyFilesFromTempToDestination(); Console.WriteLine("-----------------===========FINISHED===========-----------------"); } catch (Exception e) { Console.WriteLine(e); throw; } finally { CleanTempFiles(); } } }
private static void CopyFilesFromTempToDestination(ProductToDownload product) { // select correct sub-folder for server zip var decompressFromFolder = FolderToDecompress; if (product == ProductToDownload.Server) { decompressFromFolder = Path.Combine(FolderToDecompress, "LMPServer"); } foreach (var dirPath in Directory.GetDirectories(decompressFromFolder, "*", SearchOption.AllDirectories)) { var destFolder = dirPath.Replace(decompressFromFolder, Directory.GetCurrentDirectory()); Console.WriteLine($"Creating destination folder: {destFolder}"); Directory.CreateDirectory(destFolder); } foreach (var newPath in Directory.GetFiles(decompressFromFolder, "*.*", SearchOption.AllDirectories)) { var destPath = newPath.Replace(decompressFromFolder, Directory.GetCurrentDirectory()); Console.WriteLine($"Copying {Path.GetFileName(newPath)} to {destPath}"); File.Copy(newPath, destPath, true); } }