// What's the difference between Nuke and Uninstall? // Nuke doesn't care for dependencies (if present) public void NukePackage(string packageName) { Upbring upbring = Upbring.Instance(); InstalledPackage package = upbring.GetInstalledPackage(packageName); package.Nuke(); upbring.RemovePackage(package); upbring.SaveFile(); }
// What's the difference between Nuke and Uninstall? // Nuke doesn't care for dependencies (if present) public void NukePackage(string packageName) { Upbring upbring = Upbring.Instance(); InstalledPackage package = upbring.GetInstalledPackage(packageName); package.Nuke(); upbring.RemovePackage(package); upbring.SaveFile(); UnityHacks.BuildSettingsEnforcer.EnforceAssetSave(); }
public void SaveFileTest() { try { Directory.CreateDirectory(temp_dir); Directory.SetCurrentDirectory(temp_dir); string repo_path = Path.Combine(temp_dir, Path.GetRandomFileName()); Directory.CreateDirectory(repo_path); Upfile dummy = new Upfile() { Configuration = new Configuration() { RepositoryPath = new PathConfiguration() { Location = repo_path } }, Dependencies = new DependencyDefinition[0], Repositories = new Repository[0], UnityVersion = "foo" }; UpfileExposer.SetInstance(dummy); InstalledPackage package_A = new InstalledPackage() { Name = "packageA", Install = new InstallSpec[0], Version = "0.0.0" }; Upbring test = new Upbring() { InstalledPackage = new InstalledPackage[] { package_A } }; test.SaveFile(); XmlSerializer serializer = new XmlSerializer(typeof(Upbring)); Upbring parsed; using (FileStream fs = new FileStream(Path.Combine(repo_path, "Upbring.xml"), FileMode.Open)) { parsed = serializer.Deserialize(fs) as Upbring; } Assert.That(parsed.InstalledPackage.Any(p => p.Name == test.InstalledPackage[0].Name && p.Version == test.InstalledPackage[0].Version )); } finally { Directory.SetCurrentDirectory(pwd); Directory.Delete(temp_dir, true); } }
//FIXME: This is super unsafe right now, as we can copy down into the FS. // This should be contained using kinds of destinations. private void InstallPackage(Upset package, TemporaryDirectory td, DependencyDefinition dependencyDefinition, bool updateLockfile = false) { GitIgnorer VCSHandler = new GitIgnorer(); using (LogAggregator LA = LogAggregator.InUnity( "Package {0} was successfully installed", "Package {0} was successfully installed but raised warnings", "An error occured while installing package {0}", package.PackageName )) { Upbring upbring = Upbring.Instance(); // Note: Full package is ALWAYS copied to the upackages directory right now string localPackagePath = GetRepositoryInstallPath(package); upbring.AddPackage(package); if (!Directory.Exists(localPackagePath)) { Directory.CreateDirectory(localPackagePath); } Uplift.Common.FileSystemUtil.CopyDirectory(td.Path, localPackagePath); upbring.AddLocation(package, InstallSpecType.Root, localPackagePath); VCSHandler.HandleDirectory(upfile.GetPackagesRootPath()); InstallSpecPath[] specArray; if (package.Configuration == null) { // If there is no Configuration present we assume // that the whole package is wrapped in "InstallSpecType.Base" InstallSpecPath wrapSpec = new InstallSpecPath { Path = "", Type = InstallSpecType.Base }; specArray = new[] { wrapSpec }; } else { specArray = package.Configuration; } foreach (InstallSpecPath spec in specArray) { if (dependencyDefinition.SkipInstall != null && dependencyDefinition.SkipInstall.Any(skip => skip.Type == spec.Type)) { continue; } var sourcePath = Uplift.Common.FileSystemUtil.JoinPaths(td.Path, spec.Path); PathConfiguration PH = upfile.GetDestinationFor(spec); if (dependencyDefinition.OverrideDestination != null && dependencyDefinition.OverrideDestination.Any(over => over.Type == spec.Type)) { PH.Location = Uplift.Common.FileSystemUtil.MakePathOSFriendly(dependencyDefinition.OverrideDestination.First(over => over.Type == spec.Type).Location); } var packageStructurePrefix = PH.SkipPackageStructure ? "" : GetPackageDirectory(package); var destination = Path.Combine(PH.Location, packageStructurePrefix); // Working with single file if (File.Exists(sourcePath)) { // Working with singular file if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); VCSHandler.HandleFile(destination); } if (Directory.Exists(destination)) { // we are copying a file into a directory destination = System.IO.Path.Combine(destination, System.IO.Path.GetFileName(sourcePath)); } File.Copy(sourcePath, destination); Uplift.Common.FileSystemUtil.TryCopyMeta(sourcePath, destination); if (destination.StartsWith("Assets")) { TryUpringAddGUID(upbring, sourcePath, package, spec.Type, destination); } else { upbring.AddLocation(package, spec.Type, destination); } } // Working with directory if (Directory.Exists(sourcePath)) { // Working with directory Uplift.Common.FileSystemUtil.CopyDirectoryWithMeta(sourcePath, destination); if (!PH.SkipPackageStructure) { VCSHandler.HandleDirectory(destination); } bool useGuid = destination.StartsWith("Assets"); foreach (var file in Uplift.Common.FileSystemUtil.RecursivelyListFiles(sourcePath, true)) { if (useGuid) { TryUpringAddGUID(upbring, file, package, spec.Type, destination); } else { upbring.AddLocation(package, spec.Type, Path.Combine(destination, file)); } if (PH.SkipPackageStructure) { VCSHandler.HandleFile(Path.Combine(destination, file)); } } } } upbring.SaveFile(); if (updateLockfile) { LockfileSnapshot snapshot = LoadLockfile(); int index; bool found = false; for (index = 0; index < snapshot.installableDependencies.Length; index++) { if (snapshot.installableDependencies[index].Package.PackageName == package.PackageName) { found = true; break; } } if (found) { snapshot.installableDependencies[index].Package = package; } else { Array.Resize <PackageRepo>(ref snapshot.installableDependencies, snapshot.installableDependencies.Length + 1); snapshot.installableDependencies[snapshot.installableDependencies.Length] = new PackageRepo { Package = package }; } GenerateLockfile(snapshot); } td.Dispose(); UnityHacks.BuildSettingsEnforcer.EnforceAssetSave(); } }
//FIXME: This is super unsafe right now, as we can copy down into the FS. // This should be contained using kinds of destinations. public void InstallPackage(Upset package, TemporaryDirectory td, DependencyDefinition dependencyDefinition) { Upbring upbring = Upbring.Instance(); // Note: Full package is ALWAYS copied to the upackages directory right now string localPackagePath = GetRepositoryInstallPath(package); upbring.AddPackage(package); FileSystemUtil.CopyDirectory(td.Path, localPackagePath); upbring.AddLocation(package, InstallSpecType.Root, localPackagePath); InstallSpecPath[] specArray; if (package.Configuration == null) { // If there is no Configuration present we assume // that the whole package is wrapped in "InstallSpecType.Base" InstallSpecPath wrapSpec = new InstallSpecPath { Path = "", Type = InstallSpecType.Base }; specArray = new[] { wrapSpec }; } else { specArray = package.Configuration; } foreach (InstallSpecPath spec in specArray) { if (dependencyDefinition.SkipInstall != null && dependencyDefinition.SkipInstall.Any(skip => skip.Type == spec.Type)) { continue; } var sourcePath = Uplift.Common.FileSystemUtil.JoinPaths(td.Path, spec.Path); PathConfiguration PH = upfile.GetDestinationFor(spec); if (dependencyDefinition.OverrideDestination != null && dependencyDefinition.OverrideDestination.Any(over => over.Type == spec.Type)) { PH.Location = Uplift.Common.FileSystemUtil.MakePathOSFriendly(dependencyDefinition.OverrideDestination.First(over => over.Type == spec.Type).Location); } var packageStructurePrefix = PH.SkipPackageStructure ? "" : GetPackageDirectory(package); var destination = Path.Combine(PH.Location, packageStructurePrefix); // Working with single file if (File.Exists(sourcePath)) { // Working with singular file if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); } File.Copy(sourcePath, destination); FileSystemUtil.TryCopyMeta(sourcePath, destination); if (destination.StartsWith("Assets")) { TryUpringAddGUID(upbring, sourcePath, package, spec.Type, destination); } else { upbring.AddLocation(package, spec.Type, destination); } } // Working with directory if (Directory.Exists(sourcePath)) { // Working with directory Uplift.Common.FileSystemUtil.CopyDirectoryWithMeta(sourcePath, destination); if (destination.StartsWith("Assets")) { foreach (var file in Uplift.Common.FileSystemUtil.RecursivelyListFiles(sourcePath, true)) { TryUpringAddGUID(upbring, file, package, spec.Type, destination); } } else { foreach (var file in Uplift.Common.FileSystemUtil.RecursivelyListFiles(sourcePath, true)) { upbring.AddLocation(package, spec.Type, Path.Combine(destination, file)); } } } } upbring.SaveFile(); td.Dispose(); }