mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 21:03:30 -07:00
- Attempt to support FreeDiskSpace() on Windows platform
* Totally untested, not even sure it compiles but if not it should be easy to fix
This commit is contained in:
parent
6fcf25af52
commit
706362333d
1 changed files with 31 additions and 7 deletions
38
src/misc.h
38
src/misc.h
|
@ -44,6 +44,8 @@
|
||||||
|
|
||||||
#ifndef Q_WS_WIN
|
#ifndef Q_WS_WIN
|
||||||
#include <sys/vfs.h>
|
#include <sys/vfs.h>
|
||||||
|
#else
|
||||||
|
#include <winbase.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <libtorrent/torrent_info.hpp>
|
#include <libtorrent/torrent_info.hpp>
|
||||||
|
@ -103,14 +105,36 @@ public:
|
||||||
struct statfs stats;
|
struct statfs stats;
|
||||||
int ret = statfs ((path+"/.").toUtf8().data(), &stats) ;
|
int ret = statfs ((path+"/.").toUtf8().data(), &stats) ;
|
||||||
if(ret == 0) {
|
if(ret == 0) {
|
||||||
available = ((unsigned long long)stats.f_bavail) *
|
available = ((unsigned long long)stats.f_bavail) *
|
||||||
((unsigned long long)stats.f_bsize) ;
|
((unsigned long long)stats.f_bsize) ;
|
||||||
return available;
|
return available;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return -1;
|
typedef BOOL (WINAPI *GetDiskFreeSpaceEx_t)(LPCTSTR,
|
||||||
|
PULARGE_INTEGER,
|
||||||
|
PULARGE_INTEGER,
|
||||||
|
PULARGE_INTEGER);
|
||||||
|
GetDiskFreeSpaceEx_t
|
||||||
|
pGetDiskFreeSpaceEx = (GetDiskFreeSpaceEx_t)::GetProcAddress
|
||||||
|
(
|
||||||
|
::GetModuleHandle(_T("kernel32.dll")),
|
||||||
|
"GetDiskFreeSpaceExW"
|
||||||
|
);
|
||||||
|
if ( pGetDiskFreeSpaceEx )
|
||||||
|
{
|
||||||
|
ULARGE_INTEGER bytesFree, bytesTotal;
|
||||||
|
unsigned long long *ret;
|
||||||
|
if (pGetDiskFreeSpaceEx((LPCTSTR)path.ucs2(), &bytesFree, &bytesTotal, NULL)) {
|
||||||
|
tmp = (unsigned long long*)&bytesFree
|
||||||
|
return ret;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue