Ticket #3737: optionsReset-v3.patch

File optionsReset-v3.patch, 24.8 KB (added by mimo, 8 years ago)

improved version of the patch for the reset of options

  • binaries/data/mods/public/gui/gamesetup/gamesetup_mp.js

     
    192192function startHost(playername, servername)
    193193{
    194194    // Save player name
    195     Engine.ConfigDB_CreateValue("user", "playername", playername);
    196     Engine.ConfigDB_WriteFile("user", "config/user.cfg");
     195    Engine.ConfigDB_CreateValueAndWriteOnFile("user", "playername", playername, "config/user.cfg");
    197196    // Disallow identically named games in the multiplayer lobby
    198197    if (Engine.HasXmppClient())
    199198    {
     
    253252    if (Engine.HasXmppClient())
    254253        // Set player lobby presence
    255254        Engine.LobbySetPlayerPresence("playing");
    256     else {
     255    else
     256    {
    257257        // Only save the player name and host address if they're valid and we're not in the lobby
    258         Engine.ConfigDB_CreateValue("user", "playername", playername);
    259         Engine.ConfigDB_CreateValue("user", "multiplayerserver", ip);
    260         Engine.ConfigDB_WriteFile("user", "config/user.cfg");
     258        Engine.ConfigDB_CreateValueAndWriteOnFile("user", "playername", playername, "config/user.cfg");
     259        Engine.ConfigDB_CreateValueAndWriteOnFile("user", "multiplayerserver", ip, "config/user.cfg");
    261260    }
    262261    return true;
    263262}
  • binaries/data/mods/public/gui/lobby/prelobby.js

     
    179179        {
    180180            Engine.PopGuiPage();
    181181            Engine.SwitchGuiPage("page_lobby.xml");
    182             Engine.ConfigDB_CreateValue("user", "playername", sanitizePlayerName(username, true, true));
    183             Engine.ConfigDB_CreateValue("user", "lobby.login", username);
     182            Engine.ConfigDB_CreateValueAndWriteOnFile("user", "playername", sanitizePlayerName(username, true, true), "config/user.cfg");
     183            Engine.ConfigDB_CreateValueAndWriteOnFile("user", "lobby.login", username, "config/user.cfg");
    184184            // We only store the encrypted password, so make sure to re-encrypt it if changed before saving.
    185185            if (password != g_EncrytedPassword.substring(0, 10))
    186186                g_EncrytedPassword = Engine.EncryptPassword(password, username);
    187             Engine.ConfigDB_CreateValue("user", "lobby.password", g_EncrytedPassword);
    188             Engine.ConfigDB_WriteFile("user", "config/user.cfg");
     187            Engine.ConfigDB_CreateValueAndWriteOnFile("user", "lobby.password", g_EncrytedPassword, "config/user.cfg");
    189188            break;
    190189        }
    191190        }
  • binaries/data/mods/public/gui/options/options.js

     
    55{
    66    if (data && data.callback)
    77        g_HasCallback = true;
    8     let revert = data && data.revert;
    98    g_Controls = {};
    109
    1110    var options = Engine.ReadJSONFile("gui/options/options.json");
     
    2120            let label = Engine.GetGUIObjectByName(category + "Label[" + i + "]");
    2221            let config = option.parameters.config;
    2322            g_Controls[config] = {
    24                 "control": setupControl(option, i, category, revert),
     23                "control": setupControl(option, i, category),
    2524                "type": option.type,
    26                 "dependencies": option.dependencies || undefined
     25                "dependencies": option.dependencies || undefined,
     26                "parameters": option.parameters
    2727            };
    2828            label.caption = translate(option.label);
    2929            label.tooltip = option.tooltip ? translate(option.tooltip) : "";
     
    4747                    continue;
    4848                if (!opt.dependencies || opt.dependencies.indexOf(config) === -1)
    4949                    continue;
    50                 label.caption = "       " + label.caption;
     50                label.caption = "      " + label.caption;
    5151                break;
    5252            }
    5353            // Show element.
     
    5555        }
    5656    }
    5757
    58     updateDependencies();
    59     if (!revert)
    60         updateStatus();
     58    updateDisplay();
    6159}
    6260
    6361/**
     
    6664 * @param option Structure containing the data to setup an option.
    6765 * @param prefix Prefix to use when accessing control, for example "generalSetting" when the tickbox name is generalSettingTickbox[i].
    6866 */
    69 function setupControl(option, i, category, revert)
     67function setupControl(option, i, category)
    7068{
    7169    var control;
    7270    var onUpdate;
     
    9290            {
    9391            case "config":
    9492                keyConfig = option.parameters.config;
    95                 if (checked === undefined || revert)
     93                if (checked === undefined)
    9694                    checked = Engine.ConfigDB_GetValue("user", keyConfig) === "true";
    97                 else if ((Engine.ConfigDB_GetValue("user", keyConfig) === "true") !== checked)
    98                 {
    99                     Engine.ConfigDB_CreateValue("user", keyConfig, String(checked));
    100                     updateStatus(true);
    101                 }
    10295                break;
    10396            case "renderer":
    10497                keyRenderer = option.parameters.renderer;
     
    131124                    Engine["Renderer_Set" + keyRenderer + "Enabled"](val);
    132125                if (keyConfig)
    133126                    Engine.ConfigDB_CreateValue("user", keyConfig, String(val));
    134                 updateDependencies();
    135                 updateStatus(true);
     127                updateDisplay();
    136128            };
    137129        }(keyRenderer, keyConfig, inverted);
    138130
     
    190182                Engine.ConfigDB_CreateValue("user", key, this.caption);
    191183                if (functionBody)
    192184                    Engine[functionBody](+this.caption);
    193                 updateDependencies();
    194                 updateStatus(true);
     185                updateDisplay();
    195186            };
    196187        }(key, functionBody, minval, maxval);
    197188
     
    201192        break;
    202193    case "dropdown":
    203194        control = Engine.GetGUIObjectByName(category + "Dropdown[" + i + "]");
     195        control.onSelectionChange = function(){};  // just the time to setup the value
    204196        var caption;
    205197        var key;
    206198        var functionBody;
     
    237229                if (key === "materialmgr.quality")
    238230                    val = val == 0 ? 2 : val == 1 ? 5 : 8;
    239231                Engine.ConfigDB_CreateValue("user", key, val);
    240                 updateDependencies();
    241                 updateStatus(true);
     232                updateDisplay();
    242233            };
    243234        }(key);
    244235
     
    254245    return control;
    255246}
    256247
    257 function updateStatus(val)
     248function updateDisplay()
    258249{
    259     if (typeof val == "boolean")
    260         Engine.ConfigDB_CreateValue("user", "nosave.haschanges", String(val));
    261     else
    262         val = Engine.ConfigDB_GetValue("user", "nosave.haschanges") === "true";
     250    // Update dependencies
     251    for (let item in g_Controls)
     252    {
     253        let control = g_Controls[item];
     254        if (control.type !== "boolean" && control.type !== "invertedboolean" || !control.dependencies)
     255            continue;
    263256
    264     Engine.GetGUIObjectByName("loadOptions").enabled = val;
    265     Engine.GetGUIObjectByName("saveOptions").enabled = val;
     257        for (let dependency of control.dependencies)
     258            g_Controls[dependency].control.enabled = control.control.checked;
     259    }
     260
     261    // And main buttons
     262    let dirty = Engine.ConfigDB_IsDirty("user");
     263    let changes = Engine.ConfigDB_HasChanges("user") && !dirty;
     264    Engine.GetGUIObjectByName("resetChanges").enabled = !dirty;
     265    Engine.GetGUIObjectByName("revertChanges").enabled = changes;
     266    Engine.GetGUIObjectByName("saveChanges").enabled = changes;
     267    if (dirty)
     268    {
     269        let warning = "You need to restart the game after a reset to be able to modify again the options";
     270        Engine.GetGUIObjectByName("resetChanges").tooltip = warning;
     271        Engine.GetGUIObjectByName("revertChanges").tooltip = warning;
     272        Engine.GetGUIObjectByName("saveChanges").tooltip = warning;
     273    }
    266274}
    267275
    268276/**
     
    275283            g_Controls[item].control.onPress();
    276284}
    277285
    278 function updateDependencies()
     286function resetChanges()
    279287{
     288    let btCaptions = [translate("No"), translate("Yes")];
     289    let btCode = [null, function(){ reallyResetChanges(); }];
     290    messageBox(500, 200, translate("Resetting the options will be effective only after restarting the game. Are you sure you want to continue ?"),
     291        translate("Warning"), 0, btCaptions, btCode);
     292}
     293
     294function reallyResetChanges()
     295{
    280296    for (let item in g_Controls)
    281     {
    282         let control = g_Controls[item];
    283         if (control.type !== "boolean" && control.type !== "invertedboolean" || !control.dependencies)
    284             continue;
     297        Engine.ConfigDB_RemoveValue("user", item);
    285298
    286         for (let dependency of control.dependencies)
    287             g_Controls[dependency].control.enabled = control.control.checked;
    288     }
     299    Engine.ConfigDB_WriteFile("user", "config/user.cfg");
     300    Engine.ConfigDB_SetDirty("user");
     301    updateDisplay();
    289302}
    290303
    291304function revertChanges()
    292305{
    293306    Engine.ConfigDB_Reload("user");
    294     updateStatus(false);
    295     init({ "revert": true });
     307    // needs to update renderer values (which are all of boolean type)
     308    for (let item in g_Controls)
     309    {
     310        let control = g_Controls[item];
     311        if (!control.parameters.renderer)
     312            continue;
     313        if (control.type !== "boolean" && control.type !== "invertedboolean")
     314        {
     315            warn("Invalid type option defined in renderer '" + control.type + "': will not be reverted");
     316            continue;
     317        }
     318        let value = Engine.ConfigDB_GetValue("user", item) === "true";
     319        let keyRenderer = control.parameters.renderer;
     320        let checked = Engine["Renderer_Get" + keyRenderer + "Enabled"]();
     321        if (checked !== value)
     322            Engine["Renderer_Set" + keyRenderer + "Enabled"](value);
     323    }
     324    init();
    296325}
    297326
    298327function saveChanges()
     
    299328{
    300329    registerChanges();
    301330    Engine.ConfigDB_WriteFile("user", "config/user.cfg");
    302     updateStatus(false);
     331    updateDisplay();
    303332}
    304333
    305334/**
     
    308337function closePage()
    309338{
    310339    registerChanges();
    311     if (Engine.ConfigDB_GetValue("user", "nosave.haschanges") === "true")
     340    if (Engine.ConfigDB_HasChanges("user"))
    312341    {
    313342        let btCaptions = [translate("No"), translate("Yes")];
    314343        let btCode = [null, function(){ closePageWithoutConfirmation(); }];
  • binaries/data/mods/public/gui/options/options.xml

     
    6969                </object>
    7070            </repeat>
    7171        </object>
    72         <object name="loadOptions" type="button" style="ModernButtonRed" size="50%-170 100%-44 50%-70 100%-16" hotkey="cancel">
     72        <object name="resetChanges" type="button" style="ModernButtonRed" size="50%-236 100%-44 50%-136 100%-16">
     73            <translatableAttribute id="caption">Reset</translatableAttribute>
     74            <translatableAttribute id="tooltip">Resets user settings to their game default (needs a game restart to be effective)</translatableAttribute>
     75            <action on="Press">resetChanges();</action>
     76        </object>
     77        <object name="revertChanges" type="button" style="ModernButtonRed" size="50%-104 100%-44 50%-4 100%-16">
    7378            <translatableAttribute id="caption">Revert</translatableAttribute>
    74             <translatableAttribute id="tooltip">Revert to previous saved settings</translatableAttribute>
     79            <translatableAttribute id="tooltip">Reverts to previous saved settings</translatableAttribute>
    7580            <action on="Press">revertChanges();</action>
    7681        </object>
    77         <object name="saveOptions" type="button" style="ModernButtonRed" size="50%-62 100%-44 50%+38 100%-16">
     82        <object name="saveChanges" type="button" style="ModernButtonRed" size="50%+4 100%-44 50%+104 100%-16">
    7883            <translatableAttribute id="caption">Save</translatableAttribute>
    79             <translatableAttribute id="tooltip">Save changes</translatableAttribute>
     84            <translatableAttribute id="tooltip">Saves changes</translatableAttribute>
    8085            <action on="Press">saveChanges();</action>
    8186        </object>
    82         <object type="button" style="ModernButtonRed" size="50%+70 100%-44 50%+170 100%-16">
     87        <object type="button" style="ModernButtonRed" size="50%+136 100%-44 50%+236 100%-16">
    8388            <translatableAttribute id="caption">Close</translatableAttribute>
    8489            <translatableAttribute id="tooltip">Unsaved changes affect this session only</translatableAttribute>
    8590            <action on="Press">closePage();</action>
  • binaries/data/mods/public/gui/splashscreen/splashscreen.xml

     
    2727        <object name="btnOK" type="button" style="ModernButtonRed" size="18 100%-45 50%-5 100%-17" hotkey="cancel">
    2828            <translatableAttribute id="caption">OK</translatableAttribute>
    2929            <action on="Press"><![CDATA[
    30             if (Engine.GetGUIObjectByName("displaySplashScreen").checked)
    31                 Engine.ConfigDB_CreateValue("user", "splashscreenversion", 0);
    32             else
    33                 Engine.ConfigDB_CreateValue("user", "splashscreenversion", Engine.GetFileMTime("gui/splashscreen/splashscreen.txt"));
    34             Engine.ConfigDB_WriteFile("user", "config/user.cfg");
     30            let value = Engine.GetGUIObjectByName("displaySplashScreen").checked ? 0 : Engine.GetFileMTime("gui/splashscreen/splashscreen.txt");
     31            Engine.ConfigDB_CreateValueAndWriteOnFile("user", "splashscreenversion", value, "config/user.cfg");
    3532            Engine.PopGuiPageCB();
    3633            ]]></action>
    3734        </object>
  • source/i18n/L10n.cpp

     
    9292    if (!ValidateLocale(locale))
    9393        return false;
    9494
    95     g_ConfigDB.SetValueString(CFG_USER, "locale", locale.getName());
    96     g_ConfigDB.WriteFile(CFG_USER);
     95    g_ConfigDB.SetValueAndWriteOnFile(CFG_USER, "locale", locale.getName());
    9796    return true;
    9897}
    9998
  • source/network/NetServer.cpp

     
    309309                   externalIPAddress, psPort, protocall, intClient, intPort, duration);
    310310
    311311    // Cache root descriptor URL to try to avoid discovery next time.
    312     g_ConfigDB.SetValueString(CFG_USER, "network.upnprootdescurl", urls.controlURL);
    313     g_ConfigDB.WriteFile(CFG_USER);
     312    g_ConfigDB.SetValueAndWriteOnFile(CFG_USER, "network.upnprootdescurl", urls.controlURL);
    314313    LOGMESSAGE("Net server: cached UPnP root descriptor URL as %s", urls.controlURL);
    315314
    316315    // Make sure everything is properly freed.
  • source/ps/ConfigDB.cpp

     
    2929typedef std::map<CStr, CConfigValueSet> TConfigMap;
    3030TConfigMap CConfigDB::m_Map[CFG_LAST];
    3131VfsPath CConfigDB::m_ConfigFile[CFG_LAST];
     32bool CConfigDB::m_HasChanges[CFG_LAST];
     33bool CConfigDB::m_IsDirty[CFG_LAST];
    3234
    3335static pthread_mutex_t cfgdb_mutex = PTHREAD_MUTEX_INITIALIZER;
    3436
     
    114116GETVAL(std::string)
    115117#undef GETVAL
    116118
     119bool CConfigDB::HasChanges(EConfigNamespace ns) const
     120{
     121    CHECK_NS(false);
     122
     123    CScopeLock s(&cfgdb_mutex);
     124    return m_HasChanges[ns];
     125}
     126
     127bool CConfigDB::IsDirty(EConfigNamespace ns) const
     128{
     129    CHECK_NS(false);
     130
     131    CScopeLock s(&cfgdb_mutex);
     132    return m_IsDirty[ns];
     133}
     134
     135void CConfigDB::SetDirty(EConfigNamespace ns)
     136{
     137    CHECK_NS(;);
     138
     139    CScopeLock s(&cfgdb_mutex);
     140    m_IsDirty[ns] = true;
     141}
     142
    117143void CConfigDB::GetValues(EConfigNamespace ns, const CStr& name, CConfigValueSet& values) const
    118144{
    119145    CHECK_NS(;);
     
    187213        it = m_Map[ns].insert(m_Map[ns].begin(), make_pair(name, CConfigValueSet(1)));
    188214
    189215    it->second[0] = value;
     216    m_HasChanges[ns] = true;
    190217}
    191218
     219void CConfigDB::RemoveValue(EConfigNamespace ns, const CStr& name)
     220{
     221    CHECK_NS(;);
     222
     223    CScopeLock s(&cfgdb_mutex);
     224    TConfigMap::iterator it = m_Map[ns].find(name);
     225    if (it == m_Map[ns].end())
     226        return;
     227    m_Map[ns].erase(it);
     228    m_HasChanges[ns] = true;
     229}
     230
    192231void CConfigDB::SetConfigFile(EConfigNamespace ns, const VfsPath& path)
    193232{
    194233    CHECK_NS(;);
     
    357396
    358397    m_Map[ns].swap(newMap);
    359398
     399    m_HasChanges[ns] = false;
    360400    return true;
    361401}
    362402
     
    378418    char* pos = (char*)buf.get();
    379419    for (const std::pair<CStr, CConfigValueSet>& p : m_Map[ns])
    380420    {
    381         if (boost::algorithm::starts_with(p.first, "nosave."))
    382             continue;
    383421        size_t i;
    384422        pos += sprintf(pos, "%s = ", p.first.c_str());
    385423        for (i = 0; i < p.second.size() - 1; ++i)
     
    395433        return false;
    396434    }
    397435
     436    m_HasChanges[ns] = false;
    398437    return true;
    399438}
    400439
     440bool CConfigDB::SetValueAndWriteOnFile(EConfigNamespace ns, const CStr& name, const CStr& value)
     441{
     442    CHECK_NS(false);
     443
     444    CScopeLock s(&cfgdb_mutex);
     445    return SetValueAndWriteOnFile(ns, name, value, m_ConfigFile[ns]);
     446}
     447
     448bool CConfigDB::SetValueAndWriteOnFile(EConfigNamespace ns, const CStr& name, const CStr& value, const VfsPath& path)
     449{
     450    CHECK_NS(false);
     451
     452    CScopeLock s(&cfgdb_mutex);
     453    bool changed = m_HasChanges[ns];
     454
     455    // if there are no previous changes, we can just set the value and then write to file
     456    if (!changed)
     457    {
     458        SetValueString(ns, name, value);
     459        bool ret = WriteFile(ns, path);
     460        m_HasChanges[ns] = !ret;
     461        return ret;
     462    }
     463
     464    // otherwise we set this value in the specified namespace
     465    SetValueString(ns, name, value);
     466    TConfigMap newMap;
     467    m_Map[ns].swap(newMap);
     468    if (!Reload(ns))
     469    {
     470        m_Map[ns].swap(newMap);
     471        m_HasChanges[ns] = true;
     472        return false;
     473    }
     474    // and add it to be written on file
     475    SetValueString(ns, name, value);
     476    bool ret = WriteFile(ns, path);
     477    m_Map[ns].swap(newMap);
     478    m_HasChanges[ns] = changed || !ret;
     479    return ret;
     480}
     481
    401482#undef CHECK_NS
  • source/ps/ConfigDB.h

     
    5252{
    5353    static std::map<CStr, CConfigValueSet> m_Map[];
    5454    static VfsPath m_ConfigFile[];
     55    static bool m_HasChanges[];
     56    static bool m_IsDirty[];
    5557
    5658public:
    5759    CConfigDB();
     
    7274    void GetValue(EConfigNamespace ns, const CStr& name, std::string& value);
    7375
    7476    /**
     77     * Returns true if changed with respect to last write on file
     78     */
     79    bool HasChanges(EConfigNamespace ns) const;
     80
     81    /**
     82     * Returns true if dirty (i.e. should not anymore be writen on file)
     83     */
     84    bool IsDirty(EConfigNamespace ns) const;
     85
     86    void SetDirty(EConfigNamespace ns);
     87
     88    /**
    7589     * Attempt to retrieve a vector of values corresponding to the given setting;
    7690     * will search CFG_COMMAND first, and then all namespaces from the specified
    7791     * namespace down.
     
    96110     * existed the value is replaced.
    97111     */
    98112    void SetValueString(EConfigNamespace ns, const CStr& name, const CStr& value);
     113
     114    /**
     115     * Remove a config value in the specified namespace.
     116     */
     117    void RemoveValue(EConfigNamespace ns, const CStr& name);
    99118   
    100119    /**
    101120     * Set the path to the config file used to populate the specified namespace
     
    135154     *  false:  if an error occurred
    136155     */
    137156    bool WriteFile(EConfigNamespace ns) const;
     157
     158    /**
     159     * Save a config value in the specified namespace (if the config variable
     160     * existed the value is replaced) and write it to file specified by 'path'
     161     *
     162     * Returns:
     163     *  true:   if the config value was successfully saved and written to the file
     164     *  false:  if an error occurred
     165     */
     166    bool SetValueAndWriteOnFile(EConfigNamespace ns, const CStr& name, const CStr& value, const VfsPath& path);
     167
     168    /**
     169     * Save a config value in the specified namespace (if the config variable
     170     * existed the value is replaced) and write it to file it was originally loaded from
     171     *
     172     * Returns:
     173     *  true:   if the config value was successfully saved and written to the file
     174     *  false:  if an error occurred
     175     */
     176
     177    bool SetValueAndWriteOnFile(EConfigNamespace ns, const CStr& name, const CStr& value);
    138178};
    139179
    140180
  • source/ps/UserReport.cpp

     
    537537            userID += hex;
    538538        }
    539539
    540         g_ConfigDB.SetValueString(CFG_USER, "userreport.id", userID);
    541         g_ConfigDB.WriteFile(CFG_USER);
     540        g_ConfigDB.SetValueAndWriteOnFile(CFG_USER, "userreport.id", userID);
    542541    }
    543542
    544543    return userID;
     
    554553void CUserReporter::SetReportingEnabled(bool enabled)
    555554{
    556555    CStr val = CStr::FromInt(enabled ? REPORTER_VERSION : 0);
    557     g_ConfigDB.SetValueString(CFG_USER, "userreport.enabledversion", val);
    558     g_ConfigDB.WriteFile(CFG_USER);
     556    g_ConfigDB.SetValueAndWriteOnFile(CFG_USER, "userreport.enabledversion", val);
    559557
    560558    if (m_Worker)
    561559        m_Worker->SetEnabled(enabled);
  • source/ps/scripting/JSInterface_ConfigDB.cpp

     
    4242    return true;
    4343}
    4444
     45bool JSI_ConfigDB::HasChanges(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString)
     46{
     47    EConfigNamespace cfgNs;
     48    if (!GetConfigNamespace(cfgNsString, cfgNs))
     49        return false;
     50
     51    return g_ConfigDB.HasChanges(cfgNs);
     52}
     53
     54bool JSI_ConfigDB::IsDirty(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString)
     55{
     56    EConfigNamespace cfgNs;
     57    if (!GetConfigNamespace(cfgNsString, cfgNs))
     58        return false;
     59
     60    return g_ConfigDB.IsDirty(cfgNs);
     61}
     62
     63bool JSI_ConfigDB::SetDirty(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString)
     64{
     65    EConfigNamespace cfgNs;
     66    if (!GetConfigNamespace(cfgNsString, cfgNs))
     67        return false;
     68
     69    g_ConfigDB.SetDirty(cfgNs);
     70    return true;
     71}
     72
    4573std::string JSI_ConfigDB::GetValue(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString, const std::string& name)
    4674{
    4775    EConfigNamespace cfgNs;
     
    6391    return true;
    6492}
    6593
     94bool JSI_ConfigDB::RemoveValue(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString, const std::string& name)
     95{
     96    EConfigNamespace cfgNs;
     97    if (!GetConfigNamespace(cfgNsString, cfgNs))
     98        return false;
     99
     100    g_ConfigDB.RemoveValue(cfgNs, name);
     101    return true;
     102}
     103
    66104bool JSI_ConfigDB::WriteFile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString, const Path& path)
    67105{
    68106    EConfigNamespace cfgNs;
     
    73111    return ret;
    74112}
    75113
     114bool JSI_ConfigDB::CreateValueAndWriteOnFile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString,  const std::string& name, const std::string& value, const Path& path)
     115{
     116    EConfigNamespace cfgNs;
     117    if (!GetConfigNamespace(cfgNsString, cfgNs))
     118        return false;
     119
     120    bool ret = g_ConfigDB.SetValueAndWriteOnFile(cfgNs, name, value, path);
     121    return ret;
     122}
     123
    76124bool JSI_ConfigDB::Reload(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString)
    77125{
    78126    EConfigNamespace cfgNs;
     
    95143
    96144void JSI_ConfigDB::RegisterScriptFunctions(ScriptInterface& scriptInterface)
    97145{
     146    scriptInterface.RegisterFunction<bool, std::wstring, &JSI_ConfigDB::HasChanges>("ConfigDB_HasChanges");
     147    scriptInterface.RegisterFunction<bool, std::wstring, &JSI_ConfigDB::IsDirty>("ConfigDB_IsDirty");
     148    scriptInterface.RegisterFunction<bool, std::wstring, &JSI_ConfigDB::SetDirty>("ConfigDB_SetDirty");
    98149    scriptInterface.RegisterFunction<std::string, std::wstring, std::string, &JSI_ConfigDB::GetValue>("ConfigDB_GetValue");
    99150    scriptInterface.RegisterFunction<bool, std::wstring, std::string, std::string, &JSI_ConfigDB::CreateValue>("ConfigDB_CreateValue");
     151    scriptInterface.RegisterFunction<bool, std::wstring, std::string, &JSI_ConfigDB::RemoveValue>("ConfigDB_RemoveValue");
    100152    scriptInterface.RegisterFunction<bool, std::wstring, Path, &JSI_ConfigDB::WriteFile>("ConfigDB_WriteFile");
     153    scriptInterface.RegisterFunction<bool, std::wstring, std::string, std::string, Path, &JSI_ConfigDB::CreateValueAndWriteOnFile>("ConfigDB_CreateValueAndWriteOnFile");
    101154    scriptInterface.RegisterFunction<bool, std::wstring, Path, &JSI_ConfigDB::SetFile>("ConfigDB_SetFile");
    102155    scriptInterface.RegisterFunction<bool, std::wstring, &JSI_ConfigDB::Reload>("ConfigDB_Reload");
    103    
    104156}
  • source/ps/scripting/JSInterface_ConfigDB.h

     
    2424namespace JSI_ConfigDB
    2525{
    2626    bool GetConfigNamespace(const std::wstring& cfgNsString, EConfigNamespace& cfgNs);
     27    bool HasChanges(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString);
     28    bool IsDirty(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString);
     29    bool SetDirty(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString);
    2730    std::string GetValue(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name);
    2831    bool CreateValue(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name, const std::string& value);
     32    bool RemoveValue(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name);
    2933    bool WriteFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const Path& path);
     34    bool CreateValueAndWriteOnFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name, const std::string& value, const Path& path);
    3035    bool Reload(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString);
    3136    bool SetFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const Path& path);
    3237    void RegisterScriptFunctions(ScriptInterface& scriptInterface);