Refactor some Path to XStringW.

This commit is contained in:
Jief L 2020-04-27 12:50:49 +03:00
parent 4694008abe
commit de2bb5f950
26 changed files with 497 additions and 435 deletions

View File

@ -51,7 +51,7 @@ EFI_GUID *APFSPartitionUUIDExtract(
}
if (DevicePathType(DevicePath) == MEDIA_DEVICE_PATH && DevicePathSubType (DevicePath) == MEDIA_VENDOR_DP) {
//Check that vendor-assigned GUID defines APFS Container Partition
if (StriCmp(GuidLEToStr((EFI_GUID *)((UINT8 *)DevicePath+0x04)),GuidLEToStr(&APFSSignature)) == 0 ) {
if ( GuidLEToStr((EFI_GUID *)((UINT8 *)DevicePath+0x04)).equalIC(GuidLEToStr(&APFSSignature)) ) {
return (EFI_GUID *)((UINT8 *)DevicePath+0x14);
}
}

View File

@ -169,7 +169,7 @@ FindDevicePathNodeWithType (
EFI_STATUS
CreateBootOptionDevicePath (
IN EFI_HANDLE FileDeviceHandle,
IN CONST CHAR16 *FileName,
IN CONST XStringW& FileName,
IN BOOLEAN UseShortForm,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
)
@ -190,7 +190,7 @@ CreateBootOptionDevicePath (
//
// Create file path node with FileName
//
*DevicePath = FileDevicePath(FileDeviceHandle, FileName);
*DevicePath = FileDevicePath(FileDeviceHandle, FileName.wc_str());
if (*DevicePath == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@ -746,7 +746,7 @@ FindFreeBootNum (
EFI_STATUS
FindBootOptionForFile (
IN EFI_HANDLE FileDeviceHandle,
IN CONST CHAR16 *FileName,
IN CONST XStringW& FileName,
OUT UINT16 *BootNum,
OUT UINTN *BootIndex
)
@ -760,7 +760,7 @@ FindBootOptionForFile (
UINTN SearchedDevicePathSize[2];
DBG("FindBootOptionForFile: %p, %ls\n", FileDeviceHandle, FileName);
DBG("FindBootOptionForFile: %p, %ls\n", FileDeviceHandle, FileName.wc_str());
//
// Get BootOrder - we will search only options listed in BootOrder.
@ -1002,7 +1002,7 @@ AddBootOption (
EFI_STATUS
AddBootOptionForFile (
IN EFI_HANDLE FileDeviceHandle,
IN CONST CHAR16 *FileName,
IN CONST XStringW& FileName,
IN BOOLEAN UseShortForm,
IN CONST CHAR16 *Description,
IN UINT8 *OptionalData,
@ -1016,7 +1016,7 @@ AddBootOptionForFile (
DBG("\nAddBootOptionForFile: %p, %ls, %ls\n %ls, %llu\n",
FileDeviceHandle, FileName,
FileDeviceHandle, FileName.wc_str(),
UseShortForm ? L"ShortDevPath" : L"FullDevPath",
Description, BootIndex);
@ -1108,14 +1108,14 @@ DeleteBootOption (
EFI_STATUS
DeleteBootOptionForFile (
IN EFI_HANDLE FileDeviceHandle,
IN CONST CHAR16 *FileName
IN CONST XStringW& FileName
)
{
EFI_STATUS Status;
IN UINT16 BootNum;
DBG("\nDeleteBootOptionForFile: %p, %ls\n", FileDeviceHandle, FileName);
DBG("\nDeleteBootOptionForFile: %p, %ls\n", FileDeviceHandle, FileName.wc_str());
do {
Status = FindBootOptionForFile (FileDeviceHandle, FileName, &BootNum, NULL);
if (!EFI_ERROR(Status)) {

View File

@ -119,7 +119,7 @@ FindBootOptionForFile (
EFI_STATUS
AddBootOptionForFile (
IN EFI_HANDLE FileDeviceHandle,
IN CONST CHAR16 *FileName,
IN CONST XStringW &FileName,
IN BOOLEAN UseShortForm,
IN CONST CHAR16 *Description,
IN UINT8 *OptionalData,
@ -138,8 +138,8 @@ DeleteBootOption (
/** Deletes boot option for file specified with FileDeviceHandle and FileName. */
EFI_STATUS
DeleteBootOptionForFile (
IN EFI_HANDLE FileDeviceHandle,
IN CONST CHAR16 *FileName
IN EFI_HANDLE FileDeviceHandle,
IN CONST XStringW& FileName
);
/** Deletes all boot option that points to a file which contains FileName in it's path. */

View File

@ -917,7 +917,7 @@ IsOsxHibernated (IN LOADER_ENTRY *Entry)
//Convert BeUUID to LeUUID
//Ptr points to begin L"A82E84C6-9DD6-49D6-960A-0F4C2FE4851C"
EFI_GUID TmpGuid;
CHAR16 *TmpStr = NULL;
// CHAR16 *TmpStr = NULL;
ResumeFromCoreStorage = TRUE;
// DBG("got str=%ls\n", Ptr);
@ -926,10 +926,9 @@ IsOsxHibernated (IN LOADER_ENTRY *Entry)
DBG(" cant convert Str %ls to GUID\n", Ptr);
} else {
//TmpStr = PoolPrint(L"%s", strguid(&TmpGuid));
TmpStr = GuidLEToStr(&TmpGuid);
XStringW TmpStr = GuidLEToStr(&TmpGuid);
// DBG("got the guid %ls\n", TmpStr);
CopyMem((VOID*)Ptr, TmpStr, StrSize(TmpStr));
FreePool(TmpStr);
CopyMem((VOID*)Ptr, TmpStr.wc_str(), TmpStr.sizeInNativeChars());
}
}
if (StrCmp(gST->FirmwareVendor, L"INSYDE Corp.") != 0) {

View File

@ -1100,7 +1100,7 @@ FindStartupDiskVolume (
REFIT_VOLUME *Volume;
REFIT_VOLUME *DiskVolume;
BOOLEAN IsPartitionVolume;
CONST CHAR16 *LoaderPath;
XStringW LoaderPath;
CHAR16 *EfiBootVolumeStr;
@ -1142,9 +1142,9 @@ FindStartupDiskVolume (
//DBG(" checking '%ls'\n", DevicePathToStr (Volume->DevicePath));
//DBG(" '%ls'\n", LoaderPath);
// case insensitive cmp
if (LoaderPath != NULL && StriCmp(gEfiBootLoaderPath, LoaderPath) == 0) {
if ( LoaderPath.equalIC(gEfiBootLoaderPath) ) {
// that's the one
DBG(" - found entry %lld. '%ls', Volume '%ls', '%ls'\n", Index, LoaderEntry.Title.s(), Volume->VolName, LoaderPath);
DBG(" - found entry %lld. '%ls', Volume '%ls', '%ls'\n", Index, LoaderEntry.Title.s(), Volume->VolName, LoaderPath.wc_str());
return Index;
}
}
@ -1165,9 +1165,9 @@ FindStartupDiskVolume (
//DBG(" checking '%ls'\n", DevicePathToStr (Volume->DevicePath));
//DBG(" '%ls'\n", LoaderPath);
// case insensitive cmp
if (LoaderPath != NULL && StriCmp(gEfiBootLoaderPath, LoaderPath) == 0) {
if ( LoaderPath.equalIC(gEfiBootLoaderPath) ) {
// that's the one
DBG(" - found entry %lld. '%ls', Volume '%ls', '%ls'\n", Index, LoaderEntry.Title.s(), Volume->VolName, LoaderPath);
DBG(" - found entry %lld. '%ls', Volume '%ls', '%ls'\n", Index, LoaderEntry.Title.s(), Volume->VolName, LoaderPath.wc_str());
return Index;
}
}
@ -1268,7 +1268,7 @@ FindStartupDiskVolume (
//DBG(" LoaderType = %d\n", LoaderEntry.LoaderType);
if (LoaderEntry.LoaderType == OSTYPE_WINEFI) {
// that's the one - win loader entry
DBG(" - found loader entry %lld. '%ls', Volume '%ls', '%ls'\n", Index, LoaderEntry.Title.s(), Volume->VolName, LoaderEntry.LoaderPath);
DBG(" - found loader entry %lld. '%ls', Volume '%ls', '%ls'\n", Index, LoaderEntry.Title.s(), Volume->VolName, LoaderEntry.LoaderPath.wc_str());
return Index;
}
}
@ -1297,7 +1297,7 @@ FindStartupDiskVolume (
Volume = LoaderEntry.Volume;
if (Volume != NULL && Volume->WholeDiskBlockIO == DiskVolume->BlockIO) {
// that's the one
DBG(" - found loader entry %lld. '%ls', Volume '%ls', '%ls'\n", Index, LoaderEntry.Title.s(), Volume->VolName, LoaderEntry.LoaderPath);
DBG(" - found loader entry %lld. '%ls', Volume '%ls', '%ls'\n", Index, LoaderEntry.Title.s(), Volume->VolName, LoaderEntry.LoaderPath.wc_str());
return Index;
}
@ -1312,7 +1312,7 @@ FindStartupDiskVolume (
/** Sets efi-boot-device-data RT var to currently selected Volume and LoadePath. */
EFI_STATUS SetStartupDiskVolume (
IN REFIT_VOLUME *Volume,
IN CONST CHAR16 *LoaderPath
IN CONST XStringW& LoaderPath
)
{
EFI_STATUS Status;
@ -1327,14 +1327,14 @@ EFI_STATUS SetStartupDiskVolume (
DBG("SetStartupDiskVolume:\n");
DBG(" * Volume: '%ls'\n", Volume->VolName);
DBG(" * LoaderPath: '%ls'\n", LoaderPath);
DBG(" * LoaderPath: '%ls'\n", LoaderPath.wc_str());
//
// construct dev path for Volume/LoaderPath
//
DevPath = Volume->DevicePath;
if (LoaderPath != NULL) {
FileDevPath = FileDevicePath (NULL, LoaderPath);
if (LoaderPath.notEmpty()) {
FileDevPath = FileDevicePath (NULL, LoaderPath.wc_str());
DevPath = AppendDevicePathNode (DevPath, FileDevPath);
}
DBG(" * DevPath: %ls\n", Volume->VolName/*, FileDevicePathToStr (DevPath)*/);

View File

@ -10,7 +10,7 @@
#define NON_APPLE_SMC_SIGNATURE SIGNATURE_64('S','M','C','H','E','L','P','E')
#include "../cpp_foundation/XString.h"
extern EFI_GUID *gEfiBootDeviceGuid;
extern EFI_DEVICE_PATH_PROTOCOL *gEfiBootDeviceData;
@ -86,7 +86,7 @@ GetSmcKeys(BOOLEAN WriteToSMC);
EFI_STATUS
SetStartupDiskVolume (
IN REFIT_VOLUME *Volume,
IN CONST CHAR16 *LoaderPath
IN CONST XStringW& LoaderPath
);
VOID

View File

@ -456,7 +456,7 @@ SetBootCurrent(REFIT_MENU_ITEM_BOOTNUM *Entry)
if (VarSize > NameSize + 6) {
Data += NameSize;
if (StriCmp((CHAR16*)Data, Basename(Entry->LoaderPath)) != 0) {
if (StriCmp((CHAR16*)Data, Basename(Entry->LoaderPath.wc_str())) != 0) {
DBG("Boot option %llu has other loader name %ls\n", Entry->BootNum, (CHAR16*)Data);
FreePool(BootVariable);
return;
@ -850,9 +850,7 @@ CUSTOM_LOADER_ENTRY
DuplicateEntry->Volume = EfiStrDuplicate (Entry->Volume);
}
if (Entry->Path != NULL) {
DuplicateEntry->Path = EfiStrDuplicate (Entry->Path);
}
DuplicateEntry->Path = Entry->Path;
DuplicateEntry->LoadOptions = Entry->LoadOptions;
@ -1856,11 +1854,7 @@ FillinCustomEntry (
Prop = GetProperty(DictPointer, "Path");
if (Prop != NULL && (Prop->type == kTagTypeString)) {
if (Entry->Path) {
FreePool(Entry->Path);
}
Entry->Path = PoolPrint(L"%a", Prop->string);
Entry->Path.SWPrintf("%s", Prop->string);
}
Prop = GetProperty(DictPointer, "Settings");
@ -2031,7 +2025,7 @@ FillinCustomEntry (
Entry->Type = OSTYPE_OTHER;
}
} else {
if (Entry->Type == 0 && Entry->Path) {
if (Entry->Type == 0 && Entry->Path.notEmpty()) {
// Try to set Entry->type from Entry->Path
Entry->Type = GetOSTypeFromPath(Entry->Path);
}
@ -2298,10 +2292,7 @@ FillingCustomTool (IN OUT CUSTOM_TOOL_ENTRY *Entry, TagPtr DictPointer)
Prop = GetProperty(DictPointer, "Path");
if (Prop != NULL && (Prop->type == kTagTypeString)) {
if (Entry->Path != NULL) {
FreePool(Entry->Path);
}
Entry->Path = PoolPrint(L"%a", Prop->string);
Entry->Path.SWPrintf("%s", Prop->string);
}
Prop = GetProperty(DictPointer, "Arguments");
@ -6527,52 +6518,53 @@ CHAR8 *GetOSVersion(IN LOADER_ENTRY *Entry)
return OSVersion;
}
CONST CHAR16
*GetOSIconName (
//constexpr XStringW iconMac = L"mac"_XSW;
CONST XStringW
GetOSIconName (
IN CONST CHAR8 *OSVersion
)
{
CONST CHAR16 *OSIconName;
XStringW OSIconName;
if (OSVersion == NULL) {
OSIconName = L"mac";
OSIconName = L"mac"_XSW;
} else if (AsciiStrStr (OSVersion, "10.15") != 0) {
// Catalina
OSIconName = L"cata,mac";
OSIconName = L"cata,mac"_XSW;
} else if (AsciiStrStr (OSVersion, "10.14") != 0) {
// Mojave
OSIconName = L"moja,mac";
OSIconName = L"moja,mac"_XSW;
} else if (AsciiStrStr (OSVersion, "10.13") != 0) {
// High Sierra
OSIconName = L"hsierra,mac";
OSIconName = L"hsierra,mac"_XSW;
} else if (AsciiStrStr (OSVersion, "10.12") != 0) {
// Sierra
OSIconName = L"sierra,mac";
OSIconName = L"sierra,mac"_XSW;
} else if (AsciiStrStr (OSVersion, "10.11") != 0) {
// El Capitan
OSIconName = L"cap,mac";
OSIconName = L"cap,mac"_XSW;
} else if (AsciiStrStr (OSVersion, "10.10") != 0) {
// Yosemite
OSIconName = L"yos,mac";
OSIconName = L"yos,mac"_XSW;
} else if (AsciiStrStr (OSVersion, "10.9") != 0) {
// Mavericks
OSIconName = L"mav,mac";
OSIconName = L"mav,mac"_XSW;
} else if (AsciiStrStr (OSVersion, "10.8") != 0) {
// Mountain Lion
OSIconName = L"cougar,mac";
OSIconName = L"cougar,mac"_XSW;
} else if (AsciiStrStr (OSVersion, "10.7") != 0) {
// Lion
OSIconName = L"lion,mac";
OSIconName = L"lion,mac"_XSW;
} else if (AsciiStrStr (OSVersion, "10.6") != 0) {
// Snow Leopard
OSIconName = L"snow,mac";
OSIconName = L"snow,mac"_XSW;
} else if (AsciiStrStr (OSVersion, "10.5") != 0) {
// Leopard
OSIconName = L"leo,mac";
OSIconName = L"leo,mac"_XSW;
} else if (AsciiStrStr (OSVersion, "10.4") != 0) {
// Tiger
OSIconName = L"tiger,mac";
OSIconName = L"tiger,mac"_XSW;
} else {
OSIconName = L"mac";
OSIconName = L"mac"_XSW;
}
return OSIconName;

View File

@ -98,8 +98,8 @@ struct CUSTOM_LOADER_ENTRY {
CONST CHAR16 *ImagePath;
CONST CHAR16 *DriveImagePath;
CONST CHAR16 *Volume;
CONST CHAR16 *Path;
XStringArray LoadOptions;
XStringW Path;
XStringArray LoadOptions;
XStringW FullTitle;
XStringW Title;
@ -115,7 +115,7 @@ struct CUSTOM_LOADER_ENTRY {
EFI_GRAPHICS_OUTPUT_BLT_PIXEL BootBgColor;
KERNEL_AND_KEXT_PATCHES KernelAndKextPatches;
CUSTOM_LOADER_ENTRY() : Next(0), SubEntries(0), ImagePath(0), DriveImagePath(0), Volume(0), Path(0), Settings(0), Hotkey(0), CommonSettings(0), Flags(0), Type(0), VolumeType(0),
CUSTOM_LOADER_ENTRY() : Next(0), SubEntries(0), ImagePath(0), DriveImagePath(0), Volume(0), Settings(0), Hotkey(0), CommonSettings(0), Flags(0), Type(0), VolumeType(0),
KernelScan(0), CustomBoot(0), BootBgColor({0,0,0,0})
{ memset(&KernelAndKextPatches, 0, sizeof(KernelAndKextPatches)); }
@ -147,7 +147,7 @@ struct CUSTOM_TOOL_ENTRY {
XImage Image;
CHAR16 *ImagePath;
CHAR16 *Volume;
CHAR16 *Path;
XStringW Path;
XStringArray LoadOptions;
XStringW FullTitle;
XStringW Title;
@ -754,8 +754,8 @@ VOID
GetDevices(VOID);
CONST CHAR16
*GetOSIconName (
CONST XStringW
GetOSIconName (
IN CONST CHAR8 *OSVersion
);

View File

@ -327,13 +327,13 @@ CHAR16 * GuidBeToStr(EFI_GUID *Guid)
}
//the caller is responsible to free the buffer
CHAR16 * GuidLEToStr(EFI_GUID *Guid)
XStringW GuidLEToStr(EFI_GUID *Guid)
{
CHAR16 *Str = PoolPrint(L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
XStringW returnValue;
returnValue.SWPrintf("%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
Guid->Data1, Guid->Data2, Guid->Data3, Guid->Data4[0], Guid->Data4[1],
Guid->Data4[2], Guid->Data4[3], Guid->Data4[4], Guid->Data4[5], Guid->Data4[6], Guid->Data4[7]);
return Str;
return returnValue;
}
#if 0

View File

@ -22,7 +22,7 @@ StrToGuidLE (
OUT EFI_GUID *Guid);
CHAR16 * GuidBeToStr(EFI_GUID *Guid);
CHAR16 * GuidLEToStr(EFI_GUID *Guid);
XStringW GuidLEToStr(EFI_GUID *Guid);

View File

@ -46,6 +46,13 @@ XString32 operator"" _XS32 ( const char32_t* s, size_t len)
return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization.
}
XStringW operator"" _XSW ( const char* s, size_t len)
{
XStringW returnValue;
returnValue.takeValueFrom(s, len);
return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization.
}
XStringW operator"" _XSW ( const wchar_t* s, size_t len)
{
XStringW returnValue;

View File

@ -128,6 +128,7 @@ public:
XString operator"" _XS ( const char* s, size_t len);
XString16 operator"" _XS16 ( const char16_t* s, size_t len);
XString32 operator"" _XS32 ( const char32_t* s, size_t len);
XStringW operator"" _XSW ( const char* s, size_t len);
XStringW operator"" _XSW ( const wchar_t* s, size_t len);
extern const XString NullXString;

View File

@ -25,15 +25,11 @@
#define DBG_XSTRING(...) DebugLog(DEBUG_XStringAbstract, __VA_ARGS__)
#endif
//#include <type_traits>
#define LPATH_SEPARATOR L'\\'
#if __WCHAR_MAX__ <= 0xFFFFu
#define wchar_cast char16_t
#else
#define wchar_cast char32_t
#endif
//#if __WCHAR_MAX__ <= 0xFFFFu
// #define wchar_cast char16_t
//#else
// #define wchar_cast char32_t
//#endif
@ -183,7 +179,7 @@ size_t XStringAbstract__rindexOf(const O* s, size_t Pos, const P* other, bool to
template<class T, class ThisXStringClass>
class XStringAbstract
class XStringAbstractNoDtor
{
public:
// const SubType NullXString;
@ -232,7 +228,7 @@ public:
if ( m_allocatedSize == 0 ) m_data = (T*)malloc( (nNewSize+1)*sizeof(T) );
else m_data = (T*)Xrealloc(m_data, (nNewSize+1)*sizeof(T), (m_allocatedSize+1)*sizeof(T));
if ( !m_data ) {
panic("XStringAbstract<T>::CheckSize(%zu, %zu) : Xrealloc(%" PRIuPTR ", %lu, %zd) returned NULL. System halted\n", nNewSize, nGrowBy, uintptr_t(m_data), nNewSize*sizeof(T), m_allocatedSize*sizeof(T));
panic("XStringAbstractNoDtor<T>::CheckSize(%zu, %zu) : Xrealloc(%" PRIuPTR ", %lu, %zd) returned NULL. System halted\n", nNewSize, nGrowBy, uintptr_t(m_data), nNewSize*sizeof(T), m_allocatedSize*sizeof(T));
}
m_allocatedSize = nNewSize;
m_data[m_allocatedSize] = 0; // we allocated one more char (nNewSize+1). This \0 is an extra precaution. It's not for the normal null terminator. All string operation must considered that only m_allocatedSize bytes were allocated.
@ -244,7 +240,7 @@ public:
// //DBG_XSTRING("setLength(%d)\n", len);
// CheckSize(newSize);
// // if ( len >= size() ) {
// // DBG_XSTRING("XStringAbstract<T>::setLength(size_t len) : len >= size() (%d != %d). System halted\n", len, size());
// // DBG_XSTRING("XStringAbstractNoDtor<T>::setLength(size_t len) : len >= size() (%d != %d). System halted\n", len, size());
// // panic();
// // }
// m_data[newSize] = 0; // we may rewrite a 0 in nullChar, if no memory were allocated. That's ok.
@ -256,17 +252,13 @@ public:
// }
public:
XStringAbstract()
{
DBG_XSTRING("Construteur\n");
Init(0);
}
constexpr XStringAbstractNoDtor() : m_data(&nullChar), m_allocatedSize(0) {}
~XStringAbstract()
{
//DBG_XSTRING("Destructor :%ls\n", data());
if ( m_allocatedSize > 0 ) free((void*)m_data);
}
// ~XStringAbstractNoDtor()
// {
// //DBG_XSTRING("Destructor :%ls\n", data());
//// if ( m_allocatedSize > 0 ) free((void*)m_data);
// }
template<typename IntegralType, enable_if(is_integral(IntegralType))>
T* data(IntegralType pos) const { return _data(pos); }
@ -302,6 +294,7 @@ public:
size_t length() const { return length_of_utf_string(m_data); }
// size_t sizeZZ() const { return size_of_utf_string(m_data); }
size_t sizeInNativeChars() const { return size_of_utf_string(m_data); }
size_t sizeInBytes() const { return size_of_utf_string(m_data)*sizeof(T); }
size_t sizeInBytesIncludingTerminator() const { return (size_of_utf_string(m_data)+1)*sizeof(T); } // usefull for unit tests
size_t allocatedSize() const { return m_allocatedSize; }
@ -330,7 +323,7 @@ public:
char32_t char32At(IntegralType i) const
{
if (i < 0) {
panic("XStringAbstract<T>::char32At(size_t i) : i < 0. System halted\n");
panic("XStringAbstractNoDtor<T>::char32At(size_t i) : i < 0. System halted\n");
}
size_t nb = 0;
const T *p = m_data;
@ -339,7 +332,7 @@ public:
p = get_char32_from_string(p, &char32);
if (!char32) {
if ( (unsigned_type(IntegralType))i == nb ) return 0; // no panic if we want to access the null terminator
panic("XStringAbstract::char32At(size_t i) : i >= length(). System halted\n");
panic("XStringAbstractNoDtor::char32At(size_t i) : i >= length(). System halted\n");
}
nb += 1;
} while (nb <= (unsigned_type(IntegralType))i);
@ -447,33 +440,33 @@ public:
}
/* takeValueFrom */
template<typename O, class OtherXStringClass>
ThisXStringClass& takeValueFrom(const XStringAbstract<O, OtherXStringClass>& S) { strcpy(S.s()); return *((ThisXStringClass*)this); }
ThisXStringClass& takeValueFrom(const XStringAbstractNoDtor<O, OtherXStringClass>& S) { strcpy(S.s()); return *((ThisXStringClass*)this); }
template<typename O>
ThisXStringClass& takeValueFrom(const O* S) { strcpy(S); return *((ThisXStringClass*)this); }
template<typename O, class OtherXStringClass>
ThisXStringClass& takeValueFrom(const XStringAbstract<O, OtherXStringClass>& S, size_t len) { strncpy(S.data(0), len); return *((ThisXStringClass*)this); }
ThisXStringClass& takeValueFrom(const XStringAbstractNoDtor<O, OtherXStringClass>& S, size_t len) { strncpy(S.data(0), len); return *((ThisXStringClass*)this); }
template<typename O>
ThisXStringClass& takeValueFrom(const O* S, size_t len) { strncpy(S, len); return *((ThisXStringClass*)this); }
/* copy ctor */
XStringAbstract<T, ThisXStringClass>(const XStringAbstract<T, ThisXStringClass> &S) { Init(0); takeValueFrom(S); }
XStringAbstractNoDtor<T, ThisXStringClass>(const XStringAbstractNoDtor<T, ThisXStringClass> &S) { Init(0); takeValueFrom(S); }
/* ctor */
template<typename O, class OtherXStringClass>
explicit XStringAbstract<T, ThisXStringClass>(const XStringAbstract<O, OtherXStringClass>& S) { Init(0); takeValueFrom(S); }
explicit XStringAbstractNoDtor<T, ThisXStringClass>(const XStringAbstractNoDtor<O, OtherXStringClass>& S) { Init(0); takeValueFrom(S); }
// template<typename O>
// explicit XStringAbstract<T, ThisXStringClass>(const O* S) { Init(0); takeValueFrom(S); }
// explicit XStringAbstractNoDtor<T, ThisXStringClass>(const O* S) { Init(0); takeValueFrom(S); }
/* Copy Assign */ // Only other XString, no litteral at the moment.
XStringAbstract<T, ThisXStringClass>& operator =(const XStringAbstract<T, ThisXStringClass>& S) { strcpy(S.s()); return *this; }
XStringAbstractNoDtor<T, ThisXStringClass>& operator =(const XStringAbstractNoDtor<T, ThisXStringClass>& S) { strcpy(S.s()); return *this; }
/* Assign */
template<typename O, class OtherXStringClass>
ThisXStringClass& operator =(const XStringAbstract<O, OtherXStringClass>& S) { strcpy(S.s()); return *((ThisXStringClass*)this); }
ThisXStringClass& operator =(const XStringAbstractNoDtor<O, OtherXStringClass>& S) { strcpy(S.s()); return *((ThisXStringClass*)this); }
// template<class O>
// ThisXStringClass& operator =(const O* S) { strcpy(S); return *this; }
/* += */
template<typename O, class OtherXStringClass>
ThisXStringClass& operator += (const XStringAbstract<O, OtherXStringClass>& S) { strcat(S.s()); return *((ThisXStringClass*)this); }
ThisXStringClass& operator += (const XStringAbstractNoDtor<O, OtherXStringClass>& S) { strcat(S.s()); return *((ThisXStringClass*)this); }
template<typename O, enable_if(is_char(O))>
ThisXStringClass& operator += (O S) { strcat(S); return *((ThisXStringClass*)this); }
template<typename O>
@ -481,15 +474,15 @@ public:
template<typename O, class OtherXStringClass>
ThisXStringClass operator + (const XStringAbstract<O, OtherXStringClass>& p2) const { XStringAbstract s; s=*this; s+=p2; return s; }
ThisXStringClass operator + (const XStringAbstractNoDtor<O, OtherXStringClass>& p2) const { ThisXStringClass s; s=*this; s+=p2; return s; }
template<typename O, enable_if(is_char(O))>
ThisXStringClass operator + (O p1) const { XStringAbstract s; s=*this; s.strcat(p1); return s; }
ThisXStringClass operator + (O p1) const { ThisXStringClass s; s=*this; s.strcat(p1); return s; }
template<typename O>
ThisXStringClass operator + (const O* p2) const { XStringAbstract s; s=*this; s+=p2; return s; }
ThisXStringClass operator + (const O* p2) const { ThisXStringClass s; s=*this; s+=p2; return s; }
template<typename O, enable_if(is_char(O))>
friend ThisXStringClass operator + (O p1, const ThisXStringClass& p2) { XStringAbstract s; s.strcat(p1); s.strcat(p2.s()); return s; }
friend ThisXStringClass operator + (O p1, const ThisXStringClass& p2) { ThisXStringClass s; s.strcat(p1); s.strcat(p2.s()); return s; }
template<typename O>
friend ThisXStringClass operator + (const O *p1, const ThisXStringClass& p2) { XStringAbstract s; s.strcat(p1); s.strcat(p2.s()); return s; }
friend ThisXStringClass operator + (const O *p1, const ThisXStringClass& p2) { ThisXStringClass s; s.strcat(p1); s.strcat(p2.s()); return s; }
//--------------------------------------------------------------------- indexOf, rindexOf, contains, subString
@ -503,7 +496,7 @@ public:
template<typename O>
size_t indexOf(const O* S, size_t Pos = 0) const { return XStringAbstract__indexOf(m_data, Pos, S, false); }
template<typename O, class OtherXStringClass>
size_t indexOf(const XStringAbstract<O, OtherXStringClass>& S, size_t Pos = 0) const { return indexOf(S.s(), Pos); }
size_t indexOf(const XStringAbstractNoDtor<O, OtherXStringClass>& S, size_t Pos = 0) const { return indexOf(S.s(), Pos); }
/* IC */
size_t indexOfIC(char32_t char32Searched, size_t Pos = 0) const
{
@ -513,7 +506,7 @@ public:
template<typename O>
size_t indexOfIC(const O* S, size_t Pos = 0) const { return XStringAbstract__indexOf(m_data, Pos, S, true); }
template<typename O, class OtherXStringClass>
size_t indexOfIC(const XStringAbstract<O, OtherXStringClass>& S, size_t Pos = 0) const { return indexOfIC(S.s(), Pos); }
size_t indexOfIC(const XStringAbstractNoDtor<O, OtherXStringClass>& S, size_t Pos = 0) const { return indexOfIC(S.s(), Pos); }
/* rindexOf */
@ -525,7 +518,7 @@ public:
template<typename O>
size_t rindexOf(const O* S, size_t Pos = MAX_XSIZE-1) const { return XStringAbstract__rindexOf(m_data, Pos, S, false); }
template<typename O, class OtherXStringClass>
size_t rindexOf(const XStringAbstract<O, OtherXStringClass>& S, size_t Pos = MAX_XSIZE-1) const { return rindexOf(S.s(), Pos); }
size_t rindexOf(const XStringAbstractNoDtor<O, OtherXStringClass>& S, size_t Pos = MAX_XSIZE-1) const { return rindexOf(S.s(), Pos); }
/* IC */
size_t rindexOfIC(const char32_t char32Searched, size_t Pos = MAX_XSIZE-1) const
{
@ -535,22 +528,22 @@ public:
template<typename O>
size_t rindexOfIC(const O* S, size_t Pos = MAX_XSIZE-1) const { return XStringAbstract__rindexOf(m_data, Pos, S, true); }
template<typename O, class OtherXStringClass>
size_t rindexOfIC(const XStringAbstract<O, OtherXStringClass>& S, size_t Pos = MAX_XSIZE-1) const { return rindexOf(S.s(), Pos); }
size_t rindexOfIC(const XStringAbstractNoDtor<O, OtherXStringClass>& S, size_t Pos = MAX_XSIZE-1) const { return rindexOf(S.s(), Pos); }
template<typename O, class OtherXStringClass>
bool contains(const XStringAbstract<O, OtherXStringClass>& S) const { return indexOf(S) != MAX_XSIZE; }
bool contains(const XStringAbstractNoDtor<O, OtherXStringClass>& S) const { return indexOf(S) != MAX_XSIZE; }
template<typename O>
bool contains(const O* S) const { return indexOf(S) != MAX_XSIZE; }
template<typename O, class OtherXStringClass>
size_t containsIC(const XStringAbstract<O, OtherXStringClass>& S) const { return indexOfIC(S) != MAX_XSIZE; }
size_t containsIC(const XStringAbstractNoDtor<O, OtherXStringClass>& S) const { return indexOfIC(S) != MAX_XSIZE; }
template<typename O>
size_t containsIC(const O* S) const { return indexOfIC(S) != MAX_XSIZE; }
ThisXStringClass subString(size_t pos, size_t count) const
{
if ( pos > length() ) return ThisXStringClass();
if ( count > length()-pos ) count = length()-pos;
// if ( pos > length() ) return ThisXStringClass();
// if ( count > length()-pos ) count = length()-pos;
ThisXStringClass ret;
@ -565,11 +558,11 @@ public:
}
template<typename O, class OtherXStringClass>
bool startWith(const XStringAbstract<O, OtherXStringClass>& otherS) const { return XStringAbstract__startWith(m_data, otherS.m_data, false); }
bool startWith(const XStringAbstractNoDtor<O, OtherXStringClass>& otherS) const { return XStringAbstract__startWith(m_data, otherS.m_data, false); }
template<typename O>
bool startWith(const O* other) const { return XStringAbstract__startWith(m_data, other, false); }
template<typename O, class OtherXStringClass>
bool startWithIC(const XStringAbstract<O, OtherXStringClass>& otherS) const { return XStringAbstract__startWith(m_data, otherS.m_data, true); }
bool startWithIC(const XStringAbstractNoDtor<O, OtherXStringClass>& otherS) const { return XStringAbstract__startWith(m_data, otherS.m_data, true); }
template<typename O>
bool startWithIC(const O* other) const { return XStringAbstract__startWith(m_data, other, true); }
@ -606,6 +599,32 @@ public:
m_data[count] = 0;
}
//---------------------------------------------------------------------
ThisXStringClass basename() const
{
size_t lastSepPos = MAX_XSIZE;
size_t pos = 0;
const T *p = m_data;
char32_t char32;
p = get_char32_from_string(p, &char32);
while ( char32 ) {
if ( char32 == U'/' || char32 == U'\\' ) lastSepPos = pos;
pos += 1;
p = get_char32_from_string(p, &char32);
};
if ( lastSepPos == MAX_XSIZE ) {
if ( p == m_data ) return ThisXStringClass().takeValueFrom(".");
}
return subString(lastSepPos+1, MAX_XSIZE);
}
// ThisXStringClass dirname() const
// {
// size_t idx = rindexOf('/');
// if ( idx == MAX_XSIZE ) return ThisXStringClass();
// return subString(0, idx);
// }
// void deleteCountCharsAt(size_t pos, size_t count=1);
//{
// if ( pos < size() ) {
@ -617,7 +636,7 @@ public:
// }
// }
//}
// void insert(const XStringAbstract<T, ThisXStringClass>& Str, size_t pos);
// void insert(const XStringAbstractNoDtor<T, ThisXStringClass>& Str, size_t pos);
//{
// if ( pos < size() ) {
// CheckSize(size()+Str.size());
@ -674,10 +693,10 @@ public:
// p += 1;
// }
// }
// XStringAbstract SubStringReplace(T c1, T c2);
// XStringAbstractNoDtor SubStringReplace(T c1, T c2);
//{
// T* p;
// XStringAbstract Result;
// XStringAbstractNoDtor Result;
//
// p = s();
// while ( *p ) {
@ -687,20 +706,6 @@ public:
// }
// return Result;
//}
//
// SubType basename() const
// {
// size_t idx = RIdxOf(LPATH_SEPARATOR);
// if ( idx == MAX_XSIZE ) return SubType();
// return SubString(idx+1, size()-idx-1);
// }
// SubType dirname() const
// {
// size_t idx = RIdxOf(LPATH_SEPARATOR);
// if ( idx == MAX_XSIZE ) return SubType();
// return SubString(0, idx);
// }
// void RemoveLastEspCtrl();
//---------------------------------------------------------------------
@ -712,12 +717,12 @@ public:
// int Compare(const wchar_t* S) const { return ::Compare<T, wchar_t>(m_data, S); };
//
template<typename O, class OtherXStringClass>
bool equal(const XStringAbstract<O, OtherXStringClass>& S) const { return XStringAbstract__compare(m_data, S.s(), false) == 0; }
bool equal(const XStringAbstractNoDtor<O, OtherXStringClass>& S) const { return XStringAbstract__compare(m_data, S.s(), false) == 0; }
template<typename O>
bool equal(const O* S) const { return XStringAbstract__compare(m_data, S, false) == 0; }
template<typename O, class OtherXStringClass>
bool equalIC(const XStringAbstract<O, OtherXStringClass>& S) const { return XStringAbstract__compare(m_data, S.s(), true) == 0; }
bool equalIC(const XStringAbstractNoDtor<O, OtherXStringClass>& S) const { return XStringAbstract__compare(m_data, S.s(), true) == 0; }
template<typename O>
bool equalIC(const O* S) const { return XStringAbstract__compare(m_data, S, true) == 0; }
@ -726,42 +731,42 @@ public:
public:
// == operator
template<typename O, class OtherXStringClass>
bool operator == (const XStringAbstract<O, OtherXStringClass>& s2) const { return (*this).strcmp(s2.s()) == 0; }
bool operator == (const XStringAbstractNoDtor<O, OtherXStringClass>& s2) const { return (*this).strcmp(s2.s()) == 0; }
// template<typename O>
// bool operator == (const O* s2) const { return (*this).strcmp(s2) == 0; }
// template<typename O>
// friend bool operator == (const O* s1, ThisXStringClass& s2) { return s2.strcmp(s1) == 0; }
template<typename O, class OtherXStringClass>
bool operator != (const XStringAbstract<O, OtherXStringClass>& s2) const { return !(*this == s2); }
bool operator != (const XStringAbstractNoDtor<O, OtherXStringClass>& s2) const { return !(*this == s2); }
// template<typename O>
// bool operator != (const O* s2) const { return !(*this == s2); }
// template<typename O>
// friend bool operator != (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) != 0; }
template<typename O, class OtherXStringClass>
bool operator < (const XStringAbstract<O, OtherXStringClass>& s2) const { return (*this).strcmp(s2.s()) < 0; }
bool operator < (const XStringAbstractNoDtor<O, OtherXStringClass>& s2) const { return (*this).strcmp(s2.s()) < 0; }
// template<typename O>
// bool operator < (const O* s2) const { return (*this).strcmp(s2) < 0; }
// template<typename O>
// friend bool operator < (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) > 0; }
template<typename O, class OtherXStringClass>
bool operator > (const XStringAbstract<O, OtherXStringClass>& s2) const { return (*this).strcmp(s2.s()) > 0; }
bool operator > (const XStringAbstractNoDtor<O, OtherXStringClass>& s2) const { return (*this).strcmp(s2.s()) > 0; }
// template<typename O>
// bool operator > (const O* s2) const { return (*this).strcmp(s2) > 0; }
// template<typename O>
// friend bool operator > (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) < 0; }
template<typename O, class OtherXStringClass>
bool operator <= (const XStringAbstract<O, OtherXStringClass>& s2) const { return (*this).strcmp(s2.s()) <= 0; }
bool operator <= (const XStringAbstractNoDtor<O, OtherXStringClass>& s2) const { return (*this).strcmp(s2.s()) <= 0; }
// template<typename O>
// bool operator <= (const O* s2) const { return (*this).strcmp(s2) <= 0; }
// template<typename O>
// friend bool operator <= (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) >= 0; }
template<typename O, class OtherXStringClass>
bool operator >= (const XStringAbstract<O, OtherXStringClass>& s2) const { return (*this).strcmp(s2.s()) >= 0; }
bool operator >= (const XStringAbstractNoDtor<O, OtherXStringClass>& s2) const { return (*this).strcmp(s2.s()) >= 0; }
// template<typename O>
// bool operator >= (const O* s2) const { return (*this).strcmp(s2) >= 0; }
// template<typename O>
@ -771,9 +776,29 @@ public:
template<class T, class ThisXStringClass>
T XStringAbstract<T, ThisXStringClass>::nullChar = 0;
T XStringAbstractNoDtor<T, ThisXStringClass>::nullChar = 0;
template<class T, class ThisXStringClass>
class XStringAbstract : public XStringAbstractNoDtor<T, ThisXStringClass>
{
public:
XStringAbstract() : XStringAbstractNoDtor<T, ThisXStringClass>() {}
XStringAbstract(const XStringAbstract& S) : XStringAbstractNoDtor<T, ThisXStringClass>(S) {}
template<typename O, class OtherXStringClass>
XStringAbstract(const XStringAbstract<O, OtherXStringClass> &S) : XStringAbstractNoDtor<T, ThisXStringClass>(S) {}
//
XStringAbstract& operator=(const XStringAbstract &S) { this->XStringAbstractNoDtor<T, ThisXStringClass>::operator=(S); return *this; }
using XStringAbstractNoDtor<T, ThisXStringClass>::operator =;
~XStringAbstract()
{
//DBG_XSTRING("Destructor :%ls\n", data());
if ( XStringAbstractNoDtor<T, ThisXStringClass>::m_allocatedSize > 0 ) free((void*)XStringAbstractNoDtor<T, ThisXStringClass>::m_data);
}
};
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

View File

@ -50,7 +50,7 @@ class XStringArray_/* : public XStringArraySuper*/
XStringClass ConcatAll(const XStringClass& Separator = ", "_XS, const XStringClass& Prefix = NullXString, const XStringClass& Suffix = NullXString) const
{
xsize i;
XString s;
XStringClass s;
if ( array.size() > 0 ) {
s = Prefix;

View File

@ -230,7 +230,7 @@ size_t length_of_wchar_string(const wchar_t* s);
inline const char* get_char32_from_string(const char* s, char32_t* char32) { return get_char32_from_utf8_string(s, char32); }
inline const char16_t* get_char32_from_string(const char16_t* s, char32_t* char32) { return get_char32_from_utf16_string(s, char32); }
inline const char32_t* get_char32_from_string(const char32_t* s, char32_t* char32) { *char32 = *s; return s+1; }
inline const char32_t* get_char32_from_string(const char32_t* s, char32_t* char32) { *char32 = *s; if ( !*s ) return s; return s+1; }
inline const wchar_t* get_char32_from_string(const wchar_t* s, char32_t* char32) { return (wchar_t*)get_char32_from_string((wchar_cast*)s, char32); }
inline char32_t get_char32_from_utf_string_at_pos(const char* s, size_t pos) { return get_char32_from_utf8_string_at_pos(s, pos); }

View File

@ -240,6 +240,24 @@ const TestStringMultiCodedAndExpectedResult testStringMultiCoded4TrimArray[] = {
size_t nbTestStringMultiCoded4TrimArray = *(&testStringMultiCoded4TrimArray + 1) - testStringMultiCoded4TrimArray;
const TestStringMultiCodedAndExpectedResult testStringMultiCoded4BasenameArray[] = {
{ testStringExpectedArray_LINE(" A൧൨BC/ギDEизF", "ギDEизF") },
{ testStringExpectedArray_LINE(" A൧൨BC//ギDEизF", "ギDEизF") },
{ testStringExpectedArray_LINE(" A൧൨BC\\\\ギDEизF", "ギDEизF") },
{ testStringExpectedArray_LINE(" A൧൨BC///ギDEизF", "ギDEизF") },
{ testStringExpectedArray_LINE(" A൧൨BC\\\\\\ギDEизF", "ギDEизF") },
{ testStringExpectedArray_LINE(" A൧൨BC/ギDEизF ", "ギDEизF ") },
{ testStringExpectedArray_LINE(" /ギDEизF ", "ギDEизF ") },
{ testStringExpectedArray_LINE(" ギDEизF ", " ギDEизF ") },
{ testStringExpectedArray_LINE("", ".") },
{ testStringExpectedArray_LINE(" ", " ") },
{ testStringExpectedArray_LINE("abc聯/輦deFG\\ꇊHIjklmn", "ꇊHIjklmn") },
{ testStringExpectedArray_LINE("abc聯\\輦deFG/ꇊHIjklmn", "ꇊHIjklmn") },
};
size_t nbTestStringMultiCoded4BasenameArray = *(&testStringMultiCoded4BasenameArray + 1) - testStringMultiCoded4BasenameArray;
template<class XStringType>
struct XStringClassInfo
@ -899,7 +917,7 @@ SimpleString testSubString_(const InitialValue& initialValue)
for ( size_t count = 0 ; count < initialValue.utf32_length-pos+3 ; count+=1 )
{
size_t expectedLength = 0;
if ( pos < initialValue.utf32_length ) expectedLength = min( count, initialValue.utf32_length - pos);
if ( pos < initialValue.utf32_length ) expectedLength = Xmin( count, initialValue.utf32_length - pos);
size_t expectedSize = 0;
if ( pos < initialValue.utf32_length ) expectedSize = utf_size_of_utf_string_len(&c, initialValue.cha, pos+count) - utf_size_of_utf_string_len(&c, initialValue.cha, pos);
@ -1436,6 +1454,36 @@ SimpleString teststartWith_(const InitialValue& initialValue)
} \
/***************************** basename *****************************/
template<class XStringClass, class InitialValue, typename ExpectedResult>
SimpleString testbasename_(const InitialValue& initialValue, const TestString<ExpectedResult>& expectedResult)
{
TEST_TITLE(displayOnlyFailed, ssprintf("Test %s::basename(%s\"%s\")", XStringClassInfo<XStringClass>::xStringClassName, XStringClassInfo<InitialValue>::prefix, SimpleString(initialValue.cha).c_str()));
// typedef typename XStringClassInfo<XStringClass>::ch_t ch_t;
// ch_t c; // dummy for call utf function
XStringClass initialString;
initialString.takeValueFrom(initialValue.cha);
XStringClass xstr = initialString.basename();
CHECK_RESULT(xstr.strcmp(expectedResult.cha) == 0,
ssprintf("\"%s\".basename() == \"%s\"", SimpleString(initialString.s()).c_str(), SimpleString(expectedResult.cha).c_str()),
ssprintf("\"%s\".basename() != (\"%s\"!=\"%s\")", SimpleString(initialString.s()).c_str(), SimpleString(xstr.s()).c_str(), SimpleString(expectedResult.cha).c_str())
);
XStringClass xstr2 = initialString.basename();
return SimpleString();
}
#define testbasename(XStringClass, classEncoding) \
printf("Test %s::testbasename\n", STRINGIFY(XStringClass)); \
for ( size_t i = 0 ; i < nbTestStringMultiCoded4BasenameArray ; i++ ) { \
testbasename_<XStringClass>(testStringMultiCoded4BasenameArray[i].classEncoding, testStringMultiCoded4BasenameArray[i].classEncoding##_expectedResult); \
} \
/***************************** *****************************/
#undef realloc
@ -1443,6 +1491,7 @@ SimpleString teststartWith_(const InitialValue& initialValue)
//#include <type_traits>
//#include <typeinfo>
//#include <iostream>
//#include <libgen.h>
//std::is_class
@ -1451,12 +1500,27 @@ void func_test(XStringW& xsw)
(void)xsw;
}
template<typename T>
class CE
{
public:
const T* data;
constexpr CE() : data(0) { }
};
class CE2 : public XStringAbstractNoDtor<char, CE2>
{
};
int XString_tests()
{
#ifdef JIEF_DEBUG
// printf("XString16_tests -> Enter\n");
#endif
//constexpr CE<char> ce;
//constexpr CE2 xsw;
//const char c = ' ';
//const char* cc = " ";
//char buf[64];
@ -1528,26 +1592,35 @@ size_t utf32_size = sizeof(U"ギ") - 1; (void)utf32_size; // this char is 6 b
//testCompare(XString, utf8, utf16);
//testindexOf_<XString>(testStringMultiCoded4CaseArray[0].utf8);
//const char* p1 = "foo/bar"; // basename returns bar
//const char* p1 = "foo/"; // basename returns foo
//const char* p1 = "foo//"; // basename returns foo
//const char* p1 = "foo///"; // basename returns foo
//const char* p1 = ""; // basename returns "."
//const char* p1 = " foo/bar "; // basename returns "bar "
//const char* p1 = " foo "; // basename returns " foo "
//const char* p1 = " "; // basename returns " "
//const char* p2 = basename((char*)p1);
// TEST_ALL_CLASSES(testDefaultCtor, __TEST0);
// TEST_ALL_CLASSES(testEmpty, __TEST0);
TEST_ALL_CLASSES(testTakeValueFrom, TEST_ALL_UTF);
// TEST_ALL_CLASSES(testTakeValueFrom, TEST_ALL_UTF);
// TEST_ALL_CLASSES(testchar32At, TEST_ALL_INTEGRAL);
// TEST_ALL_CLASSES(testdataSized, TEST_ALL_INTEGRAL);
//
TEST_ALL_CLASSES(teststrncpy, TEST_ALL_UTF); // 26944 tests
TEST_ALL_CLASSES(teststrcat, TEST_ALL_UTF_ALL_UTF);
// TEST_ALL_CLASSES(teststrncpy, TEST_ALL_UTF); // 26944 tests
// TEST_ALL_CLASSES(teststrcat, TEST_ALL_UTF_ALL_UTF);
// TEST_ALL_CLASSES(teststrncat, TEST_ALL_UTF_ALL_UTF); // 2101632 tests
//
// TEST_ALL_CLASSES(testSubString, __TEST0);
TEST_ALL_CLASSES(testSubString, __TEST0);
// TEST_ALL_CLASSES(testCompare, TEST_ALL_UTF);
// TEST_ALL_CLASSES(testindexOf, TEST_ALL_UTF);
//
// TEST_ALL_CLASSES(testlastChar, __TEST0);
TEST_ALL_CLASSES(testtrim, __TEST0);
TEST_ALL_CLASSES(teststartWith, __TEST0);
TEST_ALL_CLASSES(testbasename, __TEST0);

View File

@ -31,11 +31,11 @@ bool all_tests()
bool all_ok = true;
int ret;
// ret = XString_tests();
// if ( ret != 0 ) {
// printf("XString16_tests() failed at test %d\n", ret);
// all_ok = false;
// }
ret = XString_tests();
if ( ret != 0 ) {
printf("XString16_tests() failed at test %d\n", ret);
all_ok = false;
}
//return ret;
// ret = XUINTN_tests();
// if ( ret != 0 ) {

View File

@ -70,7 +70,7 @@ const XImage& ScanVolumeDefaultIcon(REFIT_VOLUME *Volume, IN UINT8 OSType, IN EF
DevicePath = NextDevicePathNode(DevicePath);
}
if (DevicePathType(DevicePath) == MEDIA_DEVICE_PATH && DevicePathSubType (DevicePath) == MEDIA_VENDOR_DP) {
if (StriCmp(GuidLEToStr((EFI_GUID *)((UINT8 *)DevicePath+0x04)),GuidLEToStr(&APFSSignature)) == 0 ) {
if ( GuidLEToStr((EFI_GUID *)((UINT8 *)DevicePath+0x04)).equalIC(GuidLEToStr(&APFSSignature)) ) {
IconNum = BUILTIN_ICON_VOL_INTERNAL_APFS;
}
} else {

View File

@ -59,9 +59,9 @@
#define DBG(...) DebugLog(DEBUG_SCAN_LOADER, __VA_ARGS__)
#endif
#define MACOSX_LOADER_PATH L"\\System\\Library\\CoreServices\\boot.efi"
const XStringW MACOSX_LOADER_PATH = "\\System\\Library\\CoreServices\\boot.efi"_XSW;
const XStringW LINUX_ISSUE_PATH = L"\\etc\\issue"_XSW;
const XStringW LINUX_ISSUE_PATH = "\\etc\\issue"_XSW;
#define LINUX_BOOT_PATH L"\\boot"
#define LINUX_BOOT_ALT_PATH L"\\boot"
const XString LINUX_LOADER_PATH = "vmlinuz"_XS;
@ -70,9 +70,9 @@ const XStringW LINUX_FULL_LOADER_PATH = SWPrintf("%ls\\%s", LINUX_BOOT_PATH, LIN
const XStringArray LINUX_DEFAULT_OPTIONS = Split<XStringArray>("ro add_efi_memmap quiet splash vt.handoff=7", " ");
#if defined(MDE_CPU_X64)
#define BOOT_LOADER_PATH L"\\EFI\\BOOT\\BOOTX64.efi"
#define BOOT_LOADER_PATH L"\\EFI\\BOOT\\BOOTX64.efi"_XSW
#else
#define BOOT_LOADER_PATH L"\\EFI\\BOOT\\BOOTIA32.efi"
#define BOOT_LOADER_PATH L"\\EFI\\BOOT\\BOOTIA32.efi"_XSW
#endif
@ -81,10 +81,10 @@ extern LOADER_ENTRY *SubMenuKextInjectMgmt(LOADER_ENTRY *Entry);
// Linux loader path data
typedef struct LINUX_PATH_DATA
{
CONST CHAR16 *Path;
CONST CHAR16 *Title;
CONST CHAR16 *Icon;
CONST CHAR8 *Issue;
CONST XStringW Path;
CONST XStringW Title;
CONST XStringW Icon;
CONST XString Issue;
} LINUX_PATH_DATA;
typedef struct LINUX_ICON_DATA
@ -103,14 +103,14 @@ STATIC LINUX_ICON_DATA LinuxIconMapping[] = {
{ L"mx18", L"mx" },
{ L"mx19", L"mx" }
};
STATIC CONST UINTN LinuxIconMappingCount = (sizeof(LinuxIconMapping) / sizeof(LINUX_ICON_DATA));
STATIC CONST UINTN LinuxIconMappingCount = (sizeof(LinuxIconMapping) / sizeof(LinuxIconMapping[0]));
STATIC LINUX_PATH_DATA LinuxEntryData[] = {
#if defined(MDE_CPU_X64)
//comment out all common names
// { L"\\EFI\\grub\\grubx64.efi", L"Grub EFI boot menu", L"grub,linux" },
// { L"\\EFI\\Gentoo\\grubx64.efi", L"Gentoo EFI boot menu", L"gentoo,linux", "Gentoo" },
{ L"\\EFI\\Gentoo\\kernelx64.efi", L"Gentoo EFI kernel", L"gentoo,linux" },
{ L"\\EFI\\Gentoo\\kernelx64.efi"_XSW, L"Gentoo EFI kernel"_XSW, L"gentoo,linux"_XSW },
// { L"\\EFI\\RedHat\\grubx64.efi", L"RedHat EFI boot menu", L"redhat,linux", "Redhat" },
// { L"\\EFI\\debian\\grubx64.efi", L"Debian EFI boot menu", L"debian,linux", "Debian" },
// { L"\\EFI\\kali\\grubx64.efi", L"Kali EFI boot menu", L"kali,linux", "Kali" },
@ -129,7 +129,7 @@ STATIC LINUX_PATH_DATA LinuxEntryData[] = {
// { L"\\EFI\\Manjaro\\grubx64.efi", L"Manjaro EFI boot menu", L"manjaro,linux", "Manjaro" },
// { L"\\EFI\\xubuntu\\grubx64.efi", L"Xubuntu EFI boot menu", L"xubuntu,linux", "Xubuntu" },
// { L"\\EFI\\zorin\\grubx64.efi", L"Zorin EFI boot menu", L"zorin,linux", "Zorin" },
{ L"\\EFI\\goofiboot\\goofibootx64.efi", L"Solus EFI boot menu", L"solus,linux", "Solus" },
{ L"\\EFI\\goofiboot\\goofibootx64.efi"_XSW, L"Solus EFI boot menu"_XSW, L"solus,linux"_XSW, "Solus"_XSW },
// { L"\\EFI\\centos\\grubx64.efi", L"CentOS EFI boot menu", L"centos,linux", "CentOS" },
// { L"\\EFI\\pclinuxos\\grubx64.efi", L"PCLinuxOS EFI boot menu", L"pclinux,linux", "PCLinux" },
// { L"\\EFI\\neon\\grubx64.efi", L"KDE Neon EFI boot menu", L"neon,linux", "KDE Neon" },
@ -165,9 +165,9 @@ STATIC LINUX_PATH_DATA LinuxEntryData[] = {
{ L"\\EFI\\MX19\\grub.efi", L"MX Linux EFI boot menu", L"mx,linux", "MX Linux" },
{ L"\\EFI\\parrot\\grub.efi", L"Parrot OS EFI boot menu", L"parrot,linux", "Parrot OS" },
#endif
{ L"\\EFI\\SuSe\\elilo.efi", L"OpenSuse EFI boot menu", L"suse,linux" },
{ L"\\EFI\\SuSe\\elilo.efi"_XSW, L"OpenSuse EFI boot menu"_XSW, L"suse,linux"_XSW },
};
STATIC CONST UINTN LinuxEntryDataCount = (sizeof(LinuxEntryData) / sizeof(LINUX_PATH_DATA));
STATIC CONST UINTN LinuxEntryDataCount = (sizeof(LinuxEntryData) / sizeof(LinuxEntryData[0]));
#if defined(ANDX86)
#if !defined(MDE_CPU_X64)
@ -177,39 +177,39 @@ STATIC CONST UINTN LinuxEntryDataCount = (sizeof(LinuxEntryData) / sizeof(LINUX_
#define ANDX86_FINDLEN 3
typedef struct ANDX86_PATH_DATA
{
CONST CHAR16 *Path;
CONST CHAR16 *Title;
CONST CHAR16 *Icon;
CONST CHAR16 *Find[ANDX86_FINDLEN];
CONST XStringW Path;
CONST XStringW Title;
CONST XStringW Icon;
CONST XStringW Find[ANDX86_FINDLEN];
} ANDX86_PATH_DATA;
STATIC ANDX86_PATH_DATA AndroidEntryData[] = {
//{ L"\\EFI\\boot\\grubx64.efi", L"Grub", L"grub,linux" },
//{ L"\\EFI\\boot\\bootx64.efi", L"Grub", L"grub,linux" },
{ L"\\EFI\\remixos\\grubx64.efi", L"Remix", L"remix,grub,linux", { L"\\isolinux\\isolinux.bin", L"\\initrd.img", L"\\kernel" } },
{ L"\\EFI\\PhoenixOS\\boot\\grubx64.efi", L"PhoenixOS", L"phoenix,grub,linux", { L"\\EFI\\PhoenixOS\\boot\\efi.img", L"\\EFI\\PhoenixOS\\initrd.img", L"\\EFI\\PhoenixOS\\kernel" } },
{ L"\\EFI\\boot\\grubx64.efi", L"Phoenix", L"phoenix,grub,linux", { L"\\phoenix\\kernel", L"\\phoenix\\initrd.img", L"\\phoenix\\ramdisk.img" } },
{ L"\\EFI\\boot\\bootx64.efi", L"Chrome", L"chrome,grub,linux", { L"\\syslinux\\vmlinuz.A", L"\\syslinux\\vmlinuz.B", L"\\syslinux\\ldlinux.sys"} },
{ L"\\EFI\\remixos\\grubx64.efi"_XSW, L"Remix"_XSW, L"remix,grub,linux"_XSW, { L"\\isolinux\\isolinux.bin"_XSW, L"\\initrd.img"_XSW, L"\\kernel"_XSW } },
{ L"\\EFI\\PhoenixOS\\boot\\grubx64.efi"_XSW, L"PhoenixOS"_XSW, L"phoenix,grub,linux"_XSW, { L"\\EFI\\PhoenixOS\\boot\\efi.img"_XSW, L"\\EFI\\PhoenixOS\\initrd.img"_XSW, L"\\EFI\\PhoenixOS\\kernel"_XSW } },
{ L"\\EFI\\boot\\grubx64.efi"_XSW, L"Phoenix"_XSW, L"phoenix,grub,linux"_XSW, { L"\\phoenix\\kernel"_XSW, L"\\phoenix\\initrd.img"_XSW, L"\\phoenix\\ramdisk.img"_XSW } },
{ L"\\EFI\\boot\\bootx64.efi"_XSW, L"Chrome"_XSW, L"chrome,grub,linux"_XSW, { L"\\syslinux\\vmlinuz.A"_XSW, L"\\syslinux\\vmlinuz.B"_XSW, L"\\syslinux\\ldlinux.sys"_XSW} },
};
STATIC CONST UINTN AndroidEntryDataCount = (sizeof(AndroidEntryData) / sizeof(ANDX86_PATH_DATA));
#endif
#endif
CONST CHAR16 *PaperBoot = L"\\com.apple.boot.P\\boot.efi";
CONST CHAR16 *RockBoot = L"\\com.apple.boot.R\\boot.efi";
CONST CHAR16 *ScissorBoot = L"\\com.apple.boot.S\\boot.efi";
CONST XStringW PaperBoot = "\\com.apple.boot.P\\boot.efi"_XSW;
CONST XStringW RockBoot = "\\com.apple.boot.R\\boot.efi"_XSW;
CONST XStringW ScissorBoot = "\\com.apple.boot.S\\boot.efi"_XSW;
// OS X installer paths
CONST CHAR16 *OSXInstallerPaths[] = {
L"\\.IABootFiles\\boot.efi", // 10.9 - 10.13.3
L"\\Mac OS X Install Data\\boot.efi", // 10.7
L"\\OS X Install Data\\boot.efi", // 10.8 - 10.11
L"\\macOS Install Data\\boot.efi", // 10.12 - 10.12.3
L"\\macOS Install Data\\Locked Files\\Boot Files\\boot.efi" // 10.12.4+
CONST XStringW OSXInstallerPaths[] = {
L"\\.IABootFiles\\boot.efi"_XSW, // 10.9 - 10.13.3
L"\\Mac OS X Install Data\\boot.efi"_XSW, // 10.7
L"\\OS X Install Data\\boot.efi"_XSW, // 10.8 - 10.11
L"\\macOS Install Data\\boot.efi"_XSW, // 10.12 - 10.12.3
L"\\macOS Install Data\\Locked Files\\Boot Files\\boot.efi"_XSW // 10.12.4+
};
STATIC CONST UINTN OSXInstallerPathsCount = (sizeof(OSXInstallerPaths) / sizeof(CHAR16 *));
STATIC CONST UINTN OSXInstallerPathsCount = (sizeof(OSXInstallerPaths) / sizeof(OSXInstallerPaths[0]));
STATIC INTN TimeCmp(IN EFI_TIME *Time1,
IN EFI_TIME *Time2)
@ -246,39 +246,39 @@ STATIC INTN TimeCmp(IN EFI_TIME *Time1,
return Comparison;
}
UINT8 GetOSTypeFromPath(IN CONST CHAR16 *Path)
UINT8 GetOSTypeFromPath(IN CONST XStringW& Path)
{
if (Path == NULL) {
if (Path.isEmpty()) {
return OSTYPE_OTHER;
}
if (StriCmp(Path, MACOSX_LOADER_PATH) == 0) {
if ( Path.equalIC(MACOSX_LOADER_PATH)) {
return OSTYPE_OSX;
} else if ((StriCmp(Path, OSXInstallerPaths[0]) == 0) ||
(StriCmp(Path, OSXInstallerPaths[1]) == 0) ||
(StriCmp(Path, OSXInstallerPaths[2]) == 0) ||
(StriCmp(Path, OSXInstallerPaths[3]) == 0) ||
(StriCmp(Path, OSXInstallerPaths[4]) == 0) ||
(StriCmp(Path, RockBoot) == 0) || (StriCmp(Path, PaperBoot) == 0) || (StriCmp(Path, ScissorBoot) == 0) ||
(!StriCmp(Path, L"\\.IABootFiles\\boot.efi") && StriCmp(Path, L"\\.IAPhysicalMedia") && StriCmp(Path, MACOSX_LOADER_PATH))
} else if ( Path.equalIC(OSXInstallerPaths[0]) ||
( Path.equalIC(OSXInstallerPaths[1])) ||
( Path.equalIC(OSXInstallerPaths[2])) ||
( Path.equalIC(OSXInstallerPaths[3])) ||
( Path.equalIC(OSXInstallerPaths[4])) ||
( Path.equalIC(RockBoot)) || ( Path.equalIC(PaperBoot)) || ( Path.equalIC(ScissorBoot)) ||
(! Path.equalIC(L"\\.IABootFiles\\boot.efi") && Path.equalIC(L"\\.IAPhysicalMedia") && Path.equalIC(MACOSX_LOADER_PATH))
) {
return OSTYPE_OSX_INSTALLER;
} else if (StriCmp(Path, L"\\com.apple.recovery.boot\\boot.efi") == 0) {
} else if ( Path.equalIC(L"\\com.apple.recovery.boot\\boot.efi")) {
return OSTYPE_RECOVERY;
} else if ((StriCmp(Path, L"\\EFI\\Microsoft\\Boot\\bootmgfw-orig.efi") == 0) || //test first as orig
(StriCmp(Path, L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi") == 0) || //it can be Clover
// (StriCmp(Path, L"\\bootmgr.efi") == 0) || //never worked, just extra icon in menu
(StriCmp(Path, L"\\EFI\\MICROSOFT\\BOOT\\cdboot.efi") == 0)) {
} else if (( Path.equalIC(L"\\EFI\\Microsoft\\Boot\\bootmgfw-orig.efi")) || //test first as orig
( Path.equalIC(L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi")) || //it can be Clover
// ( Path.equalIC(L"\\bootmgr.efi")) || //never worked, just extra icon in menu
( Path.equalIC(L"\\EFI\\MICROSOFT\\BOOT\\cdboot.efi"))) {
return OSTYPE_WINEFI;
} else if (LINUX_FULL_LOADER_PATH.equalIC(Path)) {
return OSTYPE_LINEFI;
} else if (StriStr(Path, L"grubx64.efi") != NULL) {
} else if ( Path.containsIC("grubx64.efi") ) {
return OSTYPE_LINEFI;
} else {
UINTN Index;
#if defined(ANDX86)
Index = 0;
while (Index < AndroidEntryDataCount) {
if (StriCmp(Path, AndroidEntryData[Index].Path) == 0) {
if ( Path.equalIC(AndroidEntryData[Index].Path) ) {
return OSTYPE_LIN;
}
++Index;
@ -286,7 +286,7 @@ UINT8 GetOSTypeFromPath(IN CONST CHAR16 *Path)
#endif
Index = 0;
while (Index < LinuxEntryDataCount) {
if (StriCmp(Path, LinuxEntryData[Index].Path) == 0) {
if ( Path.equalIC(LinuxEntryData[Index].Path) ) {
return OSTYPE_LIN;
}
++Index;
@ -295,14 +295,16 @@ UINT8 GetOSTypeFromPath(IN CONST CHAR16 *Path)
return OSTYPE_OTHER;
}
STATIC CONST CHAR16 *LinuxIconNameFromPath(IN CONST CHAR16 *Path,
IN EFI_FILE_PROTOCOL *RootDir)
static const XStringW linux = L"linux"_XSW;
STATIC CONST XStringW& LinuxIconNameFromPath(IN CONST XStringW& Path,
IN EFI_FILE_PROTOCOL *RootDir)
{
UINTN Index;
#if defined(ANDX86)
Index = 0;
while (Index < AndroidEntryDataCount) {
if (StriCmp(Path, AndroidEntryData[Index].Path) == 0) {
if ( Path.equalIC(AndroidEntryData[Index].Path) ) {
return AndroidEntryData[Index].Icon;
}
++Index;
@ -312,7 +314,7 @@ STATIC CONST CHAR16 *LinuxIconNameFromPath(IN CONST CHAR16 *Path,
//check not common names
Index = 0;
while (Index < LinuxEntryDataCount) {
if (StriCmp(Path, LinuxEntryData[Index].Path) == 0) {
if ( Path.equalIC(LinuxEntryData[Index].Path) ) {
return LinuxEntryData[Index].Icon;
}
++Index;
@ -325,8 +327,7 @@ STATIC CONST CHAR16 *LinuxIconNameFromPath(IN CONST CHAR16 *Path,
if (!EFI_ERROR(egLoadFile(RootDir, LINUX_ISSUE_PATH.wc_str(), (UINT8 **)&Issue, &IssueLen)) && (Issue != NULL)) {
if (IssueLen > 0) {
for (Index = 0; Index < LinuxEntryDataCount; ++Index) {
if ((LinuxEntryData[Index].Issue != NULL) &&
(AsciiStrStr(Issue, LinuxEntryData[Index].Issue) != NULL)) {
if ( LinuxEntryData[Index].Issue.notEmpty() && AsciiStrStr(Issue, LinuxEntryData[Index].Issue.c_str()) != NULL ) {
FreePool(Issue);
return LinuxEntryData[Index].Icon;
}
@ -335,7 +336,7 @@ STATIC CONST CHAR16 *LinuxIconNameFromPath(IN CONST CHAR16 *Path,
FreePool(Issue);
}
}
return L"linux";
return linux;
}
STATIC CONST XString LinuxInitImagePath[] = {
@ -346,7 +347,7 @@ STATIC CONST XString LinuxInitImagePath[] = {
"initramfs.img%s"_XS,
"initramfs%s.img"_XS,
};
STATIC CONST UINTN LinuxInitImagePathCount = (sizeof(LinuxInitImagePath) / sizeof(CHAR16 *));
STATIC CONST UINTN LinuxInitImagePathCount = (sizeof(LinuxInitImagePath) / sizeof(LinuxInitImagePath[0]));
STATIC XStringArray LinuxKernelOptions(IN EFI_FILE_PROTOCOL *Dir,
IN CONST CHAR16 *Version,
@ -439,7 +440,7 @@ STATIC EFI_STATUS GetOSXVolumeName(LOADER_ENTRY *Entry)
}
return Status;
}
STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST XStringW& LoaderPath,
IN CONST XStringArray& LoaderOptions,
IN CONST XStringW& FullTitle,
IN CONST XStringW& LoaderTitle,
@ -458,19 +459,19 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
EFI_DEVICE_PATH *LoaderDevicePath;
CONST CHAR16 *LoaderDevicePathString;
CONST CHAR16 *FilePathAsString;
CONST CHAR16 *OSIconName = NULL;
// CONST CHAR16 *OSIconName = NULL;
CHAR16 ShortcutLetter;
LOADER_ENTRY *Entry;
CONST CHAR8 *indent = " ";
// Check parameters are valid
if ((LoaderPath == NULL) || (*LoaderPath == 0) || (Volume == NULL)) {
if ((LoaderPath.isEmpty()) || (Volume == NULL)) {
return NULL;
}
// Get the loader device path
// LoaderDevicePath = FileDevicePath(Volume->DeviceHandle, (*LoaderPath == L'\\') ? (LoaderPath + 1) : LoaderPath);
LoaderDevicePath = FileDevicePath(Volume->DeviceHandle, LoaderPath);
LoaderDevicePath = FileDevicePath(Volume->DeviceHandle, LoaderPath.wc_str());
if (LoaderDevicePath == NULL) {
return NULL;
}
@ -539,9 +540,9 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
}
// Check if the path match
if (Custom->Path != NULL) {
if (Custom->Path.notEmpty()) {
// Check if the loader path match
path_match = (StriCmp(Custom->Path, LoaderPath) == 0) ? 1 : -1;
path_match = (Custom->Path.equalIC(LoaderPath)) ? 1 : -1;
}
// Check if the type match
@ -594,7 +595,7 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
Entry->Row = 0;
Entry->Volume = Volume;
Entry->LoaderPath = EfiStrDuplicate(LoaderPath);
Entry->LoaderPath = LoaderPath;
Entry->VolName = Volume->VolName;
Entry->DevicePath = LoaderDevicePath;
Entry->DevicePathString = LoaderDevicePathString;
@ -628,7 +629,7 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
Entry->OSVersion = GetOSVersion(Entry);
//DBG("OSVersion=%s \n", Entry->OSVersion);
// detect specific loaders
OSIconName = NULL;
XStringW OSIconName;
ShortcutLetter = 0;
switch (OSType) {
@ -657,11 +658,11 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
}
break;
case OSTYPE_WIN:
OSIconName = L"win";
OSIconName = L"win"_XSW;
ShortcutLetter = 'W';
break;
case OSTYPE_WINEFI:
OSIconName = L"vista,win";
OSIconName = L"vista,win"_XSW;
//ShortcutLetter = 'V';
ShortcutLetter = 'W';
break;
@ -669,7 +670,7 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
case OSTYPE_LINEFI:
// we already detected linux and have Path and Image
Entry->LoaderType = OSType;
OSIconName = L"linux";
OSIconName = L"linux"_XSW;
if (Image == nullptr) {
DBG(" image not found\n");
OSIconName = LinuxIconNameFromPath(LoaderPath, Volume->RootDir); //something named "issue"
@ -678,12 +679,12 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
break;
//case OSTYPE_OTHER:
case OSTYPE_EFI:
OSIconName = L"clover";
OSIconName = L"clover"_XSW;
ShortcutLetter = 'E';
Entry->LoaderType = OSTYPE_OTHER;
break;
default:
OSIconName = L"unknown";
OSIconName = L"unknown"_XSW;
Entry->LoaderType = OSTYPE_OTHER;
break;
}
@ -691,9 +692,9 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
Entry->Title = FullTitle;
if (Entry->Title.isEmpty() && Volume->VolLabel != NULL) {
if (Volume->VolLabel[0] == L'#') {
Entry->Title.SWPrintf("Boot %ls from %ls", (!LoaderTitle.isEmpty()) ? LoaderTitle.wc_str() : Basename(LoaderPath), Volume->VolLabel+1);
Entry->Title.SWPrintf("Boot %ls from %ls", (!LoaderTitle.isEmpty()) ? LoaderTitle.wc_str() : LoaderPath.basename().wc_str(), Volume->VolLabel+1);
}else{
Entry->Title.SWPrintf("Boot %ls from %ls", (!LoaderTitle.isEmpty()) ? LoaderTitle.wc_str() : Basename(LoaderPath), Volume->VolLabel);
Entry->Title.SWPrintf("Boot %ls from %ls", (!LoaderTitle.isEmpty()) ? LoaderTitle.wc_str() : LoaderPath.basename().wc_str(), Volume->VolLabel);
}
}
@ -708,7 +709,7 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
Entry->Title.takeValueFrom(Basename(Volume->DevicePathString));
}
} else {
Entry->Title.SWPrintf("Boot %ls from %ls", (!LoaderTitle.isEmpty()) ? LoaderTitle.wc_str() : Basename(LoaderPath),
Entry->Title.SWPrintf("Boot %ls from %ls", (!LoaderTitle.isEmpty()) ? LoaderTitle.wc_str() : LoaderPath.basename().wc_str(),
Basename(Volume->DevicePathString));
}
}
@ -722,11 +723,11 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
if (!LoaderTitle.isEmpty()) {
Entry->Title = LoaderTitle;
} else {
Entry->Title.takeValueFrom(Basename(LoaderPath));
Entry->Title = LoaderPath.basename();
}
}
} else {
Entry->Title.SWPrintf("Boot %ls from %ls", (!LoaderTitle.isEmpty()) ? LoaderTitle.wc_str() : Basename(LoaderPath),
Entry->Title.SWPrintf("Boot %ls from %ls", (!LoaderTitle.isEmpty()) ? LoaderTitle.wc_str() : LoaderPath.basename().wc_str(),
Entry->VolName);
}
}
@ -780,7 +781,7 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST CHAR16 *LoaderPath,
STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry)
{
CONST CHAR16 *FileName;
XStringW FileName;
// CHAR16* TempOptions;
// CHAR16 DiagsFileName[256];
LOADER_ENTRY *SubEntry;
@ -803,7 +804,7 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry)
KernelIs64BitOnly = (Entry->OSVersion == NULL ||
AsciiOSVersionToUint64(Entry->OSVersion) >= AsciiOSVersionToUint64("10.8"));
FileName = Basename(Entry->LoaderPath);
FileName = Entry->LoaderPath.basename();
// create the submenu
// SubScreen = (__typeof__(SubScreen))AllocateZeroPool(sizeof(REFIT_MENU_SCREEN));
@ -929,7 +930,7 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry)
// default entry
SubEntry = Entry->getPartiallyDuplicatedEntry();
if (SubEntry) {
SubEntry->Title.SWPrintf("Run %ls", FileName);
SubEntry->Title.SWPrintf("Run %ls", FileName.wc_str());
SubScreen->AddMenuEntry(SubEntry, true);
}
@ -988,7 +989,7 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry)
// default entry
SubEntry = Entry->getPartiallyDuplicatedEntry();
if (SubEntry) {
SubEntry->Title.SWPrintf("Run %ls", FileName);
SubEntry->Title.SWPrintf("Run %ls", FileName.wc_str());
SubScreen->AddMenuEntry(SubEntry, true);
}
@ -1009,7 +1010,7 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry)
SubEntry = Entry->getPartiallyDuplicatedEntry();
if (SubEntry) {
SubEntry->Title.SWPrintf("Run %ls in text mode", FileName);
SubEntry->Title.SWPrintf("Run %ls in text mode", FileName.wc_str());
SubEntry->Flags = OSFLAG_UNSET(SubEntry->Flags, OSFLAG_USEGRAPHICS);
Entry->LoadOptions.setEmpty();
Entry->LoadOptions.Add("-v"_XS);
@ -1023,7 +1024,7 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry)
Entry->SubScreen = SubScreen;
// DBG(" Added '%ls': OSType='%d', OSVersion='%s'\n", Entry->Title, Entry->LoaderType, Entry->OSVersion);
}
BOOLEAN AddLoaderEntry(IN CONST CHAR16 *LoaderPath, IN CONST XStringArray& LoaderOptions,
BOOLEAN AddLoaderEntry(IN CONST XStringW& LoaderPath, IN CONST XStringArray& LoaderOptions,
IN CONST XStringW& LoaderTitle,
IN REFIT_VOLUME *Volume, IN XImage *Image,
IN UINT8 OSType, IN UINT8 Flags)
@ -1031,7 +1032,7 @@ BOOLEAN AddLoaderEntry(IN CONST CHAR16 *LoaderPath, IN CONST XStringArray& Loade
LOADER_ENTRY *Entry;
INTN HVi;
if ((LoaderPath == NULL) || (Volume == NULL) || (Volume->RootDir == NULL) || !FileExists(Volume->RootDir, LoaderPath)) {
if ((LoaderPath.isEmpty()) || (Volume == NULL) || (Volume->RootDir == NULL) || !FileExists(Volume->RootDir, LoaderPath.wc_str())) {
return FALSE;
}
@ -1047,8 +1048,8 @@ BOOLEAN AddLoaderEntry(IN CONST CHAR16 *LoaderPath, IN CONST XStringArray& Loade
//don't add hided entries
if (!gSettings.ShowHiddenEntries) {
for (HVi = 0; HVi < gSettings.HVCount; HVi++) {
if (StriStr(LoaderPath, gSettings.HVHideStrings[HVi])) {
DBG(" hiding entry: %ls\n", LoaderPath);
if ( LoaderPath.containsIC(gSettings.HVHideStrings[HVi]) ) {
DBG(" hiding entry: %ls\n", LoaderPath.s());
return FALSE;
}
}
@ -1078,9 +1079,9 @@ BOOLEAN AddLoaderEntry(IN CONST CHAR16 *LoaderPath, IN CONST XStringArray& Loade
return FALSE;
}
//constants
CHAR16 APFSFVBootPath[75] = L"\\00000000-0000-0000-0000-000000000000\\System\\Library\\CoreServices\\boot.efi";
CHAR16 APFSRecBootPath[47] = L"\\00000000-0000-0000-0000-000000000000\\boot.efi";
CHAR16 APFSInstallBootPath[67] = L"\\00000000-0000-0000-0000-000000000000\\com.apple.installer\\boot.efi";
//const XStringW APFSFVBootPath = L"\\00000000-0000-0000-0000-000000000000\\System\\Library\\CoreServices\\boot.efi"_XSW;
//const XStringW APFSRecBootPath = L"\\00000000-0000-0000-0000-000000000000\\boot.efi"_XSW;
//const XStringW APFSInstallBootPath = L"\\00000000-0000-0000-0000-000000000000\\com.apple.installer\\boot.efi"_XSW;
#define Paper 1
#define Rock 2
@ -1093,9 +1094,9 @@ VOID AddPRSEntry(REFIT_VOLUME *Volume)
//CONST INTN Rock = 2;
//CONST INTN Scissor = 4;
WhatBoot |= FileExists(Volume->RootDir, RockBoot)?Rock:0;
WhatBoot |= FileExists(Volume->RootDir, PaperBoot)?Paper:0;
WhatBoot |= FileExists(Volume->RootDir, ScissorBoot)?Scissor:0;
WhatBoot |= FileExists(Volume->RootDir, RockBoot.wc_str())?Rock:0;
WhatBoot |= FileExists(Volume->RootDir, PaperBoot.wc_str())?Paper:0;
WhatBoot |= FileExists(Volume->RootDir, ScissorBoot.wc_str())?Scissor:0;
switch (WhatBoot) {
case Paper:
case (Paper | Rock):
@ -1162,25 +1163,25 @@ VOID ScanLoader(VOID)
if (FileExists(Volume->RootDir, L"\\Install OS X Mavericks.app") ||
FileExists(Volume->RootDir, L"\\Install OS X Yosemite.app") ||
FileExists(Volume->RootDir, L"\\Install OS X El Capitan.app")) {
AddLoaderEntry(L"\\.IABootFiles\\boot.efi", NullXStringArray, L"OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.9 - 10.11
AddLoaderEntry("\\.IABootFiles\\boot.efi"_XSW, NullXStringArray, L"OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.9 - 10.11
} else {
AddLoaderEntry(L"\\.IABootFiles\\boot.efi", NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.12 - 10.13.3
AddLoaderEntry(L"\\.IABootFiles\\boot.efi"_XSW, NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.12 - 10.13.3
}
} else if (FileExists(Volume->RootDir, L"\\.IAPhysicalMedia") && FileExists(Volume->RootDir, MACOSX_LOADER_PATH)) {
} else if (FileExists(Volume->RootDir, L"\\.IAPhysicalMedia") && FileExists(Volume->RootDir, MACOSX_LOADER_PATH.wc_str())) {
AddLoaderEntry(MACOSX_LOADER_PATH, NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.13.4+
}
// 2nd stage - InstallESD/AppStore/startosinstall/Fusion Drive
AddLoaderEntry(L"\\Mac OS X Install Data\\boot.efi", NullXStringArray, L"Mac OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.7
AddLoaderEntry(L"\\OS X Install Data\\boot.efi", NullXStringArray, L"OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.8 - 10.11
AddLoaderEntry(L"\\macOS Install Data\\boot.efi", NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.12 - 10.12.3
AddLoaderEntry(L"\\macOS Install Data\\Locked Files\\Boot Files\\boot.efi", NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.12.4+
AddLoaderEntry("\\Mac OS X Install Data\\boot.efi"_XSW, NullXStringArray, L"Mac OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.7
AddLoaderEntry(L"\\OS X Install Data\\boot.efi"_XSW, NullXStringArray, L"OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.8 - 10.11
AddLoaderEntry(L"\\macOS Install Data\\boot.efi"_XSW, NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.12 - 10.12.3
AddLoaderEntry(L"\\macOS Install Data\\Locked Files\\Boot Files\\boot.efi"_XSW, NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.12.4+
AddPRSEntry(Volume); // 10.12+
// Netinstall
AddLoaderEntry(L"\\NetInstall macOS High Sierra.nbi\\i386\\booter", NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0);
AddLoaderEntry(L"\\NetInstall macOS High Sierra.nbi\\i386\\booter"_XSW, NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0);
// Use standard location for boot.efi, according to the install files is present
// That file indentifies a DVD/ESD/BaseSystem/Fusion Drive Install Media, so when present, check standard path to avoid entry duplication
if (FileExists(Volume->RootDir, MACOSX_LOADER_PATH)) {
if (FileExists(Volume->RootDir, MACOSX_LOADER_PATH.wc_str())) {
if (FileExists(Volume->RootDir, L"\\System\\Installation\\CDIS\\Mac OS X Installer.app")) {
// InstallDVD/BaseSystem
AddLoaderEntry(MACOSX_LOADER_PATH, NullXStringArray, L"Mac OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.6/10.7
@ -1227,48 +1228,47 @@ VOID ScanLoader(VOID)
if ((StriCmp(Volume->VolName, L"Recovery") == 0 || StriCmp(Volume->VolName, L"Preboot") == 0) && APFSSupport == TRUE) {
for (UINTN i = 0; i < APFSUUIDBankCounter + 1; i++) {
//Store current UUID
CHAR16 *CurrentUUID = GuidLEToStr((EFI_GUID *)((UINT8 *)APFSUUIDBank + i * 0x10));
XStringW CurrentUUID = GuidLEToStr((EFI_GUID *)((UINT8 *)APFSUUIDBank + i * 0x10));
//Fill with current UUID
StrnCpy(APFSFVBootPath + 1, CurrentUUID, 36);
StrnCpy(APFSRecBootPath + 1, CurrentUUID, 36);
StrnCpy(APFSInstallBootPath + 1, CurrentUUID, 36);
// StrnCpy(APFSFVBootPath + 1, CurrentUUID, 36);
// StrnCpy(APFSRecBootPath + 1, CurrentUUID, 36);
// StrnCpy(APFSInstallBootPath + 1, CurrentUUID, 36);
//Try to add FileVault entry
AddLoaderEntry(APFSFVBootPath, NullXStringArray, L"FileVault Prebooter"_XSW, Volume, NULL, OSTYPE_OSX, 0);
AddLoaderEntry(SWPrintf("\\%ls\\System\\Library\\CoreServices\\boot.efi", CurrentUUID.c_str()), NullXStringArray, L"FileVault Prebooter"_XSW, Volume, NULL, OSTYPE_OSX, 0);
//Try to add Recovery APFS entry
AddLoaderEntry(APFSRecBootPath, NullXStringArray, L"Recovery"_XSW, Volume, NULL, OSTYPE_RECOVERY, 0);
AddLoaderEntry(SWPrintf("\\%ls\\boot.efi", CurrentUUID.c_str()), NullXStringArray, L"Recovery"_XSW, Volume, NULL, OSTYPE_RECOVERY, 0);
//Try to add macOS install entry
AddLoaderEntry(APFSInstallBootPath, NullXStringArray, L"macOS Install Prebooter"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0);
FreePool(CurrentUUID);
AddLoaderEntry(SWPrintf("\\%ls\\com.apple.installer\\boot.efi", CurrentUUID.c_str()), NullXStringArray, L"macOS Install Prebooter"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0);
}
}
// check for Mac OS X Recovery Boot
AddLoaderEntry(L"\\com.apple.recovery.boot\\boot.efi", NullXStringArray, L"Recovery"_XSW, Volume, NULL, OSTYPE_RECOVERY, 0);
AddLoaderEntry(L"\\com.apple.recovery.boot\\boot.efi"_XSW, NullXStringArray, L"Recovery"_XSW, Volume, NULL, OSTYPE_RECOVERY, 0);
// Sometimes, on some systems (HP UEFI, if Win is installed first)
// it is needed to get rid of bootmgfw.efi to allow starting of
// Clover as /efi/boot/bootx64.efi from HD. We can do that by renaming
// bootmgfw.efi to bootmgfw-orig.efi
AddLoaderEntry(L"\\EFI\\microsoft\\Boot\\bootmgfw-orig.efi", NullXStringArray, L"Microsoft EFI"_XSW, Volume, NULL, OSTYPE_WINEFI, 0);
AddLoaderEntry(L"\\EFI\\microsoft\\Boot\\bootmgfw-orig.efi"_XSW, NullXStringArray, L"Microsoft EFI"_XSW, Volume, NULL, OSTYPE_WINEFI, 0);
// check for Microsoft boot loader/menu
// If there is bootmgfw-orig.efi, then do not check for bootmgfw.efi
// since on some systems this will actually be CloverX64.efi
// renamed to bootmgfw.efi
AddLoaderEntry(L"\\EFI\\microsoft\\Boot\\bootmgfw.efi", NullXStringArray, L"Microsoft EFI Boot"_XSW, Volume, NULL, OSTYPE_WINEFI, 0);
AddLoaderEntry(L"\\EFI\\microsoft\\Boot\\bootmgfw.efi"_XSW, NullXStringArray, L"Microsoft EFI Boot"_XSW, Volume, NULL, OSTYPE_WINEFI, 0);
// check for Microsoft boot loader/menu. This entry is redundant so excluded
// AddLoaderEntry(L"\\bootmgr.efi", L"", L"Microsoft EFI mgrboot", Volume, NULL, OSTYPE_WINEFI, 0);
// check for Microsoft boot loader/menu on CDROM
if (!AddLoaderEntry(L"\\EFI\\MICROSOFT\\BOOT\\cdboot.efi", NullXStringArray, L"Microsoft EFI cdboot"_XSW, Volume, NULL, OSTYPE_WINEFI, 0)) {
AddLoaderEntry(L"\\EFI\\MICROSOF\\BOOT\\CDBOOT.EFI", NullXStringArray, L"Microsoft EFI CDBOOT"_XSW, Volume, NULL, OSTYPE_WINEFI, 0);
if (!AddLoaderEntry(L"\\EFI\\MICROSOFT\\BOOT\\cdboot.efi"_XSW, NullXStringArray, L"Microsoft EFI cdboot"_XSW, Volume, NULL, OSTYPE_WINEFI, 0)) {
AddLoaderEntry(L"\\EFI\\MICROSOF\\BOOT\\CDBOOT.EFI"_XSW, NullXStringArray, L"Microsoft EFI CDBOOT"_XSW, Volume, NULL, OSTYPE_WINEFI, 0);
}
#if defined(ANDX86)
if (TRUE) { //gSettings.AndroidScan
// check for Android loaders
for (Index = 0; Index < AndroidEntryDataCount; ++Index) {
UINTN aIndex, aFound;
if (FileExists(Volume->RootDir, AndroidEntryData[Index].Path)) {
if (FileExists(Volume->RootDir, AndroidEntryData[Index].Path.wc_str())) {
aFound = 0;
for (aIndex = 0; aIndex < ANDX86_FINDLEN; ++aIndex) {
if ((AndroidEntryData[Index].Find[aIndex] == NULL) || FileExists(Volume->RootDir, AndroidEntryData[Index].Find[aIndex])) ++aFound;
if ((AndroidEntryData[Index].Find[aIndex].isEmpty()) || FileExists(Volume->RootDir, AndroidEntryData[Index].Find[aIndex])) ++aFound;
}
if (aFound && (aFound == aIndex)) {
XImage ImageX;
@ -1312,7 +1312,7 @@ VOID ScanLoader(VOID)
XImage ImageX; //will the image be destroyed or rewritten by next image after the cycle end?
// load from directory, as we don't have linux icons preloaded
ImageX.LoadXImage(ThemeX.ThemeDir, (L"os_"_XSW + OSName).wc_str());
AddLoaderEntry(File.wc_str(), NullXStringArray, LoaderTitle, Volume,
AddLoaderEntry(File, NullXStringArray, LoaderTitle, Volume,
(ImageX.isEmpty() ? NULL : &ImageX), OSTYPE_LINEFI, OSFLAG_NODEFAULTARGS);
} //anyway continue search other entries
}
@ -1333,7 +1333,7 @@ VOID ScanLoader(VOID)
REFIT_DIR_ITER Iter;
EFI_FILE_INFO *FileInfo = NULL;
EFI_TIME PreviousTime;
CHAR16 *Path = NULL;
XStringW Path;
// CHAR16 *Options;
// Get the partition UUID and make sure it's lower case
CHAR16 PartUUID[40];
@ -1354,14 +1354,11 @@ VOID ScanLoader(VOID)
continue;
}
// get the kernel file path
Path = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
if (Path != NULL) {
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, Basename(Path) + LINUX_LOADER_PATH.length(), PartUUID, NullXStringArray);
// Add the entry
AddLoaderEntry(Path, (Options.isEmpty()) ? LINUX_DEFAULT_OPTIONS : Options, L""_XSW, Volume, NULL, OSTYPE_LINEFI, OSFLAG_NODEFAULTARGS);
FreePool(Path);
}
Path.SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, Basename(Path.wc_str()) + LINUX_LOADER_PATH.length(), PartUUID, NullXStringArray);
// Add the entry
AddLoaderEntry(Path, (Options.isEmpty()) ? LINUX_DEFAULT_OPTIONS : Options, L""_XSW, Volume, NULL, OSTYPE_LINEFI, OSFLAG_NODEFAULTARGS);
Path.setEmpty();
// free the file info
FreePool(FileInfo);
FileInfo = NULL;
@ -1376,21 +1373,18 @@ VOID ScanLoader(VOID)
if (FileInfo != NULL) {
if (FileInfo->FileSize > 0) {
// get the kernel file path
if (Path != NULL) {
FreePool(Path);
}
Path = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
Path.SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
}
// free the file info
FreePool(FileInfo);
FileInfo = NULL;
}
}
if (Path != NULL) {
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, Basename(Path) + LINUX_LOADER_PATH.length(), PartUUID, NullXStringArray);
if (Path.notEmpty()) {
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, Basename(Path.wc_str()) + LINUX_LOADER_PATH.length(), PartUUID, NullXStringArray);
// Add the entry
AddLoaderEntry(Path, (Options.isEmpty()) ? LINUX_DEFAULT_OPTIONS : Options, L""_XSW, Volume, NULL, OSTYPE_LINEFI, OSFLAG_NODEFAULTARGS);
FreePool(Path);
Path.setEmpty();
}
break;
@ -1401,10 +1395,7 @@ VOID ScanLoader(VOID)
if (FileInfo->FileSize > 0) {
// get the kernel file path
if ((PreviousTime.Year == 0) || (TimeCmp(&PreviousTime, &(FileInfo->ModificationTime)) < 0)) {
if (Path != NULL) {
FreePool(Path);
}
Path = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
Path.SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
PreviousTime = FileInfo->ModificationTime;
}
}
@ -1413,11 +1404,11 @@ VOID ScanLoader(VOID)
FileInfo = NULL;
}
}
if (Path != NULL) {
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, Basename(Path) + LINUX_LOADER_PATH.length(), PartUUID, NullXStringArray);
if (Path.notEmpty()) {
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, Basename(Path.wc_str()) + LINUX_LOADER_PATH.length(), PartUUID, NullXStringArray);
// Add the entry
AddLoaderEntry(Path, (Options.isEmpty()) ? LINUX_DEFAULT_OPTIONS : Options, L""_XSW, Volume, NULL, OSTYPE_LINEFI, OSFLAG_NODEFAULTARGS);
FreePool(Path);
Path.setEmpty();
}
break;
@ -1428,10 +1419,7 @@ VOID ScanLoader(VOID)
if (FileInfo->FileSize > 0) {
// get the kernel file path
if ((PreviousTime.Year == 0) || (TimeCmp(&PreviousTime, &(FileInfo->ModificationTime)) > 0)) {
if (Path != NULL) {
FreePool(Path);
}
Path = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
Path.SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
PreviousTime = FileInfo->ModificationTime;
}
}
@ -1440,11 +1428,11 @@ VOID ScanLoader(VOID)
FileInfo = NULL;
}
}
if (Path != NULL) {
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, XStringW().takeValueFrom(Basename(Path) + LINUX_LOADER_PATH.length()).wc_str(), PartUUID, NullXStringArray);
if (Path.notEmpty()) {
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, Basename(Path.wc_str()) + LINUX_LOADER_PATH.length(), PartUUID, NullXStringArray);
// Add the entry
AddLoaderEntry(Path, (Options.isEmpty()) ? LINUX_DEFAULT_OPTIONS : Options, L""_XSW, Volume, NULL, OSTYPE_LINEFI, OSFLAG_NODEFAULTARGS);
FreePool(Path);
Path.setEmpty();
}
break;
@ -1454,29 +1442,23 @@ VOID ScanLoader(VOID)
if (FileInfo != NULL) {
if (FileInfo->FileSize > 0) {
// get the kernel file path
CHAR16 *NewPath = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
if (NewPath != NULL) {
if ((Path == NULL) || (StrCmp(Path, NewPath) < 0)) {
if (Path != NULL) {
FreePool(Path);
}
XStringW NewPath = SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
if ( Path > NewPath ) {
Path = NewPath;
} else {
FreePool(NewPath);
}
}
}else{
Path.setEmpty();
}
}
// free the file info
FreePool(FileInfo);
FileInfo = NULL;
}
}
if (Path != NULL) {
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, XStringW().takeValueFrom(Basename(Path) + LINUX_LOADER_PATH.length()).wc_str(), PartUUID, NullXStringArray);
if (Path.notEmpty()) {
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, Basename(Path.wc_str()) + LINUX_LOADER_PATH.length(), PartUUID, NullXStringArray);
// Add the entry
AddLoaderEntry(Path, (Options.isEmpty()) ? LINUX_DEFAULT_OPTIONS : Options, L""_XSW, Volume, NULL, OSTYPE_LINEFI, OSFLAG_NODEFAULTARGS);
FreePool(Path);
Path.setEmpty();
}
break;
@ -1486,27 +1468,22 @@ VOID ScanLoader(VOID)
if (FileInfo != NULL) {
if (FileInfo->FileSize > 0) {
// get the kernel file path
CHAR16 *NewPath = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
if (NewPath != NULL) {
if ((Path == NULL) || (StrCmp(Path, NewPath) > 0)) {
if (Path != NULL) {
FreePool(Path);
}
XStringW NewPath = SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
if ( Path < NewPath ) {
Path = NewPath;
} else {
FreePool(NewPath);
}
}
}else{
Path.setEmpty();
}
}
// free the file info
FreePool(FileInfo);
FileInfo = NULL;
}
}
if (Path != NULL) {
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, Basename(Path) + LINUX_LOADER_PATH.length(), PartUUID, NullXStringArray);
if (Path.notEmpty()) {
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, Basename(Path.wc_str()) + LINUX_LOADER_PATH.length(), PartUUID, NullXStringArray);
AddLoaderEntry(Path, (Options.isEmpty()) ? LINUX_DEFAULT_OPTIONS : Options, L""_XSW, Volume, NULL, OSTYPE_LINEFI, OSFLAG_NODEFAULTARGS);
FreePool(Path);
Path.setEmpty();
}
break;
@ -1516,13 +1493,11 @@ VOID ScanLoader(VOID)
if (FileInfo != NULL) {
if (FileInfo->FileSize > 0) {
// get the kernel file path
Path = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
if (Path != NULL) {
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, Basename(Path) + LINUX_LOADER_PATH.length(), PartUUID, NullXStringArray);
// Add the entry
AddLoaderEntry(Path, (Options.isEmpty()) ? LINUX_DEFAULT_OPTIONS : Options, L""_XSW, Volume, NULL, OSTYPE_LINEFI, OSFLAG_NODEFAULTARGS);
FreePool(Path);
}
Path.SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
XStringArray Options = LinuxKernelOptions(Iter.DirHandle, Basename(Path.wc_str()) + LINUX_LOADER_PATH.length(), PartUUID, NullXStringArray);
// Add the entry
AddLoaderEntry(Path, (Options.isEmpty()) ? LINUX_DEFAULT_OPTIONS : Options, L""_XSW, Volume, NULL, OSTYPE_LINEFI, OSFLAG_NODEFAULTARGS);
Path.setEmpty();
}
// free the file info
FreePool(FileInfo);
@ -1557,7 +1532,7 @@ VOID ScanLoader(VOID)
}
STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
IN CONST CHAR16 *CustomPath,
IN XStringW CustomPath,
IN CUSTOM_LOADER_ENTRY *Custom,
IN REFIT_MENU_SCREEN *SubMenu)
{
@ -1567,7 +1542,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
REFIT_DIR_ITER *Iter = &SIter;
CHAR16 PartUUID[40];
BOOLEAN IsSubEntry = (SubMenu != NULL);
BOOLEAN FindCustomPath = (CustomPath == NULL);
BOOLEAN FindCustomPath = (CustomPath.isEmpty());
if (Custom == NULL) {
return;
@ -1721,7 +1696,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
continue;
}
// get the kernel file path
CustomPath = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
CustomPath.SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
// free the file info
FreePool(FileInfo);
FileInfo = NULL;
@ -1736,10 +1711,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
if (FileInfo != NULL) {
if (FileInfo->FileSize > 0) {
// get the kernel file path
if (CustomPath != NULL) {
FreePool(CustomPath);
}
CustomPath = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
CustomPath.SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
}
// free the file info
FreePool(FileInfo);
@ -1755,10 +1727,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
if (FileInfo->FileSize > 0) {
// get the kernel file path
if ((PreviousTime.Year == 0) || (TimeCmp(&PreviousTime, &(FileInfo->ModificationTime)) < 0)) {
if (CustomPath != NULL) {
FreePool(CustomPath);
}
CustomPath = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
CustomPath.SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
PreviousTime = FileInfo->ModificationTime;
}
}
@ -1776,10 +1745,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
if (FileInfo->FileSize > 0) {
// get the kernel file path
if ((PreviousTime.Year == 0) || (TimeCmp(&PreviousTime, &(FileInfo->ModificationTime)) > 0)) {
if (CustomPath != NULL) {
FreePool(CustomPath);
}
CustomPath = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
CustomPath.SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
PreviousTime = FileInfo->ModificationTime;
}
}
@ -1796,14 +1762,11 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
if (FileInfo != NULL) {
if (FileInfo->FileSize > 0) {
// get the kernel file path
CHAR16 *NewPath = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
if ((CustomPath == NULL) || (StrCmp(CustomPath, NewPath) < 0)) {
if (CustomPath != NULL) {
FreePool(CustomPath);
}
XStringW NewPath = SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
if ( CustomPath > NewPath ) {
CustomPath = NewPath;
} else {
FreePool(NewPath);
}else{
CustomPath.setEmpty();
}
}
// free the file info
@ -1820,15 +1783,12 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
if (FileInfo->FileSize > 0) {
// get the kernel file path
// CHAR16 *NewPath = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
XStringW NewPath = LINUX_BOOT_PATH"\\"_XSW + FileInfo->FileName;
if ((CustomPath == NULL) || (StrCmp(CustomPath, NewPath.wc_str()) > 0)) {
if (CustomPath != NULL) {
FreePool(CustomPath);
}
CustomPath = EfiStrDuplicate(NewPath.wc_str());
} /*else {
FreePool(NewPath);
} */
XStringW NewPath = SWPrintf("%ls\\%ls", LINUX_BOOT_PATH"\\", FileInfo->FileName);
if ( CustomPath < NewPath ) {
CustomPath = NewPath;
}else{
CustomPath.setEmpty();
}
}
// free the file info
FreePool(FileInfo);
@ -1842,7 +1802,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
Custom->KernelScan = KERNEL_SCAN_ALL;
break;
}
} else if (!FileExists(Volume->RootDir, CustomPath)) {
} else if (!FileExists(Volume->RootDir, CustomPath.wc_str())) {
DBG("skipped because path does not exist\n");
continue;
}
@ -1897,18 +1857,18 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
continue;
}
// get the kernel file path
CustomPath = PoolPrint(L"%s\\%s", LINUX_BOOT_PATH, FileInfo->FileName);
CustomPath.SWPrintf("%ls\\%ls", LINUX_BOOT_PATH, FileInfo->FileName);
// free the file info
FreePool(FileInfo);
}
if (CustomPath == NULL) {
if (CustomPath.isEmpty()) {
DBG("skipped\n");
break;
}
// Check to make sure we should update custom options or not
if (FindCustomPath && OSFLAG_ISUNSET(Custom->Flags, OSFLAG_NODEFAULTARGS)) {
// Find the init ram image and select root
CustomOptions = LinuxKernelOptions(Iter->DirHandle, Basename(CustomPath) + LINUX_LOADER_PATH.length(), PartUUID, Custom->LoadOptions);
CustomOptions = LinuxKernelOptions(Iter->DirHandle, Basename(CustomPath.wc_str()) + LINUX_LOADER_PATH.length(), PartUUID, Custom->LoadOptions);
}
// Check to make sure that this entry is not hidden or disabled by another custom entry
if (!IsSubEntry) {
@ -1930,7 +1890,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
// Less precise volume match
if (Custom->Path != Ptr->Path) {
// Better path match
BetterMatch = ((Ptr->Path != NULL) && (StrCmp(CustomPath, Ptr->Path) == 0) &&
BetterMatch = ((Ptr->Path.notEmpty()) && CustomPath.equal(Ptr->Path) &&
((Custom->VolumeType == Ptr->VolumeType) ||
((1ull<<Volume->DiskKind) & Custom->VolumeType) != 0));
/* (Volume->DiskKind == DISK_KIND_OPTICAL && (Custom->VolumeType & VOLTYPE_OPTICAL)) ||
@ -1944,7 +1904,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
// More precise volume match
if (Custom->Path != Ptr->Path) {
// Better path match
BetterMatch = ((Ptr->Path != NULL) && (StrCmp(CustomPath, Ptr->Path) == 0) &&
BetterMatch = ((Ptr->Path.notEmpty()) && CustomPath.equal(Ptr->Path) &&
((Custom->VolumeType == Ptr->VolumeType) ||
((1ull<<Volume->DiskKind) & Custom->VolumeType) != 0));
/* (Volume->DiskKind == DISK_KIND_OPTICAL && (Custom->VolumeType & VOLTYPE_OPTICAL)) ||
@ -1966,7 +1926,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
// Duplicate volume match
} else if (Custom->Path != Ptr->Path) {
// Better path match
BetterMatch = ((Ptr->Path != NULL) && (StrCmp(CustomPath, Ptr->Path) == 0) &&
BetterMatch = ((Ptr->Path.notEmpty()) && CustomPath.equal(Ptr->Path) &&
((Custom->VolumeType == Ptr->VolumeType) ||
((1ull<<Volume->DiskKind) & Custom->VolumeType) != 0));
/* (Volume->DiskKind == DISK_KIND_OPTICAL && (Custom->VolumeType & VOLTYPE_OPTICAL)) ||
@ -1989,7 +1949,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
}
// Duplicate volume match
} else if (Custom->Path != Ptr->Path) {
if (Ptr->Path == NULL) {
if (Ptr->Path.isEmpty()) {
// Less precise path match
BetterMatch = ((Custom->VolumeType != Ptr->VolumeType) &&
((1ull<<Volume->DiskKind) & Custom->VolumeType) != 0);
@ -1997,8 +1957,8 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
(Volume->DiskKind == DISK_KIND_EXTERNAL && (Custom->VolumeType & VOLTYPE_EXTERNAL)) ||
(Volume->DiskKind == DISK_KIND_INTERNAL && (Custom->VolumeType & VOLTYPE_INTERNAL)) ||
(Volume->DiskKind == DISK_KIND_FIREWIRE && (Custom->VolumeType & VOLTYPE_FIREWIRE)))); */
} else if (StrCmp(CustomPath, Ptr->Path) == 0) {
if (Custom->Path == NULL) {
} else if (CustomPath.equal(Ptr->Path)) {
if (Custom->Path.isEmpty()) {
// More precise path and volume type match
BetterMatch = ((Custom->VolumeType == Ptr->VolumeType) ||
((1ull<<Volume->DiskKind) & Custom->VolumeType) != 0);
@ -2062,7 +2022,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
// REFIT_MENU_SCREEN *SubScreen = (__typeof__(SubScreen))AllocateZeroPool(sizeof(REFIT_MENU_SCREEN));
REFIT_MENU_SCREEN *SubScreen = new REFIT_MENU_SCREEN;
if (SubScreen) {
SubScreen->Title.SWPrintf("Boot Options for %ls on %ls", (Custom->Title.notEmpty()) ? Custom->Title.wc_str() : CustomPath, Entry->VolName);
SubScreen->Title.SWPrintf("Boot Options for %ls on %ls", (Custom->Title.notEmpty()) ? Custom->Title.wc_str() : CustomPath.wc_str(), Entry->VolName);
SubScreen->TitleImage = Entry->Image;
SubScreen->ID = Custom->Type + 20;
SubScreen->GetAnime();
@ -2078,7 +2038,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
if (!CustomSubEntry->Settings) {
CustomSubEntry->Settings = Custom->Settings;
}
AddCustomEntry(CustomSubIndex++, (CustomSubEntry->Path != NULL) ? CustomSubEntry->Path : CustomPath, CustomSubEntry, SubScreen);
AddCustomEntry(CustomSubIndex++, (CustomSubEntry->Path.notEmpty()) ? CustomSubEntry->Path : CustomPath, CustomSubEntry, SubScreen);
}
SubScreen->AddMenuEntry(&MenuEntryReturn, true);
Entry->SubScreen = SubScreen;
@ -2089,10 +2049,6 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
else
MainMenu.AddMenuEntry(Entry, true);
}
// cleanup custom
if (FindCustomPath) {
FreePool(CustomPath);
}
} while (FindCustomPath && (Custom->KernelScan == KERNEL_SCAN_ALL));
// Close the kernel boot directory
if (FindCustomPath) {
@ -2117,18 +2073,18 @@ VOID AddCustomEntries(VOID)
DbgHeader("AddCustomEntries");
// Traverse the custom entries
for (Custom = gSettings.CustomEntries; Custom; ++i, Custom = Custom->Next) {
if ((Custom->Path == NULL) && (Custom->Type != 0)) {
if ((Custom->Path.isEmpty()) && (Custom->Type != 0)) {
if (OSTYPE_IS_OSX(Custom->Type)) {
AddCustomEntry(i, MACOSX_LOADER_PATH, Custom, NULL);
} else if (OSTYPE_IS_OSX_RECOVERY(Custom->Type)) {
AddCustomEntry(i, L"\\com.apple.recovery.boot\\boot.efi", Custom, NULL);
AddCustomEntry(i, L"\\com.apple.recovery.boot\\boot.efi"_XSW, Custom, NULL);
} else if (OSTYPE_IS_OSX_INSTALLER(Custom->Type)) {
UINTN Index = 0;
while (Index < OSXInstallerPathsCount) {
AddCustomEntry(i, OSXInstallerPaths[Index++], Custom, NULL);
}
} else if (OSTYPE_IS_WINDOWS(Custom->Type)) {
AddCustomEntry(i, L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi", Custom, NULL);
AddCustomEntry(i, L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi"_XSW, Custom, NULL);
} else if (OSTYPE_IS_LINUX(Custom->Type)) {
UINTN Index;
#if defined(ANDX86)
@ -2142,7 +2098,7 @@ VOID AddCustomEntries(VOID)
AddCustomEntry(i, LinuxEntryData[Index++].Path, Custom, NULL);
}
} else if (Custom->Type == OSTYPE_LINEFI) {
AddCustomEntry(i, NULL, Custom, NULL);
AddCustomEntry(i, NullXStringW, Custom, NULL);
} else {
AddCustomEntry(i, BOOT_LOADER_PATH, Custom, NULL);
}

View File

@ -8,6 +8,8 @@
#ifndef LOADER_H_
#define LOADER_H_
#include "../cpp_foundation/XString.h"
//#define DUMP_KERNEL_KEXT_PATCHES 1
// Kernel scan states
@ -21,7 +23,8 @@
#define KERNEL_SCAN_NONE (100)
UINT8 GetOSTypeFromPath (IN CONST CHAR16 *Path);
//UINT8 GetOSTypeFromPath (IN CONST CHAR16 *Path);
UINT8 GetOSTypeFromPath(IN CONST XStringW& Path);
#ifdef DUMP_KERNEL_KEXT_PATCHES
// Utils functions

View File

@ -43,10 +43,10 @@
//
// Clover File location to boot from on removable media devices
//
#define CLOVER_MEDIA_FILE_NAME_IA32 L"\\EFI\\CLOVER\\CLOVERIA32.EFI"
#define CLOVER_MEDIA_FILE_NAME_IA64 L"\\EFI\\CLOVER\\CLOVERIA64.EFI"
#define CLOVER_MEDIA_FILE_NAME_X64 L"\\EFI\\CLOVER\\CLOVERX64.EFI"
#define CLOVER_MEDIA_FILE_NAME_ARM L"\\EFI\\CLOVER\\CLOVERARM.EFI"
#define CLOVER_MEDIA_FILE_NAME_IA32 "\\EFI\\CLOVER\\CLOVERIA32.EFI"_XSW
#define CLOVER_MEDIA_FILE_NAME_IA64 "\\EFI\\CLOVER\\CLOVERIA64.EFI"_XSW
#define CLOVER_MEDIA_FILE_NAME_X64 "\\EFI\\CLOVER\\CLOVERX64.EFI"_XSW
#define CLOVER_MEDIA_FILE_NAME_ARM "\\EFI\\CLOVER\\CLOVERARM.EFI"_XSW
#if defined (MDE_CPU_IA32)
#define CLOVER_MEDIA_FILE_NAME CLOVER_MEDIA_FILE_NAME_IA32
@ -73,14 +73,14 @@
#define DBG(...) DebugLog(DEBUG_SCAN_TOOL, __VA_ARGS__)
#endif
STATIC BOOLEAN AddToolEntry(IN CONST CHAR16 *LoaderPath, IN CONST CHAR16 *FullTitle, IN CONST CHAR16 *LoaderTitle,
STATIC BOOLEAN AddToolEntry(IN CONST XStringW& LoaderPath, IN CONST CHAR16 *FullTitle, IN CONST CHAR16 *LoaderTitle,
IN REFIT_VOLUME *Volume, const XImage& Image,
IN CHAR16 ShortcutLetter, IN CONST XStringArray& Options)
{
REFIT_MENU_ENTRY_LOADER_TOOL *Entry;
// Check the loader exists
if ((LoaderPath == NULL) || (Volume == NULL) || (Volume->RootDir == NULL) ||
!FileExists(Volume->RootDir, LoaderPath)) {
if ((LoaderPath.isEmpty()) || (Volume == NULL) || (Volume->RootDir == NULL) ||
!FileExists(Volume->RootDir, LoaderPath.wc_str())) {
return FALSE;
}
// Allocate the entry
@ -100,8 +100,8 @@ STATIC BOOLEAN AddToolEntry(IN CONST CHAR16 *LoaderPath, IN CONST CHAR16 *FullTi
Entry->ShortcutLetter = ShortcutLetter;
Entry->Image = Image;
// Entry->ImageHover = ImageHover;
Entry->LoaderPath = EfiStrDuplicate(LoaderPath);
Entry->DevicePath = FileDevicePath(Volume->DeviceHandle, Entry->LoaderPath);
Entry->LoaderPath = LoaderPath;
Entry->DevicePath = FileDevicePath(Volume->DeviceHandle, Entry->LoaderPath.wc_str());
Entry->DevicePathString = FileDevicePathToStr(Entry->DevicePath);
Entry->LoadOptions = Options;
//actions
@ -109,12 +109,12 @@ STATIC BOOLEAN AddToolEntry(IN CONST CHAR16 *LoaderPath, IN CONST CHAR16 *FullTi
Entry->AtDoubleClick = ActionEnter;
Entry->AtRightClick = ActionHelp;
DBG("found tool %ls\n", LoaderPath);
DBG("found tool %ls\n", LoaderPath.s());
MainMenu.AddMenuEntry(Entry, true);
return TRUE;
}
STATIC VOID AddCloverEntry(IN CONST CHAR16 *LoaderPath, IN CONST CHAR16 *LoaderTitle, IN REFIT_VOLUME *Volume)
STATIC VOID AddCloverEntry(IN CONST XStringW& LoaderPath, IN CONST CHAR16 *LoaderTitle, IN REFIT_VOLUME *Volume)
{
REFIT_MENU_ENTRY_CLOVER *Entry;
REFIT_MENU_ENTRY_CLOVER *SubEntry;
@ -130,9 +130,9 @@ STATIC VOID AddCloverEntry(IN CONST CHAR16 *LoaderPath, IN CONST CHAR16 *LoaderT
Entry->ShortcutLetter = 'C';
Entry->Image = ThemeX.GetIcon(BUILTIN_ICON_FUNC_CLOVER);
Entry->Volume = Volume;
Entry->LoaderPath = EfiStrDuplicate(LoaderPath);
Entry->LoaderPath = LoaderPath;
Entry->VolName = Volume->VolName;
Entry->DevicePath = FileDevicePath(Volume->DeviceHandle, Entry->LoaderPath);
Entry->DevicePath = FileDevicePath(Volume->DeviceHandle, Entry->LoaderPath.wc_str());
Entry->DevicePathString = FileDevicePathToStr(Entry->DevicePath);
Entry->Flags = 0;
Entry->LoadOptions.setEmpty();
@ -199,8 +199,8 @@ VOID ScanTool(VOID)
// DBG("Scanning for tools...\n");
if (!(ThemeX.HideUIFlags & HIDEUI_FLAG_SHELL)) {
if (!AddToolEntry(L"\\EFI\\CLOVER\\tools\\Shell64U.efi", NULL, L"UEFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NullXStringArray)) {
AddToolEntry(L"\\EFI\\CLOVER\\tools\\Shell64.efi", NULL, L"EFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NullXStringArray);
if (!AddToolEntry(L"\\EFI\\CLOVER\\tools\\Shell64U.efi"_XSW, NULL, L"UEFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NullXStringArray)) {
AddToolEntry("\\EFI\\CLOVER\\tools\\Shell64.efi"_XSW, NULL, L"EFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NullXStringArray);
}
}
@ -222,7 +222,7 @@ VOID ScanTool(VOID)
DBG(" Deleted /EFI label\n");
}
if (FileExists(Volume->RootDir, CLOVER_MEDIA_FILE_NAME)) {
if (FileExists(Volume->RootDir, CLOVER_MEDIA_FILE_NAME.wc_str())) {
DBG(" Found Clover\n");
// Volume->BootType = BOOTING_BY_EFI;
AddCloverEntry(CLOVER_MEDIA_FILE_NAME, L"Clover Boot Options", Volume);
@ -305,7 +305,7 @@ VOID AddCustomTool(VOID)
}
}
// Check the tool exists on the volume
if (!FileExists(Volume->RootDir, Custom->Path)) {
if (!FileExists(Volume->RootDir, Custom->Path.wc_str())) {
DBG("skipped because path does not exist\n");
continue;
}

View File

@ -53,7 +53,7 @@ REFIT_MENU_ENTRY_CLOVER* REFIT_MENU_ENTRY_CLOVER::getPartiallyDuplicatedEntry()
DuplicateEntry->Volume = Volume;
DuplicateEntry->DevicePathString= EfiStrDuplicate(DevicePathString);
DuplicateEntry->LoadOptions = LoadOptions;
DuplicateEntry->LoaderPath = EfiStrDuplicate(LoaderPath);
DuplicateEntry->LoaderPath = LoaderPath;
DuplicateEntry->VolName = EfiStrDuplicate(VolName);
DuplicateEntry->DevicePath = DevicePath;
DuplicateEntry->Flags = Flags;
@ -68,7 +68,7 @@ LOADER_ENTRY* LOADER_ENTRY::getPartiallyDuplicatedEntry() const
DuplicateEntry->Volume = Volume;
DuplicateEntry->DevicePathString= EfiStrDuplicate(DevicePathString);
DuplicateEntry->LoadOptions = LoadOptions;
DuplicateEntry->LoaderPath = EfiStrDuplicate(LoaderPath);
DuplicateEntry->LoaderPath = LoaderPath;
DuplicateEntry->VolName = EfiStrDuplicate(VolName);
DuplicateEntry->DevicePath = DevicePath;
DuplicateEntry->Flags = Flags;

View File

@ -261,12 +261,12 @@ class REFIT_ABSTRACT_MENU_ENTRY
public:
CONST CHAR16 *DevicePathString;
XStringArray LoadOptions; //moved here for compatibility with legacy
CONST CHAR16 *LoaderPath;
XStringW LoaderPath;
XImage DriveImage;
XImage BadgeImage;
REFIT_MENU_ITEM_ABSTRACT_ENTRY_LOADER()
: REFIT_ABSTRACT_MENU_ENTRY(), DevicePathString(0), LoaderPath(0), DriveImage(), BadgeImage()
: REFIT_ABSTRACT_MENU_ENTRY(), DevicePathString(0), DriveImage(), BadgeImage()
{}
virtual XImage* getDriveImage() { return &DriveImage; };
virtual XImage* getBadgeImage() { return &BadgeImage; };

View File

@ -1354,6 +1354,11 @@ BOOLEAN FileExists(IN CONST EFI_FILE *Root, IN CONST CHAR16 *RelativePath)
return FALSE;
}
BOOLEAN FileExists(IN CONST EFI_FILE *Root, IN CONST XStringW& RelativePath)
{
return FileExists(Root, RelativePath.wc_str());
}
BOOLEAN DeleteFile(IN EFI_FILE *Root, IN CONST CHAR16 *RelativePath)
{
EFI_STATUS Status;

View File

@ -330,6 +330,7 @@ VOID ScanVolumes(VOID);
REFIT_VOLUME *FindVolumeByName(IN CHAR16 *VolName);
BOOLEAN FileExists(IN CONST EFI_FILE *BaseDir, IN CONST CHAR16 *RelativePath);
BOOLEAN FileExists(IN CONST EFI_FILE *BaseDir, IN CONST XStringW& RelativePath);
BOOLEAN DeleteFile(IN EFI_FILE *Root, IN CONST CHAR16 *RelativePath);

View File

@ -140,7 +140,7 @@ extern EFI_AUDIO_IO_PROTOCOL *AudioIo;
//#endif
static EFI_STATUS LoadEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
IN CONST CHAR16 *ImageTitle,
IN CONST XStringW& ImageTitle,
OUT UINTN *ErrorInStep,
OUT EFI_HANDLE *NewImageHandle)
{
@ -149,7 +149,7 @@ static EFI_STATUS LoadEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
UINTN DevicePathIndex;
CHAR16 ErrorInfo[256];
DBG("Loading %ls", ImageTitle);
DBG("Loading %ls", ImageTitle.wc_str());
if (ErrorInStep != NULL) {
*ErrorInStep = 0;
}
@ -165,7 +165,7 @@ static EFI_STATUS LoadEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
if (ReturnStatus != EFI_NOT_FOUND)
break;
}
snwprintf(ErrorInfo, 512, "while loading %ls", ImageTitle);
snwprintf(ErrorInfo, 512, "while loading %ls", ImageTitle.wc_str());
if (CheckError(Status, ErrorInfo)) {
if (ErrorInStep != NULL)
*ErrorInStep = 1;
@ -180,7 +180,7 @@ static EFI_STATUS LoadEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
#ifdef JIEF_DEBUG
EFI_LOADED_IMAGE_PROTOCOL* loadedBootImage = NULL;
if (!EFI_ERROR(Status = gBS->HandleProtocol(ChildImageHandle, &gEfiLoadedImageProtocolGuid, (void**)(&loadedBootImage)))) {
DBG("%S : Image base = 0x%llx", ImageTitle, (uintptr_t)loadedBootImage->ImageBase); // Jief : Do not change this, it's used by grep to feed the debugger
DBG("%S : Image base = 0x%llx", ImageTitle.wc_str(), (uintptr_t)loadedBootImage->ImageBase); // Jief : Do not change this, it's used by grep to feed the debugger
}else{
DBG("Can't get loaded image protocol");
}
@ -198,7 +198,7 @@ bailout:
static EFI_STATUS StartEFILoadedImage(IN EFI_HANDLE ChildImageHandle,
IN CONST XStringArray& LoadOptions, IN CONST CHAR16 *LoadOptionsPrefix,
IN CONST CHAR16 *ImageTitle,
IN CONST XStringW& ImageTitle,
OUT UINTN *ErrorInStep)
{
EFI_STATUS Status, ReturnStatus;
@ -237,7 +237,7 @@ static EFI_STATUS StartEFILoadedImage(IN EFI_HANDLE ChildImageHandle,
ChildLoadedImage->LoadOptionsSize = (UINT32)loadOptionsW.sizeInBytes() + sizeof(wchar_t);
ChildLoadedImage->LoadOptions = loadOptionsW.wc_str(); //will it be deleted after the procedure exit? Yes, if we don't copy loadOptionsW, so it'll be freed at the end of method
//((UINT32)StrLen(LoadOptions) + 1) * sizeof(CHAR16);
DBG("start image '%ls'\n", ImageTitle);
DBG("start image '%ls'\n", ImageTitle.s());
DBG("Using load options '%ls'\n", (CHAR16*)ChildLoadedImage->LoadOptions);
}
@ -263,8 +263,8 @@ static EFI_STATUS StartEFILoadedImage(IN EFI_HANDLE ChildImageHandle,
//PauseForKey(L"Returned from StartImage\n");
// control returns here when the child image calls Exit()
if (ImageTitle) {
snwprintf(ErrorInfo, 512, "returned from %ls", ImageTitle);
if (ImageTitle.notEmpty()) {
snwprintf(ErrorInfo, 512, "returned from %ls", ImageTitle.s());
}
if (CheckError(Status, ErrorInfo)) {
@ -284,7 +284,7 @@ bailout:
static EFI_STATUS LoadEFIImage(IN EFI_DEVICE_PATH *DevicePath,
IN CONST CHAR16 *ImageTitle,
IN CONST XStringW& ImageTitle,
OUT UINTN *ErrorInStep,
OUT EFI_HANDLE *NewImageHandle)
{
@ -310,7 +310,7 @@ static EFI_STATUS LoadEFIImage(IN EFI_DEVICE_PATH *DevicePath,
static EFI_STATUS StartEFIImage(IN EFI_DEVICE_PATH *DevicePath,
IN CONST XStringArray& LoadOptions, IN CONST CHAR16 *LoadOptionsPrefix,
IN CONST CHAR16 *ImageTitle,
IN CONST XStringW& ImageTitle,
OUT UINTN *ErrorInStep,
OUT EFI_HANDLE *NewImageHandle)
{
@ -654,7 +654,7 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry)
//DumpKernelAndKextPatches(Entry->KernelAndKextPatches);
DBG("start loader\n");
// Load image into memory (will be started later)
Status = LoadEFIImage(Entry->DevicePath, Basename(Entry->LoaderPath), NULL, &ImageHandle);
Status = LoadEFIImage(Entry->DevicePath, Entry->LoaderPath.basename(), NULL, &ImageHandle);
if (EFI_ERROR(Status)) {
DBG("Image is not loaded, status=%s\n", strerror(Status));
return; // no reason to continue if loading image failed
@ -889,7 +889,7 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry)
}
if (gSettings.LastBootedVolume) {
SetStartupDiskVolume(Entry->Volume, Entry->LoaderType == OSTYPE_OSX ? NULL : Entry->LoaderPath);
SetStartupDiskVolume(Entry->Volume, Entry->LoaderType == OSTYPE_OSX ? NullXStringW : Entry->LoaderPath);
} else if (gSettings.DefaultVolume != NULL) {
// DefaultVolume specified in Config.plist or in Boot Option
// we'll remove macOS Startup Disk vars which may be present if it is used
@ -977,7 +977,7 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry)
// Basename(Entry->LoaderPath), Basename(Entry->LoaderPath), NULL, NULL);
// DBG("StartEFILoadedImage\n");
StartEFILoadedImage(ImageHandle, Entry->LoadOptions, Basename(Entry->LoaderPath), Basename(Entry->LoaderPath), NULL);
StartEFILoadedImage(ImageHandle, Entry->LoadOptions, Basename(Entry->LoaderPath.wc_str()), Entry->LoaderPath.basename(), NULL);
// Unlock boot screen
if (EFI_ERROR(Status = UnlockBootScreen())) {
DBG("Failed to unlock custom boot screen: %s!\n", strerror(Status));
@ -1007,7 +1007,7 @@ static VOID StartLegacy(IN LEGACY_ENTRY *Entry)
}
if (gSettings.LastBootedVolume) {
SetStartupDiskVolume(Entry->Volume, NULL);
SetStartupDiskVolume(Entry->Volume, NullXStringW);
} else if (gSettings.DefaultVolume != NULL) {
// DefaultVolume specified in Config.plist:
// we'll remove macOS Startup Disk vars which may be present if it is used
@ -1057,11 +1057,11 @@ static VOID StartLegacy(IN LEGACY_ENTRY *Entry)
static VOID StartTool(IN REFIT_MENU_ENTRY_LOADER_TOOL *Entry)
{
DBG("Start Tool: %ls\n", Entry->LoaderPath);
DBG("Start Tool: %ls\n", Entry->LoaderPath.wc_str());
egClearScreen(&MenuBackgroundPixel);
// assumes "Start <title>" as assigned below
BeginExternalScreen(OSFLAG_ISSET(Entry->Flags, OSFLAG_USEGRAPHICS)/*, &Entry->Title[6]*/); // Shouldn't we check that length of Title is at least 6 ?
StartEFIImage(Entry->DevicePath, Entry->LoadOptions, Basename(Entry->LoaderPath), Basename(Entry->LoaderPath), NULL, NULL);
StartEFIImage(Entry->DevicePath, Entry->LoadOptions, Basename(Entry->LoaderPath.wc_str()), Entry->LoaderPath.basename(), NULL, NULL);
FinishExternalScreen();
//ReinitSelfLib();
}
@ -1150,7 +1150,7 @@ static VOID ScanDriverDir(IN CONST CHAR16 *Path, OUT EFI_HANDLE **DriversToConne
snwprintf(FileName, 512, "%ls\\%ls", Path, DirEntry->FileName);
Status = StartEFIImage(FileDevicePath(SelfLoadedImage->DeviceHandle, FileName),
NullXStringArray, DirEntry->FileName, DirEntry->FileName, NULL, &DriverHandle);
NullXStringArray, DirEntry->FileName, XStringW().takeValueFrom(DirEntry->FileName), NULL, &DriverHandle);
if (EFI_ERROR(Status)) {
continue;
}
@ -1607,7 +1607,7 @@ INTN FindDefaultEntry(VOID)
}
// we alreday know that Entry.isLoader
if (SearchForLoader && (/*Entry.Tag != TAG_LOADER ||*/ !StriStr(Entry.LoaderPath, gSettings.DefaultLoader))) {
if (SearchForLoader && (/*Entry.Tag != TAG_LOADER ||*/ !Entry.LoaderPath.containsIC(gSettings.DefaultLoader))) {
continue;
}
@ -1841,7 +1841,7 @@ VOID SystemVersionInit(VOID)
//Fill Plists
for (i = 0; i < APFSUUIDBankCounter; i++) {
//Store UUID from bank
CHAR16 *CurrentUUID = GuidLEToStr((EFI_GUID *)((UINT8 *)APFSUUIDBank+i*0x10));
XStringW CurrentUUID = GuidLEToStr((EFI_GUID *)((UINT8 *)APFSUUIDBank+i*0x10));
//Init temp string with system/install/recovery APFS path
CHAR16 *TmpSysPlistPath = (__typeof__(TmpSysPlistPath))AllocateZeroPool(86*sizeof(CHAR16));
CHAR16 *TmpServerPlistPath = (__typeof__(TmpServerPlistPath))AllocateZeroPool(86*sizeof(CHAR16));
@ -1851,10 +1851,10 @@ VOID SystemVersionInit(VOID)
StrnCpy(TmpServerPlistPath, APFSServerPlistPath, 85);
StrnCpy(TmpInsPlistPath, APFSInstallPlistPath, 78);
StrnCpy(TmpRecPlistPath, APFSRecPlistPath, 57);
StrnCpy(TmpSysPlistPath+1, CurrentUUID, 36);
StrnCpy(TmpServerPlistPath+1, CurrentUUID, 36);
StrnCpy(TmpInsPlistPath+1, CurrentUUID, 36);
StrnCpy(TmpRecPlistPath+1, CurrentUUID, 36);
StrnCpy(TmpSysPlistPath+1, CurrentUUID.wc_str(), 36);
StrnCpy(TmpServerPlistPath+1, CurrentUUID.wc_str(), 36);
StrnCpy(TmpInsPlistPath+1, CurrentUUID.wc_str(), 36);
StrnCpy(TmpRecPlistPath+1, CurrentUUID.wc_str(), 36);
//Fill SystemPlists/InstallPlists/RecoveryPlists arrays
SystemPlists[SysIter] = TmpSysPlistPath;
SystemPlists[SysIter+1] = TmpServerPlistPath;
@ -2748,8 +2748,8 @@ RefitMain (IN EFI_HANDLE ImageHandle,
}
NameSize = StrSize(VolName); //can't use StrSize with NULL! Stupid UEFI!!!
Name2Size = 0;
if (Entry->LoaderPath != NULL) {
LoaderName = Basename(Entry->LoaderPath);
if (Entry->LoaderPath.notEmpty()) {
LoaderName = Basename(Entry->LoaderPath.wc_str());
} else {
LoaderName = NULL; //legacy boot
}