@@ -956,18 +956,31 @@ void MainWindow::on_MF_Sniff_loadButton_clicked() // use a tmp file to support c
956956{
957957 QString title = " " ;
958958 QString filename = " " ;
959+ QString defaultExtension;
960+ QDir clientTracePath;
961+
962+ if (Util::getClientType () == Util::CLIENTTYPE_OFFICIAL )
963+ defaultExtension = " .trc" ;
964+ else if (Util::getClientType () == Util::CLIENTTYPE_ICEMAN )
965+ defaultExtension = " .trace" ;
966+
967+ QString userTraceSavePath = mifare->getTraceSavePath ();
968+ if (userTraceSavePath.isEmpty ())
969+ clientTracePath = *clientWorkingDir;
970+ else
971+ clientTracePath = QDir (userTraceSavePath); // For v4.16717 and later
959972
960973 title = tr (" Plz select the trace file:" );
961- filename = QFileDialog::getOpenFileName (this , title, clientWorkingDir-> absolutePath (), tr (" Trace Files(*.trc) " ) + " ;;" + tr (" All Files(*.*)" ));
974+ filename = QFileDialog::getOpenFileName (this , title, clientTracePath. absolutePath (), tr (" Trace Files" ) + " (* " + defaultExtension + " ) " + " ;;" + tr (" All Files(*.*)" ));
962975 qDebug () << filename;
963976 if (filename != " " )
964977 {
965- QString tmpFile = " tmp" + QString::number (QDateTime::currentDateTime ().toTime_t ()) + " .trc " ;
966- if (QFile::copy (filename, clientWorkingDir-> absolutePath () + " /" + tmpFile))
978+ QString tmpFile = " tmp" + QString::number (QDateTime::currentDateTimeUtc ().toTime_t ()) + defaultExtension ;
979+ if (QFile::copy (filename, clientTracePath. absolutePath () + " /" + tmpFile))
967980 {
968981 mifare->loadSniff (tmpFile);
969982 util->delay (3000 );
970- QFile::remove (clientWorkingDir-> absolutePath () + " /" + tmpFile);
983+ QFile::remove (clientTracePath. absolutePath () + " /" + tmpFile);
971984 }
972985 else
973986 {
@@ -980,25 +993,41 @@ void MainWindow::on_MF_Sniff_saveButton_clicked()
980993{
981994 QString title = " " ;
982995 QString filename = " " ;
996+ QString defaultExtension;
997+ QDir clientTracePath;
998+
999+ if (Util::getClientType () == Util::CLIENTTYPE_OFFICIAL )
1000+ defaultExtension = " .trc" ;
1001+ else if (Util::getClientType () == Util::CLIENTTYPE_ICEMAN )
1002+ defaultExtension = " .trace" ;
1003+
1004+ QString userTraceSavePath = mifare->getTraceSavePath ();
1005+ if (userTraceSavePath.isEmpty ())
1006+ clientTracePath = *clientWorkingDir;
1007+ else
1008+ clientTracePath = QDir (userTraceSavePath); // For v4.16717 and later
9831009
9841010 title = tr (" Plz select the location to save trace file:" );
985- filename = QFileDialog::getSaveFileName (this , title, clientWorkingDir-> absolutePath (), tr (" Trace Files(*.trc) " ) );
1011+ filename = QFileDialog::getSaveFileName (this , title, clientTracePath. absolutePath (), tr (" Trace Files" ) + " (* " + defaultExtension + " ) " );
9861012 qDebug () << filename;
9871013 if (filename != " " )
9881014 {
989- QString tmpFile = " tmp" + QString::number (QDateTime::currentDateTime ().toTime_t ()) + " .trc " ;
1015+ QString tmpFile = " tmp" + QString::number (QDateTime::currentDateTimeUtc ().toTime_t ()) + defaultExtension ;
9901016 mifare->saveSniff (tmpFile);
9911017 for (int i = 0 ; i < 100 ; i++)
9921018 {
9931019 util->delay (100 );
994- if (QFile::exists (clientWorkingDir-> absolutePath () + " /" + tmpFile))
1020+ if (QFile::exists (clientTracePath. absolutePath () + " /" + tmpFile))
9951021 break ;
9961022 }
997- if (!QFile::copy (clientWorkingDir->absolutePath () + " /" + tmpFile, filename))
1023+ // filename is not empty -> the user has chosen to overwrite the existing file
1024+ if (QFile::exists (filename))
1025+ QFile::remove (filename);
1026+ if (!QFile::copy (clientTracePath.absolutePath () + " /" + tmpFile, filename))
9981027 {
9991028 QMessageBox::information (this , tr (" Info" ), tr (" Failed to save to" ) + " \n " + filename);
10001029 }
1001- QFile::remove (clientWorkingDir-> absolutePath () + " /" + tmpFile);
1030+ QFile::remove (clientTracePath. absolutePath () + " /" + tmpFile);
10021031 }
10031032
10041033}
0 commit comments