diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/chunks_download_strategy.cpp | 2 | ||||
-rw-r--r-- | platform/platform_tests/platform_test.cpp | 6 | ||||
-rw-r--r-- | platform/platform_win.cpp | 33 |
3 files changed, 40 insertions, 1 deletions
diff --git a/platform/chunks_download_strategy.cpp b/platform/chunks_download_strategy.cpp index 9c6be13b27..de4b66e80c 100644 --- a/platform/chunks_download_strategy.cpp +++ b/platform/chunks_download_strategy.cpp @@ -32,7 +32,7 @@ ChunksDownloadStrategy::GetChunk(RangeT const & range) else { LOG(LERROR, ("Downloader error. Invalid chunk range: ", range)); - return pair<ChunkT *, int>(0, -1); + return pair<ChunkT *, int>(reinterpret_cast<ChunkT *>(0), -1); } } diff --git a/platform/platform_tests/platform_test.cpp b/platform/platform_tests/platform_test.cpp index 3f8a0e01bb..8316d566a1 100644 --- a/platform/platform_tests/platform_test.cpp +++ b/platform/platform_tests/platform_test.cpp @@ -108,3 +108,9 @@ UNIT_TEST(CpuCores) TEST_GREATER(coresNum, 0, ()); TEST_LESS_OR_EQUAL(coresNum, 128, ()); } + +UNIT_TEST(GetWritableStorageStatus) +{ + TEST_EQUAL(Platform::STORAGE_OK, GetPlatform().GetWritableStorageStatus(100000), ()); + TEST_EQUAL(Platform::NOT_ENOUGH_SPACE, GetPlatform().GetWritableStorageStatus(0xFFFFFFFFUL), ()); +} diff --git a/platform/platform_win.cpp b/platform/platform_win.cpp index 78fac476da..ac57d3ad2e 100644 --- a/platform/platform_win.cpp +++ b/platform/platform_win.cpp @@ -1,10 +1,12 @@ #include "platform.hpp" +#include "../base/scope_guard.hpp" #include "../base/logging.hpp" #include "../coding/file_writer.hpp" #include "../std/windows.hpp" +#include "../std/bind.hpp" #include <shlobj.h> @@ -119,3 +121,34 @@ void Platform::RunAsync(TFunctor const & fn, Priority p) /// @todo fn(); } + +Platform::TStorageStatus Platform::GetWritableStorageStatus(uint64_t neededSize) +{ + ULARGE_INTEGER freeSpace; + if (0 == ::GetDiskFreeSpaceExA(m_writableDir.c_str(), &freeSpace, NULL, NULL)) + { + LOG(LWARNING, ("GetDiskFreeSpaceEx failed with error", GetLastError())); + return STORAGE_DISCONNECTED; + } + + if (freeSpace.u.LowPart + (freeSpace.u.HighPart << 32) < neededSize) + return NOT_ENOUGH_SPACE; + + return STORAGE_OK; +} + +bool Platform::GetFileSizeByFullPath(string const & filePath, uint64_t & size) +{ + HANDLE hFile = CreateFileA(filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile != INVALID_HANDLE_VALUE) + { + MY_SCOPE_GUARD(autoClose, bind(&CloseHandle, hFile)); + LARGE_INTEGER fileSize; + if (0 != GetFileSizeEx(hFile, &fileSize)) + { + size = fileSize.QuadPart; + return true; + } + } + return false; +} |