bool FileSystemManager::launchFile(QString filePath, QString arguments, QString workingDir, bool runAsElevated, bool quoteArgs, bool async) { QString errMsg; int rcVal = 0; // check if we should use the pidl LPCITEMIDLIST pidl = NULL; int virtualIconIndex = winOS->GetIconTypeFromFileName(filePath); if (virtualIconIndex > -1) pidl = winOS->GetPidlFromName(virtualIconIndex); // ensure that all the arguments are quoted QString wPath(filePath), wArgs(arguments), wDir(workingDir); ensureQuoted(wPath); if (quoteArgs) ensureQuoted(wArgs); ensureQuoted(wDir); // Try executing the file // Trying with ShellExecuteEx to see if we can fix the problems with .lnk not launching SHELLEXECUTEINFO sei = {0}; sei.cbSize = sizeof(sei); // #define SEE_MASK_NOZONECHECKS 0x00800000 sei.fMask = SEE_MASK_FLAG_LOG_USAGE | (pidl ? SEE_MASK_IDLIST : 0) | (async ? SEE_MASK_ASYNCOK : 0) | 0x00800000; sei.hwnd = winOS->GetWindowsHandle(); if (winOS->IsWindowsVersionGreaterThanOrEqualTo(WindowsVista) && runAsElevated) sei.lpVerb = L"runas"; // 'secret' verb to prompt for elevation on Vista else sei.lpVerb = NULL; // giving a null value for the verb forces it to use the default verb if (pidl) sei.lpIDList = (LPVOID) pidl; else sei.lpFile = (LPCTSTR) wPath.utf16(); sei.lpParameters = (LPCTSTR) wArgs.utf16(); sei.lpDirectory = (LPCTSTR) wDir.utf16(); sei.nShow = SW_SHOWNORMAL; return launchFile(sei,filePath); }
bool compressDir(const QString& sourceDir, const QString& subDir, const QString& targetFile, bool isUtf8) { QStringList compressFileList; compressFileList.push_back(subDir); QString sourceFolderPath = sourceDir; if (!sourceFolderPath.endsWith("/")) sourceFolderPath.append("/"); QStringList findFilesList; QDir wDir(sourceFolderPath + subDir); findFoldersAndFiles(wDir, findFilesList); wDir.setPath(sourceDir); for (int i = 0; i < findFilesList.size(); ++i) { QString rPath = wDir.relativeFilePath(findFilesList.at(i)); compressFileList.push_back(rPath); } if (!isUtf8) QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK")); QuaZip zip(targetFile); //zip.setFileNameCodec("GBK"); if (!zip.open(QuaZip::mdCreate)) { QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); return false; } QuaZipFile outFile(&zip); for (int i = 0; i < compressFileList.size(); i++) { QString sourceFolderPath = compressFileList.at(i); QFileInfo fileInfo(wDir.absoluteFilePath(compressFileList.at(i))); if (fileInfo.isDir()) { if (!sourceFolderPath.endsWith("/")) sourceFolderPath.append("/"); if (!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(sourceFolderPath, fileInfo.absoluteFilePath()))) { QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); return false; } outFile.close(); } else if (fileInfo.isFile()) { QFile inFile(fileInfo.absoluteFilePath()); if (!inFile.open(QIODevice::ReadOnly)) { zip.close(); QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); return false; } if (!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(sourceFolderPath, fileInfo.absoluteFilePath()))) { inFile.close(); zip.close(); QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); return false; } QByteArray buffer; int chunksize = 1024; buffer = inFile.read(chunksize); while (!buffer.isEmpty()) { outFile.write(buffer); buffer = inFile.read(chunksize); } outFile.close(); inFile.close(); } } zip.close(); QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); if (zip.getZipError()) return false; return true; }