summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2011-07-15 18:13:31 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2011-07-15 18:13:31 +0000
commit21a38713a685e04ab1533f487244f2dc2197e01c (patch)
treeaa397ae3fd081edd5225c9142fd35cbed4bb88c3
parentcad91ed938049037a57e9bcc4c5ad63e45dbc2e6 (diff)
downloadrockbox-21a38713a685e04ab1533f487244f2dc2197e01c.tar.gz
rockbox-21a38713a685e04ab1533f487244f2dc2197e01c.zip
Show the total size of the volume along with the free space.
This should help identifying the correct player by size, since the free space is only useful to figure if there is enough space to install Rockbox. Change units to GiB since that is more useful given the size of current devices. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30139 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--rbutil/rbutilqt/base/utils.cpp36
-rw-r--r--rbutil/rbutilqt/base/utils.h7
-rw-r--r--rbutil/rbutilqt/sysinfo.cpp5
3 files changed, 41 insertions, 7 deletions
diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp
index bd2bce0609..1a8607b8e2 100644
--- a/rbutil/rbutilqt/base/utils.cpp
+++ b/rbutil/rbutilqt/base/utils.cpp
@@ -115,6 +115,18 @@ QString Utils::resolvePathCase(QString path)
115//! @return size in bytes 115//! @return size in bytes
116qulonglong Utils::filesystemFree(QString path) 116qulonglong Utils::filesystemFree(QString path)
117{ 117{
118 return filesystemSize(path, FilesystemFree);
119}
120
121
122qulonglong Utils::filesystemTotal(QString path)
123{
124 return filesystemSize(path, FilesystemTotal);
125}
126
127
128qulonglong Utils::filesystemSize(QString path, enum Utils::Size type)
129{
118 qlonglong size = 0; 130 qlonglong size = 0;
119#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) 131#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
120 // the usage of statfs() is deprecated by the LSB so use statvfs(). 132 // the usage of statfs() is deprecated by the LSB so use statvfs().
@@ -123,16 +135,30 @@ qulonglong Utils::filesystemFree(QString path)
123 135
124 ret = statvfs(qPrintable(path), &fs); 136 ret = statvfs(qPrintable(path), &fs);
125 137
126 if(ret == 0) 138 if(ret == 0) {
127 size = (qulonglong)fs.f_frsize * (qulonglong)fs.f_bavail; 139 if(type == FilesystemFree) {
140 size = (qulonglong)fs.f_frsize * (qulonglong)fs.f_bavail;
141 }
142 if(type == FilesystemTotal) {
143 size = (qulonglong)fs.f_frsize * (qulonglong)fs.f_blocks;
144 }
145 }
128#endif 146#endif
129#if defined(Q_OS_WIN32) 147#if defined(Q_OS_WIN32)
130 BOOL ret; 148 BOOL ret;
131 ULARGE_INTEGER freeAvailBytes; 149 ULARGE_INTEGER freeAvailBytes;
150 ULARGE_INTEGER totalNumberBytes;
132 151
133 ret = GetDiskFreeSpaceExW((LPCTSTR)path.utf16(), &freeAvailBytes, NULL, NULL); 152 ret = GetDiskFreeSpaceExW((LPCTSTR)path.utf16(), &freeAvailBytes,
134 if(ret) 153 &totalNumberBytes, NULL);
135 size = freeAvailBytes.QuadPart; 154 if(ret) {
155 if(type == FilesystemFree) {
156 size = freeAvailBytes.QuadPart;
157 }
158 if(type == FilesystemTotal) {
159 size = totalNumberBytes.QuadPart;
160 }
161 }
136#endif 162#endif
137 qDebug() << "[Utils] Filesystem free:" << path << size; 163 qDebug() << "[Utils] Filesystem free:" << path << size;
138 return size; 164 return size;
diff --git a/rbutil/rbutilqt/base/utils.h b/rbutil/rbutilqt/base/utils.h
index ae02a2ca95..bff05cce0a 100644
--- a/rbutil/rbutilqt/base/utils.h
+++ b/rbutil/rbutilqt/base/utils.h
@@ -31,9 +31,16 @@
31class Utils : public QObject 31class Utils : public QObject
32{ 32{
33public: 33public:
34 enum Size {
35 FilesystemTotal,
36 FilesystemFree
37 };
38
34 static bool recursiveRmdir(const QString &dirName); 39 static bool recursiveRmdir(const QString &dirName);
35 static QString resolvePathCase(QString path); 40 static QString resolvePathCase(QString path);
36 static qulonglong filesystemFree(QString path); 41 static qulonglong filesystemFree(QString path);
42 static qulonglong filesystemTotal(QString path);
43 static qulonglong filesystemSize(QString path, enum Size type);
37 static QString findExecutable(QString name); 44 static QString findExecutable(QString name);
38 static QString checkEnvironment(bool permission); 45 static QString checkEnvironment(bool permission);
39 static int compareVersionStrings(QString s1, QString s2); 46 static int compareVersionStrings(QString s1, QString s2);
diff --git a/rbutil/rbutilqt/sysinfo.cpp b/rbutil/rbutilqt/sysinfo.cpp
index a9fa5999b7..a28a9bb812 100644
--- a/rbutil/rbutilqt/sysinfo.cpp
+++ b/rbutil/rbutilqt/sysinfo.cpp
@@ -63,9 +63,10 @@ QString Sysinfo::getInfo()
63 info += "<b>" + tr("Filesystem") + "</b><br/>"; 63 info += "<b>" + tr("Filesystem") + "</b><br/>";
64 QStringList drives = Autodetection::mountpoints(); 64 QStringList drives = Autodetection::mountpoints();
65 for(int i = 0; i < drives.size(); i++) { 65 for(int i = 0; i < drives.size(); i++) {
66 info += tr("%1, %2 MiB available") 66 info += tr("%1, %2 GiB of %3 GiB available")
67 .arg(QDir::toNativeSeparators(drives.at(i))) 67 .arg(QDir::toNativeSeparators(drives.at(i)))
68 .arg(Utils::filesystemFree(drives.at(i)) / (1024*1024)); 68 .arg((double)Utils::filesystemFree(drives.at(i)) / (1<<30), 0, 'f', 2)
69 .arg((double)Utils::filesystemTotal(drives.at(i)) / (1<<30), 0, 'f', 2);
69 if(i + 1 < drives.size()) 70 if(i + 1 < drives.size())
70 info += "<br/>"; 71 info += "<br/>";
71 } 72 }