14 * |
14 * |
15 * Description: |
15 * Description: |
16 * The source file of the file manager utilities on windows |
16 * The source file of the file manager utilities on windows |
17 */ |
17 */ |
18 |
18 |
|
19 #include "fmutils.h" |
|
20 |
19 #include <windows.h> |
21 #include <windows.h> |
20 |
22 |
21 #include "fmutils.h" |
|
22 #include <QDir> |
23 #include <QDir> |
|
24 #include <QUrl> |
|
25 #include <QVariant> |
23 #include <QFileInfo> |
26 #include <QFileInfo> |
24 #include <QDesktopServices> |
27 #include <QDesktopServices> |
25 #include <QUrl> |
|
26 #include <QVariant> |
|
27 |
28 |
28 #include <hbglobal.h> |
29 #include <hbglobal.h> |
29 |
30 |
30 #define BURCONFIGFILE "burconfig.xml" |
31 #define BURCONFIGFILE "burconfig.xml" |
31 const int KMaxFileName=0x100; |
32 const int KMaxFileName=0x100; |
32 const int KMaxPath=0x100; |
33 const int KMaxPath=0x100; |
33 |
34 |
34 QString FmUtils::getDriveNameFromPath( const QString &path ) |
35 FmDriverInfo FmUtils::queryDriverInfo( const QString &driveName ) |
35 { |
|
36 if( path.length() <3 ) { |
|
37 return QString(); |
|
38 } |
|
39 return path.left( 3 ); |
|
40 } |
|
41 |
|
42 QString FmUtils::getDriveLetterFromPath( const QString &path ) |
|
43 { |
|
44 if( path.length() <3 ) { |
|
45 return QString(); |
|
46 } |
|
47 return path.left( 1 ); |
|
48 } |
|
49 |
|
50 FmDriverInfo FmUtils::queryDriverInfo( const QString &driverName ) |
|
51 { |
36 { |
52 quint64 size = 0; |
37 quint64 size = 0; |
53 quint64 freeSize = 0; |
38 quint64 freeSize = 0; |
54 QString driver = driverName; |
39 QString drive = driveName; |
55 |
40 |
56 driver.replace( '/', "\\" ); |
41 drive.replace( '/', "\\" ); |
57 if ( driver.right(1) != "\\" ) { |
42 if ( drive.right(1) != "\\" ) { |
58 driver.append( "\\" ); |
43 drive.append( "\\" ); |
59 } |
44 } |
60 GetDiskFreeSpaceEx( (LPCWSTR)driver.constData(), |
45 GetDiskFreeSpaceEx( (LPCWSTR)drive.constData(), |
61 (PULARGE_INTEGER)&freeSize, |
46 (PULARGE_INTEGER)&freeSize, |
62 (PULARGE_INTEGER)&size, |
47 (PULARGE_INTEGER)&size, |
63 0 ); |
48 0 ); |
64 |
49 |
65 TCHAR volumeName[MAX_PATH + 1] = { 0 }; |
50 TCHAR volumeName[MAX_PATH + 1] = { 0 }; |
66 GetVolumeInformation( (LPCWSTR)driver.constData(), |
51 GetVolumeInformation( (LPCWSTR)drive.constData(), |
67 &volumeName[0], |
52 &volumeName[0], |
68 MAX_PATH + 1, |
53 MAX_PATH + 1, |
69 0, |
54 0, |
70 0, |
55 0, |
71 0, |
56 0, |
72 0, |
57 0, |
73 0 ); |
58 0 ); |
74 |
59 |
75 quint32 state( 0 ); |
60 quint32 state( 0 ); |
76 quint32 drvStatus = GetDriveType( (LPCWSTR)driver.constData() ); |
61 quint32 drvStatus = GetDriveType( (LPCWSTR)drive.constData() ); |
77 if ( drvStatus == DRIVE_REMOVABLE ) { |
62 if ( drvStatus == DRIVE_REMOVABLE ) { |
78 state |= FmDriverInfo::EDriveRemovable; |
63 state |= FmDriverInfo::EDriveRemovable; |
79 } |
64 } |
80 #ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_ |
65 |
81 if ( driverName.contains( Drive_D, Qt::CaseInsensitive ) ) { |
|
82 state |= FmDriverInfo::EDriveNotPresent; |
|
83 } |
|
84 #endif |
|
85 |
|
86 #ifdef _DEBUG_LOCKED_DRIVE_Z |
|
87 if ( driverName.contains( Drive_Z, Qt::CaseInsensitive ) ) { |
|
88 state |= FmDriverInfo::EDriveLocked; |
|
89 } |
|
90 #endif |
|
91 if( !(state&FmDriverInfo::EDriveNotPresent) && !(state&FmDriverInfo::EDriveLocked) && |
66 if( !(state&FmDriverInfo::EDriveNotPresent) && !(state&FmDriverInfo::EDriveLocked) && |
92 !(state&FmDriverInfo::EDriveCorrupted) ) { |
67 !(state&FmDriverInfo::EDriveCorrupted) ) { |
93 state |= FmDriverInfo::EDriveAvailable; |
68 state |= FmDriverInfo::EDriveAvailable; |
94 } |
69 } |
95 return FmDriverInfo( size, freeSize, driverName, QString::fromWCharArray( &volumeName[0] ), state ); |
70 return FmDriverInfo( size, freeSize, driveName, QString::fromWCharArray( &volumeName[0] ), state ); |
96 } |
71 } |
97 |
72 |
98 QString FmUtils::formatStorageSize( quint64 size ) |
73 int FmUtils::removeDrivePwd( const QString &driveName, const QString &Pwd ) |
99 { |
74 { |
100 if ( size < 1000 ) { |
75 Q_UNUSED( driveName ); |
101 return QString::number( size ) + " B"; |
|
102 } else if ( size < 1000 * 1000 ) { |
|
103 return QString::number( size / 1024.0, 'f', 2 ) + " KB"; |
|
104 } else if ( size < 1000 * 1000 * 1000 ) { |
|
105 return QString::number( size / (1024.0 * 1024.0), 'f', 1 ) + " MB"; |
|
106 } else { |
|
107 return QString::number( size / ( 1024.0 * 1024.0 * 1024.0 ), 'f', 1 ) + " GB"; |
|
108 } |
|
109 } |
|
110 |
|
111 /* |
|
112 quint32 FmUtils::getDriverState( const QString &driverName ) |
|
113 { |
|
114 quint32 state( 0 ); |
|
115 |
|
116 QString driver = driverName; |
|
117 |
|
118 driver.replace( '/', "\\" ); |
|
119 if ( driver.right(1) != "\\" ) { |
|
120 driver.append( "\\" ); |
|
121 } |
|
122 |
|
123 quint32 drvStatus = GetDriveType( (LPCWSTR)driver.constData() ); |
|
124 |
|
125 if ( drvStatus == DRIVE_REMOVABLE ) { |
|
126 state |= FmDriverInfo::EDriveRemovable; |
|
127 } |
|
128 |
|
129 return state; |
|
130 |
|
131 } |
|
132 */ |
|
133 int FmUtils::removeDrivePwd( const QString &driverName, const QString &Pwd ) |
|
134 { |
|
135 Q_UNUSED( driverName ); |
|
136 Q_UNUSED( Pwd ); |
76 Q_UNUSED( Pwd ); |
137 return 0; |
77 return 0; |
138 } |
78 } |
139 |
79 |
140 int FmUtils::unlockDrive( const QString &driverName, const QString &Pwd ) |
80 int FmUtils::unlockDrive( const QString &driveName, const QString &Pwd ) |
141 { |
81 { |
142 Q_UNUSED( driverName ); |
82 Q_UNUSED( driveName ); |
143 Q_UNUSED( Pwd ); |
83 Q_UNUSED( Pwd ); |
144 return 0; |
84 return 0; |
145 } |
85 } |
146 |
86 |
147 int FmUtils::checkDrivePwd( const QString &driverName, const QString &pwd) |
87 int FmUtils::checkDrivePwd( const QString &driveName, const QString &pwd) |
148 { |
88 { |
149 Q_UNUSED( driverName ); |
89 Q_UNUSED( driveName ); |
150 Q_UNUSED( pwd ); |
90 Q_UNUSED( pwd ); |
151 return 0; |
91 return 0; |
152 } |
92 } |
153 |
93 |
154 int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd) |
94 int FmUtils::setDrivePwd( const QString &driveName, const QString &oldPwd, const QString &newPwd) |
155 { |
95 { |
156 Q_UNUSED( driverName ); |
96 Q_UNUSED( driveName ); |
157 Q_UNUSED( oldPwd ); |
97 Q_UNUSED( oldPwd ); |
158 Q_UNUSED( newPwd ); |
98 Q_UNUSED( newPwd ); |
159 return 0; |
99 return 0; |
160 } |
100 } |
161 |
101 |
162 void FmUtils::emptyPwd( QString &pwd ) |
102 void FmUtils::emptyPwd( QString &pwd ) |
163 { |
103 { |
164 Q_UNUSED( pwd ); |
104 Q_UNUSED( pwd ); |
165 } |
105 } |
166 |
106 |
167 int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName) |
107 int FmUtils::renameDrive( const QString &driveName, const QString &newVolumeName) |
168 { |
108 { |
169 Q_UNUSED( driverName ); |
109 Q_UNUSED( driveName ); |
170 foreach( const QChar &ch, newVolumeName ) |
110 foreach( const QChar &ch, newVolumeName ) |
171 { |
111 { |
172 // If not alphadigit or space, return error |
112 // If not alphadigit or space, return error |
173 if( !ch.isLetterOrNumber() && !ch.isSpace() ) |
113 if( !ch.isLetterOrNumber() && !ch.isSpace() ) |
174 { |
114 { |
176 } |
116 } |
177 } |
117 } |
178 return 0; |
118 return 0; |
179 } |
119 } |
180 |
120 |
181 int FmUtils::ejectDrive( const QString &driverName ) |
121 int FmUtils::ejectDrive( const QString &driveName ) |
182 { |
122 { |
183 Q_UNUSED( driverName ); |
123 Q_UNUSED( driveName ); |
184 return FmErrNone; |
124 return FmErrNone; |
185 } |
125 } |
186 |
126 |
187 QString FmUtils::getFileType( const QString &filePath ) |
127 bool FmUtils::checkDriveAccessFilter( const QString &driveName ) |
188 { |
128 { |
189 Q_UNUSED( filePath ); |
129 Q_UNUSED( driveName ); |
190 return QString( "" ); |
130 return true; |
191 } |
131 } |
192 |
132 |
193 quint64 FmUtils::getDriveDetailsResult( const QString &folderPath, const QString &extension ) |
133 QString FmUtils::checkDriveToFolderFilter( const QString &path ) |
|
134 { |
|
135 Q_UNUSED( path ); |
|
136 return path; |
|
137 |
|
138 } |
|
139 |
|
140 QString FmUtils::checkFolderToDriveFilter( const QString &path ) |
|
141 { |
|
142 Q_UNUSED( path ); |
|
143 return path; |
|
144 |
|
145 } |
|
146 |
|
147 int FmUtils::isPathAccessabel( const QString &path ) |
|
148 { |
|
149 Q_UNUSED( path ); |
|
150 return FmErrNone; |
|
151 } |
|
152 |
|
153 bool FmUtils::isDriveAvailable( const QString &path ) |
|
154 { |
|
155 Q_UNUSED( path ); |
|
156 return true; |
|
157 } |
|
158 |
|
159 bool FmUtils::isDefaultFolder( const QString &folderPath ) |
194 { |
160 { |
195 Q_UNUSED( folderPath ); |
161 Q_UNUSED( folderPath ); |
196 Q_UNUSED( extension ); |
162 return false; |
197 return 0; |
163 } |
198 } |
164 |
199 |
165 void FmUtils::createDefaultFolders( const QString &driveName ) |
200 bool FmUtils::isDriveC( const QString &driverName ) |
166 { |
201 { |
167 Q_UNUSED( driveName ); |
202 if( driverName.contains(Drive_C,Qt::CaseInsensitive) ){ |
|
203 return true; |
|
204 } |
|
205 else{ |
|
206 return false; |
|
207 } |
|
208 } |
|
209 |
|
210 bool FmUtils::isDrive( const QString &path ) |
|
211 { |
|
212 bool ret( false ); |
|
213 if( path.length() <= 3 && path.length() >=2 ) { |
|
214 ret = true; |
|
215 } |
|
216 |
|
217 return ret; |
|
218 } |
|
219 |
|
220 void FmUtils::createDefaultFolders( const QString &driverName ) |
|
221 { |
|
222 Q_UNUSED( driverName ); |
|
223 } |
168 } |
224 |
169 |
225 /*! |
170 /*! |
226 fill splash in the end of \a filePath if the path is not a file |
171 set the \a desFile attributes as the same with \a srcFile |
227 All "/" and "\" will be changed to QDir::separator |
172 */ |
228 \sa formatPath only changed "/" and "\" to QDir::separator |
173 int FmUtils::setFileAttributes( const QString &srcFile, const QString &desFile ) |
229 */ |
174 { |
230 QString FmUtils::fillPathWithSplash( const QString &filePath ) |
175 Q_UNUSED( srcFile ); |
231 { |
176 Q_UNUSED( desFile ); |
232 QString newFilePath; |
177 return FmErrNone; |
233 if( filePath.isEmpty() ) { |
178 } |
234 return newFilePath; |
179 |
235 } |
180 /*! |
236 |
181 judge whether there is enough space on \a targetDrive for \a size. |
237 newFilePath = formatPath( filePath ); |
182 return true if has, false if not. |
238 |
183 */ |
239 if( newFilePath.right( 1 )!= QDir::separator() ){ |
184 bool FmUtils::hasEnoughSpace( const QString &targetDrive, qint64 size ) |
240 newFilePath.append( QDir::separator() ); |
185 { |
241 } |
186 Q_UNUSED( targetDrive ); |
242 return newFilePath; |
187 Q_UNUSED( size ); |
243 } |
|
244 |
|
245 QString FmUtils::removePathSplash( const QString &filePath ) |
|
246 { |
|
247 QString newFilePath( filePath ); |
|
248 if( filePath.right( 1 ) == QChar( '/' ) || filePath.right(1) == QString( "\\" ) ) { |
|
249 newFilePath = filePath.left( filePath.length() - 1 ); |
|
250 } |
|
251 return newFilePath; |
|
252 } |
|
253 |
|
254 bool FmUtils::checkDriveAccessFilter( const QString &driveName ) |
|
255 { |
|
256 #ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ |
|
257 if( driveName.contains( Drive_D, Qt::CaseInsensitive ) || driveName.contains( Drive_Z, Qt::CaseInsensitive ) ) { |
|
258 return false; |
|
259 } |
|
260 #endif |
|
261 return true; |
188 return true; |
262 } |
189 } |
263 |
190 |
264 QString FmUtils::checkDriveToFolderFilter( const QString &path ) |
191 /*! |
265 { |
192 move one file insice the same drive, from \a source to \a target. |
266 QFileInfo fileInfo( path ); |
193 return KErrNone if successful, otherwise one of the other system-wide error codes. |
267 if( !fileInfo.exists() ) { |
194 */ |
268 return QString(); |
195 int FmUtils::moveInsideDrive( const QString &source, const QString &target ) |
269 } |
196 { |
270 |
197 Q_UNUSED( source ); |
271 #ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ |
198 Q_UNUSED( target ); |
272 QString checkedPath = fillPathWithSplash( path ); |
|
273 if( checkedPath.compare( QString( "C:/"), Qt::CaseInsensitive ) == 0 ) { |
|
274 checkedPath += QString( "data/" ); |
|
275 QFileInfo fileInfo( checkedPath ); |
|
276 if( !fileInfo.exists() ) { |
|
277 return QString(); |
|
278 } |
|
279 return checkedPath; |
|
280 } |
|
281 #endif |
|
282 return path; |
|
283 |
|
284 } |
|
285 |
|
286 QString FmUtils::checkFolderToDriveFilter( const QString &path ) |
|
287 { |
|
288 #ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ |
|
289 QString logString; |
|
290 logString = QString( "checkFolderToDriveFilter: " ) + path; |
|
291 FM_LOG( logString ); |
|
292 QString checkedPath = fillPathWithSplash( path ); |
|
293 |
|
294 logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath; |
|
295 FM_LOG( logString ); |
|
296 |
|
297 if( checkedPath.compare( QString( "C:/data/"), Qt::CaseInsensitive ) == 0 ) { |
|
298 FM_LOG( QString( " change from c:/data/ to C:/" ) ); |
|
299 return QString( "C:/" ); |
|
300 } |
|
301 #endif |
|
302 return path; |
|
303 |
|
304 } |
|
305 |
|
306 int FmUtils::isPathAccessabel( const QString &path ) |
|
307 { |
|
308 if(!isDriveAvailable( path ) ) { //used to filter locked drive |
|
309 return FmErrDriveNotAvailable; |
|
310 } |
|
311 |
|
312 QFileInfo fileInfo( path ); |
|
313 |
|
314 #ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ |
|
315 if( fileInfo.absoluteFilePath().contains( QString( Drive_C ), Qt::CaseInsensitive ) && |
|
316 !fileInfo.absoluteFilePath().contains( QString( Folder_C_Data ), Qt::CaseInsensitive ) ) { |
|
317 return false; |
|
318 } |
|
319 if( fileInfo.absoluteFilePath().contains( QString( Drive_D ), Qt::CaseInsensitive ) ) { |
|
320 return false; |
|
321 } |
|
322 if( fileInfo.absoluteFilePath().contains( QString( Drive_Z ), Qt::CaseInsensitive ) ) { |
|
323 return false; |
|
324 } |
|
325 #endif |
|
326 if( !fileInfo.exists() ) { |
|
327 return FmErrPathNotExist; |
|
328 } |
|
329 return FmErrNone; |
199 return FmErrNone; |
330 } |
|
331 |
|
332 bool FmUtils::isDriveAvailable( const QString &path ) |
|
333 { |
|
334 #ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_ |
|
335 if(path.contains(Drive_D, Qt::CaseInsensitive)) |
|
336 return false; |
|
337 #endif |
|
338 #ifdef _DEBUG_LOCKED_DRIVE_Z |
|
339 if(path.contains(Drive_Z, Qt::CaseInsensitive)) |
|
340 return false; |
|
341 #endif |
|
342 return true; |
|
343 } |
|
344 |
|
345 void FmUtils::getDriveList( QStringList &driveList, bool isHideUnAvailableDrive ) |
|
346 { |
|
347 QFileInfoList infoList = QDir::drives(); |
|
348 |
|
349 foreach( QFileInfo fileInfo, infoList ) { |
|
350 QString driveName = fileInfo.absolutePath(); |
|
351 if( checkDriveAccessFilter( driveName ) ) { |
|
352 if( !isHideUnAvailableDrive ) { |
|
353 driveList.append( driveName ); |
|
354 } |
|
355 else if ( isDriveAvailable( driveName ) ) { |
|
356 driveList.append( driveName ); |
|
357 } |
|
358 } |
|
359 } |
|
360 return; |
|
361 } |
|
362 |
|
363 QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume ) |
|
364 { |
|
365 QString ret; |
|
366 QString tempDriveName = fillPathWithSplash( driveName ); |
|
367 |
|
368 QString checkedDriveName( removePathSplash( driveName ) ); |
|
369 |
|
370 FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName ); |
|
371 QString volumeName = driverInfo.volumeName(); |
|
372 |
|
373 if( volumeName.isEmpty() && isFillWithDefaultVolume ){ |
|
374 FmDriverInfo::DriveState driveState = queryDriverInfo( tempDriveName ).driveState(); |
|
375 if( driveState & FmDriverInfo::EDriveAvailable ){ |
|
376 if( driveState & FmDriverInfo::EDriveRemovable ) { |
|
377 if( driveState & FmDriverInfo::EDriveMassStorage ) { |
|
378 // Mass Storage |
|
379 ret = hbTrId( "txt_fmgr_dblist_1_mass_storage" ).arg( checkedDriveName ); |
|
380 } else if( driveState & FmDriverInfo::EDriveUsbMemory ) { |
|
381 // USB Memory |
|
382 ret = hbTrId( "txt_fmgr_dblist_1_usb_memory" ).arg( checkedDriveName ); |
|
383 } else{ |
|
384 // Memory Card |
|
385 ret = hbTrId( "txt_fmgr_dblist_1_memory_card" ).arg( checkedDriveName ); |
|
386 } |
|
387 } else{ |
|
388 // phone memory |
|
389 ret = hbTrId( "txt_fmgr_dblist_1_device_memory" ).arg( checkedDriveName ); |
|
390 } |
|
391 } |
|
392 } else { |
|
393 ret = hbTrId( "txt_fmgr_dblist_1_2" ).arg( checkedDriveName ).arg( volumeName ); |
|
394 } |
|
395 return ret; |
|
396 } |
200 } |
397 |
201 |
398 int FmUtils::launchFile( const QString &filePath ) |
202 int FmUtils::launchFile( const QString &filePath ) |
399 { |
203 { |
400 if( QDesktopServices::openUrl( QUrl::fromLocalFile( filePath ) ) ) { |
204 if( QDesktopServices::openUrl( QUrl::fromLocalFile( filePath ) ) ) { |
401 return FmErrNone; |
205 return FmErrNone; |
402 } else { |
206 } else { |
403 return FmErrGeneral; |
207 return FmErrGeneral; |
404 } |
208 } |
405 } |
|
406 |
|
407 void FmUtils::sendFiles( QStringList &filePathList ) |
|
408 { |
|
409 |
|
410 } |
209 } |
411 |
210 |
412 QString FmUtils::getBurConfigPath( QString appPath ) |
211 QString FmUtils::getBurConfigPath( QString appPath ) |
413 { |
212 { |
414 QFileInfo fileInfo( appPath ); |
213 QFileInfo fileInfo( appPath ); |
417 path = path + QString( "src/filemanager/" ); |
216 path = path + QString( "src/filemanager/" ); |
418 path = path + QString( BURCONFIGFILE ); |
217 path = path + QString( BURCONFIGFILE ); |
419 return path; |
218 return path; |
420 } |
219 } |
421 |
220 |
422 bool FmUtils::isPathEqual( const QString &pathFst, const QString &pathLast ) |
221 QString FmUtils::getFileType( const QString &filePath ) |
423 { |
222 { |
424 QString fst( fillPathWithSplash( pathFst ) ); |
223 Q_UNUSED( filePath ); |
425 QString last( fillPathWithSplash( pathLast ) ); |
224 return QString( "" ); |
426 if( fst.compare( last, Qt::CaseInsensitive ) == 0 ) { |
225 } |
|
226 |
|
227 bool FmUtils::isDriveC( const QString &driveName ) |
|
228 { |
|
229 if( driveName.contains(Drive_C,Qt::CaseInsensitive) ){ |
427 return true; |
230 return true; |
428 } |
231 } |
429 return false; |
232 else{ |
430 } |
233 return false; |
431 |
234 } |
432 bool FmUtils::isDefaultFolder( const QString &folderPath ) |
|
433 { |
|
434 Q_UNUSED( folderPath ); |
|
435 return false; |
|
436 } |
|
437 |
|
438 /*! |
|
439 All "/" and "\" in \a path will be changed to QDir::separator |
|
440 \sa fillPathWithSplash, fillPathWithSplash will append QDir::separator in the end if path is no a file |
|
441 */ |
|
442 QString FmUtils::formatPath( const QString &path ) |
|
443 { |
|
444 QString formatPath; |
|
445 if( path.isEmpty() ) { |
|
446 return formatPath; |
|
447 } |
|
448 |
|
449 foreach( QChar ch, path ) { |
|
450 if( ch == QChar('\\') || ch == QChar('/') ) { |
|
451 formatPath.append( QDir::separator() ); |
|
452 } else { |
|
453 formatPath.append( ch ); |
|
454 } |
|
455 } |
|
456 |
|
457 return formatPath; |
|
458 } |
235 } |
459 |
236 |
460 int FmUtils::getMaxFileNameLength() |
237 int FmUtils::getMaxFileNameLength() |
461 { |
238 { |
462 return KMaxFileName; |
239 return KMaxFileName; |
463 } |
240 } |
464 |
241 |
465 bool FmUtils::checkMaxPathLength( const QString& path ) |
242 bool FmUtils::checkMaxPathLength( const QString& path ) |
466 { |
243 { |
467 if( path.length() > KMaxPath ) { |
244 if( path.length() > KMaxPath ) { |
468 return false; |
|
469 } |
|
470 return true; |
|
471 } |
|
472 |
|
473 bool FmUtils::checkFolderFileName( const QString& name ) |
|
474 { |
|
475 // trim space firest, because there may be some spaces after "." , it is also not valid |
|
476 // or there may only have spaces in name |
|
477 QString trimmedName( name.trimmed() ); |
|
478 if( trimmedName.isEmpty() ) { |
|
479 return false; |
|
480 } |
|
481 if( trimmedName.endsWith( QChar('.'), Qt::CaseInsensitive ) ) { |
|
482 return false; |
245 return false; |
483 } |
246 } |
484 if( trimmedName.contains( QChar('\\'), Qt::CaseInsensitive ) || |
|
485 trimmedName.contains( QChar('/'), Qt::CaseInsensitive ) || |
|
486 trimmedName.contains( QChar(':'), Qt::CaseInsensitive ) || |
|
487 trimmedName.contains( QChar('*'), Qt::CaseInsensitive ) || |
|
488 trimmedName.contains( QChar('?'), Qt::CaseInsensitive ) || |
|
489 trimmedName.contains( QChar('\"'), Qt::CaseInsensitive ) || |
|
490 trimmedName.contains( QChar('<'), Qt::CaseInsensitive ) || |
|
491 trimmedName.contains( QChar('>'), Qt::CaseInsensitive ) || |
|
492 trimmedName.contains( QChar('|'), Qt::CaseInsensitive ) ){ |
|
493 return false; |
|
494 } |
|
495 // use orignal name to exam max size of file name |
|
496 if( name.length() > KMaxFileName ) { |
|
497 return false; |
|
498 } |
|
499 return true; |
247 return true; |
500 } |
248 } |
501 |
|
502 bool FmUtils::checkNewFolderOrFile( const QString &fileName, const QString &path, QString &errString ) |
|
503 { |
|
504 // first check if fileName is valid, then check if path length is valid, and check if file/foler is existed at last |
|
505 QFileInfo fileInfo( path ); |
|
506 bool ret( true ); |
|
507 if (!FmUtils::checkFolderFileName( fileName ) ) { |
|
508 errString = hbTrId( "Invalid file or folder name, try again!" ); |
|
509 ret = false; |
|
510 } else if( !FmUtils::checkMaxPathLength( path ) ) { |
|
511 errString = hbTrId( "the path you specified is too long, try again!" ); |
|
512 ret = false; |
|
513 } else if (fileInfo.exists()) { |
|
514 errString = hbTrId( "%1 already exist!" ).arg( fileInfo.fileName() ); |
|
515 ret = false; |
|
516 } |
|
517 return ret; |
|
518 } |
|
519 |
|
520 QString FmUtils::getVolumeNameWithDefaultNameIfNull( const QString &diskName, bool &defaultName ) |
|
521 { |
|
522 FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName ); |
|
523 |
|
524 // do not add default volume for win32 version as this is only the dummy implememnt for debug on windows |
|
525 return driverInfo.volumeName(); |
|
526 } |
|
527 |
|
528 /*! |
|
529 Check if \a dest is sub level path of \a src |
|
530 Used to check True/False when copy a folder to itself or its subfolder |
|
531 For example, c:\data\test is sub path of c:\data. |
|
532 But c:\data123\test is not sub path of c:\data. |
|
533 So after got right part of path, the first char must be \ or / |
|
534 */ |
|
535 bool FmUtils::isSubLevelPath( const QString &src, const QString &dest ) |
|
536 { |
|
537 FM_LOG("FmUtils::isSubFolder: src=" + src + " dest=" + dest); |
|
538 QString checkedSrc( FmUtils::fillPathWithSplash( src ) ); |
|
539 QString checkedDest( FmUtils::fillPathWithSplash( dest ) ); |
|
540 |
|
541 if( checkedDest.contains( checkedSrc, Qt::CaseInsensitive) && |
|
542 checkedDest.length() > checkedSrc.length() ) { |
|
543 // for example c:\data\ vs c:\data\123\ |
|
544 FM_LOG("FmUtils::isSubFolder: true"); |
|
545 return true; |
|
546 } |
|
547 // for example c:\data\ vs c:\data\ |
|
548 // for example c:\data\ vs c:\data123\ |
|
549 |
|
550 FM_LOG("FmUtils::isSubFolder: false"); |
|
551 return false; |
|
552 } |
|
553 |
|
554 int FmUtils::setFileAttributes( const QString &srcFile, const QString &desFile ) |
|
555 { |
|
556 return FmErrNone; |
|
557 } |
|