Update Windows OSD file functions to preferred more modern versions. All still available on XP and later.

This commit is contained in:
Brad Hughes 2016-03-18 13:37:49 -04:00
parent 4e214fd08d
commit 603d5509df
2 changed files with 11 additions and 10 deletions

View File

@ -57,8 +57,8 @@ public:
virtual error read(void *buffer, std::uint64_t offset, std::uint32_t length, std::uint32_t &actual) override virtual error read(void *buffer, std::uint64_t offset, std::uint32_t length, std::uint32_t &actual) override
{ {
// attempt to set the file pointer // attempt to set the file pointer
LONG upper(std::uint32_t(offset >> 32)); LARGE_INTEGER largeOffset = { offset };
DWORD result(SetFilePointer(m_handle, std::uint32_t(offset), &upper, FILE_BEGIN)); DWORD result(SetFilePointerEx(m_handle, largeOffset, NULL, FILE_BEGIN));
if (INVALID_SET_FILE_POINTER == result) if (INVALID_SET_FILE_POINTER == result)
{ {
DWORD const err(GetLastError()); DWORD const err(GetLastError());
@ -77,8 +77,8 @@ public:
virtual error write(void const *buffer, std::uint64_t offset, std::uint32_t length, std::uint32_t &actual) override virtual error write(void const *buffer, std::uint64_t offset, std::uint32_t length, std::uint32_t &actual) override
{ {
// attempt to set the file pointer // attempt to set the file pointer
LONG upper(std::uint32_t(offset >> 32)); LARGE_INTEGER largeOffset = { offset };
DWORD result(SetFilePointer(m_handle, std::uint32_t(offset), &upper, FILE_BEGIN)); DWORD result(SetFilePointerEx(m_handle, largeOffset, NULL, FILE_BEGIN));
if (INVALID_SET_FILE_POINTER == result) if (INVALID_SET_FILE_POINTER == result)
{ {
DWORD const err(GetLastError()); DWORD const err(GetLastError());
@ -97,8 +97,8 @@ public:
virtual error truncate(std::uint64_t offset) override virtual error truncate(std::uint64_t offset) override
{ {
// attempt to set the file pointer // attempt to set the file pointer
LONG upper(std::uint32_t(offset >> 32)); LARGE_INTEGER largeOffset = { offset };
DWORD const result(SetFilePointer(m_handle, std::uint32_t(offset), &upper, FILE_BEGIN)); DWORD const result(SetFilePointerEx(m_handle, largeOffset, NULL, FILE_BEGIN));
if (INVALID_SET_FILE_POINTER == result) if (INVALID_SET_FILE_POINTER == result)
{ {
DWORD const err(GetLastError()); DWORD const err(GetLastError());
@ -163,7 +163,8 @@ DWORD create_path_recursive(TCHAR *path)
} }
// if the path already exists, we're done // if the path already exists, we're done
if (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES) WIN32_FILE_ATTRIBUTE_DATA fileinfo;
if (GetFileAttributesEx(path, GetFileExInfoStandard, &fileinfo) != INVALID_FILE_ATTRIBUTES)
return NO_ERROR; return NO_ERROR;
else if (!CreateDirectory(path, NULL)) else if (!CreateDirectory(path, NULL))
return GetLastError(); return GetLastError();
@ -376,12 +377,12 @@ osd_directory_entry *osd_stat(const std::string &path)
{ {
// need to do special logic for root directories // need to do special logic for root directories
memset(&find_data, 0, sizeof(find_data)); memset(&find_data, 0, sizeof(find_data));
find_data.dwFileAttributes = GetFileAttributes(t_path); GetFileAttributesEx(t_path, GetFileExInfoStandard, &find_data.dwFileAttributes);
} }
else else
{ {
// attempt to find the first file // attempt to find the first file
find = FindFirstFile(t_path, &find_data); find = FindFirstFileEx(t_path, FindExInfoStandard, &find_data, FindExSearchNameMatch, NULL, 0);
if (find == INVALID_HANDLE_VALUE) if (find == INVALID_HANDLE_VALUE)
goto done; goto done;
} }

View File

@ -72,7 +72,7 @@ osd_directory *osd_opendir(const char *dirname)
_sntprintf(dirfilter, dirfilter_size, TEXT("%s\\*.*"), t_dirname); _sntprintf(dirfilter, dirfilter_size, TEXT("%s\\*.*"), t_dirname);
// attempt to find the first file // attempt to find the first file
dir->find = FindFirstFile(dirfilter, &dir->data); dir->find = FindFirstFileEx(dirfilter, FindExInfoStandard, &dir->data, FindExSearchNameMatch, nullptr, 0);
error: error:
// cleanup // cleanup