summaryrefslogtreecommitdiffstats
path: root/qtools/qdir_win32.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qtools/qdir_win32.cpp')
-rw-r--r--qtools/qdir_win32.cpp149
1 files changed, 114 insertions, 35 deletions
diff --git a/qtools/qdir_win32.cpp b/qtools/qdir_win32.cpp
index 33c8cec..f1515a1 100644
--- a/qtools/qdir_win32.cpp
+++ b/qtools/qdir_win32.cpp
@@ -59,6 +59,24 @@ extern int qt_cmp_si( const void *, const void * );
}
#endif
+static QString p_getenv( QString name )
+{
+ DWORD len = GetEnvironmentVariableW( ( LPCWSTR ) qt_winTchar ( name, TRUE ), NULL, 0 );
+ if ( len == 0 )
+ return QString::null;
+ /* ansi: we allocate too much memory, but this shouldn't be the problem here ... */
+ LPWSTR buf = (LPWSTR)new WCHAR[ len ];
+ len = GetEnvironmentVariableW ( ( LPCWSTR ) qt_winTchar ( name, TRUE ), buf, len );
+ if ( len == 0 )
+ {
+ delete[] buf;
+ return QString::null;
+ }
+ QString ret = qt_winQString ( buf );
+ delete[] buf;
+ return ret;
+}
+
void QDir::slashify( QString& n )
{
@@ -71,12 +89,21 @@ void QDir::slashify( QString& n )
QString QDir::homeDirPath()
{
- QString d;
- d = QFile::decodeName(getenv("HOME"));
- slashify( d );
- if ( d.isNull() )
- d = rootDirPath();
- return d;
+ QString d = p_getenv ( "HOME" );
+ if ( d.isNull () ) {
+ d = p_getenv ( "USERPROFILE" );
+ if ( d.isNull () ) {
+ QString homeDrive = p_getenv ( "HOMEDRIVE" );
+ QString homePath = p_getenv ( "HOMEPATH" );
+ if ( !homeDrive.isNull () && !homePath.isNull () ) {
+ d = homeDrive + homePath;
+ } else {
+ d = rootDirPath ();
+ }
+ }
+ }
+ slashify( d );
+ return d;
}
QString QDir::canonicalPath() const
@@ -99,27 +126,38 @@ QString QDir::canonicalPath() const
bool QDir::mkdir( const QString &dirName, bool acceptAbsPath ) const
{
#if defined(__CYGWIN32_)
- return MKDIR( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 )
- == 0;
+ return MKDIR( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 ) == 0;
#else
- return MKDIR( QFile::encodeName(filePath(dirName,acceptAbsPath)) ) == 0;
-
+ return _wmkdir( ( LPCWSTR ) filePath( dirName, acceptAbsPath ).ucs2() ) == 0;
#endif
}
bool QDir::rmdir( const QString &dirName, bool acceptAbsPath ) const
{
+#if defined(__CYGWIN32_)
return RMDIR( QFile::encodeName(filePath(dirName,acceptAbsPath)) ) == 0;
+#else
+ return _wrmdir( ( LPCWSTR ) filePath( dirName, acceptAbsPath ).ucs2() ) == 0;
+#endif
}
bool QDir::isReadable() const
{
+ QString path = dPath;
+ if ( ( path[ 0 ] == '\\' ) || ( path[ 0 ] == '/' ) )
+ path = rootDirPath() + path;
+#if defined(__CYGWIN32_)
return ACCESS( QFile::encodeName(dPath), R_OK ) == 0;
+#else
+ return ( _waccess( (wchar_t*) path.ucs2(), R_OK ) == 0 );
+#endif
}
bool QDir::isRoot() const
{
- return dPath == QString::fromLatin1("/");
+ QString path = dPath;
+ slashify( path );
+ return path == rootDirPath ();
}
bool QDir::rename( const QString &name, const QString &newName,
@@ -133,21 +171,33 @@ bool QDir::rename( const QString &name, const QString &newName,
}
QString fn1 = filePath( name, acceptAbsPaths );
QString fn2 = filePath( newName, acceptAbsPaths );
+#if defined(__CYGWIN32_)
return ::rename( QFile::encodeName(fn1),
QFile::encodeName(fn2) ) == 0;
+#else
+ return MoveFileW( ( LPCWSTR ) fn1.ucs2(), ( LPCWSTR ) fn2.ucs2() ) != 0;
+#endif
}
bool QDir::setCurrent( const QString &path )
{
+#if defined(__CYGWIN32_)
int r;
r = CHDIR( QFile::encodeName(path) );
return r >= 0;
+#else
+ if ( !QDir( path ).exists() )
+ return false;
+ return ( SetCurrentDirectoryW( ( LPCWSTR ) path.ucs2() ) >= 0 );
+#endif
}
QString QDir::currentDirPath()
{
QString result;
+#if defined(__CYGWIN32_)
+
STATBUF st;
if ( STAT( ".", &st ) == 0 ) {
char currentName[PATH_MAX];
@@ -162,25 +212,47 @@ QString QDir::currentDirPath()
qWarning( "QDir::currentDirPath: stat(\".\") failed" );
#endif
}
+
+#else
+
+ DWORD size = 0;
+ WCHAR currentName[ PATH_MAX ];
+ size = ::GetCurrentDirectoryW( PATH_MAX, currentName );
+ if ( size != 0 ) {
+ if ( size > PATH_MAX ) {
+ WCHAR * newCurrentName = new WCHAR[ size ];
+ if ( ::GetCurrentDirectoryW( PATH_MAX, newCurrentName ) != 0 )
+ result = QString::fromUcs2( ( ushort* ) newCurrentName );
+ delete [] newCurrentName;
+ } else {
+ result = QString::fromUcs2( ( ushort* ) currentName );
+ }
+ }
+
+ if ( result.length() >= 2 && result[ 1 ] == ':' )
+ result[ 0 ] = result.at( 0 ).upper(); // Force uppercase drive letters.
+#endif
slashify( result );
return result;
}
QString QDir::rootDirPath()
{
- QString d = QString::fromLatin1( "/" );
- return d;
+ QString d = p_getenv ( "SystemDrive" );
+ if ( d.isNull () )
+ d = QString::fromLatin1( "c:" ); // not "c:\\" !
+ slashify ( d );
+ return d;
}
bool QDir::isRelativePath( const QString &path )
{
- int len = path.length();
- if ( len == 0 )
- return TRUE;
- int i = 0;
- if ( isalpha(path[0]) && path[1] == ':' ) // drive, e.g. a:
- i = 2;
- return path[i] != '/' && path[i] != '\\';
+ if ( path.isEmpty() )
+ return TRUE;
+ int p = 0;
+ if ( path[ 0 ].isLetter() && path[ 1 ] == ':' )
+ p = 2; // we have checked the first 2.
+ return ( ( path[ p ] != '/' ) && ( path[ p ] != '\\' ) );
}
#undef IS_SUBDIR
@@ -249,7 +321,7 @@ bool QDir::readDirEntries( const QString &nameFilter,
int plen = p.length();
#if defined(_OS_WIN32_)
HANDLE ff;
- WIN32_FIND_DATA finfo;
+ WIN32_FIND_DATAW finfo;
#else
long ff;
_finddata_t finfo;
@@ -266,7 +338,11 @@ bool QDir::readDirEntries( const QString &nameFilter,
p += '/';
p += "*.*";
+#if defined(__CYGWIN32_)
ff = FF_GETFIRST( p.data(), &finfo );
+#else
+ ff = FindFirstFileW ( ( LPCWSTR ) p.ucs2(), &finfo );
+#endif
if ( ff == FF_ERROR )
{
#if defined(DEBUG)
@@ -282,18 +358,20 @@ bool QDir::readDirEntries( const QString &nameFilter,
first = FALSE;
else
{
-#if defined(_OS_WIN32_)
- if ( !FF_GETNEXT(ff,&finfo) )
- break;
-#else
+#if defined(__CYGWIN32_)
if ( FF_GETNEXT(ff,&finfo) == -1 )
break;
+#else
+ //if ( !FF_GETNEXT(ff,&finfo) )
+ // break;
+ if (!FindNextFileW(ff, &finfo ))
+ break;
#endif
}
-#if defined(_OS_WIN32_)
- int attrib = finfo.dwFileAttributes;
-#else
+#if defined(__CYGWIN32_)
int attrib = finfo.attrib;
+#else
+ int attrib = finfo.dwFileAttributes;
#endif
bool isDir = (attrib & IS_SUBDIR) != 0;
bool isFile = !isDir;
@@ -305,12 +383,13 @@ bool QDir::readDirEntries( const QString &nameFilter,
bool isHidden = (attrib & IS_HIDDEN) != 0;
bool isSystem = (attrib & IS_SYSTEM) != 0;
-#if defined(_OS_WIN32_)
- const char *fname = finfo.cFileName;
-#else
+#if defined(__CYGWIN32_)
const char *fname = finfo.name;
+#else
+ //const char *fname = finfo.cFileName;
+ QString fname = QString::fromUcs2( ( const unsigned short* ) finfo.cFileName);
#endif
- if ( wc.match(fname) == -1 && !(allDirs && isDir) )
+ if ( wc.match(fname.utf8()) == -1 && !(allDirs && isDir) )
continue;
QString name = fname;
@@ -341,10 +420,10 @@ bool QDir::readDirEntries( const QString &nameFilter,
fiList->append( new QFileInfo( fi ) );
}
}
-#if defined(_OS_WIN32_)
- FindClose( ff );
-#else
+#if defined(__CYGWIN32_)
_findclose( ff );
+#else
+ FindClose( ff );
#endif
// Sort...