Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="packages"></param>
        /// <param name="listingRoot">version in subdir name, contents in subdir/package.tgz, version and displayName also in subdir/package/package.json</param>
        /// <param name="contentCacheRoot">version number = "dir name@version", contents in dir, version and displayName in package.json</param>
        public static void Load(List <AbstractPackage> packages)
        {
            if (packages is null)
            {
                throw new ArgumentNullException(nameof(packages));
            }

            var packageFactory = new JsonFactory <NpmPackage>();

            var localAppDataPath             = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            var unityCachePath               = Path.Combine(localAppDataPath, "Unity", "cache");
            var unityPackageListingRoot      = Path.Combine(unityCachePath, "npm", "packages.unity.com");      // version in subdir name, contents in subdir/package.tgz, version and displayName also in subdir/package/package.json
            var unityPackageContentCacheRoot = Path.Combine(unityCachePath, "packages", "packages.unity.com"); // version number = "dir name@version", contents in dir, version and displayName in package.json

            var listingRootDir = new DirectoryInfo(unityPackageListingRoot);

            foreach (var packageDir in listingRootDir.GetDirectories())
            {
                if (packageDir.Name != "packages.unity.com")
                {
                    foreach (var versionDir in packageDir.GetDirectories())
                    {
                        var packageFileName = Path.Combine(versionDir.FullName, "package", "package.json");
                        using var stream = FileDataSource.Instance.GetStream(packageFileName);
                        var package     = packageFactory.Deserialize(stream);
                        var packageName = package.DisplayName;
                        if (packageName.StartsWith("Oculus", StringComparison.OrdinalIgnoreCase))
                        {
                            packageName = packageName.Replace("(", "")
                                          .Replace(")", "");
                        }
                        var version     = package.Version;
                        var packagePath = Path.Combine(unityPackageContentCacheRoot, $"{packageDir.Name}@{version}");
                        packages.Add(new UnityPackage(package.Name, packageName, version, versionDir.FullName, packagePath));
                    }
                }
            }

            if (Project.UnityEditorRoot != null)
            {
                var builtInRoot    = Path.Combine(Project.UnityEditorRoot, "Editor", "Data", "Resources", "PackageManager", "BuiltInPackages");
                var builtInRootDir = new DirectoryInfo(builtInRoot);
                foreach (var packageDir in builtInRootDir.GetDirectories())
                {
                    var packageFileName = Path.Combine(packageDir.FullName, "package.json");
                    using var stream = FileDataSource.Instance.GetStream(packageFileName);
                    var package     = packageFactory.Deserialize(stream);
                    var packageName = package.DisplayName;
                    var version     = package.Version;
                    packages.Add(new UnityPackage(package.Name, packageName, version, packageDir.FullName));
                }
            }
        }
Exemplo n.º 2
0
        public static Platforms Load()
        {
            if (platforms is null)
            {
                using var stream = FileDataSource.Instance.GetStream(Project.JuniperPlatformsFileName);
                var configFactory = new JsonFactory <Platforms>();
                platforms = configFactory.Deserialize(stream);
            }

            return(platforms);
        }
Exemplo n.º 3
0
        public static UnityPackageManifest Load()
        {
            if (manifest is null)
            {
                var unityPackageManifestPath = Path.Combine(Project.UnityProjectRoot, "Packages", "manifest.json");
                using var stream = FileDataSource.Instance.GetStream(unityPackageManifestPath);
                var factory = new JsonFactory <UnityPackageManifest>();
                manifest = factory.Deserialize(stream);
            }

            return(manifest);
        }