summaryrefslogtreecommitdiffstats
path: root/installerbuilder/common
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2011-04-21 11:59:53 +0200
committerkh1 <qt-info@nokia.com>2011-04-21 11:59:53 +0200
commitab8044c68dd6f4ffd7a37ded488944479257e01d (patch)
treeeb8581e142dbb29984b4224a5717599f589213e3 /installerbuilder/common
parent53b6164460a9bf478013f8447db7b6730806effc (diff)
Cleanup. Whitespaces. Style.
Diffstat (limited to 'installerbuilder/common')
-rw-r--r--installerbuilder/common/fileutils.cpp453
-rw-r--r--installerbuilder/common/fileutils.h115
2 files changed, 287 insertions, 281 deletions
diff --git a/installerbuilder/common/fileutils.cpp b/installerbuilder/common/fileutils.cpp
index 9f1ce91ed..0beda56e4 100644
--- a/installerbuilder/common/fileutils.cpp
+++ b/installerbuilder/common/fileutils.cpp
@@ -31,111 +31,115 @@
**
**************************************************************************/
#include "fileutils.h"
+
#include <common/errors.h>
#include <common/utils.h>
-#include <QDateTime>
-#include <QDir>
-#include <QDirIterator>
-#include <QEventLoop>
-#include <QFileInfo>
-#include <QString>
-#include <QTemporaryFile>
-#include <QThread>
-#include <QUrl>
-
-#include <cassert>
-#include <cerrno>
+#include <QtCore/QDateTime>
+#include <QtCore/QDir>
+#include <QtCore/QDirIterator>
+#include <QtCore/QEventLoop>
+#include <QtCore/QTemporaryFile>
+#include <QtCore/QThread>
using namespace QInstaller;
-TempDirDeleter::TempDirDeleter( const QString& path )
- : m_paths( QStringList() << path )
+
+// -- TempDirDeleter
+
+TempDirDeleter::TempDirDeleter(const QString &path)
{
+ m_paths.insert(path);
}
-TempDirDeleter::TempDirDeleter( const QStringList& paths_ )
- : m_paths( paths_ )
+TempDirDeleter::TempDirDeleter(const QStringList &paths)
+ : m_paths(paths.toSet())
{
}
TempDirDeleter::~TempDirDeleter()
{
- for( QStringList::const_iterator it = m_paths.constBegin(); it != m_paths.constEnd(); ++it )
- {
- const QString& path = *it;
- if( !path.isEmpty() )
+ foreach (const QString &path, m_paths) {
+ if (!path.isEmpty()) {
try {
- removeDirectory( path );
- } catch ( const Error& e ) {
+ removeDirectory(path);
+ } catch (const Error &e) {
qCritical() << Q_FUNC_INFO << "Exception caught:" << e.message();
- } catch ( ... ) {
+ } catch (...) {
qCritical() << Q_FUNC_INFO << "Unknown exception caught.";
}
+ }
}
}
-void TempDirDeleter::passAndReleaseAll( TempDirDeleter& tdd ) {
- tdd.m_paths = m_paths;
- releaseAll();
+QStringList TempDirDeleter::paths() const
+{
+ return m_paths.toList();
}
-void TempDirDeleter::passAndRelease( TempDirDeleter& tdd, const QString& path ) {
- tdd.add( path );
- release( path );
+void TempDirDeleter::add(const QString &path)
+{
+ m_paths.insert(path);
}
-void TempDirDeleter::releaseAll() {
- m_paths.clear();
+void TempDirDeleter::add(const QStringList &paths)
+{
+ m_paths += paths.toSet();
}
-void TempDirDeleter::release( const QString& path ) {
- m_paths.removeAll( path );
+void TempDirDeleter::releaseAll()
+{
+ m_paths.clear();
}
-QStringList TempDirDeleter::paths() const {
- return m_paths;
+void TempDirDeleter::release(const QString &path)
+{
+ m_paths.remove(path);
}
-void TempDirDeleter::add( const QString& path )
+void TempDirDeleter::passAndReleaseAll(TempDirDeleter &tdd)
{
- if( !m_paths.contains( path ) )
- m_paths.push_back( path );
+ tdd.m_paths = m_paths;
+ releaseAll();
}
-void TempDirDeleter::add( const QStringList& paths )
+void TempDirDeleter::passAndRelease(TempDirDeleter &tdd, const QString &path)
{
- for( QStringList::const_iterator it = paths.begin(); it != paths.end(); ++it )
- add( *it );
+ tdd.add(path);
+ release(path);
}
-bool QInstaller::isLocalUrl( const QUrl& url ) {
+
+// -- read, write operations
+
+bool QInstaller::isLocalUrl(const QUrl &url)
+{
return url.scheme().isEmpty() || url.scheme().toLower() == QLatin1String("file");
}
-QString QInstaller::pathFromUrl( const QUrl& url )
+QString QInstaller::pathFromUrl(const QUrl &url)
{
- if( isLocalUrl( url ) )
+ if (isLocalUrl(url))
return url.toLocalFile();
const QString str = url.toString();
- if ( url.scheme() == QLatin1String("resource") )
- return str.mid( QString::fromLatin1("resource").length() );
+ if (url.scheme() == QLatin1String("resource"))
+ return str.mid(QString::fromLatin1("resource").length());
return str;
}
-void QInstaller::openForWrite(QIODevice* dev, const QString& name)
+void QInstaller::openForWrite(QIODevice *dev, const QString &name)
{
- assert( dev );
+ Q_ASSERT(dev);
if (!dev->open(QIODevice::WriteOnly))
- throw Error(QObject::tr("Cannot open file %1 for writing: %2").arg( name, dev->errorString() ) );
+ throw Error(QObject::tr("Cannot open file %1 for writing: %2").arg(name, dev->errorString()));
}
-void QInstaller::openForRead(QIODevice* dev, const QString& name)
+void QInstaller::openForRead(QIODevice *dev, const QString &name)
{
- assert( dev );
+ Q_ASSERT(dev);
if (!dev->open(QIODevice::ReadOnly))
- throw Error(QObject::tr( "Cannot open file %1 for reading: %2" ).arg( name, dev->errorString() ) );
+ throw Error(QObject::tr("Cannot open file %1 for reading: %2").arg(name, dev->errorString()));
}
qint64 QInstaller::blockingWrite(QIODevice *out, const char *buffer, qint64 size)
@@ -143,45 +147,47 @@ qint64 QInstaller::blockingWrite(QIODevice *out, const char *buffer, qint64 size
qint64 left = size;
while (left > 0) {
const qint64 n = out->write(buffer, left);
- if (n < 0)
- throw Error( QObject::tr("Write failed after %1 bytes: %2").arg( QString::number(size-left), out->errorString() ) );
+ if (n < 0) {
+ throw Error(QObject::tr("Write failed after %1 bytes: %2").arg(QString::number(size-left),
+ out->errorString()));
+ }
left -= n;
}
return size;
}
-qint64 QInstaller::blockingWrite(QIODevice *out, const QByteArray& ba)
+qint64 QInstaller::blockingWrite(QIODevice *out, const QByteArray &ba)
{
- return blockingWrite( out, ba.constData(), ba.size() );
+ return blockingWrite(out, ba.constData(), ba.size());
}
qint64 QInstaller::blockingRead(QIODevice *in, char *buffer, qint64 size)
{
- if ( in->atEnd() )
+ if (in->atEnd())
return 0;
qint64 left = size;
while (left > 0) {
const qint64 n = in->read(buffer, left);
- if ( n < 0 )
- throw Error( QObject::tr("Read failed after %1 bytes: %2").arg( QString::number(size-left), in->errorString() ) );
-
+ if (n < 0) {
+ throw Error(QObject::tr("Read failed after %1 bytes: %2").arg(QString::number(size-left),
+ in->errorString()));
+ }
left -= n;
buffer += n;
}
return size;
}
-void QInstaller::blockingCopy( QIODevice* in, QIODevice* out, qint64 size )
+void QInstaller::blockingCopy(QIODevice *in, QIODevice *out, qint64 size)
{
static const qint64 blockSize = 4096;
- QByteArray ba( blockSize, '\0' );
- qint64 actual = qMin( blockSize, size );
- while( actual > 0 )
- {
- blockingRead( in, ba.data(), actual );
- blockingWrite( out, ba.constData(), actual );
+ QByteArray ba(blockSize, '\0');
+ qint64 actual = qMin(blockSize, size);
+ while (actual > 0) {
+ blockingRead(in, ba.data(), actual);
+ blockingWrite(out, ba.constData(), actual);
size -= actual;
- actual = qMin( blockSize, size );
+ actual = qMin(blockSize, size);
}
}
@@ -197,7 +203,7 @@ void QInstaller::removeFiles(const QString &path, bool ignoreErrors)
}
}
-void QInstaller::removeDirectory(const QString& path, bool ignoreErrors)
+void QInstaller::removeDirectory(const QString &path, bool ignoreErrors)
{
if (path.isEmpty()) // QDir("") points to the working directory! We never want to remove that one.
return;
@@ -227,14 +233,14 @@ void QInstaller::removeDirectory(const QString& path, bool ignoreErrors)
class RemoveDirectoryThread : public QThread
{
public:
- explicit RemoveDirectoryThread( const QString& path, bool ignoreErrors = false, QObject* parent = 0 )
- : QThread( parent ),
- p( path ),
- ignore( ignoreErrors )
+ explicit RemoveDirectoryThread(const QString &path, bool ignoreErrors = false, QObject *parent = 0)
+ : QThread(parent),
+ p(path),
+ ignore(ignoreErrors)
{
}
-
- const QString& error() const
+
+ const QString &error() const
{
return err;
}
@@ -245,12 +251,9 @@ protected:
*/
void run()
{
- try
- {
- removeDirectory( p, ignore );
- }
- catch( const Error& e )
- {
+ try {
+ removeDirectory(p, ignore);
+ } catch (const Error &e) {
err = e.message();
}
}
@@ -261,216 +264,216 @@ private:
const bool ignore;
};
-void QInstaller::removeDirectoryThreaded( const QString& path, bool ignoreErrors )
+void QInstaller::removeDirectoryThreaded(const QString &path, bool ignoreErrors)
{
- RemoveDirectoryThread thread( path, ignoreErrors );
+ RemoveDirectoryThread thread(path, ignoreErrors);
QEventLoop loop;
- QObject::connect( &thread, SIGNAL( finished() ), &loop, SLOT( quit() ) );
+ QObject::connect(&thread, SIGNAL(finished()), &loop, SLOT(quit()));
thread.start();
loop.exec();
- if( !thread.error().isEmpty() )
- throw Error( thread.error() );
+ if (!thread.error().isEmpty())
+ throw Error(thread.error());
}
-void QInstaller::copyDirectoryContents( const QString& sourceDir, const QString& targetDir ) {
+void QInstaller::copyDirectoryContents(const QString &sourceDir, const QString &targetDir)
+{
verbose() << "Copying " << sourceDir << " to " << targetDir << std::endl;
- Q_ASSERT( QFileInfo( sourceDir ).isDir() );
- Q_ASSERT( !QFileInfo( targetDir ).exists() || QFileInfo( targetDir ).isDir() );
- if ( !QDir().mkpath( targetDir ) )
- throw Error( QObject::tr("Could not create folder %1").arg( targetDir ) );
+ Q_ASSERT(QFileInfo(sourceDir).isDir());
+ Q_ASSERT(!QFileInfo(targetDir).exists() || QFileInfo(targetDir).isDir());
+ if (!QDir().mkpath(targetDir))
+ throw Error(QObject::tr("Could not create folder %1").arg(targetDir));
- QDirIterator it( sourceDir, QDir::NoDotAndDotDot | QDir::AllEntries );
- while( it.hasNext() )
- {
- const QFileInfo i( it.next() );
- if( i.isDir() )
- {
- copyDirectoryContents( QDir( sourceDir ).absoluteFilePath( i.fileName() ), QDir( targetDir ).absoluteFilePath( i.fileName() ) );
- }
- else
- {
- QFile f( i.filePath() );
- const QString target = QDir( targetDir ).absoluteFilePath( i.fileName() );
- if( !f.copy( target ) )
- throw Error( QObject::tr("Could not copy file from %1 to %2: %3").arg( f.fileName(), target, f.errorString() ) );
+ QDirIterator it(sourceDir, QDir::NoDotAndDotDot | QDir::AllEntries);
+ while (it.hasNext()) {
+ const QFileInfo i(it.next());
+ if (i.isDir()) {
+ copyDirectoryContents(QDir(sourceDir).absoluteFilePath(i.fileName()),
+ QDir(targetDir).absoluteFilePath(i.fileName()));
+ } else {
+ QFile f(i.filePath());
+ const QString target = QDir(targetDir).absoluteFilePath(i.fileName());
+ if (!f.copy(target)) {
+ throw Error(QObject::tr("Could not copy file from %1 to %2: %3").arg(f.fileName(), target,
+ f.errorString()));
+ }
}
}
}
-void QInstaller::moveDirectoryContents( const QString& sourceDir, const QString& targetDir ) {
+void QInstaller::moveDirectoryContents(const QString &sourceDir, const QString &targetDir)
+{
verbose() << "Moving " << sourceDir << " to " << targetDir << std::endl;
- Q_ASSERT( QFileInfo( sourceDir ).isDir() );
- Q_ASSERT( !QFileInfo( targetDir ).exists() || QFileInfo( targetDir ).isDir() );
- if ( !QDir().mkpath( targetDir ) )
- throw Error( QObject::tr("Could not create folder %1").arg( targetDir ) );
-
- QDirIterator it( sourceDir, QDir::NoDotAndDotDot | QDir::AllEntries );
- while( it.hasNext() )
- {
- const QFileInfo i( it.next() );
- if( i.isDir() )
- {
- moveDirectoryContents( QDir( sourceDir ).absoluteFilePath( i.fileName() ), QDir( targetDir ).absoluteFilePath( i.fileName() ) );
- }
- else
- {
- QFile f( i.filePath() );
- const QString target = QDir( targetDir ).absoluteFilePath( i.fileName() );
- if( !f.rename( target ) )
- throw Error( QObject::tr("Could not move file from %1 to %2: %3").arg( f.fileName(), target, f.errorString() ) );
+ Q_ASSERT(QFileInfo(sourceDir).isDir());
+ Q_ASSERT(!QFileInfo(targetDir).exists() || QFileInfo(targetDir).isDir());
+ if (!QDir().mkpath(targetDir))
+ throw Error(QObject::tr("Could not create folder %1").arg(targetDir));
+
+ QDirIterator it(sourceDir, QDir::NoDotAndDotDot | QDir::AllEntries);
+ while (it.hasNext()) {
+ const QFileInfo i(it.next());
+ if (i.isDir()) {
+ moveDirectoryContents(QDir(sourceDir).absoluteFilePath(i.fileName()),
+ QDir(targetDir).absoluteFilePath(i.fileName()));
+ } else {
+ QFile f(i.filePath());
+ const QString target = QDir(targetDir).absoluteFilePath(i.fileName());
+ if (!f.rename(target)) {
+ throw Error(QObject::tr("Could not move file from %1 to %2: %3").arg(f.fileName(), target,
+ f.errorString()));
+ }
}
}
}
-void QInstaller::mkdir( const QString& path ) {
+void QInstaller::mkdir(const QString &path)
+{
errno = 0;
- if ( !QDir().mkdir( QFileInfo( path ).absoluteFilePath() ) )
- throw Error( QObject::tr("Could not create folder %1: %2" ).arg( path, QString::fromLocal8Bit( strerror( errno ) ) ) );
+ if (!QDir().mkdir(QFileInfo(path).absoluteFilePath())) {
+ throw Error(QObject::tr("Could not create folder %1: %2").arg(path,
+ QString::fromLocal8Bit(strerror(errno))));
+ }
}
-void QInstaller::mkpath( const QString& path ) {
+void QInstaller::mkpath(const QString &path)
+{
errno = 0;
- if ( !QDir().mkpath( QFileInfo( path ).absoluteFilePath() ) )
- throw Error( QObject::tr("Could not create folder %1: %2" ).arg( path, QString::fromLocal8Bit( strerror( errno ) ) ) );
+ if (!QDir().mkpath(QFileInfo(path).absoluteFilePath())) {
+ throw Error(QObject::tr("Could not create folder %1: %2").arg(path,
+ QString::fromLocal8Bit(strerror(errno))));
+ }
}
-QString QInstaller::generateTemporaryFileName( const QString& templ )
+QString QInstaller::generateTemporaryFileName(const QString &templ)
{
- if ( templ.isEmpty() )
- {
+ if (templ.isEmpty()) {
QTemporaryFile f;
- if ( !f.open() )
- throw Error( QObject::tr("Could not open temporary file: %1").arg( f.errorString() ) );
- return f.fileName();
- }
- else
- {
- static const QString characters = QLatin1String( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" );
-/* const QFileInfo fi( path );
- const QString dir = fi.absolutePath();
- const QString file = fi.fileName();*/
- QString suffix;
- qsrand( qrand() * QDateTime::currentDateTime().toTime_t() );
- for( int i = 0; i < 5; ++i )
- suffix += characters[ qrand() % characters.length() ];
- const QString tmp = QLatin1String( "%1.tmp.%2.%3" );
- int count = 1;
- while ( QFile::exists( tmp.arg( templ, suffix ).arg( count ) ) )
- ++count;
- QFile f( tmp.arg( templ, suffix ).arg( count ) );
- if( !f.open( QIODevice::WriteOnly ) )
- throw Error( QObject::tr("Could not open temporary file for template %1: %2").arg( templ, f.errorString() ) );
- f.remove();
+ if (!f.open())
+ throw Error(QObject::tr("Could not open temporary file: %1").arg(f.errorString()));
return f.fileName();
}
+
+ static const QString characters = QLatin1String("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
+ QString suffix;
+ qsrand(qrand() * QDateTime::currentDateTime().toTime_t());
+ for (int i = 0; i < 5; ++i)
+ suffix += characters[qrand() % characters.length()];
+
+ const QString tmp = QLatin1String("%1.tmp.%2.%3");
+ int count = 1;
+ while (QFile::exists(tmp.arg(templ, suffix).arg(count)))
+ ++count;
+
+ QFile f(tmp.arg(templ, suffix).arg(count));
+ if (!f.open(QIODevice::WriteOnly))
+ throw Error(QObject::tr("Could not open temporary file for template %1: %2").arg(templ, f.errorString()));
+ f.remove();
+ return f.fileName();
}
-QString QInstaller::createTemporaryDirectory( const QString& templ ) {
+QString QInstaller::createTemporaryDirectory(const QString &templ)
+{
const QString t = QDir::tempPath() + QLatin1String("/") + templ + QLatin1String("XXXXXX");
- QTemporaryFile f( t );
- if ( !f.open() )
- throw Error( QObject::tr("Could not create temporary folder for template %1: %2").arg( t, f.errorString() ) );
- const QString path = f.fileName() + QString::fromLatin1( "meta" );
+ QTemporaryFile f(t);
+ if (!f.open())
+ throw Error(QObject::tr("Could not create temporary folder for template %1: %2").arg(t, f.errorString()));
+ const QString path = f.fileName() + QString::fromLatin1("meta");
verbose() << "Creating meta data directory at " << path << std::endl;
- QInstaller::mkpath( path );
+ QInstaller::mkpath(path);
return path;
}
#ifdef Q_WS_WIN
#include <windows.h>
-#pragma pack( push )
+#pragma pack(push)
#pragma pack(2)
-typedef struct
-{
-BYTE bWidth; // Width, in pixels, of the image
-BYTE bHeight; // Height, in pixels, of the image
-BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
-BYTE bReserved; // Reserved
-WORD wPlanes; // Color Planes
-WORD wBitCount; // Bits per pixel
-DWORD dwBytesInRes; // how many bytes in this resource?
-DWORD dwImageOffset; // the ID
+typedef struct {
+ BYTE bWidth; // Width, in pixels, of the image
+ BYTE bHeight; // Height, in pixels, of the image
+ BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
+ BYTE bReserved; // Reserved
+ WORD wPlanes; // Color Planes
+ WORD wBitCount; // Bits per pixel
+ DWORD dwBytesInRes; // how many bytes in this resource?
+ DWORD dwImageOffset; // the ID
} ICONDIRENTRY;
-typedef struct
-{
-WORD idReserved; // Reserved (must be 0)
-WORD idType; // Resource type (1 for icons)
-WORD idCount; // How many images?
-ICONDIRENTRY idEntries[1]; // The entries for each image
+typedef struct {
+ WORD idReserved; // Reserved (must be 0)
+ WORD idType; // Resource type (1 for icons)
+ WORD idCount; // How many images?
+ ICONDIRENTRY idEntries[1]; // The entries for each image
} ICONDIR;
-typedef struct
-{
-BYTE bWidth; // Width, in pixels, of the image
-BYTE bHeight; // Height, in pixels, of the image
-BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
-BYTE bReserved; // Reserved
-WORD wPlanes; // Color Planes
-WORD wBitCount; // Bits per pixel
-DWORD dwBytesInRes; // how many bytes in this resource?
-WORD nID; // the ID
+typedef struct {
+ BYTE bWidth; // Width, in pixels, of the image
+ BYTE bHeight; // Height, in pixels, of the image
+ BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
+ BYTE bReserved; // Reserved
+ WORD wPlanes; // Color Planes
+ WORD wBitCount; // Bits per pixel
+ DWORD dwBytesInRes; // how many bytes in this resource?
+ WORD nID; // the ID
} GRPICONDIRENTRY, *LPGRPICONDIRENTRY;
-typedef struct
-{
-WORD idReserved; // Reserved (must be 0)
-WORD idType; // Resource type (1 for icons)
-WORD idCount; // How many images?
-GRPICONDIRENTRY idEntries[1]; // The entries for each image
+typedef struct {
+ WORD idReserved; // Reserved (must be 0)
+ WORD idType; // Resource type (1 for icons)
+ WORD idCount; // How many images?
+ GRPICONDIRENTRY idEntries[1]; // The entries for each image
} GRPICONDIR, *LPGRPICONDIR;
-#pragma pack( pop )
+#pragma pack(pop)
-void QInstaller::setApplicationIcon( const QString& application, const QString& icon )
+void QInstaller::setApplicationIcon(const QString &application, const QString &icon)
{
- wchar_t* const path = new wchar_t[ application.length() + 1 ];
- QDir::toNativeSeparators( application ).toWCharArray( path );
- path[ application.length() ] = 0;
+ wchar_t* const path = new wchar_t[application.length() + 1];
+ QDir::toNativeSeparators(application).toWCharArray(path);
+ path[application.length()] = 0;
- HANDLE updateRes = BeginUpdateResource( path, false );
+ HANDLE updateRes = BeginUpdateResource(path, false);
delete[] path;
- QFile iconFile( icon );
- if( !iconFile.open( QIODevice::ReadOnly ) )
+ QFile iconFile(icon);
+ if (!iconFile.open(QIODevice::ReadOnly))
return;
QByteArray temp = iconFile.readAll();
- ICONDIR* ig = reinterpret_cast< ICONDIR* >( temp.data() );
+ ICONDIR* ig = reinterpret_cast< ICONDIR* >(temp.data());
- DWORD newSize = sizeof( GRPICONDIR ) + sizeof( GRPICONDIRENTRY ) * ( ig->idCount - 1 );
- GRPICONDIR* newDir = reinterpret_cast< GRPICONDIR* >( new char[ newSize ] );
+ DWORD newSize = sizeof(GRPICONDIR) + sizeof(GRPICONDIRENTRY) * (ig->idCount - 1);
+ GRPICONDIR* newDir = reinterpret_cast< GRPICONDIR* >(new char[newSize]);
newDir->idReserved = ig->idReserved;
newDir->idType = ig->idType;
newDir->idCount = ig->idCount;
- for( int i = 0; i < ig->idCount; ++i )
- {
- char* temp1 = temp.data() + ig->idEntries[ i ].dwImageOffset;
- DWORD size1 = ig->idEntries[ i ].dwBytesInRes;
-
- newDir->idEntries[ i ].bWidth = ig->idEntries[ i ].bWidth;
- newDir->idEntries[ i ].bHeight = ig->idEntries[ i ].bHeight;
- newDir->idEntries[ i ].bColorCount = ig->idEntries[ i ].bColorCount;
- newDir->idEntries[ i ].bReserved = ig->idEntries[ i ].bReserved;
- newDir->idEntries[ i ].wPlanes = ig->idEntries[ i ].wPlanes;
- newDir->idEntries[ i ].wBitCount = ig->idEntries[ i ].wBitCount;
- newDir->idEntries[ i ].dwBytesInRes = ig->idEntries[ i ].dwBytesInRes;
- newDir->idEntries[ i ].nID = i + 1;
-
- UpdateResource( updateRes, RT_ICON, MAKEINTRESOURCE( i + 1 ),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), temp1, size1 );
+ for (int i = 0; i < ig->idCount; ++i) {
+ char* temp1 = temp.data() + ig->idEntries[i].dwImageOffset;
+ DWORD size1 = ig->idEntries[i].dwBytesInRes;
+
+ newDir->idEntries[i].bWidth = ig->idEntries[i].bWidth;
+ newDir->idEntries[i].bHeight = ig->idEntries[i].bHeight;
+ newDir->idEntries[i].bColorCount = ig->idEntries[i].bColorCount;
+ newDir->idEntries[i].bReserved = ig->idEntries[i].bReserved;
+ newDir->idEntries[i].wPlanes = ig->idEntries[i].wPlanes;
+ newDir->idEntries[i].wBitCount = ig->idEntries[i].wBitCount;
+ newDir->idEntries[i].dwBytesInRes = ig->idEntries[i].dwBytesInRes;
+ newDir->idEntries[i].nID = i + 1;
+
+ UpdateResource(updateRes, RT_ICON, MAKEINTRESOURCE(i + 1),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), temp1, size1);
}
- UpdateResource( updateRes, RT_GROUP_ICON, L"IDI_ICON1", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), newDir, newSize );
+ UpdateResource(updateRes, RT_GROUP_ICON, L"IDI_ICON1", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), newDir
+ , newSize);
- delete[] newDir;
+ delete [] newDir;
- EndUpdateResource( updateRes, false );
+ EndUpdateResource(updateRes, false);
}
+
#endif
diff --git a/installerbuilder/common/fileutils.h b/installerbuilder/common/fileutils.h
index c9af75384..8be14f08f 100644
--- a/installerbuilder/common/fileutils.h
+++ b/installerbuilder/common/fileutils.h
@@ -26,11 +26,12 @@
#ifndef QINSTALLER_FILEUTILS_H
#define QINSTALLER_FILEUTILS_H
+#include "installer_global.h"
+
+#include <QtCore/QSet>
#include <QtCore/QString>
#include <QtCore/QStringList>
-#include "installer_global.h"
-
QT_BEGIN_NAMESPACE
class QByteArray;
class QIODevice;
@@ -38,69 +39,71 @@ class QUrl;
QT_END_NAMESPACE
namespace QInstaller {
- void INSTALLER_EXPORT openForWrite(QIODevice* dev, const QString& name);
- void INSTALLER_EXPORT openForRead(QIODevice* dev, const QString& name);
-
- qint64 INSTALLER_EXPORT blockingRead( QIODevice* in, char *buffer, qint64 size );
- qint64 INSTALLER_EXPORT blockingWrite( QIODevice* out, const char* buffer, qint64 size);
- qint64 INSTALLER_EXPORT blockingWrite( QIODevice* out, const QByteArray& ba );
- void INSTALLER_EXPORT blockingCopy( QIODevice* in, QIODevice* out, qint64 size );
-
- /**
- * Removes the directory at \a path recursively.
- * @param path The directory to remove
- * @param ignoreErrors if @p true, errors will be silently ignored. Otherwise an exception will be thrown if removing fails.
- *
- * @throws QInstaller::Error if the directory cannot be removed and ignoreErrors is @p false
- */
+class INSTALLER_EXPORT TempDirDeleter
+{
+public:
+ explicit TempDirDeleter(const QString &path);
+ explicit TempDirDeleter(const QStringList &paths = QStringList());
+ ~TempDirDeleter();
+
+ QStringList paths() const;
+
+ void add(const QString &path);
+ void add(const QStringList &paths);
+
+ void releaseAll();
+ void release(const QString &path);
+ void passAndReleaseAll(TempDirDeleter &tdd);
+ void passAndRelease(TempDirDeleter &tdd, const QString &path);
+
+private:
+ Q_DISABLE_COPY(TempDirDeleter)
+ QSet<QString> m_paths;
+};
+
+ void INSTALLER_EXPORT openForWrite(QIODevice *dev, const QString &name);
+ void INSTALLER_EXPORT openForRead(QIODevice *dev, const QString &name);
+
+ qint64 INSTALLER_EXPORT blockingRead(QIODevice *in, char *buffer, qint64 size);
+ void INSTALLER_EXPORT blockingCopy(QIODevice *in, QIODevice *out, qint64 size);
+ qint64 INSTALLER_EXPORT blockingWrite(QIODevice *out, const char* buffer, qint64 size);
+ qint64 INSTALLER_EXPORT blockingWrite(QIODevice *out, const QByteArray& ba);
+
+ /*!
+ Removes the directory at \a path recursively.
+ @param path The directory to remove
+ @param ignoreErrors if @p true, errors will be silently ignored. Otherwise an exception will be thrown
+ if removing fails.
+
+ @throws QInstaller::Error if the directory cannot be removed and ignoreErrors is @p false
+ */
void INSTALLER_EXPORT removeFiles(const QString &path, bool ignoreErrors = false);
- void INSTALLER_EXPORT removeDirectory( const QString& path, bool ignoreErrors = false );
- void INSTALLER_EXPORT removeDirectoryThreaded( const QString& path, bool ignoreErrors = false );
+ void INSTALLER_EXPORT removeDirectory(const QString &path, bool ignoreErrors = false);
+ void INSTALLER_EXPORT removeDirectoryThreaded(const QString &path, bool ignoreErrors = false);
- /**
- * Creates a temporary directory
- * @throws QInstaller::Error if creating the temporary directory fails
- */
- QString INSTALLER_EXPORT createTemporaryDirectory( const QString& templ=QString() );
+ /*!
+ Creates a temporary directory
+ @throws QInstaller::Error if creating the temporary directory fails
+ */
+ QString INSTALLER_EXPORT createTemporaryDirectory(const QString &templ=QString());
- QString INSTALLER_EXPORT generateTemporaryFileName( const QString& templ=QString() );
+ QString INSTALLER_EXPORT generateTemporaryFileName(const QString &templ=QString());
- void INSTALLER_EXPORT moveDirectoryContents( const QString& sourceDir, const QString& targetDir );
- void INSTALLER_EXPORT copyDirectoryContents( const QString& sourceDir, const QString& targetDir );
+ void INSTALLER_EXPORT moveDirectoryContents(const QString &sourceDir, const QString &targetDir);
+ void INSTALLER_EXPORT copyDirectoryContents(const QString &sourceDir, const QString &targetDir);
- bool INSTALLER_EXPORT isLocalUrl( const QUrl& url );
- QString INSTALLER_EXPORT pathFromUrl( const QUrl& url );
+ bool INSTALLER_EXPORT isLocalUrl(const QUrl &url);
+ QString INSTALLER_EXPORT pathFromUrl(const QUrl &url);
- void INSTALLER_EXPORT mkdir( const QString& path );
- void INSTALLER_EXPORT mkpath( const QString& path );
+ void INSTALLER_EXPORT mkdir(const QString &path);
+ void INSTALLER_EXPORT mkpath(const QString &path);
#ifdef Q_WS_WIN
- /**
- * Sets the .ico file at \a icon as application icon for \a application.
- */
- void INSTALLER_EXPORT setApplicationIcon( const QString& application, const QString& icon );
-
+ /*!
+ Sets the .ico file at \a icon as application icon for \a application.
+ */
+ void INSTALLER_EXPORT setApplicationIcon(const QString &application, const QString &icon);
#endif
-
- class INSTALLER_EXPORT TempDirDeleter
- {
- public:
- explicit TempDirDeleter( const QString& path );
- explicit TempDirDeleter( const QStringList& paths = QStringList() );
- ~TempDirDeleter();
- void releaseAll();
- void release( const QString& path );
- void passAndReleaseAll( TempDirDeleter& tdd );
- void passAndRelease( TempDirDeleter& tdd, const QString& path );
-
- void add( const QString& path );
- void add( const QStringList& paths );
- QStringList paths() const;
-
- private:
- Q_DISABLE_COPY(TempDirDeleter)
- QStringList m_paths;
- };
}
#endif // QINSTALLER_FILEUTILS_H