diff -r 27cb122a88a6 -r 7ee5bf3647d3 file.cpp --- a/file.cpp Wed Jun 20 11:58:46 2007 +0000 +++ b/file.cpp Thu Nov 08 15:28:03 2007 +0000 @@ -1,3 +1,4 @@ +#include #include #include #include @@ -7,6 +8,11 @@ #include "file.h" #include "process.h" +// Avoid full inclusion of io.h by just defining mktemp's prototype here. +#if defined(Q_OS_WIN32) +extern "C" char *_mktemp(char *fmt); +#include +#endif QString maskPath(QString p) { @@ -95,7 +101,7 @@ QMessageBox::Warning, QMessageBox::Yes , QMessageBox::Cancel | QMessageBox::Default, - QMessageBox::QMessageBox::NoButton ); + QMessageBox::NoButton ); mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") ); mb.setButtonText( QMessageBox::No, QObject::tr("Cancel")); @@ -112,11 +118,29 @@ return true; } +QString makeTmpDir (bool &ok, QString prefix) +{ + bool b; + QString path=makeUniqueDir (b,QDir::tempPath()+"/"+prefix+"-XXXXXX"); + ok=b; + return path; +} + +bool isInTmpDir(QString fn) +{ + QString temp=QDir::tempPath(); + int l=temp.length(); + return fn.left(l)==temp; +} + QString makeUniqueDir (bool &ok,QString s) { - // Create unique directory e.g. s="/tmp/vym-XXXXXX" + // Create unique directory e.g. for s="/tmp/vym-XXXXXX" - // Convert QString to string first + // Convert Separators + s=QDir::convertSeparators(s); + + // Convert QString to string ok=true; char *p; int bytes=s.length(); @@ -125,7 +149,13 @@ for (i=0;isetWorkingDirectory (zipDir.path()); @@ -317,6 +348,45 @@ } } } +#else + // Do this process creation using Win32 API. + //! Create process. + PROCESS_INFORMATION piProcInfo; + STARTUPINFO siStartInfo; + + // Initialize members of the PROCESS_INFORMATION structure. + ::ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) ); + + // Set up members of the STARTUPINFO structure. + ::ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) ); + siStartInfo.cb = sizeof(STARTUPINFO); + + // Create command line. + QString argv("unzip -o "); + argv.append(QDir::convertSeparators(zipName)); + argv.append(" -d "); + argv.append(QDir::convertSeparators(zipDir.path())); + + // Create the child process. + if( !::CreateProcess(NULL, + (LPWSTR)argv.unicode(), // command line + NULL, // process security attributes + NULL, // primary thread security attributes + TRUE, // handles are inherited + 0, // creation flags + NULL, // use parent's environment + NULL, // use parent's current directory + &siStartInfo, // STARTUPINFO pointer + &piProcInfo) ) // receives PROCESS_INFORMATION + { + err = aborted; + } + else + { + // Wait for it to finish. + ::WaitForSingleObject( piProcInfo.hProcess, 10000 ); + } +#endif return err; }