private void DownloadAssembliesForPreviousVersion() { Profiler.BeginSample("DownloadAssembliesForPreviousVersion"); if (Directory.Exists(PreviousVersionBinaryPath)) { Directory.Delete(PreviousVersionBinaryPath, true); } Directory.CreateDirectory(PreviousVersionBinaryPath); ActivityLogger.Log("Retrieving assemblies for previous package version {0}", PreviousPackageInfo.version); var packageDataZipFilename = PackageBinaryZipping.PackageDataZipFilename(PreviousPackageInfo.name, PreviousPackageInfo.version); var zipPath = Path.Combine(PreviousVersionBinaryPath, packageDataZipFilename); var uri = Path.Combine("https://artifactory.eu-cph-1.unityops.net/pkg-api-validation", packageDataZipFilename); UnityWebRequest request = new UnityWebRequest(uri); request.timeout = 60; // 60 seconds time out request.downloadHandler = new DownloadHandlerFile(zipPath); var operation = request.SendWebRequest(); while (!operation.isDone) { Thread.Sleep(1); } // Starting in 2020_1, isHttpError and isNetworkError are deprecated // which caused API obsolete errors to be shown for PVS // https://jira.unity3d.com/browse/PAI-1215 var requestError = false; #if UNITY_2020_1_OR_NEWER requestError = request.result == UnityWebRequest.Result.ProtocolError || request.result == UnityWebRequest.Result.ConnectionError; #else requestError = request.isHttpError || request.isNetworkError; #endif if (requestError || !PackageBinaryZipping.Unzip(zipPath, PreviousVersionBinaryPath)) { ActivityLogger.Log(String.Format("Could not download binary assemblies for previous package version from {0}. {1}", uri, request.responseCode)); PreviousPackageBinaryDirectory = null; } else { PreviousPackageBinaryDirectory = PreviousVersionBinaryPath; } ActivityLogger.Log("Done retrieving assemblies for previous package", PreviousPackageInfo.version); Profiler.EndSample(); }
public static string ExtractPackage(string fullPackagePath, string workingPath, string outputDirectory, string packageName, bool deleteOutputDir = true) { Profiler.BeginSample("ExtractPackage"); //verify if package exists if (!fullPackagePath.EndsWith(".tgz")) { throw new ArgumentException("Package should be a .tgz file"); } if (!File.Exists(fullPackagePath)) { throw new FileNotFoundException(fullPackagePath + " was not found."); } if (deleteOutputDir) { try { if (Directory.Exists(outputDirectory)) { Directory.Delete(outputDirectory, true); } Directory.CreateDirectory(outputDirectory); } catch (IOException e) { if (e.Message.ToLowerInvariant().Contains("1921")) { throw new ApplicationException("Failed to remove previous module in " + outputDirectory + ". Directory might be in use."); } throw; } } var tarPath = fullPackagePath.Replace(".tgz", ".tar"); if (File.Exists(tarPath)) { File.Delete(tarPath); } //Unpack the tgz into temp. This should leave us a .tar file PackageBinaryZipping.Unzip(fullPackagePath, workingPath); //See if the tar exists and unzip that var tgzFileName = Path.GetFileName(fullPackagePath); var targetTarPath = Path.Combine(workingPath, packageName + "-tar"); if (Directory.Exists(targetTarPath)) { Directory.Delete(targetTarPath, true); } if (File.Exists(tarPath)) { PackageBinaryZipping.Unzip(tarPath, targetTarPath); } //Move the contents of the tar file into outputDirectory var packageFolderPath = Path.Combine(targetTarPath, "package"); if (Directory.Exists(packageFolderPath)) { //Move directories and meta files foreach (var dir in Directory.GetDirectories(packageFolderPath)) { var dirName = Path.GetFileName(dir); if (dirName != null) { Directory.Move(dir, Path.Combine(outputDirectory, dirName)); } } foreach (var file in Directory.GetFiles(packageFolderPath)) { if (file.Contains("package.json") && !fullPackagePath.Contains(".tests") && !fullPackagePath.Contains(".samples") || !file.Contains("package.json")) { File.Move(file, Path.Combine(outputDirectory, Path.GetFileName(file))); } } } //Remove the .tgz and .tar artifacts from temp List <string> cleanupPaths = new List <string>(); cleanupPaths.Add(fullPackagePath); cleanupPaths.Add(tarPath); cleanupPaths.Add(targetTarPath); foreach (var p in cleanupPaths) { try { FileAttributes attr = File.GetAttributes(p); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { // This is a directory Directory.Delete(targetTarPath, true); continue; } File.Delete(p); } catch (DirectoryNotFoundException) { //Pass since there is nothing to delete } } Profiler.EndSample(); return(outputDirectory); }