KNFoundation.KNBundle.PathsForResourcesOfTypeInDirectory C# (CSharp) Method

PathsForResourcesOfTypeInDirectory() public method

public PathsForResourcesOfTypeInDirectory ( string type, string subDirectory ) : string[]
type string
subDirectory string
return string[]
        public string[] PathsForResourcesOfTypeInDirectory(string type, string subDirectory)
        {
            Dictionary<string, string> namesAndPaths = new Dictionary<string, string>();

            string nonLocalisedPathToSearch = ResourcesPath;
            if (!String.IsNullOrEmpty(subDirectory)) {
                nonLocalisedPathToSearch = Path.Combine(ResourcesPath, subDirectory);
            }

            if (Directory.Exists(nonLocalisedPathToSearch)) {

                foreach (string resourceName in Directory.GetFiles(nonLocalisedPathToSearch)) {

                    string fullPath = Path.Combine(nonLocalisedPathToSearch, resourceName);

                    if (Path.GetExtension(fullPath).Replace(".", "") == type) {
                        namesAndPaths.Add(resourceName, fullPath);
                    }
                }
            }

            // Now do localized. The localized should override the non-localized.

            string localisedPathToSearch = LocalisedResourcesPath;
            if (!String.IsNullOrEmpty(subDirectory)) {
                localisedPathToSearch = Path.Combine(LocalisedResourcesPath, subDirectory);
            }

            if (Directory.Exists(localisedPathToSearch)) {

                foreach (string resourceName in Directory.GetFiles(localisedPathToSearch)) {

                    string fullPath = Path.Combine(localisedPathToSearch, resourceName);

                    if (Path.GetExtension(fullPath).Replace(".", "") == type) {
                        if (namesAndPaths.ContainsKey(resourceName)) {
                            namesAndPaths.Remove(resourceName);
                        }
                        namesAndPaths.Add(resourceName, fullPath);
                    }
                }
            }

            return namesAndPaths.Values.ToArray<string>();
        }