mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-14 23:52:26 -05:00
Move utils.cpp functions into separate class and split it up.
Move class-less functions in utils.cpp into a new Utils class and make the old functions static. This prevents clashes with system C functions. Rename some functions to avoid macro problems (check() is a macro on OS X). Split out the RockboxInfo class into a separate file. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25441 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
c5d9516a68
commit
9fedc8187f
20 changed files with 170 additions and 105 deletions
|
|
@ -18,6 +18,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "utils.h"
|
||||
#include "rockboxinfo.h"
|
||||
#include "system.h"
|
||||
#include "rbsettings.h"
|
||||
#include "systeminfo.h"
|
||||
|
|
@ -41,7 +42,7 @@
|
|||
#endif
|
||||
|
||||
// recursive function to delete a dir with files
|
||||
bool recRmdir( const QString &dirName )
|
||||
bool Utils::recursiveRmdir( const QString &dirName )
|
||||
{
|
||||
QString dirN = dirName;
|
||||
QDir dir(dirN);
|
||||
|
|
@ -54,19 +55,21 @@ bool recRmdir( const QString &dirName )
|
|||
curItem = dirN + "/" + name;
|
||||
fileInfo.setFile(curItem);
|
||||
if(fileInfo.isDir()) // is directory
|
||||
recRmdir(curItem); // call recRmdir() recursively for deleting subdirectory
|
||||
recursiveRmdir(curItem); // call recRmdir() recursively for
|
||||
// deleting subdirectory
|
||||
else // is file
|
||||
QFile::remove(curItem); // ok, delete file
|
||||
QFile::remove(curItem); // ok, delete file
|
||||
}
|
||||
dir.cdUp();
|
||||
return dir.rmdir(dirN); // delete empty dir and return if (now empty) dir-removing was successfull
|
||||
return dir.rmdir(dirN); // delete empty dir and return if (now empty)
|
||||
// dir-removing was successfull
|
||||
}
|
||||
|
||||
|
||||
//! @brief resolves the given path, ignoring case.
|
||||
//! @param path absolute path to resolve.
|
||||
//! @return returns exact casing of path, empty string if path not found.
|
||||
QString resolvePathCase(QString path)
|
||||
QString Utils::resolvePathCase(QString path)
|
||||
{
|
||||
QStringList elems;
|
||||
QString realpath;
|
||||
|
|
@ -110,7 +113,7 @@ QString resolvePathCase(QString path)
|
|||
//! @brief figure the free disk space on a filesystem
|
||||
//! @param path path on the filesystem to check
|
||||
//! @return size in bytes
|
||||
qulonglong filesystemFree(QString path)
|
||||
qulonglong Utils::filesystemFree(QString path)
|
||||
{
|
||||
qlonglong size = 0;
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
|
||||
|
|
@ -135,7 +138,7 @@ qulonglong filesystemFree(QString path)
|
|||
}
|
||||
|
||||
//! \brief searches for a Executable in the Environement Path
|
||||
QString findExecutable(QString name)
|
||||
QString Utils::findExecutable(QString name)
|
||||
{
|
||||
QString exepath;
|
||||
//try autodetect tts
|
||||
|
|
@ -167,7 +170,7 @@ QString findExecutable(QString name)
|
|||
* @param permission if it should check for permission
|
||||
* @return string with error messages if problems occurred, empty strings if none.
|
||||
*/
|
||||
QString check(bool permission)
|
||||
QString Utils::checkEnvironment(bool permission)
|
||||
{
|
||||
QString text = "";
|
||||
|
||||
|
|
@ -201,47 +204,3 @@ QString check(bool permission)
|
|||
return text;
|
||||
}
|
||||
|
||||
|
||||
RockboxInfo::RockboxInfo(QString mountpoint)
|
||||
{
|
||||
qDebug() << "[RockboxInfo] trying to find rockbox-info at" << mountpoint;
|
||||
QFile file(mountpoint + "/.rockbox/rockbox-info.txt");
|
||||
m_success = false;
|
||||
if(!file.exists())
|
||||
return;
|
||||
|
||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
return;
|
||||
|
||||
// read file contents
|
||||
while (!file.atEnd())
|
||||
{
|
||||
QString line = file.readLine();
|
||||
|
||||
if(line.contains("Version:"))
|
||||
{
|
||||
m_version = line.remove("Version:").trimmed();
|
||||
}
|
||||
else if(line.contains("Target: "))
|
||||
{
|
||||
m_target = line.remove("Target: ").trimmed();
|
||||
}
|
||||
else if(line.contains("Features:"))
|
||||
{
|
||||
m_features = line.remove("Features:").trimmed();
|
||||
}
|
||||
else if(line.contains("Target id:"))
|
||||
{
|
||||
m_targetid = line.remove("Target id:").trimmed();
|
||||
}
|
||||
else if(line.contains("Memory:"))
|
||||
{
|
||||
m_ram = line.remove("Memory:").trimmed().toInt();
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
m_success = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue