view o3pack.cpp @ 4:e30f00f760d3 default tip

Cleanup OSTC label and removed url The computer type will now show OSTC 4/5 instead of only 4. The url has been removed because it is no longer maintained. The ui header have been deleted because they are generated files shich should not be under version controll. Delete locally if you want to force an update of the dialog layout.
author Ideenmodellierer
date Sun, 30 Nov 2025 18:37:32 +0100
parents 0b3630a29ad8
children
line wrap: on
line source

#include <QApplication>
#include <QDir>
#include <QProgressBar>
#include <QProgressDialog>
#include <QtDebug>

#include "HexFile.h"

//////////////////////////////////////////////////////////////////////////////
static unsigned char frogSecretKey[16] = {
    111, 85, 190, 69,
    108,254, 242, 19,
    231, 49, 248,255,
    233, 48, 176,241
};
static unsigned char ostc3SecretKey[16] = {
    241,233, 176, 48,
     69,111, 190, 85,
    255,231, 248, 49,
     19,108, 242,254
};

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    app.processEvents();

    //---- Parse parameters --------------------------------------------------
    QString in, out;
    QDir current;
    bool force = false;
    bool ostc3 = true;

    if( argc < 2 ) goto Usage;

    if( QString(argv[1]).toLower() == "-frog" ) {
        ostc3 = false;
        argc--, argv++;
    } else if(  QString(argv[1]).toLower() == "-ostc3" ) {
        ostc3 = true;
        argc--, argv++;
    }

    in  = QDir::cleanPath(current.absoluteFilePath(argv[1]));
    out = QDir::cleanPath(current.absoluteFilePath(argv[2]));
    if( argv[2] == QString("-f") && argc >= 3 ) {
        out = QDir::cleanPath(current.absoluteFilePath(argv[3]));
        force = true;
    }

    //---- Check parameters consistency --------------------------------------
    {
        QFileInfo fi(in);
        if( ! fi.exists() || ! fi.isReadable() ) {
            qWarning().nospace() << "Cannot read input file " << in;
            goto Usage;
        }
    }

    {
        QFileInfo fo(out);
        if( fo.exists() ) {
            if( !force ) {
                qWarning().nospace() << "File " << out << " exists. Use -f to force overwrite.";
                goto Usage;
            }

            if( !fo.isWritable() ) {
                qWarning().nospace() << "Cannot write to " << out << ". Protected file ?";
                goto Usage;
            }
            current.remove(out);
        }
    }

    //---- Load the HEX file -------------------------------------------------
    {
        QProgressBar* progress = new QProgressBar(0);
        progress->setFormat("Loading %p%");
        progress->show();

        try {
            HexFile hex;
            hex.allocate(0x20000);

            hex.load(in, progress);
            hex.sqwiz(0x1E000);

            char sum[10];
            sprintf(sum, "%08X", hex.checksum());
            qDebug() << "Checksum " << sum;

    //---- Save encrypted HEX file -------------------------------------------
            progress->setFormat("Saving %p%");
            hex.saveEncrypted(out, (ostc3 ? ostc3SecretKey : frogSecretKey), progress);
        }
        catch(const char* msg) {
            qWarning() << "Failed: " << msg;
        }

        delete progress;
    }

    //---- End --------------------------------------------------------------
    return 0;

Usage:
    qWarning() << "Usage:" << endl
               << "    " << QString(app.arguments()[0]).section('/', -1).section('\\',-1)
               << "[-frog|-ostc3]"
               << " input.hex [-f] output.hex";
    exit(-1);
}