464 if( path.length() > KMaxPath ) { |
464 if( path.length() > KMaxPath ) { |
465 return false; |
465 return false; |
466 } |
466 } |
467 return true; |
467 return true; |
468 } |
468 } |
|
469 |
469 bool FmUtils::checkFolderFileName( const QString& name ) |
470 bool FmUtils::checkFolderFileName( const QString& name ) |
470 { |
471 { |
471 if( name.endsWith( QChar('.'), Qt::CaseInsensitive ) ) { |
472 // trim space firest, because there may be some spaces after "." , it is also not valid |
472 return false; |
473 // or there may only have spaces in name |
473 } |
474 QString trimmedName( name.trimmed() ); |
474 if( name.contains( QChar('\\'), Qt::CaseInsensitive ) || |
475 if( trimmedName.isEmpty() ) { |
475 name.contains( QChar('/'), Qt::CaseInsensitive ) || |
476 return false; |
476 name.contains( QChar(':'), Qt::CaseInsensitive ) || |
477 } |
477 name.contains( QChar('*'), Qt::CaseInsensitive ) || |
478 if( trimmedName.endsWith( QChar('.'), Qt::CaseInsensitive ) ) { |
478 name.contains( QChar('?'), Qt::CaseInsensitive ) || |
479 return false; |
479 name.contains( QChar('\"'), Qt::CaseInsensitive ) || |
480 } |
480 name.contains( QChar('<'), Qt::CaseInsensitive ) || |
481 if( trimmedName.contains( QChar('\\'), Qt::CaseInsensitive ) || |
481 name.contains( QChar('>'), Qt::CaseInsensitive ) || |
482 trimmedName.contains( QChar('/'), Qt::CaseInsensitive ) || |
482 name.contains( QChar('|'), Qt::CaseInsensitive ) ){ |
483 trimmedName.contains( QChar(':'), Qt::CaseInsensitive ) || |
483 return false; |
484 trimmedName.contains( QChar('*'), Qt::CaseInsensitive ) || |
484 } |
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 return false; |
|
491 } |
|
492 // use orignal name to exam max size of file name |
485 if( name.length() > KMaxFileName ) { |
493 if( name.length() > KMaxFileName ) { |
486 return false; |
494 return false; |
487 } |
495 } |
488 return true; |
496 return true; |
489 } |
497 } |
490 |
498 |
491 bool FmUtils::checkNewFolderOrFile( const QString &path, QString &errString ) |
499 bool FmUtils::checkNewFolderOrFile( const QString &fileName, const QString &path, QString &errString ) |
492 { |
500 { |
|
501 // first check if fileName is valid, then check if path length is valid, and check if file/foler is existed at last |
493 QFileInfo fileInfo( path ); |
502 QFileInfo fileInfo( path ); |
494 bool ret( true ); |
503 bool ret( true ); |
495 if (!FmUtils::checkFolderFileName( fileInfo.fileName() ) ) { |
504 if (!FmUtils::checkFolderFileName( fileName ) ) { |
496 errString = hbTrId( "Invalid file or folder name, try again!" ); |
505 errString = hbTrId( "Invalid file or folder name, try again!" ); |
497 ret = false; |
506 ret = false; |
498 } else if( !FmUtils::checkMaxPathLength( path ) ) { |
507 } else if( !FmUtils::checkMaxPathLength( path ) ) { |
499 errString = hbTrId( "the path you specified is too long, try again!" ); |
508 errString = hbTrId( "the path you specified is too long, try again!" ); |
500 ret = false; |
509 ret = false; |