VirtualBox

Changeset 22173 in vbox for trunk/src/VBox/Frontends/VBoxSDL


Ignore:
Timestamp:
Aug 11, 2009 3:38:59 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
50951
Message:

Main: the big XML settings rework. Move XML reading/writing out of interface implementation code into separate layer so it can handle individual settings versions in the future.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r21520 r22173  
    771771}
    772772#endif /* VBOXSDL_WITH_X11 */
    773 
    774 enum ConvertSettings
    775 {
    776     ConvertSettings_No      = 0,
    777     ConvertSettings_Yes     = 1,
    778     ConvertSettings_Backup  = 2,
    779     ConvertSettings_Ignore  = 3,
    780 };
    781 
    782 /**
    783  * Checks if any of the settings files were auto-converted and informs the
    784  * user if so.
    785  *
    786  * @return @false if the program should terminate and @true otherwise.
    787  *
    788  * @note The function is taken from VBoxManage.cpp almost unchanged (except the
    789  *       help text).
    790  */
    791 static bool checkForAutoConvertedSettings (ComPtr<IVirtualBox> virtualBox,
    792                                            ComPtr<ISession> session,
    793                                            ConvertSettings fConvertSettings)
    794 {
    795     /* return early if nothing to do */
    796     if (fConvertSettings == ConvertSettings_Ignore)
    797         return true;
    798 
    799     HRESULT rc;
    800 
    801     do
    802     {
    803         Bstr formatVersion;
    804         CHECK_ERROR_BREAK(virtualBox, COMGETTER(SettingsFormatVersion) (formatVersion.asOutParam()));
    805 
    806         bool isGlobalConverted = false;
    807         std::list <ComPtr <IMachine> > cvtMachines;
    808         std::list <Utf8Str> fileList;
    809         Bstr version;
    810         Bstr filePath;
    811 
    812         com::SafeIfaceArray <IMachine> machines;
    813         CHECK_ERROR_BREAK(virtualBox, COMGETTER(Machines)(ComSafeArrayAsOutParam (machines)));
    814 
    815         for (size_t i = 0; i < machines.size(); ++ i)
    816         {
    817             BOOL accessible;
    818             CHECK_ERROR_BREAK(machines[i], COMGETTER(Accessible) (&accessible));
    819             if (!accessible)
    820                 continue;
    821 
    822             CHECK_ERROR_BREAK(machines[i], COMGETTER(SettingsFileVersion) (version.asOutParam()));
    823 
    824             if (version != formatVersion)
    825             {
    826                 cvtMachines.push_back (machines[i]);
    827                 Bstr filePath;
    828                 CHECK_ERROR_BREAK(machines[i], COMGETTER(SettingsFilePath) (filePath.asOutParam()));
    829                 fileList.push_back (Utf8StrFmt ("%ls  (%ls)", filePath.raw(),
    830                                                 version.raw()));
    831             }
    832         }
    833 
    834         if (FAILED(rc))
    835             break;
    836 
    837         CHECK_ERROR_BREAK(virtualBox, COMGETTER(SettingsFileVersion) (version.asOutParam()));
    838         if (version != formatVersion)
    839         {
    840             isGlobalConverted = true;
    841             CHECK_ERROR_BREAK(virtualBox, COMGETTER(SettingsFilePath) (filePath.asOutParam()));
    842             fileList.push_back (Utf8StrFmt ("%ls  (%ls)", filePath.raw(),
    843                                             version.raw()));
    844         }
    845 
    846         if (fileList.size() > 0)
    847         {
    848             switch (fConvertSettings)
    849             {
    850                 case ConvertSettings_No:
    851                 {
    852                     RTPrintf (
    853 "WARNING! The following VirtualBox settings files have been automatically\n"
    854 "converted to the new settings file format version '%ls':\n"
    855 "\n",
    856                               formatVersion.raw());
    857 
    858                     for (std::list <Utf8Str>::const_iterator f = fileList.begin();
    859                          f != fileList.end(); ++ f)
    860                         RTPrintf ("  %S\n", (*f).raw());
    861                     RTPrintf (
    862 "\n"
    863 "The current command was aborted to prevent overwriting the above settings\n"
    864 "files with the results of the auto-conversion without your permission.\n"
    865 "Please add one of the following command line switches to the VBoxSDL command\n"
    866 "line and repeat the command:\n"
    867 "\n"
    868 "  --convertSettings       - to save all auto-converted files (it will not\n"
    869 "                            be possible to use these settings files with an\n"
    870 "                            older version of VirtualBox in the future);\n"
    871 "  --convertSettingsBackup - to create backup copies of the settings files in\n"
    872 "                            the old format before saving them in the new format;\n"
    873 "  --convertSettingsIgnore - to not save the auto-converted settings files.\n"
    874 "\n"
    875 "Note that if you use --convertSettingsIgnore, the auto-converted settings files\n"
    876 "will be implicitly saved in the new format anyway once you change a setting or\n"
    877 "start a virtual machine, but NO backup copies will be created in this case.\n");
    878                     return false;
    879                 }
    880                 case ConvertSettings_Yes:
    881                 case ConvertSettings_Backup:
    882                 {
    883                     break;
    884                 }
    885                 default:
    886                     AssertFailedReturn (false);
    887             }
    888 
    889             for (std::list <ComPtr <IMachine> >::const_iterator m = cvtMachines.begin();
    890                  m != cvtMachines.end(); ++ m)
    891             {
    892                 Bstr id;
    893                 CHECK_ERROR_BREAK((*m), COMGETTER(Id) (id.asOutParam()));
    894 
    895                 /* open a session for the VM */
    896                 CHECK_ERROR_BREAK (virtualBox, OpenSession (session, id));
    897 
    898                 ComPtr <IMachine> sm;
    899                 CHECK_ERROR_BREAK(session, COMGETTER(Machine) (sm.asOutParam()));
    900 
    901                 Bstr bakFileName;
    902                 if (fConvertSettings == ConvertSettings_Backup)
    903                     CHECK_ERROR (sm, SaveSettingsWithBackup (bakFileName.asOutParam()));
    904                 else
    905                     CHECK_ERROR (sm, SaveSettings());
    906 
    907                 session->Close();
    908 
    909                 if (FAILED(rc))
    910                     break;
    911             }
    912 
    913             if (FAILED(rc))
    914                 break;
    915 
    916             if (isGlobalConverted)
    917             {
    918                 Bstr bakFileName;
    919                 if (fConvertSettings == ConvertSettings_Backup)
    920                     CHECK_ERROR (virtualBox, SaveSettingsWithBackup (bakFileName.asOutParam()));
    921                 else
    922                     CHECK_ERROR (virtualBox, SaveSettings());
    923             }
    924 
    925             if (FAILED(rc))
    926                 break;
    927         }
    928     }
    929     while (0);
    930 
    931     return SUCCEEDED (rc);
    932 }
    933773
    934774/** entry point */
     
    11841024    sysInfo->COMGETTER (NetworkAdapterCount) (&NetworkAdapterCount);
    11851025
    1186     ConvertSettings fConvertSettings = ConvertSettings_No;
    1187 
    11881026    // command line argument parsing stuff
    11891027    for (int curArg = 1; curArg < argc; curArg++)
     
    16021440            gHostKeyMod = atoi(argv[curArg]);
    16031441        }
    1604         else if (   !strcmp(argv[curArg], "--convertSettings")
    1605                  || !strcmp(argv[curArg], "-convertSettings"))
    1606             fConvertSettings = ConvertSettings_Yes;
    1607         else if (   !strcmp(argv[curArg], "--convertSettingsBackup")
    1608                  || !strcmp(argv[curArg], "-convertSettingsBackup"))
    1609             fConvertSettings = ConvertSettings_Backup;
    1610         else if (   !strcmp(argv[curArg], "--convertSettingsIgnore")
    1611                  || !strcmp(argv[curArg], "-convertSettingsIgnore"))
    1612             fConvertSettings = ConvertSettings_Ignore;
    16131442        /* just show the help screen */
    16141443        else
     
    16231452    }
    16241453    if (FAILED (rc))
    1625         break;
    1626 
    1627     if (!checkForAutoConvertedSettings (virtualBox, session, fConvertSettings))
    16281454        break;
    16291455
Note: See TracChangeset for help on using the changeset viewer.

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