From 931cb7126d4bb7fc5f597a02e7d6deb8653700d7 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Mon, 16 Apr 2018 14:40:46 -0700 Subject: [PATCH] Make SDK installation more robust Fixes #120 --- Ooui.Wasm.Build.Tasks/BuildDistTask.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Ooui.Wasm.Build.Tasks/BuildDistTask.cs b/Ooui.Wasm.Build.Tasks/BuildDistTask.cs index 2f112c9..59010e9 100644 --- a/Ooui.Wasm.Build.Tasks/BuildDistTask.cs +++ b/Ooui.Wasm.Build.Tasks/BuildDistTask.cs @@ -49,17 +49,25 @@ namespace Ooui.Wasm.Build.Tasks { var sdkName = Path.GetFileNameWithoutExtension (new Uri (SdkUrl).AbsolutePath.Replace ('/', Path.DirectorySeparatorChar)); Log.LogMessage ("SDK: " + sdkName); - sdkPath = Path.Combine (Path.GetTempPath (), sdkName); + string tmpDir = Path.GetTempPath (); + sdkPath = Path.Combine (tmpDir, sdkName); Log.LogMessage ("SDK Path: " + sdkPath); - if (Directory.Exists (sdkPath)) + if (Directory.Exists (sdkPath) + && Directory.Exists (Path.Combine (sdkPath, "release"))) return; var client = new WebClient (); var zipPath = sdkPath + ".zip"; Log.LogMessage ($"Downloading {sdkName} to {zipPath}"); + if (File.Exists (zipPath)) + File.Delete (zipPath); client.DownloadFile (SdkUrl, zipPath); - ZipFile.ExtractToDirectory (zipPath, sdkPath); + var sdkTempPath = Path.Combine (tmpDir, Guid.NewGuid ().ToString ()); + ZipFile.ExtractToDirectory (zipPath, sdkTempPath); + if (Directory.Exists (sdkPath)) + Directory.Delete (sdkPath, true); + Directory.Move (sdkTempPath, sdkPath); Log.LogMessage ($"Extracted {sdkName} to {sdkPath}"); }