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