From 969abb5c6de202114026ee799243c22a39b7185a Mon Sep 17 00:00:00 2001 From: Dagen Brock Date: Sun, 15 Jan 2017 16:39:11 -0600 Subject: [PATCH] latest for builds --- .gitignore | 1 + assets/.DS_Store | Bin 6148 -> 0 bytes buckshot/buckshot.pro.user | 2 +- buckshot/mainwindow.cpp | 261 ++++++++++++++++++++++++++++++++++++- buckshot/mainwindow.h | 11 +- buckshot/mainwindow.ui | 25 +++- make_dist_mac.sh | 6 +- 7 files changed, 283 insertions(+), 23 deletions(-) create mode 100644 .gitignore delete mode 100644 assets/.DS_Store diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/assets/.DS_Store b/assets/.DS_Store deleted file mode 100644 index ac3088126042e2fec783f404379a539e03bfcfc1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!AiqG5Pj1|Tdjv4J?_zy*l3H#P^#cne?VG6gwlBNp3m^3`~d%^zS$j0%Gw@P zWCmv6W->36yeye40GYl$jesG5K3%bM#Niv$^Xi#(EYc%Nyv7I@C~<{zyk^-R_=^hY zyF0-P7O1g8`~9u(e7CF@^JP6}jxLZ7`a50LYmUI6#Vc_g-+IQ9duE=|3u7I(Sd%>* zt<=jZl^A0e>(eTAvr3m-mAWRgyTh$<4zo&QsFh&l~g^|;lMbYy14?b zfGhAz3b1FZ^#=)kbOl@iS74)nejfr|u`+BD#!m-_xCI~<3`gT!e-)Jz3@gJXA1vwSB-~IqiLIEq+KNx<(HIXpAy$S>LPlu* OBM@cq!4>#X1-<~*Oi(od diff --git a/buckshot/buckshot.pro.user b/buckshot/buckshot.pro.user index 7f6efbb..0b4ea68 100644 --- a/buckshot/buckshot.pro.user +++ b/buckshot/buckshot.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/buckshot/mainwindow.cpp b/buckshot/mainwindow.cpp index c09a868..83d49e9 100644 --- a/buckshot/mainwindow.cpp +++ b/buckshot/mainwindow.cpp @@ -5,9 +5,10 @@ #include "qdebug.h" #include "qtimer.h" #include "qmessagebox.h" +#include "qinputdialog.h" const QString MainWindow::programName = QString("buckshot"); -const QString MainWindow::version = QString("0.00"); +const QString MainWindow::version = QString("0.02"); const QString MainWindow::imageName = QString("saved"); MainWindow::MainWindow(QWidget *parent) : @@ -137,6 +138,7 @@ void MainWindow::on_pushButton_sourceFilename_clicked() QSize sourceSize = ui->label_source->pixmap()->size(); QString resolutionString = QString("%1 x %2").arg(sourceSize.width()).arg(sourceSize.height()); ui->label_sourceResolution->setText(resolutionString); + updateNeeded=1; } } @@ -233,7 +235,6 @@ void MainWindow::on_pushButton_preview_clicked() QString converterPath = "/Users/dbrock/appleiigs/grlib/b2d"; - //converterPath = QString("%1/b2d").arg(QDir::currentPath()); converterPath = QString("%1/b2d").arg(QCoreApplication::applicationDirPath()); QProcess process; @@ -333,7 +334,14 @@ void MainWindow::on_checkBox_livePreview_stateChanged(int arg1) } -void MainWindow::on_pushButton_saveImage_pressed() +void MainWindow::on_actionWhat_is_this_triggered() +{ + QMessageBox msgBox; + msgBox.setText("This is an image conversion utility to output images for use on classic 8-bit Apple II computers.\n\nPlease see readme for instructions.\n\nSorry for bugs, it's just a toy.\n\n(c)2016 Dagen Brock *\n\n\n * bmp2dhr is by Bill Buckles and does the the actual heavy lifting of conversion! But don't bug him about this software, please."); + msgBox.exec(); +} + +void MainWindow::on_pushButton_saveImage_clicked() { if (ui->label_preview->pixmap() == NULL) { ui->plainTextEdit_lastCmd->document()->setPlainText("Please open a source image and run a preview first!"); @@ -372,9 +380,248 @@ void MainWindow::on_pushButton_saveImage_pressed() } -void MainWindow::on_actionWhat_is_this_triggered() +// HOLY CRAP WHAT IS THIS?? +// Well you see, Johnny, this is a layer of hacks to try +// to wrap CADIUS, but it has no API. So I can clean this up +// but it's more of a proof of concept. I think it'd be +// smarter to add JSON output to CADIUS in the long run. +// I consider this small feature a present to the community. +void MainWindow::on_pushButton_saveToProdos_clicked() { - QMessageBox msgBox; - msgBox.setText("This is an image conversion utility to output images for use on classic 8-bit Apple II computers.\n\nPlease see readme for instructions.\n\nSorry for bugs, it's just a toy.\n\n(c)2016 Dagen Brock *\n\n\n * bmp2dhr is by Bill Buckles and does the the actual heavy lifting of conversion! But don't bug him about this software, please."); - msgBox.exec(); + // @Todo: This isn't appropriate when someone changes res/source and has + // a previous preview pixmap, it will think we are all OK. + if (ui->label_preview->pixmap() == NULL) { + ui->plainTextEdit_lastCmd->document()->setPlainText("Please open a source image and run a preview first!"); + return; + } + + QString cadiusPath = "/Users/dbrock/appleiigs/tools/Cadius"; + cadiusPath = QString("%1/Cadius").arg(QCoreApplication::applicationDirPath()); + + + // KSYNTHED=Type(06),AuxType(2000),VersionCreate(70),MinVersion(BE),Access(E3),FolderInfo1(000000000000000000000000000000000000),FolderInfo2(000000000000000000000000000000000000) + QString filetype = "06"; + QString auxtype = "2000"; + + + QString suffix = ".po"; + QString defaultFilter = tr("All ProDOS Images (*.po *.hdv *.2mg)"); + QString filters = QString(tr("All ProDOS Images (*.po *.hdv *.2mg);;ProDOS Order (*.po);;HDV (*.hdv);;2MG (*.2mg);;All files (*.*)")); + + + // PROMPT FOR SAVE FILENAME AND COPY (HOPEFULLY) TO SAVE FILENAME + QString prodosImageFile = QFileDialog::getSaveFileName(0, "Choose ProDOS Image to Save to", QDir::currentPath(), filters, &defaultFilter, QFileDialog::DontConfirmOverwrite); + + // ALSO GENERATE PRODOS SAFE BASENAME + QFileInfo fi(prodosImageFile); + QString prodosVolumeName = fi.baseName().left(15); // get max volume name + // EMPTY FILENAME?! + if (prodosImageFile.length() == 0) { + return; + } + + QString imageSize = "140KB"; + + // NOW SEE IF IT'S A NEW FILE OR EXISTING IMAGE + QFileInfo check_file(prodosImageFile); + // check if file exists and if yes: Is it really a file and no directory? + if (check_file.exists() && check_file.isFile()) { + // nothing yet. We'll open it below, either way. + } else { + // NEW FILE, PROMPT FOR IMAGE SIZE + QMessageBox msgBox; + msgBox.setText(tr("Select size for new ProDOS image")); + msgBox.addButton(tr("Cancel"), QMessageBox::NoRole); + QAbstractButton* pButton140 = msgBox.addButton(tr("140KB"), QMessageBox::ApplyRole); + QAbstractButton* pButton800 = msgBox.addButton(tr("800KB"), QMessageBox::ApplyRole); + msgBox.setDefaultButton(QMessageBox::Yes); + + msgBox.exec(); + + if (msgBox.clickedButton()==pButton140) { + // set above, nothing to do + } else if (msgBox.clickedButton()==pButton800) { + imageSize = "800KB"; + } else { + return; // cancelled + } + + // NOW CREATE AN IMAGE + QProcess process; + QStringList args; + args << "CREATEVOLUME"; + args << prodosImageFile; + args << prodosVolumeName; + args << imageSize; + QString commandString = QString("%1 %2").arg(cadiusPath, args.join(" ")); + + // RUN THE IMAGE CREATE + process.start(cadiusPath,args); + process.waitForFinished(); // BLOCKS!!! + + // NOW CHECK AGAIN TO SEE IF OUR IMAGE FILE GOT CREATED + if (check_file.exists() && check_file.isFile()) { + qDebug() << "IMAGE FILE CREATED."; + } else { + ui->plainTextEdit_lastCmd->document()->setPlainText(QString("Failed creating image with command: %1").arg(commandString)); + return; + } + + ui->plainTextEdit_lastCmd->document()->setPlainText(commandString); + } + + // NOW CATALOG WHATEVER IMAGE WE GOT... NEW/EXISTING + QProcess cat_process; + QStringList cat_args; + cat_args << "CATALOG"; + cat_args << prodosImageFile; + + // RUN THE CATALOG AND GET OUTPUT + cat_process.start(cadiusPath,cat_args); + cat_process.waitForFinished(); // BLOCKS!!! + QString cat_output = QString(cat_process.readAllStandardOutput()); + qDebug() << "CATALOG OUTPUT (cat_output)\n " << cat_output; + + // regex scanner index + int pos = 0; + QStringList list; + + // MUST MATCH FOR NEWLINES (VS USING ^ or &) + QRegExp vol_rx("\n(/.{1,15}/)\n"); + // OVERWRITE PRODOS VOLUME NAME IF WE KNOW BETTER + while ((pos = vol_rx.indexIn(cat_output, pos)) != -1) { + prodosVolumeName = vol_rx.cap(1); + break; + } + + // NOW MATCH FOR SOME EXTRA DETAILS JUST BECAUSE WE CAN + QRegExp rx("(Block|Free|File|Directory) : (\\d+)"); + pos = 0; + + while ((pos = rx.indexIn(cat_output, pos)) != -1) { + list << rx.cap(1); + qDebug() << rx.cap(1); + pos += rx.matchedLength(); + } + + int diskBlocks, diskFree, diskFiles, diskDirs = 0; + if (list.length() == 4) { + diskBlocks = list[0].toInt(); + diskFree = list[1].toInt(); + diskFiles = list[2].toInt(); + diskDirs = list[3].toInt(); + } else { + ui->plainTextEdit_lastCmd->document()->setPlainText(QString("Failed to catalog ProDOS volume. Make sure that the file is one of: .po .hdv .2mg")); + return; + } + + + + QString a2Filename; + QString savedFilename; + if (ui->comboBox_outputFormat->currentText() == "LR") { + savedFilename = QString("%1/%2.SLO").arg(tmpDirPath,imageName.toUpper()); + a2Filename = QString("%1.SLO").arg(imageName.toUpper()); + auxtype = "400"; // different auxtype (not that is matters) + } else if (ui->comboBox_outputFormat->currentText() == "DLR") { + savedFilename = QString("%1/%2.DLO").arg(tmpDirPath,imageName.toUpper()); + a2Filename = QString("%1.DLO").arg(imageName.toUpper()); + auxtype = "400"; // different auxtype (not that is matters) + } else if (ui->comboBox_outputFormat->currentText() == "HGR") { + savedFilename = QString("%1/%2CH.BIN").arg(tmpDirPath,imageName.toUpper()); + a2Filename = QString("%1CH.BIN").arg(imageName.toUpper()); + } else if (ui->comboBox_outputFormat->currentText() == "DHGR") { + savedFilename = QString("%1/%2.A2FC").arg(tmpDirPath,imageName.toUpper()); + a2Filename = QString("%1.A2FC").arg(imageName.toUpper()); + } else if (ui->comboBox_outputFormat->currentText() == "MONO") { + savedFilename = QString("%1/%2M.BIN").arg(tmpDirPath,imageName.toUpper()); + a2Filename = QString("%1M.BIN").arg(imageName.toUpper()); + } + + + bool ok; + QString prodosFileName = QInputDialog::getText(this, tr("Save Image to ProDOS as"), + tr("ProDOS Name (max 15 chars):"), QLineEdit::Normal, + a2Filename, &ok); + if (ok && !prodosFileName.isEmpty()) { + // COPY IT ... OVER EXISTING NAME? + QString saveFile = QString("%1/%2").arg(tmpDirPath,prodosFileName); + QFile::copy(savedFilename, saveFile); + + // GENERATE OUR STUPID _FileInformation.txt in the same directory + QString fileinfo_text = QString("%1=Type(%2),AuxType(%3),VersionCreate(70),MinVersion(BE),Access(E3),FolderInfo1(000000000000000000000000000000000000),FolderInfo2(000000000000000000000000000000000000)").arg(prodosFileName, filetype, auxtype); + QString fileinfo_file = QString("%1/_FileInformation.txt").arg(tmpDirPath); + qDebug() << "TMP FILE: " << fileinfo_file; + QFile file( fileinfo_file ); + if (file.open(QIODevice::ReadWrite)) { + QTextStream stream( &file ); + stream << fileinfo_text << endl; + } + + // NOW ADD / SAVE OUR FILE + QProcess addfile_process; + QStringList addfile_args; + addfile_args << "ADDFILE" << prodosImageFile << prodosVolumeName << saveFile; // our tmp file + + addfile_process.start(cadiusPath,addfile_args); + addfile_process.waitForFinished(); // BLOCKS!!! + QString addfile_output = QString(addfile_process.readAllStandardOutput()); + + // IF FILE ALREADY EXISTS, ASK IF THEY WANT TO OVERWRITE + if (addfile_output.contains("A file already exist with the same nam")) { + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this, "File exists in image", "File exists, Replace?", + QMessageBox::Yes|QMessageBox::No); + if (reply == QMessageBox::Yes) { + + // ../tools/Cadius DELETEFILE <[2mg|hdv|po]_image_path> + // YES - DELETE + QString deleteFile = QString("%1%2").arg(prodosVolumeName,prodosFileName); + qDebug() << "DELETEFILE : " <plainTextEdit_lastCmd->document()->setPlainText("Save failed. Couldn't delete/overwrite file? I really am not sure what went wrong. Try saving the pictures to your computer and transferring them to ProDOS with another program."); + return; + } + } else { + if (ui->label_preview->pixmap() == NULL) { + ui->plainTextEdit_lastCmd->document()->setPlainText("Save cancelled because file exists."); + return; + } + } + } + + + // IF WE MADE IT THIS FAR, ALL GOOD? + QFile::remove(saveFile); // remove our tmp file + ui->plainTextEdit_lastCmd->document()->setPlainText("File saved."); + + } else { + ui->plainTextEdit_lastCmd->document()->setPlainText("Save cancelled."); + // cancelled? + } + + + return; } diff --git a/buckshot/mainwindow.h b/buckshot/mainwindow.h index 61fc516..150fb09 100644 --- a/buckshot/mainwindow.h +++ b/buckshot/mainwindow.h @@ -26,22 +26,21 @@ private slots: void on_pushButton_sourceFilename_clicked(); - void on_pushButton_preview_clicked(); - void on_horizontalSlider_crossHatch_valueChanged(int value); - void on_horizontalSlider_colorBleed_valueChanged(int value); - void on_comboBox_outputFormat_currentIndexChanged(int index); - void on_comboBox_inputResolution_currentIndexChanged(int index); void on_checkBox_livePreview_stateChanged(int arg1); void previewTimerTimeout(); - void on_pushButton_saveImage_pressed(); void on_actionWhat_is_this_triggered(); + void on_pushButton_preview_clicked(); + void on_pushButton_saveImage_clicked(); + void on_pushButton_saveToProdos_clicked(); + + private: Ui::MainWindow *ui; void updateInputSize(); diff --git a/buckshot/mainwindow.ui b/buckshot/mainwindow.ui index 0ec26f4..c660e40 100644 --- a/buckshot/mainwindow.ui +++ b/buckshot/mainwindow.ui @@ -97,9 +97,9 @@ - 550 + 530 260 - 111 + 131 32 @@ -136,7 +136,7 @@ - 440 + 420 260 101 30 @@ -351,14 +351,14 @@ - 550 + 530 290 - 111 + 131 32 - Save Image + Save Image File @@ -374,6 +374,19 @@ Qt::Vertical + + + + 530 + 320 + 131 + 32 + + + + Save To ProDOS + + diff --git a/make_dist_mac.sh b/make_dist_mac.sh index 67e3fca..89284ce 100755 --- a/make_dist_mac.sh +++ b/make_dist_mac.sh @@ -23,9 +23,9 @@ cp $ADIR/icons.icns $DDIR/Contents/Resources #cp doc/gsplusmanual.txt $DEXTRAS cp README.txt $DEXTRAS cp LICENSE.txt $DEXTRAS -cp ../b2d $DDIR/Contents/MacOS -#cp COPYING.txt $DEXTRAS -#tar -cvzf gsplus-osx.tar.gz gsplus-osx/ +# COPY BINARIES FROM EXTERNAL PROJECTS +cp ../b2d $DDIR/Contents/MacOS +cp ../tools/Cadius $DDIR/Contents/MacOS # packaging now in DMG script