+// Returns an icon with any extension in ICON_EXTENSIONS from either the directory
+// specified by GlobalConfig.IconsDir or DEFAULT_ICONS_DIR. The input BaseName
+// should be the icon name without an extension. For instance, if BaseName is
+// os_linux, GlobalConfig.IconsDir is myicons, DEFAULT_ICONS_DIR is icons, and
+// ICON_EXTENSIONS is "icns,png", this function will return myicons/os_linux.icns,
+// myicons/os_linux.png, icons/os_linux.icns, or icons/os_linux.png, in that
+// order of preference. Returns NULL if no such icon can be found. All file
+// references are relative to SelfDir.
+EG_IMAGE * egFindIcon(IN CHAR16 *BaseName, IN UINTN IconSize) {
+ CHAR16 *LoadDir, *Extension;
+ CHAR16 FileName[256];
+ UINTN i;
+ EG_IMAGE *Image = NULL;
+
+ if (GlobalConfig.IconsDir != NULL)
+ LoadDir = GlobalConfig.IconsDir;
+ else
+ LoadDir = StrDuplicate(DEFAULT_ICONS_DIR);
+
+ while ((LoadDir != NULL) && (Image == NULL)) {
+ i = 0;
+ while (((Extension = FindCommaDelimited(ICON_EXTENSIONS, i++)) != NULL) && (Image == NULL)) {
+ SPrint(FileName, 255, L"%s\\%s.%s", LoadDir, BaseName, Extension);
+ Image = egLoadIcon(SelfDir, FileName, IconSize);
+ MyFreePool(Extension);
+ } // while()
+ if (LoadDir == GlobalConfig.IconsDir) {
+ LoadDir = StrDuplicate(DEFAULT_ICONS_DIR);
+ } else {
+ MyFreePool(LoadDir);
+ LoadDir = NULL;
+ } // if/else
+ } // while()
+ return Image;
+} // EG_IMAGE * egFindIcon()
+