1.1 --- a/file.cpp Wed Jun 20 11:58:46 2007 +0000
1.2 +++ b/file.cpp Fri Nov 09 12:07:20 2007 +0000
1.3 @@ -1,3 +1,4 @@
1.4 +#include <QDir>
1.5 #include <QMessageBox>
1.6 #include <QPixmap>
1.7 #include <QLabel>
1.8 @@ -7,6 +8,11 @@
1.9 #include "file.h"
1.10 #include "process.h"
1.11
1.12 +// Avoid full inclusion of io.h by just defining mktemp's prototype here.
1.13 +#if defined(Q_OS_WIN32)
1.14 +extern "C" char *_mktemp(char *fmt);
1.15 +#include <windows.h>
1.16 +#endif
1.17
1.18 QString maskPath(QString p)
1.19 {
1.20 @@ -95,7 +101,7 @@
1.21 QMessageBox::Warning,
1.22 QMessageBox::Yes ,
1.23 QMessageBox::Cancel | QMessageBox::Default,
1.24 - QMessageBox::QMessageBox::NoButton );
1.25 + QMessageBox::NoButton );
1.26
1.27 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
1.28 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
1.29 @@ -112,11 +118,29 @@
1.30 return true;
1.31 }
1.32
1.33 +QString makeTmpDir (bool &ok, QString prefix)
1.34 +{
1.35 + bool b;
1.36 + QString path=makeUniqueDir (b,QDir::tempPath()+"/"+prefix+"-XXXXXX");
1.37 + ok=b;
1.38 + return path;
1.39 +}
1.40 +
1.41 +bool isInTmpDir(QString fn)
1.42 +{
1.43 + QString temp=QDir::tempPath();
1.44 + int l=temp.length();
1.45 + return fn.left(l)==temp;
1.46 +}
1.47 +
1.48 QString makeUniqueDir (bool &ok,QString s)
1.49 {
1.50 - // Create unique directory e.g. s="/tmp/vym-XXXXXX"
1.51 + // Create unique directory e.g. for s="/tmp/vym-XXXXXX"
1.52
1.53 - // Convert QString to string first
1.54 + // Convert Separators
1.55 + s=QDir::convertSeparators(s);
1.56 +
1.57 + // Convert QString to string
1.58 ok=true;
1.59 char *p;
1.60 int bytes=s.length();
1.61 @@ -125,7 +149,13 @@
1.62 for (i=0;i<bytes;i++)
1.63 p[i]=s.at(i).latin1();
1.64 p[bytes]=0;
1.65 +
1.66 +#if defined(Q_OS_WIN32)
1.67 + // There's no mkdtemp on VCEE.
1.68 + QString r=_mktemp(p);
1.69 +#else
1.70 QString r=mkdtemp (p);
1.71 +#endif
1.72 if (r.isEmpty()) ok=false;
1.73 free (p);
1.74 return r;
1.75 @@ -133,9 +163,9 @@
1.76
1.77 void removeDir(QDir d)
1.78 {
1.79 - if (d.path().left(4)!="/tmp")
1.80 + // This check should_ not be necessary, but proved to be useful ;-)
1.81 + if (!isInTmpDir(d.path()))
1.82 {
1.83 - // This _should_ not be necessary, but proved to be useful ;-)
1.84 qWarning ("file.cpp::removeDir should remove "+d.path()+" - aborted.");
1.85 return;
1.86 }
1.87 @@ -276,6 +306,7 @@
1.88 ErrorCode err=success;
1.89
1.90 // Try to unzip file
1.91 +#if !defined(Q_OS_WIN32)
1.92 QStringList args;
1.93 Process *zipProc=new Process ();
1.94 zipProc->setWorkingDirectory (zipDir.path());
1.95 @@ -317,6 +348,45 @@
1.96 }
1.97 }
1.98 }
1.99 +#else
1.100 + // Do this process creation using Win32 API.
1.101 + //! Create process.
1.102 + PROCESS_INFORMATION piProcInfo;
1.103 + STARTUPINFO siStartInfo;
1.104 +
1.105 + // Initialize members of the PROCESS_INFORMATION structure.
1.106 + ::ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
1.107 +
1.108 + // Set up members of the STARTUPINFO structure.
1.109 + ::ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
1.110 + siStartInfo.cb = sizeof(STARTUPINFO);
1.111 +
1.112 + // Create command line.
1.113 + QString argv("unzip -o ");
1.114 + argv.append(QDir::convertSeparators(zipName));
1.115 + argv.append(" -d ");
1.116 + argv.append(QDir::convertSeparators(zipDir.path()));
1.117 +
1.118 + // Create the child process.
1.119 + if( !::CreateProcess(NULL,
1.120 + (LPWSTR)argv.unicode(), // command line
1.121 + NULL, // process security attributes
1.122 + NULL, // primary thread security attributes
1.123 + TRUE, // handles are inherited
1.124 + 0, // creation flags
1.125 + NULL, // use parent's environment
1.126 + NULL, // use parent's current directory
1.127 + &siStartInfo, // STARTUPINFO pointer
1.128 + &piProcInfo) ) // receives PROCESS_INFORMATION
1.129 + {
1.130 + err = aborted;
1.131 + }
1.132 + else
1.133 + {
1.134 + // Wait for it to finish.
1.135 + ::WaitForSingleObject( piProcInfo.hProcess, 10000 );
1.136 + }
1.137 +#endif
1.138 return err;
1.139 }
1.140