bool B9UpdateManager::OnDownloadDone()
{
    QString downloadFileName = QString(CROSS_OS_GetDirectoryFromLocationTag("TEMP_DIR") + "/" + updateEntries[currentUpdateIndx].fileName);
    QByteArray data = currentReply->readAll();

    //make directories needed for file int the temp folder.
    QDir().mkpath(QFileInfo(downloadFileName).absolutePath());


    QFile downloadCopy(downloadFileName);
    downloadCopy.open(QIODevice::WriteOnly | QIODevice::Truncate);
    int success = downloadCopy.write(data);
    downloadCopy.close();

    if(!success)
    {
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Warning);
        msgBox.setText("Unable to to copy download to temp directory");
        msgBox.exec();
        return false;
    }
    qDebug() << "UpdateManager: Downloaded " << updateEntries[currentUpdateIndx].fileName << " to temp folder";
    return true;
}
Пример #2
0
void LogFileManager::openLogFileInFolder()
{
    QString path = CROSS_OS_GetDirectoryFromLocationTag("DOCUMENTS_DIR");
    path += "/" + sLogFileName;
    qDebug() << "Log File Location "+path;
    path = "file:///" + path;
    QDesktopServices::openUrl(QUrl(path));
}
Пример #3
0
//upload the firware hex file to the current port - this will freeze the program.
bool B9FirmwareUpdate::UploadHex(QString sCurPort)
{

    QDir avrdir = QDir(CROSS_OS_GetDirectoryFromLocationTag("APPLICATION_DIR"));



    QString launchcommand = "avrdude ";
    #ifndef Q_OS_WIN
        launchcommand = "./avrdude ";
    #endif


    QString args = "-Cavrdude.conf -v -v -v -v -patmega328p -carduino -P" + sCurPort + " -b" + QString::number(FIRMWAREUPDATESPEED) + " -D -Uflash:w:\"" + sHexFilePath + "\":i";


    qDebug() << "B9FirwareUpdate: Calling AVRDude...";

    QCoreApplication::processEvents(); //Process all pending events prior to proceeding.
    QProcess* myProcess = new QProcess(this);
    qDebug() << "Looking for avrdude, avrdude.conf, and .hex file in working dir:" <<avrdir.path();
    QDir::setCurrent(avrdir.path());
    myProcess->setProcessChannelMode(QProcess::MergedChannels);
    myProcess->start(launchcommand + args);



    if (!myProcess->waitForFinished(120000)) //Allow 120 seconds for avrdude to program firmware before timing out
    {
        qDebug() << "B9FirmwareUpdate: AVRDude Firmware Update Timed Out.";
        return false;
    }
    else
    {
        qDebug() << "B9FirmwareUpdate: Begin Firmware Update on Port: " + sCurPort;
        qDebug() << myProcess->readAll();
    }


    if(myProcess->exitCode() != 0)
    {
        qDebug() << "B9FirmwareUpdate: Firmware Update FAILED, exit code:" << QString::number(myProcess->exitCode());
        return false;
    }
    qDebug() << "B9FirmwareUpdate: Firmware Update Complete";

    return true;
}
Пример #4
0
int main(int argc, char *argv[])
{
    B9NativeApp a(argc, argv);

	
    QPixmap pixmap(CROSS_OS_GetDirectoryFromLocationTag("APPLICATION_DIR")+"/"+"splash.png");
    QSplashScreen splash(pixmap,Qt::WindowStaysOnTopHint);
    //processEvents();
    a.mainWindow->setSplash(&splash);
    a.mainWindow->show();
    //a.mainWindow->showSplash();

    a.ProccessArguments();

    return a.exec();
}
bool B9UpdateManager::CopyFromTemp()
{
    qDebug() << "UpdateManager: Copying downloaded files from temp into actuall locations...";
    waitingbar->setDescription("Copying...");
    waitingbar->setMax(updateEntries.size());

    for(int i = 0; i < updateEntries.size(); i++)
    {

        QString src = CROSS_OS_GetDirectoryFromLocationTag("TEMP_DIR") + "/" + updateEntries[i].fileName;
        QString dest = CROSS_OS_GetDirectoryFromLocationTag(updateEntries[i].localLocationTag) + "/"
                + updateEntries[i].fileName;


        qDebug() << "from: " << src;
        qDebug() << "to: " << dest;

        if(QFile::exists(dest))
        {   //if were updating the executable - we must rename the old one instead of removing it..

            #ifdef Q_OS_WIN
            if(updateEntries[i].fileName == "B9Creator.exe")
            {
            #endif
            #ifdef Q_OS_MAC
            if(updateEntries[i].fileName == "B9Creator")
            {
            #endif
            #ifdef Q_OS_LINUX
            if(updateEntries[i].fileName == "B9Creator")
            {
            #endif

                //remove any old b9creator.exe.old files
                if(QFile::exists(QString(dest).append(".old")))
                    QFile::remove(QString(dest).append(".old"));

                //rename the executable we are running. to the .old
                if(rename(dest.toAscii(),
                           QString(dest).append(".old").toAscii()))
                    return false;
            }
            else
                QFile::remove(dest);
        }

        //were about to copy so we need to make any sub directories needed.
         QDir().mkpath(QFileInfo(dest).absolutePath());

        if(!QFile::copy(src,dest))
            return false;
        else
        {
            //at this point we have copied the file.
            //on unix - we have to mark the files as executable files.
            if(updateEntries[i].fileName == "B9Creator")
            {
                #ifdef Q_OS_MAC
                system(QString("chmod +x " + dest).toAscii());
                #endif
                #ifdef Q_OS_LINUX
                    system(QString("chmod +x \"" + dest + "\"").toAscii());
                #endif
            }
            if(updateEntries[i].fileName == "avrdude")
            {
                qDebug() << "APPLYING EXECUTABLNESS TO AVRDUDE!";
                #ifdef Q_OS_MAC
                    system(QString("chmod +x \"" + dest + "\"").toAscii());
                #endif
                #ifdef Q_OS_LINUX
                    system(QString("chmod +x \"" +  dest + "\"").toAscii());
                #endif
            }
            if(updateEntries[i].fileName == "avrdude.conf")
            {
                #ifdef Q_OS_MAC
                system(QString("chmod +x \"" + dest + "\"").toAscii());
                #endif
                #ifdef Q_OS_LINUX
                system(QString("chmod +x \"" + dest + "\"").toAscii());
                #endif
            }
        }

        waitingbar->setValue(i);

    }

    return true;
}


bool B9UpdateManager::UpdateLocalFileVersionList()
{
    int i;
    qDebug() << "UpdateManager: Updating Local File Versions List...";

    QFile vfile(CROSS_OS_GetDirectoryFromLocationTag("APPLICATION_DIR") + "/FileVersions.txt");
    if(!vfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
    {
        return false;
    }
    QTextStream outStream(&vfile);

    for(i = 0; i < remoteEntries.size(); i++)
    {
        outStream << remoteEntries[i].localLocationTag;
        outStream << " ";
        outStream << "\"" << remoteEntries[i].fileName << "\"";
        outStream << " ";
        outStream << remoteEntries[i].version;
        if(i != remoteEntries.size() - 1)
            outStream << "\n";

    }

    vfile.close();
    return true;
}


//move files to proper locations or delete depreciated stuff.
void B9UpdateManager::TransitionFromPreviousVersions()
{
#ifndef Q_OS_LINUX
    //old 1.4 files in the wrong location
    QFile::remove(CROSS_OS_GetDirectoryFromLocationTag("EXECUTABLE_DIR") + "/B9Creator_LOG.txt");
    QFile::remove(CROSS_OS_GetDirectoryFromLocationTag("EXECUTABLE_DIR") + "/B9Firmware_1_0_9.hex");
    QFile::remove(CROSS_OS_GetDirectoryFromLocationTag("EXECUTABLE_DIR") + "/avrdude.exe");
    QFile::remove(CROSS_OS_GetDirectoryFromLocationTag("EXECUTABLE_DIR") + "/avrdude");
    QFile::remove(CROSS_OS_GetDirectoryFromLocationTag("EXECUTABLE_DIR") + "/avrdude.conf");
#endif
    //OLD Material file sould be salvaged by b9matcat and removed.

    //check for old executables and delete them
    QFile(CROSS_OS_GetDirectoryFromLocationTag("EXECUTABLE_DIR") + "/B9Creator.exe.old").remove();
}
void B9UpdateManager::PromptDoUpdates(bool showCheckingBar, bool promptLocalLocation)
{

    silentUpdateChecking = !showCheckingBar;
    //only even think about Doing Updates if the state machine isnt doing anything
    if(downloadState != "Idle" && !silentUpdateChecking)
    {
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Warning);
        msgBox.setText("B9Creator is already checking for updates");
        msgBox.exec();
        return;
    }


    if(netManager->networkAccessible() == QNetworkAccessManager::NotAccessible && !silentUpdateChecking)
    {
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Warning);
        msgBox.setText("B9Creator does not have accesss to the network");
        msgBox.exec();
        return;

    }
    //maybe do some other early checks if possible.



    //create waiting bar now
    waitingbar = new LoadingBar(0,0,false);
    if(silentUpdateChecking) waitingbar->hide();
    connect(waitingbar,SIGNAL(rejected()),this,SLOT(OnCancelUpdate()));


    //get the network access manager looking for the file versions.txt on the manifest;
    QNetworkRequest request;

    if(promptLocalLocation)//prompt the user for new manifest location.
    {
        QString path = QFileDialog::getExistingDirectory(NULL,
                       "Locate the B9Creator Update Pack Folder",
                       CROSS_OS_GetDirectoryFromLocationTag("DOCUMENTS_DIR"));
        qDebug() << "Opening Update Pack: " << path;
        if(path.isEmpty())
            return;

        QString manifestURL = QUrl().fromLocalFile(path + "/" + RemoteManifestFileName).toString();
        RemoteManifestPath = QUrl().fromLocalFile(path).toString();
        request.setUrl(QUrl(manifestURL));
    }
    else//user internet manifest location.
    {
        request.setUrl(QUrl(RemoteManifestPath + RemoteManifestFileName));
    }


    //and set the state
    downloadState = "DownloadingFileVersions";

    qDebug() << "UpdateManager: User Started Update Check and Download";

    StartNewDownload(request);
}
//copies downloaded versions file into internal data structure;
void B9UpdateManager::CopyInRemoteEntries()
{
    QString entryPlatform;

    remoteEntries.clear();


    currentReply->setTextModeEnabled(true);
    QTextStream inStream(currentReply);



    B9UpdateEntry entry;

    while(!inStream.atEnd())
    {
        inStream >> entry.localLocationTag;
        if(entry.localLocationTag.startsWith("//"))
        {   inStream.readLine();
            inStream.skipWhiteSpace();
            continue;
        }
        entry.fileName = StreamInTextQuotes(inStream);
        inStream >> entry.version;
        inStream >> entryPlatform;

        if(entryPlatform == "ANY")
        {
            entry.OSDir = "COMMON/";
            remoteEntries.push_back(entry);
        }
        else
        {
            #ifdef Q_OS_WIN
            if((entryPlatform == "WIN"))
            {
                entry.OSDir = "WINDOWS/";
            #endif
            #ifdef Q_OS_MAC
            if((entryPlatform == "MAC"))
            {
                entry.OSDir = "MAC/";
            #endif
            #ifdef Q_OS_LINUX
            if((entryPlatform == "LINUX"))
            {
                entry.OSDir = "LINUX/";
            #endif

                remoteEntries.push_back(entry);
            }
        }

        inStream.skipWhiteSpace();
    }
    qDebug() << "UpdateManager: " << remoteEntries.size() << " Remote Entrees Loaded";
}


void B9UpdateManager::CopyInLocalEntries()
{
    localEntries.clear();

    QFile localvfile(CROSS_OS_GetDirectoryFromLocationTag("APPLICATION_DIR") + "/FileVersions.txt");
    localvfile.open(QIODevice::ReadOnly);
    QTextStream stream(&localvfile);

    while(!stream.atEnd())
    {
        B9UpdateEntry newEntry;
        stream >> newEntry.localLocationTag;
        newEntry.fileName = StreamInTextQuotes(stream);

        stream >> newEntry.version;
        //as we read in from local fileversions.txt, it is possible that the local file
        //is missing even though it is listed in the text file,
        //to counter this, we need to actuall check if the file exists.
        // and set the version to a really low number so it has to be updated later on.
        if(!QFile::exists(CROSS_OS_GetDirectoryFromLocationTag(newEntry.localLocationTag) + "/" + newEntry.fileName))
            newEntry.version = -1;


        localEntries.push_back(newEntry);
        stream.skipWhiteSpace();//eat up new line
    }
    localvfile.close();

    qDebug() << "UpdateManager: " << localEntries.size() << " Local Entrees Loaded";
}


//compare remote entries and local entries and fill a updateEntries list
//so we know to whole list of files to be updates
void B9UpdateManager::CalculateUpdateEntries()
{
    int r;
    int l;
    bool dne;
    updateEntries.clear();
    for(r = 0; r < remoteEntries.size(); r++)
    {
        dne = true;
        for(l = 0; l < localEntries.size(); l++)
        {
            if(localEntries[l].fileName == remoteEntries[r].fileName)
            {
                dne = false;
                if(NeedsUpdated(localEntries[l],remoteEntries[r]))
                {
                    updateEntries.push_back(remoteEntries[r]);
                }
            }
        }
        if(dne == true)//if there isnt a file match local we still to update
        {
                updateEntries.push_back(remoteEntries[r]);
        }
    }
}
Пример #8
0
//Imports
void B9SupportStructure::ImportAttachmentDataFromStls()
{
    int i;
    bool s;
    bool triangleError;
    STLTri* pLoadedTri = NULL;
    Triangle3D newtri;
    QDir appdir(CROSS_OS_GetDirectoryFromLocationTag("APPLICATION_DIR"));
    QStringList filters;
    B9SupportAttachmentData importedData;

    qDebug() << "B9SupportStructure: Importing Stl Attachments...";

    //Import All Stl in the application directory begining with "SUPPORT"
    filters << "SUPPORT_*";
    appdir.setNameFilters(filters);
    QFileInfoList stlFiles = appdir.entryInfoList();
    for(i = 0; i < stlFiles.size(); i++)
    {
        B9ModelLoader stlLoader(stlFiles[i].filePath(),s);
        if(s)
        {
            while(stlLoader.LoadNextTri(pLoadedTri,triangleError))
            {
                if(triangleError)
                {
                    qDebug() << "B9SupportStructure: ErrorLoading triangle";
                    return;
                }
                newtri.normal.setX(pLoadedTri->nx);
                newtri.normal.setY(pLoadedTri->ny);
                newtri.normal.setZ(pLoadedTri->nz);

                newtri.vertex[0].setX(pLoadedTri->x0);
                newtri.vertex[0].setY(pLoadedTri->y0);
                newtri.vertex[0].setZ(pLoadedTri->z0);
                newtri.vertex[1].setX(pLoadedTri->x1);
                newtri.vertex[1].setY(pLoadedTri->y1);
                newtri.vertex[1].setZ(pLoadedTri->z1);
                newtri.vertex[2].setX(pLoadedTri->x2);
                newtri.vertex[2].setY(pLoadedTri->y2);
                newtri.vertex[2].setZ(pLoadedTri->z2);

                delete pLoadedTri;
                newtri.UpdateBounds();

                importedData.GetTriangles()->push_back(newtri);
            }

            //save the data into the Static List.
            importedData.SetName(stlFiles[i].baseName().remove("SUPPORT_"));
            importedData.CenterGeometry();//center the triangles around 0,0,0
            B9SupportStructure::AttachmentDataList.push_back(importedData);
            //clear out importedData
            importedData = B9SupportAttachmentData();
        }
        else
        {
            qDebug() << "B9SupportStructure: Error Loading: " << stlFiles[i].fileName();
        }

    }

    qDebug() << "B9SupportStructure: Succesfully Loaded "
             << B9SupportStructure::AttachmentDataList.size()
             << " Attachment Types";
}