X-Git-Url: https://code.delx.au/refind/blobdiff_plain/5cef5a4a05120d224fc8d6d72743c3432c546904..83d9696df1452690a2a7cb2c17208feaee3e411f:/refind/lib.c diff --git a/refind/lib.c b/refind/lib.c index db3a6dd..66dbe00 100644 --- a/refind/lib.c +++ b/refind/lib.c @@ -48,6 +48,7 @@ #include "screen.h" #include "../include/refit_call_wrapper.h" #include "../include/RemovableMedia.h" +//#include "../include/UsbMass.h" #ifdef __MAKEWITH_GNUEFI #define EfiReallocatePool ReallocatePool @@ -92,9 +93,6 @@ UINTN VolumesCount = 0; // and identify its boot loader, and hence probable BIOS-mode OS installation #define SAMPLE_SIZE 69632 /* 68 KiB -- ReiserFS superblock begins at 64 KiB */ -// Default names for volume badges (mini-icon to define disk type) and icons -#define VOLUME_BADGE_NAMES L".VolumeBadge.icns,.VolumeBadge.png" -#define VOLUME_ICON_NAMES L".VolumeIcon.icns,.VolumeIcon.png" // functions @@ -153,24 +151,26 @@ VOID CleanUpPathNameSlashes(IN OUT CHAR16 *PathName) { // after that string (after some cleanup) as the return value, and truncating the original // input value. // If InString contains no ")" character, this function leaves the original input string -// unmodified and also returns that string. +// unmodified and also returns that string. If InString is NULL, this function returns NULL. static CHAR16* SplitDeviceString(IN OUT CHAR16 *InString) { INTN i; CHAR16 *FileName = NULL; BOOLEAN Found = FALSE; - i = StrLen(InString) - 1; - while ((i >= 0) && (!Found)) { - if (InString[i] == L')') { - Found = TRUE; - FileName = StrDuplicate(&InString[i + 1]); - CleanUpPathNameSlashes(FileName); - InString[i + 1] = '\0'; - } // if - i--; - } // while - if (FileName == NULL) - FileName = StrDuplicate(InString); + if (InString != NULL) { + i = StrLen(InString) - 1; + while ((i >= 0) && (!Found)) { + if (InString[i] == L')') { + Found = TRUE; + FileName = StrDuplicate(&InString[i + 1]); + CleanUpPathNameSlashes(FileName); + InString[i + 1] = '\0'; + } // if + i--; + } // while + if (FileName == NULL) + FileName = StrDuplicate(InString); + } // if return FileName; } // static CHAR16* SplitDeviceString() @@ -850,9 +850,9 @@ VOID ScanVolume(REFIT_VOLUME *Volume) // get custom volume icon if present if (!Volume->VolBadgeImage) - Volume->VolBadgeImage = LoadIcns(Volume->RootDir, VOLUME_BADGE_NAMES, 32); + Volume->VolBadgeImage = egLoadIconAnyType(Volume->RootDir, L"", L".VolumeBadge", 32); if (!Volume->VolIconImage) - Volume->VolIconImage = LoadIcns(Volume->RootDir, VOLUME_ICON_NAMES, 128); + Volume->VolIconImage = egLoadIconAnyType(Volume->RootDir, L"", L".VolumeIcon", 128); } // ScanVolume() static VOID ScanExtendedPartition(REFIT_VOLUME *WholeDiskVolume, MBR_PARTITION_INFO *MbrEntry) @@ -1273,11 +1273,12 @@ BOOLEAN DirIterNext(IN OUT REFIT_DIR_ITER *DirIter, IN UINTN FilterMode, IN CHAR while (KeepGoing && (OnePattern = FindCommaDelimited(FilePattern, i++)) != NULL) { if (MetaiMatch(DirIter->LastFileInfo->FileName, OnePattern)) KeepGoing = FALSE; +// Print(L"%s did%s match %s\n", DirIter->LastFileInfo->FileName, KeepGoing ? L" not" : L"", OnePattern); } // while // else continue loop } else break; - } while (KeepGoing); + } while (KeepGoing && FilePattern); *DirEntry = DirIter->LastFileInfo; return TRUE; @@ -1336,21 +1337,6 @@ CHAR16 * StripEfiExtension(CHAR16 *FileName) { return Copy; } // CHAR16 * StripExtension() -// Replaces a filename extension of ".efi" with the specified string -// (Extension). If the input Path doesn't end in ".efi", Extension -// is added to the existing filename. -// VOID ReplaceEfiExtension(IN OUT CHAR16 *Path, IN CHAR16 *Extension) -// { -// UINTN PathLen; -// -// PathLen = StrLen(Path); -// // Note: Do StriCmp() twice to work around Gigabyte Hybrid EFI case-sensitivity bug.... -// if ((PathLen >= 4) && ((StriCmp(&Path[PathLen - 4], L".efi") == 0) || (StriCmp(&Path[PathLen - 4], L".EFI") == 0))) { -// Path[PathLen - 4] = 0; -// } // if -// StrCat(Path, Extension); -// } // VOID ReplaceEfiExtension() - // // memory string search // @@ -1471,6 +1457,9 @@ CHAR16 *FindLastDirName(IN CHAR16 *Path) { UINTN i, StartOfElement = 0, EndOfElement = 0, PathLength, CopyLength; CHAR16 *Found = NULL; + if (Path == NULL) + return NULL; + PathLength = StrLen(Path); // Find start & end of target element for (i = 0; i < PathLength; i++) { @@ -1501,14 +1490,16 @@ CHAR16 *FindLastDirName(IN CHAR16 *Path) { // freeing the returned string's memory. CHAR16 *FindPath(IN CHAR16* FullPath) { UINTN i, LastBackslash = 0; - CHAR16 *PathOnly; + CHAR16 *PathOnly = NULL; - for (i = 0; i < StrLen(FullPath); i++) { - if (FullPath[i] == '\\') - LastBackslash = i; - } // for - PathOnly = StrDuplicate(FullPath); - PathOnly[LastBackslash] = 0; + if (FullPath != NULL) { + for (i = 0; i < StrLen(FullPath); i++) { + if (FullPath[i] == '\\') + LastBackslash = i; + } // for + PathOnly = StrDuplicate(FullPath); + PathOnly[LastBackslash] = 0; + } // if return (PathOnly); } @@ -1581,6 +1572,9 @@ CHAR16 *FindNumbers(IN CHAR16 *InString) { UINTN i, StartOfElement, EndOfElement = 0, InLength, CopyLength; CHAR16 *Found = NULL; + if (InString == NULL) + return NULL; + InLength = StartOfElement = StrLen(InString); // Find start & end of target element for (i = 0; i < InLength; i++) {