public static void extract_all_resources_to_relative_directory(IFileSystem fileSystem, IAssembly assembly, string directoryPath, IList <string> relativeDirectories, string resourcesToInclude, bool overwriteExisting = false, bool logOutput = false, bool throwError = true)
        {
            var resourceString = new StringBuilder();

            foreach (var resourceName in assembly.GetManifestResourceNames())
            {
                if (!resourceName.StartsWith(resourcesToInclude))
                {
                    continue;
                }
                resourceString.Clear();
                resourceString.Append(resourceName);

                //var fileExtensionLocation = resourceName.LastIndexOf('.');
                //resourceString.Remove(fileExtensionLocation, resourceString.Length - fileExtensionLocation);
                resourceString.Replace(resourcesToInclude + ".", "");
                foreach (var directory in relativeDirectories)
                {
                    resourceString.Replace("{0}".format_with(directory), "{0}{1}".format_with(directory, fileSystem.get_path_directory_separator_char()));
                }

                // replacing \. with \
                resourceString.Replace("{0}.".format_with(fileSystem.get_path_directory_separator_char()), "{0}".format_with(fileSystem.get_path_directory_separator_char()));

                var fileLocation = resourceString.ToString();
                //var fileLocation = fileSystem.combine_paths("", resourceString.ToString().Split('.')) + resourceName.Substring(fileExtensionLocation);

                var filePath = fileSystem.combine_paths(directoryPath, fileLocation);
                if (logOutput)
                {
                    "chocolatey".Log().Debug("Unpacking {0} to '{1}'".format_with(fileLocation, filePath));
                }
                extract_binary_file_from_assembly(fileSystem, assembly, resourceName, filePath, overwriteExisting, throwError);
            }
        }
        public static void extract_all_resources_to_relative_directory(IFileSystem fileSystem, IAssembly assembly, string directoryPath, IList<string> relativeDirectories, string resourcesToInclude, bool overwriteExisting = false, bool logOutput = false)
        {
            var resourceString = new StringBuilder();
            foreach (var resourceName in assembly.GetManifestResourceNames())
            {
                if (!resourceName.StartsWith(resourcesToInclude))
                {
                    continue;
                }
                resourceString.Clear();
                resourceString.Append(resourceName);

                //var fileExtensionLocation = resourceName.LastIndexOf('.');
                //resourceString.Remove(fileExtensionLocation, resourceString.Length - fileExtensionLocation);
                resourceString.Replace(resourcesToInclude + ".", "");
                foreach (var directory in relativeDirectories)
                {
                    resourceString.Replace("{0}".format_with(directory), "{0}{1}".format_with(directory, fileSystem.get_path_directory_separator_char()));
                }

                // replacing \. with \
                resourceString.Replace("{0}.".format_with(fileSystem.get_path_directory_separator_char()), "{0}".format_with(fileSystem.get_path_directory_separator_char()));

                var fileLocation = resourceString.ToString();
                //var fileLocation = fileSystem.combine_paths("", resourceString.ToString().Split('.')) + resourceName.Substring(fileExtensionLocation);

                var filePath = fileSystem.combine_paths(directoryPath, fileLocation);
                if (logOutput) "chocolatey".Log().Debug("Unpacking {0} to '{1}'".format_with(fileLocation,filePath));
                extract_binary_file_from_assembly(fileSystem, assembly, resourceName, filePath, overwriteExisting);
            }
        }
Esempio n. 3
0
        private TextureData LoadTextureDataFromEmbeddedPngResource(string assetPathWithoutExtension, ImageFormat imageFormat)
        {
            var extension = GetFileExtensionFromImageFormat(imageFormat);

            var fullAssemblyName = string.Concat(_applicationAssembly.Name, ".", assetPathWithoutExtension, extension);

            var stream = _applicationAssembly.GetManifestResourceStream(fullAssemblyName);

            if (stream == null)
            {
                var names = _applicationAssembly.GetManifestResourceNames();

                if (names.Contains(fullAssemblyName))
                {
                    _frameworkMessenger.Report("Unable to load texture data. Unknown Error. Asset stream was found by name in manifest: " + fullAssemblyName);
                }
                else
                {
                    _frameworkMessenger.Report("Unable to load texture colour data. The provided texture name was not found in assembly: " + fullAssemblyName + " | Expect location format as ASSEMBLYNAME.PATHTOTEXTURES.NAMEPROVIDED.PNG");
                }
                return(default(TextureData));
            }

            return(_imageSharpLoader.GenerateTextureDataFromStream(stream));
        }
Esempio n. 4
0
        private ITexture LoadTextureFromEmbeddedPngResource(bool isFrameworkInternal,
                                                            bool isFontTexture,
                                                            IAssembly assembly,
                                                            string assetPathWithoutExtension,
                                                            ImageFormat imageFormat,
                                                            SamplerType samplerType,
                                                            bool generateMipMaps)
        {
            var extension = GetFileExtensionFromImageFormat(imageFormat);

            var fullAssemblyName = string.Concat(assembly.Name, ".", assetPathWithoutExtension, extension);

            var stream = assembly.GetManifestResourceStream(fullAssemblyName);

            if (stream == null)
            {
                var names = assembly.GetManifestResourceNames();

                if (names.Contains(fullAssemblyName))
                {
                    _frameworkMessenger.Report("Unable to load texture. Unknown Error. Asset stream was found by name in manifest: " + fullAssemblyName);
                }
                else
                {
                    _frameworkMessenger.Report("Unable to load texture. The provided texture name was not found in assembly: " + fullAssemblyName + " | Expect location format as ASSEMBLYNAME.PATHTOTEXTURES.NAMEPROVIDED.PNG");
                }
                return(null);
            }

            return(GenerateTextureFromStream(stream, isFrameworkInternal, isFontTexture, samplerType, generateMipMaps));
        }
Esempio n. 5
0
        public bool IsResourcePathInAssembly(IAssembly assembly, string commonPath)
        {
            var assemblyPath = string.Concat(assembly.Name, ".", commonPath);

            var resourceNames = assembly.GetManifestResourceNames();

            return(resourceNames.Contains(assemblyPath));
        }
Esempio n. 6
0
        public List <string> FindDotFntFileNamePartialMatchesFromEmbeddedResource(bool isFrameworkInternal, string providedAssetPathNameWithoutAssemblyOrExtension)
        {
            //Append correct assembly name
            var fullSearchPath = string.Concat(isFrameworkInternal ? _fontsAssembly.Name : _applicationAssembly.Name, ".", providedAssetPathNameWithoutAssemblyOrExtension);

            var resourceNames = isFrameworkInternal ? _fontsAssembly.GetManifestResourceNames() : _applicationAssembly.GetManifestResourceNames();

            //Find all .fnt files that start with full search path
            var matches = resourceNames.Where(x => x.Contains(fullSearchPath)).Where(x => x.Contains(".fnt")).ToList();

            return(matches);
        }
Esempio n. 7
0
        public virtual bool IsValidEmbeddedResource(IAssembly assembly, string name)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            // ReSharper disable ConvertIfStatementToReturnStatement
            if (!assembly.GetManifestResourceNames().Contains(name, StringComparer.OrdinalIgnoreCase))
            {
                return(false);
            }
            // ReSharper restore ConvertIfStatementToReturnStatement

            return(this.IsValidEmbeddedResourceInternal(assembly, name));
        }