Exemplo n.º 1
0
        private static Stream TryGetStream(ResourceType resourceType, string resource, IEnvironment environment)
        {
            /*
             *      This function attempts to get files embedded in the callers assembly.
             *      Unity.VersionControl.Git which tends to contain logos
             *      Git.Api which tends to contain application resources
             *
             *      Each file's name is their physical path in the project.
             *
             *      When running tests, we assume the tests are looking for application resources, and default to returning Git.Api
             *
             *      First check for the resource in the calling assembly.
             *      If the resource cannot be found, fallback to looking in Git.Api's assembly.
             *      If the resource is still not found, it attempts to find it in the file system
             */

            (string type, string os) = ParseResourceType(resourceType, environment);

            var stream = TryGetResource(resourceType, type, os, resource);

            if (stream != null)
            {
                return(stream);
            }

            SPath possiblePath = environment.ExtensionInstallPath.Combine(type, os, resource);

            if (possiblePath.FileExists())
            {
                return(new MemoryStream(possiblePath.ReadAllBytes()));
            }
            return(null);
        }
Exemplo n.º 2
0
        private static SPath TryGetFile(ResourceType resourceType, string resource, IEnvironment environment)
        {
            /*
             *      This function attempts to get files embedded in the callers assembly.
             *
             *      Each file's name is their physical path in the project.
             *
             *      First check for the resource in the calling assembly.
             *      If the resource is still not found, it attempts to find it in the file system
             */

            (string type, string os) = ParseResourceType(resourceType, environment);

            var stream = TryGetResource(resourceType, type, os, resource);

            if (stream != null)
            {
                var target = SPath.GetTempFilename();
                return(target.WriteAllBytes(stream.ToByteArray()));
            }

            SPath possiblePath = environment.ExtensionInstallPath.Combine(type, os, resource);

            if (possiblePath.FileExists())
            {
                return(possiblePath);
            }

            return(SPath.Default);
        }
Exemplo n.º 3
0
        private static SPath TryGetFile(ResourceType resourceType, string resource, IGitEnvironment environment)
        {
            /*
             *  This function attempts to get files embedded in the callers assembly.
             *  Unity.VersionControl.Git which tends to contain logos
             *  Git.Api which tends to contain application resources
             *
             *  Each file's name is their physical path in the project.
             *
             *  When running tests, we assume the tests are looking for application resources, and default to returning Git.Api
             *
             *  First check for the resource in the calling assembly.
             *  If the resource cannot be found, fallback to looking in Git.Api's assembly.
             *  If the resource is still not found, it attempts to find it in the file system
             */

            (string type, string os) = ParseResourceType(resourceType, environment);

            var stream = TryGetResource(resourceType, type, os, resource);

            if (stream != null)
            {
                var target = SPath.GetTempFilename();
                return(target.WriteAllBytes(stream.ToByteArray()));
            }

            SPath possiblePath = environment.ExtensionInstallPath.Combine(type, os, resource);

            if (possiblePath.FileExists())
            {
                return(possiblePath);
            }

            var basePath = resourceType == ResourceType.Icon ? "Editor" : "Api";

            possiblePath = environment.ExtensionInstallPath.Parent.Combine(basePath, type, os, resource);
            if (possiblePath.FileExists())
            {
                return(possiblePath);
            }

            return(SPath.Default);
        }
        public static DugiteReleaseManifest Load(ITaskManager taskManager, SPath localCacheFile,
                                                 UriString packageFeed, IGitEnvironment environment,
                                                 bool alwaysDownload = false)
        {
            DugiteReleaseManifest package = null;
            var filename = localCacheFile.FileName;
            var cacheDir = localCacheFile.Parent;
            var key      = localCacheFile.FileNameWithoutExtension + "_updatelastCheckTime";
            var now      = DateTimeOffset.Now;

            if (!localCacheFile.FileExists() ||
                (alwaysDownload || now.Date > environment.UserSettings.Get <DateTimeOffset>(key).Date))
            {
                var result = new DownloadTask(taskManager, packageFeed,
                                              localCacheFile.Parent, filename)
                             .Catch(ex => {
                    Logger.Warning(@"Error downloading package feed:{0} ""{1}"" Message:""{2}""", packageFeed,
                                   ex.GetType().ToString(), ex.GetExceptionMessageShort());
                    return(true);
                }).RunSynchronously();
                localCacheFile = result.ToSPath();
                if (localCacheFile.IsInitialized && !alwaysDownload)
                {
                    environment.UserSettings.Set <DateTimeOffset>(key, now);
                }
            }

            if (!localCacheFile.IsInitialized)
            {
                // try from assembly resources
                localCacheFile = AssemblyResources.ToFile(ResourceType.Platform, filename, cacheDir, environment);
            }

            if (localCacheFile.IsInitialized)
            {
                try
                {
                    package = Load(taskManager, localCacheFile, cacheDir, environment);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
            }
            return(package);
        }
Exemplo n.º 5
0
        public static bool VerifyFileIntegrity(SPath file, string hash)
        {
            if (!file.IsInitialized || !file.FileExists())
            {
                return(false);
            }
            string actual = null;

            if (hash.Length == 32)
            {
                actual = file.ToMD5();
            }
            else
            {
                actual = file.ToSha256();
            }
            return(hash.Equals(actual, StringComparison.InvariantCultureIgnoreCase));
        }
Exemplo n.º 6
0
        public static DugiteReleaseManifest Load(SPath localCacheFile, UriString packageFeed, IEnvironment environment)
        {
            DugiteReleaseManifest package = null;
            //SPath localCacheFeed = environment.UserCachePath.Combine("embedded-git.json");
            var filename = localCacheFile.FileName;
            var key      = localCacheFile.FileNameWithoutExtension + "_updatelastCheckTime";
            var now      = DateTimeOffset.Now;

            if (!localCacheFile.FileExists() || now.Date > environment.UserSettings.Get <DateTimeOffset>(key).Date)
            {
                localCacheFile = new DownloadTask(TaskManager.Instance.Token, environment.FileSystem, packageFeed, environment.UserCachePath, filename)
                                 .Catch(ex => {
                    LogHelper.Warning(@"Error downloading package feed:{0} ""{1}"" Message:""{2}""", packageFeed, ex.GetType().ToString(), ex.GetExceptionMessageShort());
                    return(true);
                })
                                 .RunSynchronously();

                if (localCacheFile.IsInitialized)
                {
                    environment.UserSettings.Set <DateTimeOffset>(key, now);
                }
            }

            if (!localCacheFile.IsInitialized)
            {
                // try from assembly resources
                localCacheFile = AssemblyResources.ToFile(ResourceType.Platform, packageFeed.Filename, environment.UserCachePath, environment);
            }

            if (localCacheFile.IsInitialized)
            {
                try
                {
                    package = Load(localCacheFile, environment);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
            }
            return(package);
        }