Various patches: Better windows support, branch sorting, Freedesktop support
authorinsilmaril
Mon, 22 Oct 2007 09:50:03 +0000
changeset 60684c73902f727
parent 605 12e4596e7bb7
child 607 53c66cb9f5bd
Various patches: Better windows support, branch sorting, Freedesktop support
exports.cpp
file.cpp
     1.1 --- a/exports.cpp	Mon Oct 22 09:50:03 2007 +0000
     1.2 +++ b/exports.cpp	Mon Oct 22 09:50:03 2007 +0000
     1.3 @@ -14,7 +14,7 @@
     1.4  {
     1.5  	indentPerDepth="  ";
     1.6  	bool ok;
     1.7 -    tmpDir.setPath (makeUniqueDir(ok,"/tmp/vym-export-XXXXXX"));
     1.8 +    tmpDir.setPath (makeTmpDir(ok,"vym-export"));
     1.9  	if (!tmpDir.exists() || !ok)
    1.10  		QMessageBox::critical( 0, QObject::tr( "Error" ),
    1.11  					   QObject::tr("Couldn't access temporary directory\n"));
     2.1 --- a/file.cpp	Mon Oct 22 09:50:03 2007 +0000
     2.2 +++ b/file.cpp	Mon Oct 22 09:50:03 2007 +0000
     2.3 @@ -1,3 +1,4 @@
     2.4 +#include <QDir>
     2.5  #include <QMessageBox>
     2.6  #include <QPixmap>
     2.7  #include <QLabel>
     2.8 @@ -7,6 +8,11 @@
     2.9  #include "file.h"
    2.10  #include "process.h"
    2.11  
    2.12 +// Avoid full inclusion of io.h by just defining mktemp's prototype here.
    2.13 +#if defined(Q_OS_WIN32)
    2.14 +extern "C" char *_mktemp(char *fmt);
    2.15 +#include <windows.h>
    2.16 +#endif
    2.17  
    2.18  QString maskPath(QString p)
    2.19  {
    2.20 @@ -95,7 +101,7 @@
    2.21  		QMessageBox::Warning,
    2.22  		QMessageBox::Yes ,
    2.23  		QMessageBox::Cancel | QMessageBox::Default,
    2.24 -		QMessageBox::QMessageBox::NoButton );
    2.25 +		QMessageBox::NoButton );
    2.26  
    2.27  		mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
    2.28  		mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
    2.29 @@ -112,11 +118,29 @@
    2.30  	return true;
    2.31  }
    2.32  
    2.33 +QString makeTmpDir (bool &ok, QString prefix)
    2.34 +{
    2.35 +	bool b;
    2.36 +	QString path=makeUniqueDir (b,QDir::tempPath()+"/"+prefix+"-XXXXXX");
    2.37 +	ok=b;
    2.38 +	return path;
    2.39 +}
    2.40 +
    2.41 +bool isInTmpDir(QString fn)
    2.42 +{
    2.43 +	QString temp=QDir::tempPath();
    2.44 +	int l=temp.length();
    2.45 +	return fn.left(l)==temp;
    2.46 +}
    2.47 +
    2.48  QString makeUniqueDir (bool &ok,QString s)
    2.49  {
    2.50 -	// Create unique directory e.g. s="/tmp/vym-XXXXXX"
    2.51 +	// Create unique directory e.g. for s="/tmp/vym-XXXXXX"
    2.52  
    2.53 -	// Convert QString to string first
    2.54 +	// Convert Separators
    2.55 +	s=QDir::convertSeparators(s);
    2.56 +
    2.57 +	// Convert QString to string 
    2.58  	ok=true;
    2.59  	char *p;
    2.60  	int bytes=s.length();
    2.61 @@ -125,7 +149,13 @@
    2.62  	for (i=0;i<bytes;i++)
    2.63  		p[i]=s.at(i).latin1();
    2.64  	p[bytes]=0;	
    2.65 +
    2.66 +#if defined(Q_OS_WIN32)
    2.67 +    // There's no mkdtemp on VCEE.
    2.68 +    QString r=_mktemp(p);
    2.69 +#else
    2.70  	QString r=mkdtemp (p);
    2.71 +#endif
    2.72  	if (r.isEmpty()) ok=false;
    2.73  	free (p);
    2.74  	return r;
    2.75 @@ -133,9 +163,9 @@
    2.76  
    2.77  void removeDir(QDir d)
    2.78  {
    2.79 -	if (d.path().left(4)!="/tmp")
    2.80 +	// This check should_ not be necessary, but proved to be useful ;-)
    2.81 +	if (!isInTmpDir(d.path()))
    2.82  	{
    2.83 -		// This _should_ not be necessary, but proved to be useful ;-)
    2.84  		qWarning ("file.cpp::removeDir should remove "+d.path()+" - aborted.");
    2.85  		return;
    2.86  	}
    2.87 @@ -276,6 +306,7 @@
    2.88  	ErrorCode err=success;
    2.89  
    2.90  	// Try to unzip file
    2.91 +#if !defined(Q_OS_WIN32)
    2.92  	QStringList args;
    2.93  	Process *zipProc=new Process ();
    2.94  	zipProc->setWorkingDirectory (zipDir.path());
    2.95 @@ -317,6 +348,45 @@
    2.96  			} 
    2.97  		}
    2.98  	}
    2.99 +#else
   2.100 +    // Do this process creation using Win32 API.
   2.101 +    //! Create process.
   2.102 +    PROCESS_INFORMATION piProcInfo;
   2.103 +    STARTUPINFO siStartInfo;
   2.104 +
   2.105 +    // Initialize members of the PROCESS_INFORMATION structure.
   2.106 +    ::ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
   2.107 +
   2.108 +    // Set up members of the STARTUPINFO structure.
   2.109 +    ::ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
   2.110 +    siStartInfo.cb = sizeof(STARTUPINFO);
   2.111 +
   2.112 +    // Create command line.
   2.113 +    QString argv("unzip -o ");
   2.114 +    argv.append(QDir::convertSeparators(zipName));
   2.115 +    argv.append(" -d ");
   2.116 +    argv.append(QDir::convertSeparators(zipDir.path()));
   2.117 +
   2.118 +    // Create the child process.
   2.119 +    if( !::CreateProcess(NULL, 
   2.120 +        (LPWSTR)argv.unicode(), // command line
   2.121 +        NULL, // process security attributes
   2.122 +        NULL, // primary thread security attributes
   2.123 +        TRUE, // handles are inherited
   2.124 +        0, // creation flags
   2.125 +        NULL, // use parent's environment
   2.126 +        NULL, // use parent's current directory
   2.127 +        &siStartInfo, // STARTUPINFO pointer
   2.128 +        &piProcInfo) ) // receives PROCESS_INFORMATION
   2.129 +    {
   2.130 +        err = aborted;
   2.131 +    }
   2.132 +    else
   2.133 +    {
   2.134 +        // Wait for it to finish.
   2.135 +        ::WaitForSingleObject( piProcInfo.hProcess, 10000 );
   2.136 +    }
   2.137 +#endif
   2.138  	return err;	
   2.139  }
   2.140