VirtualBox

Changeset 100093 in vbox


Ignore:
Timestamp:
Jun 7, 2023 12:25:18 PM (18 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9080. Some refactoring.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoCreator.cpp

    r100081 r100093  
    3131#include <QPushButton>
    3232#include <QStyle>
     33#include <QTextStream>
    3334
    3435/* GUI includes: */
     
    527528
    528529/* static */
    529 int UIVisoCreatorWidget::visoWriteQuotedString(PRTSTREAM pStrmDst, const char *pszPrefix,
    530                                                QString const &rStr, const char *pszPostFix)
    531 {
    532     QByteArray const utf8Array   = rStr.toUtf8();
    533     const char      *apszArgv[2] = { utf8Array.constData(), NULL };
    534     char            *pszQuoted;
    535     int vrc = RTGetOptArgvToString(&pszQuoted, apszArgv, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);
    536     if (RT_SUCCESS(vrc))
    537     {
    538         if (pszPrefix)
    539             vrc = RTStrmPutStr(pStrmDst, pszPrefix);
    540         if (RT_SUCCESS(vrc))
    541         {
    542             vrc = RTStrmPutStr(pStrmDst, pszQuoted);
    543             if (pszPostFix && RT_SUCCESS(vrc))
    544                 vrc = RTStrmPutStr(pStrmDst, pszPostFix);
    545         }
    546         RTStrFree(pszQuoted);
    547     }
    548     return vrc;
    549 }
    550 
    551 /* static */
    552530QUuid UIVisoCreatorWidget::createViso(UIActionPool *pActionPool, QWidget *pParent,
    553531                                      const QString &strDefaultFolder /* = QString() */,
     
    564542    if (pVisoCreator->exec(false /* not application modal */))
    565543    {
    566         QStringList files = pVisoCreator->entryList();
     544        QStringList VisoEntryList = pVisoCreator->entryList();
    567545        QString strVisoName = pVisoCreator->visoName();
    568546        if (strVisoName.isEmpty())
    569547            strVisoName = strMachineName;
    570548
    571         if (files.empty() || files[0].isEmpty())
     549        if (VisoEntryList.empty() || VisoEntryList[0].isEmpty())
    572550        {
    573551            delete pVisoCreator;
     
    577555        gEDataManager->setVISOCreatorRecentFolder(pVisoCreator->currentPath());
    578556
    579         /* Produce the VISO. */
    580         char szVisoPath[RTPATH_MAX];
    581         QString strFileName = QString("%1%2").arg(strVisoName).arg(".viso");
    582 
    583557        QString strVisoSaveFolder(strDefaultFolder);
    584558        if (strVisoSaveFolder.isEmpty())
    585559            strVisoSaveFolder = uiCommon().defaultFolderPathForType(UIMediumDeviceType_DVD);
    586560
    587         int vrc = RTPathJoin(szVisoPath, sizeof(szVisoPath), strVisoSaveFolder.toUtf8().constData(), strFileName.toUtf8().constData());
    588         if (RT_SUCCESS(vrc))
     561        if (QDir(strVisoSaveFolder).exists())
    589562        {
    590             PRTSTREAM pStrmViso;
    591             vrc = RTStrmOpen(szVisoPath, "w", &pStrmViso);
    592             if (RT_SUCCESS(vrc))
     563            QString strFileName = QString("%1/%2%3").arg(strVisoSaveFolder).arg(strVisoName).arg(".viso");
     564
     565            QFile file(strFileName);
     566            if (file.open(QFile::WriteOnly | QFile::Truncate))
    593567            {
    594                 RTUUID Uuid;
    595                 vrc = RTUuidCreate(&Uuid);
    596                 if (RT_SUCCESS(vrc))
    597                 {
    598                     RTStrmPrintf(pStrmViso, "--iprt-iso-maker-file-marker-bourne-sh %RTuuid\n", &Uuid);
    599                     vrc = UIVisoCreatorWidget::visoWriteQuotedString(pStrmViso, "--volume-id=", strVisoName, "\n");
    600 
    601                     for (int iFile = 0; iFile < files.size() && RT_SUCCESS(vrc); iFile++)
    602                         vrc = UIVisoCreatorWidget::visoWriteQuotedString(pStrmViso, NULL, files[iFile], "\n");
    603 
    604                     /* Append custom options if any to the file: */
    605                     const QStringList &customOptions = pVisoCreator->customOptions();
    606                     foreach (QString strLine, customOptions)
    607                         RTStrmPrintf(pStrmViso, "%s\n", strLine.toUtf8().constData());
    608 
    609                     RTStrmFlush(pStrmViso);
    610                     if (RT_SUCCESS(vrc))
    611                         vrc = RTStrmError(pStrmViso);
    612                 }
    613 
    614                 RTStrmClose(pStrmViso);
     568                QTextStream stream(&file);
     569                stream << QString("%1 %2").arg("--iprt-iso-maker-file-marker-bourne-sh").arg(QUuid::createUuid().toString());
     570                stream << "\n";
     571                stream << VisoEntryList.join("\n");
     572                stream << pVisoCreator->customOptions().join("\n");
     573                file.close();
    615574            }
    616575        }
    617 
    618         /* Done. */
    619         if (RT_SUCCESS(vrc))
    620         {
    621             delete pVisoCreator;
    622             return uiCommon().openMedium(UIMediumDeviceType_DVD, QString(szVisoPath), pParent);
    623         }
    624         /** @todo error message. */
    625         else
    626         {
    627             delete pVisoCreator;
    628             return QUuid();
    629         }
    630     }
     576    } // if (pVisoCreator->exec(false /* not application modal */))
    631577    delete pVisoCreator;
    632578    return QUuid();
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoCreator.h

    r100071 r100093  
    9393    QIToolBar *toolbar() const { return m_pToolBar; }
    9494#endif
    95 
    96     /**
    97       * Helper for createVisoMediumWithVisoCreator.
    98       * @returns IPRT status code.
    99       * @param   pStrmDst            Where to write the quoted string.
    100       * @param   pszPrefix           Stuff to put in front of it.
    101       * @param   rStr                The string to quote and write out.
    102       * @param   pszPrefix           Stuff to put after it.
    103       */
    104     static int visoWriteQuotedString(PRTSTREAM pStrmDst, const char *pszPrefix,
    105                                      QString const &rStr, const char *pszPostFix);
    10695
    10796protected:
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette