Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp	(revision 66507)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp	(revision 66508)
@@ -60,4 +60,5 @@
 # include "CParallelPort.h"
 # include "CSerialPort.h"
+# include "CSharedFolder.h"
 # include "CConsole.h"
 # include "CMachine.h"
@@ -1253,4 +1254,46 @@
 }
 
+void UIMessageCenter::cannotLoadFoldersSettings(const CMachine &comMachine, QWidget *pParent /* = 0 */)
+{
+    error(pParent, MessageType_Error,
+          tr("Cannot load shared folders settings."),
+          formatErrorInfo(comMachine));
+}
+
+void UIMessageCenter::cannotSaveFoldersSettings(const CMachine &comMachine, QWidget *pParent /* = 0 */)
+{
+    error(pParent, MessageType_Error,
+          tr("Cannot save shared folders settings."),
+          formatErrorInfo(comMachine));
+}
+
+void UIMessageCenter::cannotLoadFoldersSettings(const CConsole &comConsole, QWidget *pParent /* = 0 */)
+{
+    error(pParent, MessageType_Error,
+          tr("Cannot load shared folders settings."),
+          formatErrorInfo(comConsole));
+}
+
+void UIMessageCenter::cannotSaveFoldersSettings(const CConsole &comConsole, QWidget *pParent /* = 0 */)
+{
+    error(pParent, MessageType_Error,
+          tr("Cannot save shared folders settings."),
+          formatErrorInfo(comConsole));
+}
+
+void UIMessageCenter::cannotLoadFolderSettings(const CSharedFolder &comFolder, QWidget *pParent /* = 0 */)
+{
+    error(pParent, MessageType_Error,
+          tr("Cannot load shared folder settings."),
+          formatErrorInfo(comFolder));
+}
+
+void UIMessageCenter::cannotSaveFolderSettings(const CSharedFolder &comFolder, QWidget *pParent /* = 0 */)
+{
+    error(pParent, MessageType_Error,
+          tr("Cannot save shared folder settings."),
+          formatErrorInfo(comFolder));
+}
+
 void UIMessageCenter::cannotAttachDevice(const CMachine &machine, UIMediumType type,
                                          const QString &strLocation, const StorageSlot &storageSlot,
@@ -1334,44 +1377,4 @@
                           QString() /* cancel button text */,
                           false /* ok button by default? */);
