Exemplo n.º 1
0
        public void LoadPackages(Repository repository)
        {
            using (LogAggregator la = LogAggregator.InUnity(
                       "Packages successfully loaded from {0}",
                       "Packages successfully loaded from {0}, but warning were raised",
                       "Error(s) occured while loading packages from {0}",
                       repository.ToString()
                       ))
            {
                Upset[] packages;
                try
                {
                    packages = repository.ListPackages();
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    return;
                }

                PackageRepo pr;
                foreach (Upset package in packages)
                {
                    pr = new PackageRepo
                    {
                        Package    = package,
                        Repository = repository
                    };
                    Packages.Add(pr);
                }
            }
        }
Exemplo n.º 2
0
        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)
                        {
                        }
                    }
                }
            }
        }