예제 #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);
            }

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

            if (possiblePath.FileExists())
            {
                return(new MemoryStream(possiblePath.ReadAllBytes()));
            }

            var basePath = resourceType == ResourceType.Icon ? "Unity.VersionControl.Git" : "Git.Api";

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

            return(null);
        }