-}
-
-void UIMessageCenter::cannotCreateSharedFolder(const CMachine &machine, const QString &strName, const QString &strPath, QWidget *pParent /* = 0*/)
-{
-    error(pParent, MessageType_Error,
-          tr("Failed to create the shared folder <b>%1</b> (pointing to "
-             "<nobr><b>%2</b></nobr>) for the virtual machine <b>%3</b>.")
-          .arg(strName, strPath, CMachine(machine).GetName()),
-          formatErrorInfo(machine));
-}
-
-void UIMessageCenter::cannotCreateSharedFolder(const CConsole &console, const QString &strName, const QString &strPath, QWidget *pParent /* = 0*/)
-{
-    error(pParent, MessageType_Error,
-          tr("Failed to create the shared folder <b>%1</b> (pointing to "
-             "<nobr><b>%2</b></nobr>) for the virtual machine <b>%3</b>.")
-             .arg(strName, strPath, CConsole(console).GetMachine().GetName()),
-          formatErrorInfo(console));
-}
-
-void UIMessageCenter::cannotRemoveSharedFolder(const CMachine &machine, const QString &strName, const QString &strPath, QWidget *pParent /* = 0*/)
-{
-    error(pParent, MessageType_Error,
-          tr("<p>Failed to remove the shared folder <b>%1</b> (pointing to "
-             "<nobr><b>%2</b></nobr>) from the virtual machine <b>%3</b>.</p>"
-             "<p>Please close all programs in the guest OS that "
-             "may be using this shared folder and try again.</p>")
-             .arg(strName, strPath, CMachine(machine).GetName()),
-          formatErrorInfo(machine));
-}
-
-void UIMessageCenter::cannotRemoveSharedFolder(const CConsole &console, const QString &strName, const QString &strPath, QWidget *pParent /* = 0*/)
-{
-    error(pParent, MessageType_Error,
-          tr("<p>Failed to remove the shared folder <b>%1</b> (pointing to "
-             "<nobr><b>%2</b></nobr>) from the virtual machine <b>%3</b>.</p>"
-             "<p>Please close all programs in the guest OS that "
-             "may be using this shared folder and try again.</p>")
-             .arg(strName, strPath, CConsole(console).GetMachine().GetName()),
-          formatErrorInfo(console));
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h	(revision 66507)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h	(revision 66508)
@@ -253,4 +253,10 @@
     void cannotSaveSerialSettings(const CMachine &comMachine, QWidget *pParent = 0);
     void cannotSaveSerialPortSettings(const CSerialPort &comPort, QWidget *pParent = 0);
+    void cannotLoadFoldersSettings(const CMachine &comMachine, QWidget *pParent = 0);
+    void cannotSaveFoldersSettings(const CMachine &comMachine, QWidget *pParent = 0);
+    void cannotLoadFoldersSettings(const CConsole &comConsole, QWidget *pParent = 0);
+    void cannotSaveFoldersSettings(const CConsole &comConsole, QWidget *pParent = 0);
+    void cannotLoadFolderSettings(const CSharedFolder &comFolder, QWidget *pParent = 0);
+    void cannotSaveFolderSettings(const CSharedFolder &comFolder, QWidget *pParent = 0);
     void cannotAttachDevice(const CMachine &machine, UIMediumType type, const QString &strLocation, const StorageSlot &storageSlot, QWidget *pParent = 0);
     bool warnAboutIncorrectPort(QWidget *pParent = 0) const;
@@ -260,8 +266,4 @@
     bool warnAboutRulesConflict(QWidget *pParent = 0) const;
     bool confirmCancelingPortForwardingDialog(QWidget *pParent = 0) const;
-    void cannotCreateSharedFolder(const CMachine &machine, const QString &strName, const QString &strPath, QWidget *pParent = 0);
-    void cannotCreateSharedFolder(const CConsole &console, const QString &strName, const QString &strPath, QWidget *pParent = 0);
-    void cannotRemoveSharedFolder(const CMachine &machine, const QString &strName, const QString &strPath, QWidget *pParent = 0);
-    void cannotRemoveSharedFolder(const CConsole &console, const QString &strName, const QString &strPath, QWidget *pParent = 0);
     void cannotSaveMachineSettings(const CMachine &machine, QWidget *pParent = 0) const;
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp	(revision 66507)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp	(revision 66508)
@@ -396,37 +396,6 @@
     UISettingsPageMachine::fetchData(data);
 
-    /* Make sure machine is in valid mode & folders data was changed: */
-    if (isMachineInValidMode() && m_pCache->wasChanged())
-    {
-        /* For each folder record: */
-        for (int iFolderIndex = 0; iFolderIndex < m_pCache->childCount(); ++iFolderIndex)
-        {
-            /* Get folder cache: */
-            const UISettingsCacheSharedFolder &folderCache = m_pCache->child(iFolderIndex);
-
-            /* Check if this folder data was changed: */
-            if (folderCache.wasChanged())
-            {
-                /* If folder was removed: */
-                if (folderCache.wasRemoved())
-                    removeSharedFolder(folderCache);
-
-                else
-
-                /* If folder was created: */
-                if (folderCache.wasCreated())
-                    createSharedFolder(folderCache);
-
-                else
-
-                /* If folder was updated: */
-                if (folderCache.wasUpdated())
-                {
-                    removeSharedFolder(folderCache);
-                    createSharedFolder(folderCache);
-                }
-            }
-        }
-    }
+    /* Update folders data and failing state: */
+    setFailed(!saveFoldersData());
 
     /* Upload machine to data: */
@@ -847,30 +816,4 @@
 }
 
