VirtualBox

Changeset 101274 in vbox


Ignore:
Timestamp:
Sep 26, 2023 6:13:37 PM (14 months ago)
Author:
vboxsync
Message:

Main: Added guest OS type ID conversion in the settings code to internally migrate guest OS type IDs of settings < v1.20, as Main always works with the latest definitions internally. See comments for details.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/settings.h

    r101168 r101274  
    15621562    static bool isAudioDriverAllowedOnThisHost(AudioDriverType_T enmDrvType);
    15631563    static AudioDriverType_T getHostDefaultAudioDriver();
     1564    static bool convertGuestOSTypeSuffix(com::Utf8Str &str, const char *pszToReplace, const char *pszReplacement);
    15641565
    15651566private:
     
    15861587    void readGroups(const xml::ElementNode &elmGroups, StringsList &llGroups);
    15871588    bool readSnapshot(const com::Guid &curSnapshotUuid, const xml::ElementNode &elmSnapshot, Snapshot &snap);
    1588     void convertOldOSType_pre1_5(com::Utf8Str &str);
     1589    void convertGuestOSTypeFromPre1_5(com::Utf8Str &str);
     1590    void convertGuestOSTypeFromPre1_20(com::Utf8Str &str);
     1591    void convertGuestOSTypeToPre1_20(com::Utf8Str &str);
    15891592    void readMachine(const xml::ElementNode &elmMachine);
    15901593    void readMachineEncrypted(const xml::ElementNode &elmMachine, PCVBOXCRYPTOIF pCryptoIf, const char *pszPassword);
  • trunk/src/VBox/Main/xml/Settings.cpp

    r101200 r101274  
    68296829    const char *pcszOld;
    68306830    const char *pcszNew;
    6831 } aConvertOSTypes[] =
     6831} aConvertGuestOSTypesPre1_5[] =
    68326832{
    68336833    { "unknown", "Other" },
     
    68686868};
    68696869
    6870 void MachineConfigFile::convertOldOSType_pre1_5(Utf8Str &str)
    6871 {
    6872     for (unsigned u = 0;
    6873          u < RT_ELEMENTS(aConvertOSTypes);
    6874          ++u)
    6875     {
    6876         if (str == aConvertOSTypes[u].pcszOld)
    6877         {
    6878             str = aConvertOSTypes[u].pcszNew;
     6870void MachineConfigFile::convertGuestOSTypeFromPre1_5(Utf8Str &str)
     6871{
     6872    for (size_t u = 0; u < RT_ELEMENTS(aConvertGuestOSTypesPre1_5); ++u)
     6873        if (str == aConvertGuestOSTypesPre1_5[u].pcszOld)
     6874        {
     6875            str = aConvertGuestOSTypesPre1_5[u].pcszNew;
    68796876            break;
    68806877        }
    6881     }
     6878}
     6879
     6880/**
     6881 * Static function to convert a guest OS type ID suffix.
     6882 *
     6883 * @returns \c true if suffix got converted, or \c false if not.
     6884 * @param   strOsType               Guest OS type ID to convert.
     6885 * @param   pszToReplace            Suffix to replace.
     6886 * @param   pszReplacement          What to replace the suffix with.
     6887 */
     6888/* static */
     6889bool MachineConfigFile::convertGuestOSTypeSuffix(com::Utf8Str &strOsType, const char *pszToReplace, const char *pszReplacement)
     6890{
     6891    AssertPtrReturn(pszToReplace, false);
     6892    AssertPtrReturn(pszReplacement, false);
     6893
     6894    size_t const cchSuffix = strlen(pszToReplace);
     6895    size_t const idxSuffix = strOsType.find(pszToReplace);
     6896    if (idxSuffix == strOsType.length() - cchSuffix) /* Be extra cautious to only replace the real suffix. */
     6897    {
     6898        strOsType.replace(idxSuffix, cchSuffix, pszReplacement);
     6899        return true;
     6900    }
     6901    return false;
     6902}
     6903
     6904/**
     6905 * Converts guest OS type IDs to be compatible with settings >= v1.20.
     6906 *
     6907 * @param   str                 Guest OS type ID to convert.
     6908 *
     6909 * @note    Settings < v1.20 require converting some guest OS type IDs, so that the rest of Main can recognize them.
     6910 *          We always work with the latest guest OS type ID internally.
     6911 *
     6912 *          However, we never write back those modified guest OS type IDs for settings < v1.20, as this would break
     6913 *          compatibility with older VBox versions.
     6914 */
     6915void MachineConfigFile::convertGuestOSTypeFromPre1_20(Utf8Str &str)
     6916{
     6917    convertGuestOSTypeSuffix(str, "_64", "_x64");
     6918}
     6919
     6920/**
     6921 * Converts guest OS type IDs to be compatible with settings < v1.20.
     6922 *
     6923 * @param   str                 Guest OS type ID to convert.
     6924 *
     6925 * @note    For settings < v1.20 we have to make sure that we replace the new guest OS type ID suffix "_x64"
     6926 *          with "_64" so that we don't break loading (valid) settings for old(er) VBox versions, which don't
     6927 *          know about the new suffix.
     6928 */
     6929void MachineConfigFile::convertGuestOSTypeToPre1_20(Utf8Str &str)
     6930{
     6931    convertGuestOSTypeSuffix(str, "_x64", "_64");
    68826932}
    68836933
     
    69026952        elmMachine.getAttributeValue("OSType", machineUserData.strOsType);
    69036953        if (m->sv < SettingsVersion_v1_5)
    6904             convertOldOSType_pre1_5(machineUserData.strOsType);
     6954            convertGuestOSTypeFromPre1_5(machineUserData.strOsType);
     6955        if (m->sv <= SettingsVersion_v1_19)
     6956            convertGuestOSTypeFromPre1_20(machineUserData.strOsType);
    69056957
    69066958        elmMachine.getAttributeValue("stateKeyId", strStateKeyId);
     
    90709122    if (machineUserData.strDescription.length())
    90719123        elmMachine.createChild("Description")->addContent(machineUserData.strDescription);
    9072     elmMachine.setAttribute("OSType", machineUserData.strOsType);
    9073 
     9124
     9125    com::Utf8Str strOsType = machineUserData.strOsType;
     9126    if (m->sv < SettingsVersion_v1_20)
     9127        convertGuestOSTypeToPre1_20(strOsType);
     9128    /* else use the unmodified guest OS type ID. */
     9129    elmMachine.setAttribute("OSType", strOsType);
    90749130
    90759131    if (m->sv >= SettingsVersion_v1_19)
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