| 1398 | } |
| 1399 | |
| 1400 | bool FrameFileIO::isNativeCSVFile(QString filename) |
| 1401 | { |
| 1402 | QFile *inFile = new QFile(filename); |
| 1403 | QByteArray line; |
| 1404 | int fileVersion = 1; |
| 1405 | bool isMatch = true; |
| 1406 | |
| 1407 | if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text)) |
| 1408 | { |
| 1409 | delete inFile; |
| 1410 | return false; |
| 1411 | } |
| 1412 | try |
| 1413 | { |
| 1414 | line = inFile->readLine().toUpper(); //read out the header first and discard it. |
| 1415 | if (line.length() < 23) isMatch = false; |
| 1416 | else if (line.at(23) == 'D') fileVersion = 2; //Dir is found starting at position 23 if this is a V2 file |
| 1417 | |
| 1418 | if (!line.contains("TIME STAMP")) isMatch = false; |
| 1419 | if (!line.contains("EXTENDED")) isMatch = false; |
| 1420 | if (!line.contains("D1")) isMatch = false; |
| 1421 | |
| 1422 | if (!inFile->atEnd()) { |
| 1423 | line = inFile->readLine().simplified(); |
| 1424 | if (line.length() > 2) |
| 1425 | { |
| 1426 | QList<QByteArray> tokens = line.split(','); |
| 1427 | if (tokens.length() >= 5) |
| 1428 | { |
| 1429 | if (fileVersion == 1) |
| 1430 | { |
| 1431 | if (tokens[4].toUInt() > 8) isMatch = false; |
| 1432 | } |
| 1433 | else if (fileVersion == 2) |
| 1434 | { |
| 1435 | if ( tokens[5].toUInt() > 8) isMatch = false; |
| 1436 | } |
| 1437 | } |
| 1438 | else isMatch = false; |
| 1439 | } |
| 1440 | } |
| 1441 | } |
| 1442 | catch (...) |
| 1443 | { |
| 1444 | isMatch = false; |
| 1445 | } |
| 1446 | inFile->close(); |
| 1447 | delete inFile; |
| 1448 | |
| 1449 | return isMatch; |
| 1450 | } |
| 1451 | |
| 1452 | //The "native" file format for this program |
| 1453 | //Time Stamp,ID,Extended,Dir,Bus,LEN,D1,D2,D3,D4,D5,D6,D7,D8 |