VirtualBox

Changeset 91285 in vbox


Ignore:
Timestamp:
Sep 16, 2021 2:57:57 PM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9996: A bit of clenaup for Export Appliance wizard.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportApp.cpp

    r91262 r91285  
    55
    66/*
    7  * Copyright (C) 2009-2020 Oracle Corporation
     7 * Copyright (C) 2009-2021 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    5656}
    5757
    58 bool UIWizardExportApp::exportAppliance()
    59 {
    60     /* Check whether there was cloud target selected: */
    61     const bool fIsFormatCloudOne = field("isFormatCloudOne").toBool();
    62     if (fIsFormatCloudOne)
    63     {
    64         /* Get appliance: */
    65         CAppliance comAppliance = field("cloudAppliance").value<CAppliance>();
    66         AssertReturn(comAppliance.isNotNull(), false);
    67 
    68         /* Export the VMs, on success we are finished: */
    69         return exportVMs(comAppliance);
    70     }
    71     else
    72     {
    73         /* Get appliance: */
    74         CAppliance comAppliance = field("localAppliance").value<CAppliance>();
    75         AssertReturn(comAppliance.isNotNull(), false);
    76 
    77         /* We need to know every filename which will be created, so that we can ask the user for confirmation of overwriting.
    78          * For that we iterating over all virtual systems & fetch all descriptions of the type HardDiskImage. Also add the
    79          * manifest file to the check. In the .ova case only the target file itself get checked. */
    80 
    81         /* Compose a list of all required files: */
    82         QFileInfo fi(field("path").toString());
    83         QVector<QString> files;
    84 
    85         /* Add arhive itself: */
    86         files << fi.fileName();
    87 
    88         /* If archive is of .ovf type: */
    89         if (fi.suffix().toLower() == "ovf")
    90         {
    91             /* Add manifest file if requested: */
    92             if (field("manifestSelected").toBool())
    93                 files << fi.baseName() + ".mf";
    94 
    95             /* Add all hard disk images: */
    96             CVirtualSystemDescriptionVector vsds = comAppliance.GetVirtualSystemDescriptions();
    97             for (int i = 0; i < vsds.size(); ++i)
    98             {
    99                 QVector<KVirtualSystemDescriptionType> types;
    100                 QVector<QString> refs, origValues, configValues, extraConfigValues;
    101                 vsds[i].GetDescriptionByType(KVirtualSystemDescriptionType_HardDiskImage, types,
    102                                              refs, origValues, configValues, extraConfigValues);
    103                 foreach (const QString &strValue, origValues)
    104                     files << QString("%2").arg(strValue);
    105             }
    106         }
    107 
    108         /* Initialize VFS explorer: */
    109         CVFSExplorer comExplorer = comAppliance.CreateVFSExplorer(uri(false /* fWithFile */));
    110         if (comExplorer.isNotNull())
    111         {
    112             CProgress comProgress = comExplorer.Update();
    113             if (comExplorer.isOk() && comProgress.isNotNull())
    114             {
    115                 msgCenter().showModalProgressDialog(comProgress, QApplication::translate("UIWizardExportApp", "Checking files ..."),
    116                                                     ":/progress_refresh_90px.png", this);
    117                 if (comProgress.GetCanceled())
    118                     return false;
    119                 if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
    120                     return msgCenter().cannotCheckFiles(comProgress, this);
    121             }
    122             else
    123                 return msgCenter().cannotCheckFiles(comExplorer, this);
    124         }
    125         else
    126             return msgCenter().cannotCheckFiles(comAppliance, this);
    127 
    128         /* Confirm overwriting for existing files: */
    129         QVector<QString> exists = comExplorer.Exists(files);
    130         if (!msgCenter().confirmOverridingFiles(exists, this))
    131             return false;
    132 
    133         /* DELETE all the files which exists after everything is confirmed: */
    134         if (!exists.isEmpty())
    135         {
    136             CProgress comProgress = comExplorer.Remove(exists);
    137             if (comExplorer.isOk() && comProgress.isNotNull())
    138             {
    139                 msgCenter().showModalProgressDialog(comProgress, QApplication::translate("UIWizardExportApp", "Removing files ..."),
    140                                                     ":/progress_delete_90px.png", this);
    141                 if (comProgress.GetCanceled())
    142                     return false;
    143                 if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
    144                     return msgCenter().cannotRemoveFiles(comProgress, this);
    145             }
    146             else
    147                 return msgCenter().cannotCheckFiles(comExplorer, this);
    148         }
    149 
    150         /* Export the VMs, on success we are finished: */
    151         return exportVMs(comAppliance);
    152     }
    153 }
    154 
    15558QString UIWizardExportApp::uri(bool fWithFile) const
    15659{
     
    17174        /* Just path by default: */
    17275        return strPath;
     76    }
     77}
     78
     79bool UIWizardExportApp::exportAppliance()
     80{
     81    /* Check whether there was cloud target selected: */
     82    const bool fIsFormatCloudOne = field("isFormatCloudOne").toBool();
     83    if (fIsFormatCloudOne)
     84    {
     85        /* Get appliance: */
     86        CAppliance comAppliance = field("cloudAppliance").value<CAppliance>();
     87        AssertReturn(comAppliance.isNotNull(), false);
     88
     89        /* Export the VMs, on success we are finished: */
     90        return exportVMs(comAppliance);
     91    }
     92    else
     93    {
     94        /* Get appliance: */
     95        CAppliance comAppliance = field("localAppliance").value<CAppliance>();
     96        AssertReturn(comAppliance.isNotNull(), false);
     97
     98        /* We need to know every filename which will be created, so that we can ask the user for confirmation of overwriting.
     99         * For that we iterating over all virtual systems & fetch all descriptions of the type HardDiskImage. Also add the
     100         * manifest file to the check. In the .ova case only the target file itself get checked. */
     101
     102        /* Compose a list of all required files: */
     103        QFileInfo fi(field("path").toString());
     104        QVector<QString> files;
     105
     106        /* Add arhive itself: */
     107        files << fi.fileName();
     108
     109        /* If archive is of .ovf type: */
     110        if (fi.suffix().toLower() == "ovf")
     111        {
     112            /* Add manifest file if requested: */
     113            if (field("manifestSelected").toBool())
     114                files << fi.baseName() + ".mf";
     115
     116            /* Add all hard disk images: */
     117            CVirtualSystemDescriptionVector vsds = comAppliance.GetVirtualSystemDescriptions();
     118            for (int i = 0; i < vsds.size(); ++i)
     119            {
     120                QVector<KVirtualSystemDescriptionType> types;
     121                QVector<QString> refs, origValues, configValues, extraConfigValues;
     122                vsds[i].GetDescriptionByType(KVirtualSystemDescriptionType_HardDiskImage, types,
     123                                             refs, origValues, configValues, extraConfigValues);
     124                foreach (const QString &strValue, origValues)
     125                    files << QString("%2").arg(strValue);
     126            }
     127        }
     128
     129        /* Initialize VFS explorer: */
     130        CVFSExplorer comExplorer = comAppliance.CreateVFSExplorer(uri(false /* fWithFile */));
     131        if (comExplorer.isNotNull())
     132        {
     133            CProgress comProgress = comExplorer.Update();
     134            if (comExplorer.isOk() && comProgress.isNotNull())
     135            {
     136                msgCenter().showModalProgressDialog(comProgress, QApplication::translate("UIWizardExportApp", "Checking files ..."),
     137                                                    ":/progress_refresh_90px.png", this);
     138                if (comProgress.GetCanceled())
     139                    return false;
     140                if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
     141                    return msgCenter().cannotCheckFiles(comProgress, this);
     142            }
     143            else
     144                return msgCenter().cannotCheckFiles(comExplorer, this);
     145        }
     146        else
     147            return msgCenter().cannotCheckFiles(comAppliance, this);
     148
     149        /* Confirm overwriting for existing files: */
     150        QVector<QString> exists = comExplorer.Exists(files);
     151        if (!msgCenter().confirmOverridingFiles(exists, this))
     152            return false;
     153
     154        /* DELETE all the files which exists after everything is confirmed: */
     155        if (!exists.isEmpty())
     156        {
     157            CProgress comProgress = comExplorer.Remove(exists);
     158            if (comExplorer.isOk() && comProgress.isNotNull())
     159            {
     160                msgCenter().showModalProgressDialog(comProgress, QApplication::translate("UIWizardExportApp", "Removing files ..."),
     161                                                    ":/progress_delete_90px.png", this);
     162                if (comProgress.GetCanceled())
     163                    return false;
     164                if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
     165                    return msgCenter().cannotRemoveFiles(comProgress, this);
     166            }
     167            else
     168                return msgCenter().cannotCheckFiles(comExplorer, this);
     169        }
     170
     171        /* Export the VMs, on success we are finished: */
     172        return exportVMs(comAppliance);
    173173    }
    174174}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportApp.h

    r91259 r91285  
    55
    66/*
    7  * Copyright (C) 2009-2020 Oracle Corporation
     7 * Copyright (C) 2009-2021 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    5151    /** Constructs export appliance wizard passing @a pParent to the base-class.
    5252      * @param  selectedVMNames  Brings the names of VMs to be exported. */
    53     UIWizardExportApp(QWidget *pParent, const QStringList &selectedVMNames = QStringList(), bool fFastTraverToExportOCI = false);
    54 
    55     /** Exports full appliance. */
    56     bool exportAppliance();
     53    UIWizardExportApp(QWidget *pParent,
     54                      const QStringList &selectedVMNames = QStringList(),
     55                      bool fFastTraverToExportOCI = false);
    5756
    5857    /** Composes universal resource identifier.
     
    6059    QString uri(bool fWithFile = true) const;
    6160
     61    /** Exports Appliance. */
     62    bool exportAppliance();
     63
    6264protected slots:
    6365
    6466    /** Handles page change to @a iId. */
    65     virtual void sltCurrentIdChanged(int iId) /* override */;
     67    virtual void sltCurrentIdChanged(int iId) /* override final */;
    6668
    6769protected:
    6870
    6971    /** Handles translation event. */
    70     virtual void retranslateUi() /* override */;
     72    virtual void retranslateUi() /* override final */;
    7173
    7274    /** Prepares all. */
    73     virtual void prepare() /* override */;
     75    virtual void prepare() /* override final */;
    7476
    7577private:
    7678
    77     /** Exports @a comAppliance VMs. */
     79    /** Exports VMs enumerated in @a comAppliance. */
    7880    bool exportVMs(CAppliance &comAppliance);
    7981
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