Mercurial > public > ostc_companion
comparison o3pack.cpp @ 8:21ce6187d32e
Minor changes done by automatic style checker
| author | Ideenmodellierer |
|---|---|
| date | Mon, 12 Jan 2026 13:51:17 +0000 |
| parents | 0b3630a29ad8 |
| children |
comparison
equal
deleted
inserted
replaced
| 7:0969ef86c42d | 8:21ce6187d32e |
|---|---|
| 5 #include <QtDebug> | 5 #include <QtDebug> |
| 6 | 6 |
| 7 #include "HexFile.h" | 7 #include "HexFile.h" |
| 8 | 8 |
| 9 ////////////////////////////////////////////////////////////////////////////// | 9 ////////////////////////////////////////////////////////////////////////////// |
| 10 static unsigned char frogSecretKey[16] = { | 10 static unsigned char frogSecretKey[16] |
| 11 111, 85, 190, 69, | 11 = {111, 85, 190, 69, 108, 254, 242, 19, 231, 49, 248, 255, 233, 48, 176, 241}; |
| 12 108,254, 242, 19, | 12 static unsigned char ostc3SecretKey[16] |
| 13 231, 49, 248,255, | 13 = {241, 233, 176, 48, 69, 111, 190, 85, 255, 231, 248, 49, 19, 108, 242, 254}; |
| 14 233, 48, 176,241 | |
| 15 }; | |
| 16 static unsigned char ostc3SecretKey[16] = { | |
| 17 241,233, 176, 48, | |
| 18 69,111, 190, 85, | |
| 19 255,231, 248, 49, | |
| 20 19,108, 242,254 | |
| 21 }; | |
| 22 | 14 |
| 23 int main(int argc, char *argv[]) | 15 int main(int argc, char *argv[]) |
| 24 { | 16 { |
| 25 QApplication app(argc, argv); | 17 QApplication app(argc, argv); |
| 26 app.processEvents(); | 18 app.processEvents(); |
| 29 QString in, out; | 21 QString in, out; |
| 30 QDir current; | 22 QDir current; |
| 31 bool force = false; | 23 bool force = false; |
| 32 bool ostc3 = true; | 24 bool ostc3 = true; |
| 33 | 25 |
| 34 if( argc < 2 ) goto Usage; | 26 if (argc < 2) |
| 27 goto Usage; | |
| 35 | 28 |
| 36 if( QString(argv[1]).toLower() == "-frog" ) { | 29 if (QString(argv[1]).toLower() == "-frog") { |
| 37 ostc3 = false; | 30 ostc3 = false; |
| 38 argc--, argv++; | 31 argc--, argv++; |
| 39 } else if( QString(argv[1]).toLower() == "-ostc3" ) { | 32 } else if (QString(argv[1]).toLower() == "-ostc3") { |
| 40 ostc3 = true; | 33 ostc3 = true; |
| 41 argc--, argv++; | 34 argc--, argv++; |
| 42 } | 35 } |
| 43 | 36 |
| 44 in = QDir::cleanPath(current.absoluteFilePath(argv[1])); | 37 in = QDir::cleanPath(current.absoluteFilePath(argv[1])); |
| 45 out = QDir::cleanPath(current.absoluteFilePath(argv[2])); | 38 out = QDir::cleanPath(current.absoluteFilePath(argv[2])); |
| 46 if( argv[2] == QString("-f") && argc >= 3 ) { | 39 if (argv[2] == QString("-f") && argc >= 3) { |
| 47 out = QDir::cleanPath(current.absoluteFilePath(argv[3])); | 40 out = QDir::cleanPath(current.absoluteFilePath(argv[3])); |
| 48 force = true; | 41 force = true; |
| 49 } | 42 } |
| 50 | 43 |
| 51 //---- Check parameters consistency -------------------------------------- | 44 //---- Check parameters consistency -------------------------------------- |
| 52 { | 45 { |
| 53 QFileInfo fi(in); | 46 QFileInfo fi(in); |
| 54 if( ! fi.exists() || ! fi.isReadable() ) { | 47 if (!fi.exists() || !fi.isReadable()) { |
| 55 qWarning().nospace() << "Cannot read input file " << in; | 48 qWarning().nospace() << "Cannot read input file " << in; |
| 56 goto Usage; | 49 goto Usage; |
| 57 } | 50 } |
| 58 } | 51 } |
| 59 | 52 |
| 60 { | 53 { |
| 61 QFileInfo fo(out); | 54 QFileInfo fo(out); |
| 62 if( fo.exists() ) { | 55 if (fo.exists()) { |
| 63 if( !force ) { | 56 if (!force) { |
| 64 qWarning().nospace() << "File " << out << " exists. Use -f to force overwrite."; | 57 qWarning().nospace() << "File " << out << " exists. Use -f to force overwrite."; |
| 65 goto Usage; | 58 goto Usage; |
| 66 } | 59 } |
| 67 | 60 |
| 68 if( !fo.isWritable() ) { | 61 if (!fo.isWritable()) { |
| 69 qWarning().nospace() << "Cannot write to " << out << ". Protected file ?"; | 62 qWarning().nospace() << "Cannot write to " << out << ". Protected file ?"; |
| 70 goto Usage; | 63 goto Usage; |
| 71 } | 64 } |
| 72 current.remove(out); | 65 current.remove(out); |
| 73 } | 66 } |
| 74 } | 67 } |
| 75 | 68 |
| 76 //---- Load the HEX file ------------------------------------------------- | 69 //---- Load the HEX file ------------------------------------------------- |
| 77 { | 70 { |
| 78 QProgressBar* progress = new QProgressBar(0); | 71 QProgressBar *progress = new QProgressBar(0); |
| 79 progress->setFormat("Loading %p%"); | 72 progress->setFormat("Loading %p%"); |
| 80 progress->show(); | 73 progress->show(); |
| 81 | 74 |
| 82 try { | 75 try { |
| 83 HexFile hex; | 76 HexFile hex; |
| 88 | 81 |
| 89 char sum[10]; | 82 char sum[10]; |
| 90 sprintf(sum, "%08X", hex.checksum()); | 83 sprintf(sum, "%08X", hex.checksum()); |
| 91 qDebug() << "Checksum " << sum; | 84 qDebug() << "Checksum " << sum; |
| 92 | 85 |
| 93 //---- Save encrypted HEX file ------------------------------------------- | 86 //---- Save encrypted HEX file ------------------------------------------- |
| 94 progress->setFormat("Saving %p%"); | 87 progress->setFormat("Saving %p%"); |
| 95 hex.saveEncrypted(out, (ostc3 ? ostc3SecretKey : frogSecretKey), progress); | 88 hex.saveEncrypted(out, (ostc3 ? ostc3SecretKey : frogSecretKey), progress); |
| 96 } | 89 } catch (const char *msg) { |
| 97 catch(const char* msg) { | |
| 98 qWarning() << "Failed: " << msg; | 90 qWarning() << "Failed: " << msg; |
| 99 } | 91 } |
| 100 | 92 |
| 101 delete progress; | 93 delete progress; |
| 102 } | 94 } |
| 104 //---- End -------------------------------------------------------------- | 96 //---- End -------------------------------------------------------------- |
| 105 return 0; | 97 return 0; |
| 106 | 98 |
| 107 Usage: | 99 Usage: |
| 108 qWarning() << "Usage:" << endl | 100 qWarning() << "Usage:" << endl |
| 109 << " " << QString(app.arguments()[0]).section('/', -1).section('\\',-1) | 101 << " " << QString(app.arguments()[0]).section('/', -1).section('\\', -1) |
| 110 << "[-frog|-ostc3]" | 102 << "[-frog|-ostc3]" |
| 111 << " input.hex [-f] output.hex"; | 103 << " input.hex [-f] output.hex"; |
| 112 exit(-1); | 104 exit(-1); |
| 113 } | 105 } |
