mirror of https://github.com/AxioDL/metaforce.git
hecl/hecl: Tidy up GetSystemLocations()
Converts a define into a constexpr variable, also joins declarations with assignments where applicable.
This commit is contained in:
parent
bc7a6563cf
commit
0a6edbad2c
|
@ -442,8 +442,6 @@ hecl::DirectoryEnumerator::DirectoryEnumerator(SystemStringView path, Mode mode,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FILE_MAXDIR 768
|
|
||||||
|
|
||||||
static std::pair<hecl::SystemString, std::string> NameFromPath(hecl::SystemStringView path) {
|
static std::pair<hecl::SystemString, std::string> NameFromPath(hecl::SystemStringView path) {
|
||||||
hecl::SystemUTF8Conv utf8(path);
|
hecl::SystemUTF8Conv utf8(path);
|
||||||
if (utf8.str().size() == 1 && utf8.str()[0] == '/')
|
if (utf8.str().size() == 1 && utf8.str()[0] == '/')
|
||||||
|
@ -461,46 +459,44 @@ std::vector<std::pair<hecl::SystemString, std::string>> GetSystemLocations() {
|
||||||
#if !WINDOWS_STORE
|
#if !WINDOWS_STORE
|
||||||
/* Add the drive names to the listing (as queried by blender) */
|
/* Add the drive names to the listing (as queried by blender) */
|
||||||
{
|
{
|
||||||
|
constexpr uint32_t FILE_MAXDIR = 768;
|
||||||
wchar_t wline[FILE_MAXDIR];
|
wchar_t wline[FILE_MAXDIR];
|
||||||
wchar_t* name;
|
const uint32_t tmp = GetLogicalDrives();
|
||||||
__int64 tmp;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
tmp = GetLogicalDrives();
|
for (uint32_t i = 0; i < 26; i++) {
|
||||||
|
|
||||||
for (i = 0; i < 26; i++) {
|
|
||||||
if ((tmp >> i) & 1) {
|
if ((tmp >> i) & 1) {
|
||||||
wline[0] = L'A' + i;
|
wline[0] = L'A' + i;
|
||||||
wline[1] = L':';
|
wline[1] = L':';
|
||||||
wline[2] = L'/';
|
wline[2] = L'/';
|
||||||
wline[3] = L'\0';
|
wline[3] = L'\0';
|
||||||
name = nullptr;
|
wchar_t* name = nullptr;
|
||||||
|
|
||||||
/* Flee from horrible win querying hover floppy drives! */
|
/* Flee from horrible win querying hover floppy drives! */
|
||||||
if (i > 1) {
|
if (i > 1) {
|
||||||
/* Try to get volume label as well... */
|
/* Try to get volume label as well... */
|
||||||
if (GetVolumeInformationW(wline, wline + 4, FILE_MAXDIR - 4, nullptr, nullptr, nullptr, nullptr, 0)) {
|
if (GetVolumeInformationW(wline, wline + 4, FILE_MAXDIR - 4, nullptr, nullptr, nullptr, nullptr, 0)) {
|
||||||
size_t labelLen = wcslen(wline + 4);
|
const size_t labelLen = std::wcslen(wline + 4);
|
||||||
_snwprintf(wline + 4 + labelLen, FILE_MAXDIR - 4 - labelLen, L" (%.2s)", wline);
|
_snwprintf(wline + 4 + labelLen, FILE_MAXDIR - 4 - labelLen, L" (%.2s)", wline);
|
||||||
name = wline + 4;
|
name = wline + 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wline[2] = L'\0';
|
wline[2] = L'\0';
|
||||||
if (name)
|
if (name == nullptr) {
|
||||||
ret.emplace_back(wline, hecl::WideToUTF8(name));
|
|
||||||
else
|
|
||||||
ret.push_back(NameFromPath(wline));
|
ret.push_back(NameFromPath(wline));
|
||||||
|
} else {
|
||||||
|
ret.emplace_back(wline, hecl::WideToUTF8(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adding Desktop and My Documents */
|
/* Adding Desktop and My Documents */
|
||||||
SystemString wpath;
|
SystemString wpath;
|
||||||
SHGetSpecialFolderPathW(0, wline, CSIDL_PERSONAL, 0);
|
SHGetSpecialFolderPathW(nullptr, wline, CSIDL_PERSONAL, 0);
|
||||||
wpath.assign(wline);
|
wpath.assign(wline);
|
||||||
SanitizePath(wpath);
|
SanitizePath(wpath);
|
||||||
ret.push_back(NameFromPath(wpath));
|
ret.push_back(NameFromPath(wpath));
|
||||||
SHGetSpecialFolderPathW(0, wline, CSIDL_DESKTOPDIRECTORY, 0);
|
SHGetSpecialFolderPathW(nullptr, wline, CSIDL_DESKTOPDIRECTORY, 0);
|
||||||
wpath.assign(wline);
|
wpath.assign(wline);
|
||||||
SanitizePath(wpath);
|
SanitizePath(wpath);
|
||||||
ret.push_back(NameFromPath(wpath));
|
ret.push_back(NameFromPath(wpath));
|
||||||
|
@ -524,18 +520,20 @@ std::vector<std::pair<hecl::SystemString, std::string>> GetSystemLocations() {
|
||||||
/*https://developer.apple.com/library/mac/#documentation/CoreFOundation/Reference/CFURLRef/Reference/reference.html*/
|
/*https://developer.apple.com/library/mac/#documentation/CoreFOundation/Reference/CFURLRef/Reference/reference.html*/
|
||||||
/* we get all volumes sorted including network and do not relay on user-defined finder visibility, less confusing */
|
/* we get all volumes sorted including network and do not relay on user-defined finder visibility, less confusing */
|
||||||
|
|
||||||
CFURLRef cfURL = NULL;
|
CFURLRef cfURL = nullptr;
|
||||||
CFURLEnumeratorResult result = kCFURLEnumeratorSuccess;
|
CFURLEnumeratorResult result = kCFURLEnumeratorSuccess;
|
||||||
CFURLEnumeratorRef volEnum = CFURLEnumeratorCreateForMountedVolumes(NULL, kCFURLEnumeratorSkipInvisibles, NULL);
|
CFURLEnumeratorRef volEnum =
|
||||||
|
CFURLEnumeratorCreateForMountedVolumes(nullptr, kCFURLEnumeratorSkipInvisibles, nullptr);
|
||||||
|
|
||||||
while (result != kCFURLEnumeratorEnd) {
|
while (result != kCFURLEnumeratorEnd) {
|
||||||
char defPath[1024];
|
char defPath[1024];
|
||||||
|
|
||||||
result = CFURLEnumeratorGetNextURL(volEnum, &cfURL, NULL);
|
result = CFURLEnumeratorGetNextURL(volEnum, &cfURL, nullptr);
|
||||||
if (result != kCFURLEnumeratorSuccess)
|
if (result != kCFURLEnumeratorSuccess) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
CFURLGetFileSystemRepresentation(cfURL, false, (UInt8*)defPath, 1024);
|
CFURLGetFileSystemRepresentation(cfURL, false, reinterpret_cast<UInt8*>(defPath), std::size(defPath));
|
||||||
ret.push_back(NameFromPath(defPath));
|
ret.push_back(NameFromPath(defPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -593,13 +591,10 @@ std::wstring Char16ToWide(std::u16string_view src) { return std::wstring(src.beg
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
int RecursiveMakeDir(const SystemChar* dir) {
|
int RecursiveMakeDir(const SystemChar* dir) {
|
||||||
SystemChar tmp[1024];
|
SystemChar tmp[1024];
|
||||||
SystemChar* p = nullptr;
|
|
||||||
Sstat sb;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
/* copy path */
|
/* copy path */
|
||||||
wcsncpy(tmp, dir, 1024);
|
std::wcsncpy(tmp, dir, 1024);
|
||||||
len = wcslen(tmp);
|
const size_t len = std::wcslen(tmp);
|
||||||
if (len >= 1024) {
|
if (len >= 1024) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -610,6 +605,8 @@ int RecursiveMakeDir(const SystemChar* dir) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* recursive mkdir */
|
/* recursive mkdir */
|
||||||
|
SystemChar* p = nullptr;
|
||||||
|
Sstat sb;
|
||||||
for (p = tmp + 1; *p; p++) {
|
for (p = tmp + 1; *p; p++) {
|
||||||
if (*p == '/' || *p == '\\') {
|
if (*p == '/' || *p == '\\') {
|
||||||
*p = 0;
|
*p = 0;
|
||||||
|
@ -641,13 +638,10 @@ int RecursiveMakeDir(const SystemChar* dir) {
|
||||||
#else
|
#else
|
||||||
int RecursiveMakeDir(const SystemChar* dir) {
|
int RecursiveMakeDir(const SystemChar* dir) {
|
||||||
SystemChar tmp[1024];
|
SystemChar tmp[1024];
|
||||||
SystemChar* p = nullptr;
|
|
||||||
Sstat sb;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
/* copy path */
|
/* copy path */
|
||||||
strncpy(tmp, dir, 1024);
|
std::strncpy(tmp, dir, 1024);
|
||||||
len = strlen(tmp);
|
const size_t len = std::strlen(tmp);
|
||||||
if (len >= 1024) {
|
if (len >= 1024) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -658,6 +652,8 @@ int RecursiveMakeDir(const SystemChar* dir) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* recursive mkdir */
|
/* recursive mkdir */
|
||||||
|
SystemChar* p = nullptr;
|
||||||
|
Sstat sb;
|
||||||
for (p = tmp + 1; *p; p++) {
|
for (p = tmp + 1; *p; p++) {
|
||||||
if (*p == '/') {
|
if (*p == '/') {
|
||||||
*p = 0;
|
*p = 0;
|
||||||
|
|
Loading…
Reference in New Issue