VirtualBox

Changeset 34837 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 8, 2010 2:37:42 PM (14 years ago)
Author:
vboxsync
Message:

Main/Settings: always use forward slashes in media & snapshot folder paths to make things more portable between windows & other OSes

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/string.cpp

    r33805 r34837  
    9797}
    9898
     99Utf8Str& Utf8Str::useForwardSlashes()
     100{
     101    for (size_t i = 0; i < length(); ++i)
     102    {
     103        char *p = &m_psz[i];
     104        if (*p == '\\')
     105            *p = '/';
     106    }
     107
     108    return *this;
     109}
     110
    99111/**
    100112 * Internal function used in Utf8Str copy constructors and assignment when
  • trunk/src/VBox/Main/xml/Settings.cpp

    r34598 r34837  
    646646
    647647            if (fNeedsFilePath)
     648            {
    648649                if (!(pelmImage->getAttributeValue("filePath", med.strLocation)))
    649650                    throw ConfigFileError(this, &elmMedium, N_("Required %s/@filePath attribute is missing"), elmMedium.getName());
     651                else
     652                    // IPRT can handle forward slashes in file paths everywhere, but there might be
     653                    // backslashes in the settings file, so convert them into forward slashes.
     654                    med.strLocation.useForwardSlashes();
     655            }
    650656        }
    651657
     
    10021008
    10031009    pelmMedium->setAttribute("uuid", mdm.uuid.toStringCurly());
    1004     pelmMedium->setAttribute("location", mdm.strLocation);
     1010
     1011    // always use forward slashes when writing out settings, never '\'
     1012    Utf8Str strLocation(mdm.strLocation);
     1013    strLocation.useForwardSlashes();
     1014    pelmMedium->setAttribute("location", strLocation);
     1015
    10051016    pelmMedium->setAttribute("format", mdm.strFormat);
    10061017    if (mdm.fAutoReset)
     
    31683179        if (elmMachine.getAttributeValue("currentSnapshot", str))
    31693180            parseUUID(uuidCurrentSnapshot, str);
     3181
    31703182        elmMachine.getAttributeValue("snapshotFolder", machineUserData.strSnapshotFolder);
     3183        // IPRT can handle forward slashes in file paths everywhere, but there might be
     3184        // backslashes in the settings file, so convert them into forward slashes.
     3185        machineUserData.strSnapshotFolder.useForwardSlashes();
     3186
    31713187        if (!elmMachine.getAttributeValue("currentStateModified", fCurrentStateModified))
    31723188            fCurrentStateModified = true;
     
    41904206         && !uuidCurrentSnapshot.isEmpty())
    41914207        elmMachine.setAttribute("currentSnapshot", uuidCurrentSnapshot.toStringCurly());
     4208
    41924209    if (machineUserData.strSnapshotFolder.length())
    4193         elmMachine.setAttribute("snapshotFolder", machineUserData.strSnapshotFolder);
     4210    {
     4211        // always use forward slashes when writing out settings, never '\'
     4212        Utf8Str strSnapshotFolder(machineUserData.strSnapshotFolder);
     4213        strSnapshotFolder.useForwardSlashes();
     4214        elmMachine.setAttribute("snapshotFolder", strSnapshotFolder);
     4215    }
    41944216    if (!fCurrentStateModified)
    41954217        elmMachine.setAttribute("currentStateModified", fCurrentStateModified);
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