1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
26 #if defined(Q_OS_WIN32)
35 // recursive function to delete a dir with files
36 bool recRmdir( const QString
&dirName
)
38 QString dirN
= dirName
;
40 // make list of entries in directory
41 QStringList list
= dir
.entryList(QDir::AllEntries
| QDir::NoDotAndDotDot
);
43 QString curItem
, lstAt
;
44 for(int i
= 0; i
< list
.size(); i
++){ // loop through all items of list
45 QString name
= list
.at(i
);
46 curItem
= dirN
+ "/" + name
;
47 fileInfo
.setFile(curItem
);
48 if(fileInfo
.isDir()) // is directory
49 recRmdir(curItem
); // call recRmdir() recursively for deleting subdirectory
51 QFile::remove(curItem
); // ok, delete file
54 return dir
.rmdir(dirN
); // delete empty dir and return if (now empty) dir-removing was successfull
58 //! @brief resolves the given path, ignoring case.
59 //! @param path absolute path to resolve.
60 //! @return returns exact casing of path, empty string if path not found.
61 QString
resolvePathCase(QString path
)
66 elems
= path
.split("/", QString::SkipEmptyParts
);
68 #if defined(Q_OS_WIN32)
69 // on windows we must make sure to start with the first entry (i.e. the
70 // drive letter) instead of a single / to make resolving work.
72 realpath
= elems
.at(0) + "/";
78 for(int i
= start
; i
< elems
.size(); i
++) {
80 = QDir(realpath
).entryList(QDir::AllEntries
|QDir::Hidden
|QDir::System
);
81 if(direlems
.contains(elems
.at(i
), Qt::CaseInsensitive
)) {
82 // need to filter using QRegExp as QStringList::filter(QString)
83 // matches any substring
84 QString expr
= QString("^" + elems
.at(i
) + "$");
85 QRegExp rx
= QRegExp(expr
, Qt::CaseInsensitive
);
86 QStringList a
= direlems
.filter(rx
);
90 if(!realpath
.endsWith("/"))
97 qDebug() << __func__
<< path
<< "->" << realpath
;
102 //! @brief get system proxy value.
103 QUrl
systemProxy(void)
105 #if defined(Q_OS_LINUX)
106 return QUrl(getenv("http_proxy"));
107 #elif defined(Q_OS_WIN32)
109 wchar_t proxyval
[80];
113 DWORD enalen
= sizeof(DWORD
);
115 ret
= RegOpenKeyEx(HKEY_CURRENT_USER
,
116 _TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
117 0, KEY_QUERY_VALUE
, &hk
);
118 if(ret
!= ERROR_SUCCESS
) return QUrl("");
120 ret
= RegQueryValueEx(hk
, _TEXT("ProxyServer"), NULL
, NULL
, (LPBYTE
)proxyval
, &buflen
);
121 if(ret
!= ERROR_SUCCESS
) return QUrl("");
123 ret
= RegQueryValueEx(hk
, _TEXT("ProxyEnable"), NULL
, NULL
, (LPBYTE
)&enable
, &enalen
);
124 if(ret
!= ERROR_SUCCESS
) return QUrl("");
128 //qDebug() << QString::fromWCharArray(proxyval) << QString("%1").arg(enable);
130 return QUrl("http://" + QString::fromWCharArray(proxyval
));
138 QString
installedVersion(QString mountpoint
)
140 // read rockbox-info.txt
141 QFile
info(mountpoint
+"/.rockbox/rockbox-info.txt");
142 if(!info
.open(QIODevice::ReadOnly
))
147 QString target
, features
,version
;
148 while (!info
.atEnd()) {
149 QString line
= info
.readLine();
151 if(line
.contains("Version:"))
153 return line
.remove("Version:").trimmed();