private void AddUnityPackages(List <Upset> upsetList) { string[] files = Directory.GetFiles(Path, "*.*"); Version Unity5 = new Version { Major = 5 }; foreach (string FileName in files) { try { if (!IsUnityPackage(FileName)) { continue; } // assume unityPackage doesn't contain an upset file for now. In the future we can support it Upset upset = TryLoadUpset(FileName); if (upset == null) { continue; } // Note: the spec may contain incomplete unity version here (e.g. 5.6). Maybe we should have a ParseThinUnityVersion if (VersionParser.ParseIncompleteVersion(upset.UnityVersion, false) < Unity5) { throw new NotSupportedException("The package has been packed by a Unity version prior to Unity5, and we do not support this. Contact the package maintainer for updated version."); } upsetList.Add(upset); } catch (Exception e) { UnityEngine.Debug.LogErrorFormat("Could not load package at {0}, ignoring it ({1}):\n{2}", FileName, e.Message, e.StackTrace); } } }
private static Upset TryLoadUpset(string packagePath) { string upsetPath = Regex.Replace(packagePath, ".unitypackage$", ".Upset.xml", RegexOptions.IgnoreCase); if (File.Exists(upsetPath)) { StrictXmlDeserializer <Upset> deserializer = new StrictXmlDeserializer <Upset>(); using (FileStream file = new FileStream(upsetPath, FileMode.Open)) { Upset upset = deserializer.Deserialize(file); if (upset.Configuration != null && upset.Configuration.Length != 0) { foreach (InstallSpecPath spec in upset.Configuration) { spec.Path = Uplift.Common.FileSystemUtil.MakePathOSFriendly(spec.Path); } } upset.MetaInformation.dirName = packagePath.Split(System.IO.Path.DirectorySeparatorChar).Last(); return(upset); } } else { Debug.LogWarning("Unity package found at " + packagePath + " has no matching Upset. It should be at " + upsetPath); } return(null); }
internal void AddGUID(Upset package, InstallSpecType kind, string guid) { InstalledPackage internalPackage; if (!SetupInternalPackage(package, out internalPackage)) { return; } // Note: not catching in case of internalPackage not found // as it is valid error throwing condition // Check if guid doesn't exist and return if it does if (internalPackage.Install.Any(spec => spec is InstallSpecGUID && spec.Type == kind && (spec as InstallSpecGUID).Guid == guid)) { return; } // Create new spec InstallSpec newSpec = new InstallSpecGUID { Type = kind, Guid = guid }; InstallSpec[] newArray = new InstallSpec[internalPackage.Install.Length + 1]; internalPackage.Install.CopyTo(newArray, 0); newArray[newArray.Length - 1] = newSpec; internalPackage.Install = newArray; }
private bool SetupInternalPackage(Upset package, out InstalledPackage internalPackage) { internalPackage = null; foreach (InstalledPackage t in InstalledPackage) { if (t.Name == package.PackageName) { internalPackage = t; break; } } // No package has been found if (internalPackage == null) { return(false); } // 0 is better than null :) if (internalPackage.Install == null) { internalPackage.Install = new InstallSpec[0]; } return(true); }
private static Upset InferUpsetFromUnityPackage(string FileName) { string ShortFileName = System.IO.Path.GetFileNameWithoutExtension(FileName); string[] split = ShortFileName.Split('-'); if (split.Length != 2) { Debug.LogWarning("Skipping file " + FileName + " as it doesn't follow the pattern 'PackageName-PackageVersion.unitypackage'"); return(null); } string PackageName = split[0]; string PackageVersion = split[1]; string PackageLicense = "Unknown"; string MinUnityVersion = "0.0.0"; Upset upset = new Upset(); upset.PackageLicense = PackageLicense; upset.PackageName = PackageName; upset.PackageVersion = PackageVersion; upset.UnityVersion = new VersionSpec(); upset.UnityVersion.ItemElementName = ItemChoiceType.MinVersion; upset.UnityVersion.Item = MinUnityVersion; upset.MetaInformation.dirName = FileName.Split(System.IO.Path.DirectorySeparatorChar).Last(); // we need to move things around here // upset.InstallSpecifications = new InstallSpec[0]; return(upset); }
internal void AddLocation(Upset package, InstallSpecType kind, string path) { string unixPath = Uplift.Common.FileSystemUtil.MakePathUnix(path); InstalledPackage internalPackage; if (!SetupInternalPackage(package, out internalPackage)) { return; } // Note: not catching in case of internalPackage not found // as it is valid error throwing condition // Check if path doesn't exist and return if it does if (internalPackage.Install.Any(spec => spec is InstallSpecPath && spec.Type == kind && (spec as InstallSpecPath).Path == unixPath)) { return; } // Create new spec InstallSpec newSpec = new InstallSpecPath { Type = kind, Path = unixPath }; InstallSpec[] newArray = new InstallSpec[internalPackage.Install.Length + 1]; internalPackage.Install.CopyTo(newArray, 0); newArray[newArray.Length - 1] = newSpec; internalPackage.Install = newArray; }
private static Upset LoadUpsetOrInfer(string packagePath) { string upsetPath = packagePath.Replace(".unitypackage", ".Upset.xml"); if (File.Exists(upsetPath)) { XmlSerializer serializer = new XmlSerializer(typeof(Upset)); using (FileStream file = new FileStream(upsetPath, FileMode.Open)) { Upset upset = serializer.Deserialize(file) as Upset; if (upset.Configuration != null && upset.Configuration.Length != 0) { foreach (InstallSpecPath spec in upset.Configuration) { spec.Path = FileSystemUtil.MakePathOSFriendly(spec.Path); } } upset.MetaInformation.dirName = packagePath.Split(System.IO.Path.DirectorySeparatorChar).Last(); return(upset); } } else { return(InferUpsetFromUnityPackage(packagePath)); } }
private void AddExplodedDirectories(List <Upset> upsetList) { string[] directories = Directory.GetDirectories(Path); foreach (string directoryPath in directories) { string directoryName = directoryPath.Split(System.IO.Path.DirectorySeparatorChar).Last(); // Don't look at me. System.IO.Path.Combine(string, string, string) doesn't work in Unity :( char SC = System.IO.Path.DirectorySeparatorChar; string upsetPath = Path + SC + directoryName + SC + UpsetFile; if (!File.Exists(upsetPath)) { continue; } XmlSerializer serializer = new XmlSerializer(typeof(Upset)); using (FileStream file = new FileStream(upsetPath, FileMode.Open)) { Upset upset = serializer.Deserialize(file) as Upset; if (upset.Configuration != null && upset.Configuration.Length != 0) { foreach (InstallSpecPath spec in upset.Configuration) { spec.Path = FileSystemUtil.MakePathOSFriendly(spec.Path); } } upset.MetaInformation.dirName = directoryName; upsetList.Add(upset); } } }
private void AddUnityPackages(List <Upset> upsetList) { string[] files = Directory.GetFiles(Path, "*.*"); foreach (string FileName in files) { if (!IsUnityPackage(FileName)) { continue; } // assume unityPackage doesn't contain an upset file for now. In the future we can support it Upset upset = LoadUpsetOrInfer(FileName); if (upset == null) { continue; } upsetList.Add(upset); } }
public override TemporaryDirectory DownloadPackage(Upset package) { string sourceName = Regex.Replace(package.MetaInformation.dirName, ".Upset.xml$", ".unitypackage", RegexOptions.IgnoreCase); releases = GetPackagesReleases(); GitHubRelease release = releases.FirstOrDefault(rel => rel.assets.Any(asset => asset.name.Contains(sourceName))); if (release == null) { throw new ArgumentException(string.Format("Package {0} is not present in this repository", package.PackageName)); } GitHubAsset packageAsset = release.assets.First(asset => asset.name.Contains(sourceName)); TemporaryDirectory td = new TemporaryDirectory(); using (StreamReader sr = new StreamReader(GitHub.GetAssetStream(packageAsset, GetToken()))) { UnityPackage unityPackage = new UnityPackage(); unityPackage.Extract(sr.BaseStream, td.Path); } return(td); }
public override TemporaryDirectory DownloadPackage(Upset package) { TemporaryDirectory td = new TemporaryDirectory(); string sourcePath = System.IO.Path.Combine(Path, package.MetaInformation.dirName); if (Directory.Exists(sourcePath)) { Uplift.Common.FileSystemUtil.CopyDirectoryWithMeta(sourcePath, td.Path); } else if (IsUnityPackage(sourcePath)) { var unityPackage = new UnityPackage(); unityPackage.Extract(sourcePath, td.Path); } else { Debug.LogError(string.Format("Package {0} version {1} found at {2} has an unexpected format and cannot be downloaded ", package.PackageName, package.PackageVersion, sourcePath)); } return(td); }
private void AddExplodedDirectories(List <Upset> upsetList) { string[] directories = Directory.GetDirectories(Path); foreach (string directoryPath in directories) { string directoryName = directoryPath.Split(System.IO.Path.DirectorySeparatorChar).Last(); try { string upsetPath = Uplift.Common.FileSystemUtil.JoinPaths(Path, directoryName, UpsetFile); if (!File.Exists(upsetPath)) { continue; } StrictXmlDeserializer <Upset> deserializer = new StrictXmlDeserializer <Upset>(); using (FileStream file = new FileStream(upsetPath, FileMode.Open)) { Upset upset = deserializer.Deserialize(file); if (upset.Configuration != null && upset.Configuration.Length != 0) { foreach (InstallSpecPath spec in upset.Configuration) { spec.Path = Uplift.Common.FileSystemUtil.MakePathOSFriendly(spec.Path); } } upset.MetaInformation.dirName = directoryName; upsetList.Add(upset); } } catch (Exception e) { UnityEngine.Debug.LogErrorFormat("Could not load package at {0}, ignoring it ({1}):\n{2}", directoryName, e.Message, e.StackTrace); } } }
internal void AddPackage(Upset package) { if (InstalledPackage == null) { InstalledPackage = new InstalledPackage[0]; } InstalledPackage newPackage = new InstalledPackage { Name = package.PackageName, Version = package.PackageVersion }; if (InstalledPackage.Any(ip => ip.Name == newPackage.Name)) { return; } InstalledPackage[] finalArray = new InstalledPackage[InstalledPackage.Length + 1]; InstalledPackage.CopyTo(finalArray, 0); finalArray[InstalledPackage.Length] = newPackage; InstalledPackage = finalArray; }
public override TemporaryDirectory DownloadPackage(Upset package) { throw new NotImplementedException(); }
public override Upset[] ListPackages() { releases = GetPackagesReleases(); GitHubAsset[] upsetAssets = releases .SelectMany <GitHubRelease, GitHubAsset>(rel => rel.assets.Where(asset => asset.name.EndsWith("Upset.xml"))) .ToArray(); string progressBarTitle = "Parsing Upsets from GitHub repository"; int index = 0; List <Upset> upsetList = new List <Upset>(); EditorUtility.DisplayProgressBar(progressBarTitle, "Please wait a little bit while Uplift parses the Upset in the GitHub repository at " + urlField, 0f); string assetPath; try { foreach (GitHubAsset asset in upsetAssets) { try { StrictXmlDeserializer <Upset> deserializer = new StrictXmlDeserializer <Upset>(); EditorUtility.DisplayProgressBar( progressBarTitle, "Parsing " + asset.name, (float)(index++) / upsetAssets.Length ); if (!TryGetCachedItem(asset.name, out assetPath)) { using (StreamReader sr = new StreamReader(GitHub.GetAssetStream(asset, GetToken()))) using (FileStream fs = new FileStream(assetPath, FileMode.Create)) { sr.BaseStream.CopyTo(fs); } } using (FileStream fs = new FileStream(assetPath, FileMode.Open)) { Upset upset = deserializer.Deserialize(fs); upset.MetaInformation.dirName = asset.name; upsetList.Add(upset); } } catch (Exception e) { Debug.LogErrorFormat("An error occured while trying to get asset {0} ({1}, {2}) from GithubRepository", asset.name, asset.htmlURL, asset.apiURL); throw e; } } } finally { EditorUtility.ClearProgressBar(); } return(upsetList.ToArray()); }
public override TemporaryDirectory DownloadPackage(Upset package) { TemporaryDirectory td = new TemporaryDirectory(); string sourcePath = string.Format(formatPattern, Path, System.IO.Path.DirectorySeparatorChar, package.MetaInformation.dirName); if (Directory.Exists(sourcePath)) { FileSystemUtil.CopyDirectoryWithMeta(sourcePath, td.Path); } else if (IsUnityPackage(sourcePath)) { using (MemoryStream TarArchiveMS = new MemoryStream()) { using (FileStream originalFileStream = new FileStream(sourcePath, FileMode.Open)) { using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress)) { decompressionStream.CopyTo(TarArchiveMS); TarArchiveMS.Position = 0; } } TarArchive reader = TarArchive.Open(TarArchiveMS); string assetPath = null; MemoryStream assetMS = null; MemoryStream metaMS = null; foreach (TarArchiveEntry entry in reader.Entries) { if (entry.IsDirectory) { continue; } if (entry.Key.EndsWith("asset")) { if (assetMS != null) { throw new InvalidOperationException("Unexpected state: assetMS not null"); } assetMS = new MemoryStream(); entry.WriteTo(assetMS); assetMS.Position = 0; continue; } if (entry.Key.EndsWith("metaData")) { throw new NotSupportedException("The package has been packed by a Unity version prior to Unity5, and we do not support this. Contact the package maintainer for updated version."); } if (entry.Key.EndsWith("meta")) { metaMS = new MemoryStream(); entry.WriteTo(metaMS); metaMS.Position = 0; continue; } if (entry.Key.EndsWith("pathname")) { MemoryStream MSM = new MemoryStream(); entry.WriteTo(MSM); MSM.Position = 0; using (StreamReader SR = new StreamReader(MSM)) { assetPath = SR.ReadToEnd().Split('\n')[0]; } } if (assetPath != null) { if (assetMS == null) { // these are for directories inside the file Debug.Log("path not null " + assetPath + " but asset not yet read"); assetPath = null; continue; } string AssetPath = td.Path + System.IO.Path.DirectorySeparatorChar + assetPath.Replace('/', System.IO.Path.DirectorySeparatorChar); var AssetPathDir = new FileInfo(AssetPath).Directory.FullName; if (!Directory.Exists(AssetPathDir)) { Directory.CreateDirectory(AssetPathDir); } using (FileStream FS = new FileStream(AssetPath, FileMode.Create)) { assetMS.CopyTo(FS); } assetMS.Dispose(); assetMS = null; if (metaMS != null) { string MetaPath = AssetPath + ".meta"; using (FileStream FS = new FileStream(MetaPath, FileMode.Create)) { metaMS.CopyTo(FS); } metaMS.Dispose(); metaMS = null; } assetPath = null; } } } string commonRoot = ""; string[] directories = Directory.GetDirectories(td.Path); string inspectedPath = td.Path; // Lone directory while (directories.Length == 1) { string[] entries = Directory.GetFiles(inspectedPath); if (entries.Length > 1 || (entries.Length == 1 && !entries[0].EndsWith(".meta"))) { break; } commonRoot = System.IO.Path.Combine(commonRoot, directories[0]); inspectedPath = System.IO.Path.Combine(td.Path, commonRoot); directories = Directory.GetDirectories(inspectedPath); } if (commonRoot != "") { FileSystemUtil.MoveDirectoryContent(inspectedPath, td.Path); Directory.Delete(System.IO.Path.Combine(td.Path, commonRoot.Replace(td.Path, "").Split(System.IO.Path.DirectorySeparatorChar)[1]), true); if (package.Configuration != null) { foreach (InstallSpecPath spec in package.Configuration) { spec.Path.Replace(commonRoot, ""); } } } } else { Debug.LogError(string.Format("Package {0} version {1} has an unexpected format and cannot be downloaded ", package.PackageName, package.PackageVersion)); } return(td); }