-CSharedFolderVector UIMachineSettingsSF::getSharedFolders(UISharedFolderType enmSharedFoldersType)
-{
-    CSharedFolderVector sharedFolders;
-    if (isSharedFolderTypeSupported(enmSharedFoldersType))
-    {
-        switch (enmSharedFoldersType)
-        {
-            case MachineType:
-            {
-                AssertMsg(!m_machine.isNull(), ("Machine is NOT set!\n"));
-                sharedFolders = m_machine.GetSharedFolders();
-                break;
-            }
-            case ConsoleType:
-            {
-                AssertMsg(!m_console.isNull(), ("Console is NOT set!\n"));
-                sharedFolders = m_console.GetSharedFolders();
-                break;
-            }
-            default:
-                break;
-        }
-    }
-    return sharedFolders;
-}
-
 void UIMachineSettingsSF::addSharedFolderItem(const UIDataSettingsSharedFolder &sharedFolderData, bool fChoose)
 {
@@ -897,118 +840,241 @@
 }
 
-bool UIMachineSettingsSF::createSharedFolder(const UISettingsCacheSharedFolder &folderCache)
-{
-    /* Get new folder data: */
-    const UIDataSettingsSharedFolder &newFolderData = folderCache.data();
-    const UISharedFolderType enmSharedFoldersType = newFolderData.m_enmType;
-    const QString strName = newFolderData.m_strName;
-    const QString strPath = newFolderData.m_strPath;
-    const bool fIsAutoMount = newFolderData.m_fAutoMount;
-    const bool fIsWritable = newFolderData.m_fWritable;
-
-    /* Get current folders: */
-    const CSharedFolderVector sharedFolders = getSharedFolders(enmSharedFoldersType);
-    /* Make sure such folder doesn't exist: */
-    CSharedFolder sharedFolder;
-    for (int iFolderIndex = 0; iFolderIndex < sharedFolders.size(); ++iFolderIndex)
-        if (sharedFolders.at(iFolderIndex).GetName() == strName)
-            sharedFolder = sharedFolders.at(iFolderIndex);
-    if (sharedFolder.isNull())
-    {
-        /* Create new folder: */
-        switch(enmSharedFoldersType)
+CSharedFolderVector UIMachineSettingsSF::getSharedFolders(UISharedFolderType enmFoldersType)
+{
+    /* Wrap up the getter below: */
+    CSharedFolderVector folders;
+    getSharedFolders(enmFoldersType, folders);
+    return folders;
+}
+
+bool UIMachineSettingsSF::getSharedFolders(UISharedFolderType enmFoldersType, CSharedFolderVector &folders)
+{
+    /* Prepare result: */
+    bool fSuccess = true;
+    /* Load folders of passed type: */
+    if (fSuccess)
+    {
+        /* Make sure folder type is supported: */
+        AssertReturn(isSharedFolderTypeSupported(enmFoldersType), false);
+        switch (enmFoldersType)
         {
             case MachineType:
             {
-                /* Create new folder: */
-                m_machine.CreateSharedFolder(strName, strPath, fIsWritable, fIsAutoMount);
-                if (!m_machine.isOk())
-                {
-                    /* Mark the page as failed: */
-                    setFailed(true);
-                    /* Show error message: */
-                    msgCenter().cannotCreateSharedFolder(m_machine, strName, strPath, this);
-                    /* Finish early: */
-                    return false;
-                }
+                /* Make sure machine was specified: */
+                AssertReturn(!m_machine.isNull(), false);
+                /* Load machine folders: */
+                folders = m_machine.GetSharedFolders();
+                fSuccess = m_machine.isOk();
+                /* Show error message if necessary: */
+                if (!fSuccess)
+                    msgCenter().cannotLoadFoldersSettings(m_machine, this);
                 break;
             }
             case ConsoleType:
             {
-                /* Create new folder: */
-                m_console.CreateSharedFolder(strName, strPath, fIsWritable, fIsAutoMount);
-                if (!m_console.isOk())
-                {
-                    /* Mark the page as failed: */
-                    setFailed(true);
-                    /* Show error message: */
-                    msgCenter().cannotCreateSharedFolder(m_console, strName, strPath, this);
-                    /* Finish early: */
-                    return false;
-                }
+                /* Make sure console was specified: */
+                AssertReturn(!m_console.isNull(), false);
+                /* Load console folders: */
+                folders = m_console.GetSharedFolders();
+                fSuccess = m_console.isOk();
+                /* Show error message if necessary: */
+                if (!fSuccess)
+                    msgCenter().cannotLoadFoldersSettings(m_console, this);
                 break;
             }
             default:
-                break;
-        }
-    }
-    return true;
+                AssertFailedReturn(false);
+        }
+    }
+    /* Return result: */
+    return fSuccess;
+}
+
+bool UIMachineSettingsSF::getSharedFolder(const QString &strFolderName, const CSharedFolderVector &folders, CSharedFolder &comFolder)
+{
+    /* Prepare result: */
+    bool fSuccess = true;
+    /* Look for a folder with passed name: */
+    for (int iFolderIndex = 0; fSuccess && iFolderIndex < folders.size(); ++iFolderIndex)
+    {
+        /* Get current folder: */
+        const CSharedFolder &comCurrentFolder = folders.at(iFolderIndex);
+
+        /* Get current folder name for further activities: */
+        QString strCurrentFolderName;
+        if (fSuccess)
+        {
+            strCurrentFolderName = comCurrentFolder.GetName();
+            fSuccess = comCurrentFolder.isOk();
+        }
+        /* Show error message if necessary: */
+        if (!fSuccess)
+            msgCenter().cannotLoadFolderSettings(comCurrentFolder, this);
+
+        /* If that's the folder we are looking for => take it: */
+        if (fSuccess && strCurrentFolderName == strFolderName)
+            comFolder = folders[iFolderIndex];
+    }
+    /* Return result: */
+    return fSuccess;
+}
+
+bool UIMachineSettingsSF::saveFoldersData()
+{
+    /* Prepare result: */
+    bool fSuccess = true;
+    /* Save folders settings from the cache: */
+    if (fSuccess && isMachineInValidMode() && m_pCache->wasChanged())
+    {
+        /* For each folder: */
+        for (int iFolderIndex = 0; fSuccess && iFolderIndex < m_pCache->childCount(); ++iFolderIndex)
+        {
+            /* Get folder cache: */
+            const UISettingsCacheSharedFolder &folderCache = m_pCache->child(iFolderIndex);
+
+            /* Check if this folder data was changed: */
+            if (folderCache.wasChanged())
+            {
+                /* If folder was removed or updated: */
+                if (folderCache.wasRemoved() || folderCache.wasUpdated())
+                    fSuccess = removeSharedFolder(folderCache);
+
+                /* If folder was created or updated: */
+                if (folderCache.wasCreated() || folderCache.wasUpdated())
+                    fSuccess = createSharedFolder(folderCache);
+            }
+        }
+    }
+    /* Return result: */
+    return fSuccess;
 }
 
 bool UIMachineSettingsSF::removeSharedFolder(const UISettingsCacheSharedFolder &folderCache)
 {
-    /* Get old folder data: */
-    const UIDataSettingsSharedFolder &oldFolderData = folderCache.base();
-    const UISharedFolderType enmSharedFoldersType = oldFolderData.m_enmType;
-    const QString strName = oldFolderData.m_strName;
-    const QString strPath = oldFolderData.m_strPath;
-
-    /* Get current folders: */
-    const CSharedFolderVector sharedFolders = getSharedFolders(enmSharedFoldersType);
-    /* Make sure such folder really exists: */
-    CSharedFolder sharedFolder;
-    for (int iFolderIndex = 0; iFolderIndex < sharedFolders.size(); ++iFolderIndex)
-        if (sharedFolders.at(iFolderIndex).GetName() == strName)
-            sharedFolder = sharedFolders.at(iFolderIndex);
-    if (!sharedFolder.isNull())
-    {
-        /* Remove existing folder: */
-        switch(enmSharedFoldersType)
-        {
-            case MachineType:
+    /* Prepare result: */
+    bool fSuccess = true;
+    /* Remove folder: */
+    if (fSuccess)
+    {
+        /* Get folder data: */
+        const UIDataSettingsSharedFolder &newFolderData = folderCache.base();
+        const UISharedFolderType enmFoldersType = newFolderData.m_enmType;
+        const QString strFolderName = newFolderData.m_strName;
+
+        /* Get current folders: */
+        CSharedFolderVector folders;
+        if (fSuccess)
+            fSuccess = getSharedFolders(enmFoldersType, folders);
+
+        /* Search for a folder with the same name: */
+        CSharedFolder comFolder;
+        if (fSuccess)
+            /* fSuccess = */ getSharedFolder(strFolderName, folders, comFolder);
+
+        /* Make sure such folder really exists: */
+        if (!comFolder.isNull())
+        {
+            /* Remove existing folder: */
+            switch (enmFoldersType)
             {
-                /* Remove existing folder: */
-                m_machine.RemoveSharedFolder(strName);
-                if (!m_machine.isOk())
+                case MachineType:
                 {
-                    /* Mark the page as failed: */
-                    setFailed(true);
-                    /* Show error message: */
-                    msgCenter().cannotRemoveSharedFolder(m_machine, strName, strPath, this);
-                    /* Finish early: */
-                    return false;
+                    /* Remove existing folder: */
+                    m_machine.RemoveSharedFolder(strFolderName);
+                    /* Check that machine is OK: */
+                    fSuccess = m_machine.isOk();
+                    if (!fSuccess)
+                    {
+                        /* Show error message: */
+                        msgCenter().cannotSaveFoldersSettings(m_machine, this);
+                    }
+                    break;
                 }
-                break;
+                case ConsoleType:
+                {
+                    /* Remove existing folder: */
+                    m_console.RemoveSharedFolder(strFolderName);
+                    /* Check that console is OK: */
+                    fSuccess = m_console.isOk();
+                    if (!fSuccess)
+                    {
+                        /* Show error message: */
+                        msgCenter().cannotSaveFoldersSettings(m_console, this);
+                    }
+                    break;
+                }
+                default:
+                    break;
             }
-            case ConsoleType:
+        }
+    }
+    /* Return result: */
+    return fSuccess;
+}
+
+bool UIMachineSettingsSF::createSharedFolder(const UISettingsCacheSharedFolder &folderCache)
+{
+    /* Prepare result: */
+    bool fSuccess = true;
+    /* Remove folder: */
+    if (fSuccess)
+    {
+        /* Get folder data: */
+        const UIDataSettingsSharedFolder &newFolderData = folderCache.data();
+        const UISharedFolderType enmFoldersType = newFolderData.m_enmType;
+        const QString strFolderName = newFolderData.m_strName;
+        const QString strFolderPath = newFolderData.m_strPath;
+        const bool fIsAutoMount = newFolderData.m_fAutoMount;
+        const bool fIsWritable = newFolderData.m_fWritable;
+
+        /* Get current folders: */
+        CSharedFolderVector folders;
+        if (fSuccess)
+            fSuccess = getSharedFolders(enmFoldersType, folders);
+
+        /* Search for a folder with the same name: */
+        CSharedFolder comFolder;
+        if (fSuccess)
+            /* fSuccess = */ getSharedFolder(strFolderName, folders, comFolder);
+
+        /* Make sure such folder doesn't exist: */
+        if (comFolder.isNull())
+        {
+            /* Create new folder: */
+            switch (enmFoldersType)
             {
-                /* Remove existing folder: */
-                m_console.RemoveSharedFolder(strName);
-                if (!m_console.isOk())
+                case MachineType:
                 {
-                    /* Mark the page as failed: */
-                    setFailed(true);
-                    /* Show error message: */
-                    msgCenter().cannotRemoveSharedFolder(m_console, strName, strPath, this);
-                    /* Finish early: */
-                    return false;
+                    /* Create new folder: */
+                    m_machine.CreateSharedFolder(strFolderName, strFolderPath, fIsWritable, fIsAutoMount);
+                    /* Check that machine is OK: */
+                    fSuccess = m_machine.isOk();
+                    if (!fSuccess)
+                    {
+                        /* Show error message: */
+                        msgCenter().cannotSaveFoldersSettings(m_machine, this);
+                    }
+                    break;
                 }
-                break;
+                case ConsoleType:
+                {
+                    /* Create new folder: */
+                    m_console.CreateSharedFolder(strFolderName, strFolderPath, fIsWritable, fIsAutoMount);
+                    /* Check that console is OK: */
+                    fSuccess = m_console.isOk();
+                    if (!fSuccess)
+                    {
+                        /* Show error message: */
+                        msgCenter().cannotSaveFoldersSettings(m_console, this);
+                    }
+                    break;
+                }
+                default:
+                    break;
             }
-            default:
-                break;
-        }
-    }
-    return true;
-}
-
+        }
+    }
+    /* Return result: */
+    return fSuccess;
+}
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.h	(revision 66507)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.h	(revision 66508)
@@ -118,21 +118,27 @@
     QStringList usedList(bool fIncludeSelected);
 
