Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't allow invalid project files! #2523

Merged
merged 1 commit into from
Sep 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions src/core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,27 @@ void printHelp()



void fileCheck( QString &file )
{
QFileInfo fileToCheck( file );

if( !fileToCheck.size() )
{
printf( "The file %s does not have any content.\n",
file.toUtf8().constData() );
exit( EXIT_FAILURE );
}
else if( fileToCheck.isDir() )
{
printf( "%s is a directory.\n",
file.toUtf8().constData() );
exit( EXIT_FAILURE );
}
}




int main( int argc, char * * argv )
{
// initialize memory managers
Expand Down Expand Up @@ -567,6 +588,15 @@ int main( int argc, char * * argv )
}
}

// Test file argument before continuing
if( !fileToLoad.isEmpty() )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be the other way around? Shouldn't we only instantiate fileInfoLoad if the QString isn't null or empty? This would also remove the need for setting an empty QString above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above code comment from April still remains unanswered and you have a commented line that should be removed prior to merging.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we only instantiate fileInfoLoad if the QString isn't null or empty? This would also remove the need for setting an empty QString above.

No, I don't think so, but this part is essentially the same as before. I just moved it and expanded on the functionality.

you have a commented line that should be removed

comment removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileInfoLoad should be instantiated in the if( !fileToLoad.isEmpty() ) block; fileInfoImport, in the if( !fileToImport.isEmpty() ) one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I updated the according to Javiers suggestions.

{
fileCheck( fileToLoad );
}
else if( !fileToImport.isEmpty() )
{
fileCheck( fileToImport );
}

ConfigManager::inst()->loadConfigFile(configFile);

Expand Down Expand Up @@ -636,15 +666,13 @@ int main( int argc, char * * argv )
Engine::init( true );
destroyEngine = true;

QFileInfo fileInfo( fileToLoad );
if ( !fileInfo.exists() )
{
printf("The file %s does not exist!\n", fileToLoad.toStdString().c_str());
exit( 1 );
}

printf( "Loading project...\n" );
Engine::getSong()->loadProject( fileToLoad );
if( Engine::getSong()->isEmpty() )
{
printf("The project %s is empty, aborting!\n", fileToLoad.toUtf8().constData() );
exit( EXIT_FAILURE );
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is exit() even a good way to terminate the application at this point?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may omit exit() and avoid the export, so an upgraded .lmmsrc.xml can be written, but exit() (or return) is not a bad way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oK. I just skimmed past some comment on the net that exit() could be a problem with multi threaded applications. I'm happy with .lmmsrc.xml not being written so we keep failing loads from appearing in the recently opened projects list.

printf( "Done\n" );

Engine::getSong()->setExportLoop( renderLoop );
Expand Down