comparison kdiff3/src/fileaccess.cpp @ 58:8af4bb9d9a5a

Version 0.9.83
author joachim99
date Sun, 07 Mar 2004 09:59:09 +0000
parents 32d5cbf9db71
children efe33e938730
comparison
equal deleted inserted replaced
57:023fbd76c1e3 58:8af4bb9d9a5a
33 #include <sys/stat.h> 33 #include <sys/stat.h>
34 34
35 #ifdef _WIN32 35 #ifdef _WIN32
36 #include <sys/utime.h> 36 #include <sys/utime.h>
37 #include <io.h> 37 #include <io.h>
38 #include <windows.h>
38 #else 39 #else
39 #include <unistd.h> // Needed for creating symbolic links via symlink(). 40 #include <unistd.h> // Needed for creating symbolic links via symlink().
40 #include <utime.h> 41 #include <utime.h>
41 #endif 42 #endif
42 43
202 S_IROTH 00004 others have read permission 203 S_IROTH 00004 others have read permission
203 S_IWOTH 00002 others have write permisson 204 S_IWOTH 00002 others have write permisson
204 S_IXOTH 00001 others have execute permission 205 S_IXOTH 00001 others have execute permission
205 */ 206 */
206 207
208 #ifdef KREPLACEMENTS_H
209 void FileAccess::setUdsEntry( const KIO::UDSEntry& ){} // not needed if KDE is not available
210 #else
207 void FileAccess::setUdsEntry( const KIO::UDSEntry& e ) 211 void FileAccess::setUdsEntry( const KIO::UDSEntry& e )
208 { 212 {
209 #ifndef KREPLACEMENTS_H
210 KIO::UDSEntry::const_iterator ei; 213 KIO::UDSEntry::const_iterator ei;
211 long acc = 0; 214 long acc = 0;
212 long fileType = 0; 215 long fileType = 0;
213 for( ei=e.begin(); ei!=e.end(); ++ei ) 216 for( ei=e.begin(); ei!=e.end(); ++ei )
214 { 217 {
260 { 263 {
261 int pos = m_path.findRev('/') + 1; 264 int pos = m_path.findRev('/') + 1;
262 m_name = m_path.mid( pos ); 265 m_name = m_path.mid( pos );
263 } 266 }
264 m_bHidden = m_name[0]=='.'; 267 m_bHidden = m_name[0]=='.';
268 }
265 #endif 269 #endif
266 }
267 270
268 271
269 bool FileAccess::isValid() const { return m_bValidData; } 272 bool FileAccess::isValid() const { return m_bValidData; }
270 bool FileAccess::isFile() const { return m_bFile; } 273 bool FileAccess::isFile() const { return m_bFile; }
271 bool FileAccess::isDir() const { return m_bDir; } 274 bool FileAccess::isDir() const { return m_bDir; }
340 return jh.get( pDestBuffer, maxLength ); 343 return jh.get( pDestBuffer, maxLength );
341 } 344 }
342 return false; 345 return false;
343 } 346 }
344 347
345 bool FileAccess::writeFile( void* pSrcBuffer, unsigned long length ) 348 bool FileAccess::writeFile( const void* pSrcBuffer, unsigned long length )
346 { 349 {
347 if (m_bLocal) 350 if (m_bLocal)
348 { 351 {
349 QFile f( filePath() ); 352 QFile f( filePath() );
350 if ( f.open( IO_WriteOnly ) ) 353 if ( f.open( IO_WriteOnly ) )
422 #ifdef _WIN32 425 #ifdef _WIN32
423 QString tmpDir = getenv("TEMP"); 426 QString tmpDir = getenv("TEMP");
424 for(int i=0; ;++i) 427 for(int i=0; ;++i)
425 { 428 {
426 // short filenames for WIN98 because for system() the command must not exceed 120 characters. 429 // short filenames for WIN98 because for system() the command must not exceed 120 characters.
427 fileName = tmpDir + "/" + QString::number(i); 430 fileName = tmpDir + "\\" + QString::number(i);
428 if ( ! FileAccess::exists(fileName) ) 431 if ( ! FileAccess::exists(fileName) )
429 break; 432 break;
430 } 433 }
431 #else 434 #else
432 QString tmpDir = "/tmp"; 435 QString tmpDir = "/tmp";
622 ::memcpy( m_pTransferBuffer + m_transferredBytes, newData.data(), newData.size() ); 625 ::memcpy( m_pTransferBuffer + m_transferredBytes, newData.data(), newData.size() );
623 m_transferredBytes += length; 626 m_transferredBytes += length;
624 } 627 }
625 } 628 }
626 629
627 bool FileAccessJobHandler::put(void* pSrcBuffer, long maxLength, bool bOverwrite, bool bResume, int permissions ) 630 bool FileAccessJobHandler::put(const void* pSrcBuffer, long maxLength, bool bOverwrite, bool bResume, int permissions )
628 { 631 {
629 if ( maxLength>0 ) 632 if ( maxLength>0 )
630 { 633 {
631 KIO::TransferJob* pJob = KIO::put( m_pFileAccess->m_url, permissions, bOverwrite, bResume, false ); 634 KIO::TransferJob* pJob = KIO::put( m_pFileAccess->m_url, permissions, bOverwrite, bResume, false );
632 m_transferredBytes = 0; 635 m_transferredBytes = 0;
1165 if( m_pFileAccess->isLocal() ) 1168 if( m_pFileAccess->isLocal() )
1166 { 1169 {
1167 m_bSuccess = QDir::setCurrent( m_pFileAccess->absFilePath() ); 1170 m_bSuccess = QDir::setCurrent( m_pFileAccess->absFilePath() );
1168 if ( m_bSuccess ) 1171 if ( m_bSuccess )
1169 { 1172 {
1173 #ifndef _WIN32
1170 m_bSuccess = true; 1174 m_bSuccess = true;
1171 QDir dir( "." ); 1175 QDir dir( "." );
1172 1176
1173 dir.setSorting( QDir::Name | QDir::DirsFirst ); 1177 dir.setSorting( QDir::Name | QDir::DirsFirst );
1174 dir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden ); 1178 dir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden );
1190 continue; 1194 continue;
1191 1195
1192 pDirList->push_back( FileAccess( nicePath(*fi) ) ); 1196 pDirList->push_back( FileAccess( nicePath(*fi) ) );
1193 } 1197 }
1194 } 1198 }
1199 #else
1200 QString pattern ="*.*";
1201 WIN32_FIND_DATA findData;
1202 WIN32_FIND_DATAA& findDataA=*(WIN32_FIND_DATAA*)&findData; // Needed for Win95
1203
1204 HANDLE searchHandle = QT_WA_INLINE(
1205 FindFirstFile( (TCHAR*)pattern.ucs2(), &findData ),
1206 FindFirstFileA( pattern.local8Bit(), &findDataA )
1207 );
1208
1209 if ( searchHandle != INVALID_HANDLE_VALUE )
1210 {
1211 QString absPath = m_pFileAccess->absFilePath();
1212 QString relPath = m_pFileAccess->filePath();
1213 bool bFirst=true;
1214 while( ! g_pProgressDialog->wasCancelled() )
1215 {
1216 if (!bFirst)
1217 {
1218 if ( ! QT_WA_INLINE(
1219 FindNextFile(searchHandle,&findData),
1220 FindNextFileA(searchHandle,&findDataA)) )
1221 break;
1222 }
1223 bFirst = false;
1224 FileAccess fa;
1225 fa.m_size = findData.nFileSizeLow ;//+ findData.nFileSizeHigh;
1226
1227 FILETIME ft;
1228 SYSTEMTIME t;
1229 FileTimeToLocalFileTime( &findData.ftLastWriteTime, &ft ); FileTimeToSystemTime(&ft,&t);
1230 fa.m_modificationTime = QDateTime( QDate(t.wYear, t.wMonth, t.wDay), QTime(t.wHour, t.wMinute, t.wSecond) );
1231 FileTimeToLocalFileTime( &findData.ftLastAccessTime, &ft ); FileTimeToSystemTime(&ft,&t);
1232 fa.m_accessTime = QDateTime( QDate(t.wYear, t.wMonth, t.wDay), QTime(t.wHour, t.wMinute, t.wSecond) );
1233 FileTimeToLocalFileTime( &findData.ftCreationTime, &ft ); FileTimeToSystemTime(&ft,&t);
1234 fa.m_creationTime = QDateTime( QDate(t.wYear, t.wMonth, t.wDay), QTime(t.wHour, t.wMinute, t.wSecond) );
1235
1236 int a = findData.dwFileAttributes;
1237 fa.m_bWritable = ( a & FILE_ATTRIBUTE_READONLY) == 0;
1238 fa.m_bDir = ( a & FILE_ATTRIBUTE_DIRECTORY ) != 0;
1239 fa.m_bFile = !fa.m_bDir;
1240 fa.m_bHidden = ( a & FILE_ATTRIBUTE_HIDDEN) != 0;
1241
1242 fa.m_bExecutable = false; // Useless on windows
1243 fa.m_bExists = true;
1244 fa.m_bReadable = true;
1245 fa.m_bLocal = true;
1246 fa.m_bValidData = true;
1247 fa.m_bSymLink = false;
1248 fa.m_fileType = 0;
1249
1250 fa.m_name = QT_WA_INLINE(
1251 QString::fromUcs2(findData.cFileName),
1252 QString::fromLocal8Bit(findDataA.cFileName)
1253 );
1254
1255 fa.m_path = fa.m_name;
1256 fa.m_absFilePath = absPath + "/" + fa.m_name;
1257 fa.m_url.setPath( fa.m_absFilePath );
1258 if ( fa.m_name!="." && fa.m_name!=".." )
1259 pDirList->push_back( fa );
1260 }
1261 FindClose( searchHandle );
1262 }
1263 else
1264 {
1265 return false;
1266 }
1267 #endif
1195 } 1268 }
1196 } 1269 }
1197 else 1270 else
1198 { 1271 {
1199 bool bShowProgress = false; 1272 bool bShowProgress = false;