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; }
public void Nuke() { GitIgnorer ignorer = new GitIgnorer(); using (LogAggregator LA = LogAggregator.InUnity( "Package {0} was successfully nuked", "Package {0} was successfully nuked but raised warnings", "An error occured while installing package {0}", Name )) { var dirPaths = new List <string>(); foreach (InstallSpec spec in Install) { if (spec is InstallSpecPath) { InstallSpecPath specPath = spec as InstallSpecPath; var friendlyPath = Uplift.Common.FileSystemUtil.MakePathWindowsFriendly(specPath.Path); if (specPath.Type == InstallSpecType.Root) { // Removing Root package Directory.Delete(friendlyPath, true); } if (friendlyPath.Contains("gitignore")) { // Do not remove the file but rather the reference to the package if (!ignorer.TryRemoveFile(friendlyPath)) { Debug.LogFormat("The .gitignore at {0} cannot be deleted by Uplift. Please make sure it doesn't cause any kind of issue.", friendlyPath); } } else { try { File.Delete(friendlyPath); File.Delete(friendlyPath + ".meta"); // Removing meta files as well. } catch (FileNotFoundException) { Debug.Log("Warning, tracked file not found: " + friendlyPath); } catch (DirectoryNotFoundException) { Debug.Log("Warning, tracked directory not found: " + friendlyPath); } string dirName = Path.GetDirectoryName(friendlyPath); if (!string.IsNullOrEmpty(dirName)) { dirPaths.Add(dirName); } } } else if (spec is InstallSpecGUID) { InstallSpecGUID specGuid = spec as InstallSpecGUID; string guidPath = AssetDatabase.GUIDToAssetPath(specGuid.Guid); if (String.IsNullOrEmpty(guidPath)) { Debug.Log("Warning, tracked file not found: guid: " + specGuid.Guid + " " + specGuid.Type); return; } if (specGuid.Type == InstallSpecType.Root) { // Removing Root package Directory.Delete(guidPath, true); } else { try { File.Delete(guidPath); File.Delete(guidPath + ".meta"); // Removing meta files as well. } catch (FileNotFoundException) { Debug.Log("Warning, tracked file not found: " + guidPath); } catch (DirectoryNotFoundException) { Debug.Log("Warning, tracked directory not found: " + guidPath); } string dirName = Path.GetDirectoryName(guidPath); if (!string.IsNullOrEmpty(dirName)) { dirPaths.Add(dirName); } } } } // An itchy bit. // Paths can nest. Ordering of paths is not guaranteed. // So we'll loop over removing dirs to the point, where no action has been made. var actionsDone = 1; var loopCounter = 1; while (actionsDone != 0) { if (loopCounter > 5) { Debug.LogWarning( "Warning: Nuke Dependency Loop has done more than 5 rounds. This might or might not be error, depending on setup" ); } actionsDone = 0; loopCounter++; // We're recursively listing the directories we're keeping so that we can extract empty directories. var recursiveDirPaths = Uplift.Common.FileSystemUtil.RecursivelyDirPaths(dirPaths).Distinct().ToList(); foreach (var p in recursiveDirPaths) { if (string.IsNullOrEmpty(p)) { continue; } if (!Directory.Exists(p)) { continue; } var filesInDirectory = Directory.GetFiles(p).Length; var directoriesInDirectory = Directory.GetDirectories(p).Length; if (filesInDirectory + directoriesInDirectory > 0) { continue; } try { Directory.Delete(p, true); actionsDone += 1; File.Delete(p + ".meta"); // .meta file for directory might exist, remove it as well } catch (DirectoryNotFoundException) { } } } } }
public void Nuke() { var dirPaths = new List <string>(); foreach (InstallSpec spec in Install) { if (spec is InstallSpecPath) { InstallSpecPath specPath = spec as InstallSpecPath; if (specPath.Type == InstallSpecType.Root) { // Removing Root package Directory.Delete(specPath.Path, true); } else { var filePath = specPath.Path; try { File.Delete(filePath); File.Delete(filePath + ".meta"); // Removing meta files as well. } catch (FileNotFoundException) { Debug.Log("Warning, tracked file not found: " + filePath); } catch (DirectoryNotFoundException) { Debug.Log("Warning, tracked directory not found: " + filePath); } string dirName = Path.GetDirectoryName(specPath.Path); if (!string.IsNullOrEmpty(dirName)) { dirPaths.Add(dirName); } } } else if (spec is InstallSpecGUID) { InstallSpecGUID specGuid = spec as InstallSpecGUID; string guidPath = AssetDatabase.GUIDToAssetPath(specGuid.Guid); if (specGuid.Type == InstallSpecType.Root) { // Removing Root package Directory.Delete(guidPath, true); } else { try { Debug.Log(specGuid.Guid + guidPath); File.Delete(guidPath); File.Delete(guidPath + ".meta"); // Removing meta files as well. } catch (FileNotFoundException) { Debug.Log("Warning, tracked file not found: " + guidPath); } catch (DirectoryNotFoundException) { Debug.Log("Warning, tracked directory not found: " + guidPath); } string dirName = Path.GetDirectoryName(guidPath); if (!string.IsNullOrEmpty(dirName)) { dirPaths.Add(dirName); } } } } // An itchy bit. // Paths can nest. Ordering of paths is not guaranteed. // So we'll loop over removing dirs to the point, where no action has been made. var actionsDone = 1; var loopCounter = 1; while (actionsDone != 0) { if (loopCounter > 5) { Debug.LogWarning( "Warning: Nuke Dependency Loop has done more than 5 rounds. This might or might not be error, depending on setup" ); } actionsDone = 0; loopCounter++; // We're recursively listing the directories we're keeping so that we can extract empty directories. var recursiveDirPaths = Uplift.Common.FileSystemUtil.RecursivelyDirPaths(dirPaths).Distinct().ToList(); foreach (var p in recursiveDirPaths) { if (string.IsNullOrEmpty(p)) { continue; } if (!Directory.Exists(p)) { continue; } var filesInDirectory = Directory.GetFiles(p).Length; var directoriesInDirectory = Directory.GetDirectories(p).Length; if (filesInDirectory + directoriesInDirectory > 0) { continue; } try { Directory.Delete(p, true); actionsDone += 1; File.Delete(p + ".meta"); // .meta file for directory might exist, remove it as well } catch (DirectoryNotFoundException) { } } } }