-    /** Returns whether the corresponding @a enmSharedFoldersType supported. */
-    bool isSharedFolderTypeSupported(UISharedFolderType enmSharedFoldersType) const;
+    /** Returns whether the corresponding @a enmFoldersType supported. */
+    bool isSharedFolderTypeSupported(UISharedFolderType enmFoldersType) const;
     /** Updates root item visibility. */
     void updateRootItemsVisibility();
-    /** Defines whether the root item of @a enmSharedFoldersType is @a fVisible. */
-    void setRootItemVisible(UISharedFolderType enmSharedFoldersType, bool fVisible);
-
-    /** Gathers a vector of shared folders of the passed @a enmSharedFoldersType. */
-    CSharedFolderVector getSharedFolders(UISharedFolderType enmSharedFoldersType);
+    /** Defines whether the root item of @a enmFoldersType is @a fVisible. */
+    void setRootItemVisible(UISharedFolderType enmFoldersType, bool fVisible);
 
     /** Creates shared folder item based on passed @a data. */
     void addSharedFolderItem(const UIDataSettingsSharedFolder &sharedFolderData, bool fChoose);
 
+    /** Gathers a vector of shared folders of the passed @a enmFoldersType. */
+    CSharedFolderVector getSharedFolders(UISharedFolderType enmFoldersType);
+    /** Gathers a vector of shared folders of the passed @a enmFoldersType. */
+    bool getSharedFolders(UISharedFolderType enmFoldersType, CSharedFolderVector &folders);
+    /** Look for a folder with the the passed @a strFolderName. */
+    bool getSharedFolder(const QString &strFolderName, const CSharedFolderVector &folders, CSharedFolder &comFolder);
+
+    /** Saves existing folder data from the cache. */
+    bool saveFoldersData();
+    /** Removes shared folder defined by a @a folderCache. */
+    bool removeSharedFolder(const UISettingsCacheSharedFolder &folderCache);
     /** Creates shared folder defined by a @a folderCache. */
     bool createSharedFolder(const UISettingsCacheSharedFolder &folderCache);
-    /** Removes shared folder defined by a @a folderCache. */
-    bool removeSharedFolder(const UISettingsCacheSharedFolder &folderCache);
 
     /** Holds the Add action instance. */
