Пример #1
0
        internal static IEnumerable <Sample> FindByPackage(PackageInfo package, UpmCache upmCache, IOProxy ioProxy, AssetDatabaseProxy assetDatabaseProxy)
        {
            if (string.IsNullOrEmpty(package?.upmReserved) && string.IsNullOrEmpty(package.resolvedPath))
            {
                return(Enumerable.Empty <Sample>());
            }

            try
            {
                IEnumerable <IDictionary <string, object> > samples = null;
                var upmReserved = upmCache.ParseUpmReserved(package);
                if (upmReserved != null)
                {
                    samples = upmReserved.GetList <IDictionary <string, object> >("samples");
                }

                if (samples == null)
                {
                    var jsonPath = ioProxy.PathsCombine(package.resolvedPath, "package.json");
                    if (ioProxy.FileExists(jsonPath))
                    {
                        var packageJson = Json.Deserialize(ioProxy.FileReadAllText(jsonPath)) as Dictionary <string, object>;
                        samples = packageJson.GetList <IDictionary <string, object> >("samples");
                    }
                }

                return(samples?.Select(sample =>
                {
                    var displayName = sample.GetString("displayName");
                    var path = sample.GetString("path");
                    var description = sample.GetString("description");
                    var interactiveImport = sample.Get("interactiveImport", false);

                    var resolvedSamplePath = ioProxy.PathsCombine(package.resolvedPath, path);
                    var importPath = ioProxy.PathsCombine(
                        Application.dataPath,
                        "Samples",
                        IOUtils.SanitizeFileName(package.displayName),
                        package.version,
                        string.IsNullOrEmpty(displayName) ? string.Empty : IOUtils.SanitizeFileName(displayName)
                        );
                    return new Sample(ioProxy, assetDatabaseProxy, displayName, description, resolvedSamplePath, importPath, interactiveImport);
                }).ToArray() ?? Enumerable.Empty <Sample>());
            }
            catch (IOException e)
            {
                Debug.Log($"[Package Manager Window] Cannot find samples for package {package.displayName}: {e}");
                return(Enumerable.Empty <Sample>());
            }
            catch (InvalidCastException e)
            {
                Debug.Log($"[Package Manager Window] Invalid sample data for package {package.displayName}: {e}");
                return(Enumerable.Empty <Sample>());
            }
            catch (Exception)
            {
                return(Enumerable.Empty <Sample>());
            }
        }
Пример #2
0
 private static string GetOfflineLicensesUrl(IOProxy IOProxy, UpmPackageVersion version)
 {
     if (version?.isAvailableOnDisk ?? false)
     {
         var licenseFile = Path.Combine(version.packageInfo.resolvedPath, "LICENSE.md");
         return(IOProxy.FileExists(licenseFile) ? new Uri(licenseFile).AbsoluteUri : string.Empty);
     }
     return(string.Empty);
 }
Пример #3
0
 private static string GetOfflineChangelogUrl(IOProxy IOProxy, UpmPackageVersion version)
 {
     if (version?.isAvailableOnDisk ?? false)
     {
         var changelogFile = Path.Combine(version.packageInfo.resolvedPath, "CHANGELOG.md");
         return(IOProxy.FileExists(changelogFile) ? new Uri(changelogFile).AbsoluteUri : string.Empty);
     }
     return(string.Empty);
 }
Пример #4
0
        private IEnumerable <Sample> GetSamplesFromPackageInfo(PackageInfo packageInfo)
        {
            if (string.IsNullOrEmpty(packageInfo?.resolvedPath))
            {
                return(Enumerable.Empty <Sample>());
            }

            var jsonPath = Path.Combine(packageInfo.resolvedPath, "package.json");

            if (!m_IOProxy.FileExists(jsonPath))
            {
                return(Enumerable.Empty <Sample>());
            }

            try
            {
                var packageJson = Json.Deserialize(m_IOProxy.FileReadAllText(jsonPath)) as Dictionary <string, object>;
                var samples     = packageJson.GetList <IDictionary <string, object> >("samples");
                return(samples?.Select(sample =>
                {
                    var displayName = sample.GetString("displayName");
                    var path = sample.GetString("path");
                    var description = sample.GetString("description");
                    var interactiveImport = sample.Get("interactiveImport", false);

                    var resolvedSamplePath = Path.Combine(packageInfo.resolvedPath, path);
                    var importPath = IOUtils.CombinePaths(
                        Application.dataPath,
                        "Samples",
                        IOUtils.SanitizeFileName(packageInfo.displayName),
                        packageInfo.version,
                        IOUtils.SanitizeFileName(displayName)
                        );
                    return new Sample(m_IOProxy, m_AssetDatabase, displayName, description, resolvedSamplePath, importPath, interactiveImport);
                }));
            }
            catch (Exception)
            {
                return(Enumerable.Empty <Sample>());
            }
        }
Пример #5
0
        public virtual void Import(IPackage package)
        {
            if (!(package is AssetStorePackage))
            {
                return;
            }

            var path = package.versions.primary.localPath;

            if (m_IOProxy.FileExists(path))
            {
                AssetDatabase.ImportPackage(path, true);
            }
        }
Пример #6
0
        public virtual Texture2D LoadImage(long productId, string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(null);
            }

            var hash = Hash128.Compute(url);
            var path = Paths.Combine(m_Application.userAppDataPath, "Asset Store", "Cache", "Images", productId.ToString(), hash.ToString());

            if (m_IOProxy.FileExists(path))
            {
                var texture = new Texture2D(2, 2);
                if (texture.LoadImage(m_IOProxy.FileReadAllBytes(path)))
                {
                    return(texture);
                }
            }

            return(null);
        }
Пример #7
0
 public void SetLocalPath(string path)
 {
     m_LocalPath         = path ?? string.Empty;
     m_IsAvailableOnDisk = !string.IsNullOrEmpty(m_LocalPath) && m_IOProxy.FileExists(m_LocalPath);
 }