Changeset View
Changeset View
Standalone View
Standalone View
source/ps/scripting/JSInterface_ConfigDB.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | bool JSI_ConfigDB::WriteValueToFile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString, const std::string& name, const std::string& value, const Path& path) | ||||
EConfigNamespace cfgNs; | EConfigNamespace cfgNs; | ||||
if (!GetConfigNamespace(cfgNsString, cfgNs)) | if (!GetConfigNamespace(cfgNsString, cfgNs)) | ||||
return false; | return false; | ||||
return g_ConfigDB.WriteValueToFile(cfgNs, name, value, path); | return g_ConfigDB.WriteValueToFile(cfgNs, name, value, path); | ||||
} | } | ||||
void JSI_ConfigDB::CreateAndWriteValueToFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name, const std::string& value) | |||||
{ | |||||
CreateValue(pCxPrivate, cfgNsString, name, value); | |||||
WriteValueToFile(pCxPrivate, cfgNsString, name, value, L"config/" + cfgNsString + L".cfg"); | |||||
} | |||||
elexis: The other functions don't hardcode the filename this way, but specify those two strings in the… | |||||
vladislavbelovUnsubmitted Not Done Inline ActionsMaybe it needs to be specified in the name? That it uses the certain config path. vladislavbelov: Maybe it needs to be specified in the name? That it uses the certain config path. | |||||
elexisUnsubmitted Not Done Inline ActionsJust mimic WriteValueToFile by adding const Path& path and replace L"config/" + cfgNsString + L".cfg" with path. If the logic of that argument would be changed, it would have to be consistent for all functions with the identical argument. elexis: Just mimic `WriteValueToFile` by adding `const Path& path` and replace `L"config/" +… | |||||
bool JSI_ConfigDB::Reload(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString) | bool JSI_ConfigDB::Reload(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& cfgNsString) | ||||
{ | { | ||||
EConfigNamespace cfgNs; | EConfigNamespace cfgNs; | ||||
if (!GetConfigNamespace(cfgNsString, cfgNs)) | if (!GetConfigNamespace(cfgNsString, cfgNs)) | ||||
return false; | return false; | ||||
return g_ConfigDB.Reload(cfgNs); | return g_ConfigDB.Reload(cfgNs); | ||||
} | } | ||||
Show All 12 Lines | |||||
{ | { | ||||
scriptInterface.RegisterFunction<bool, std::wstring, &JSI_ConfigDB::HasChanges>("ConfigDB_HasChanges"); | scriptInterface.RegisterFunction<bool, std::wstring, &JSI_ConfigDB::HasChanges>("ConfigDB_HasChanges"); | ||||
scriptInterface.RegisterFunction<bool, std::wstring, bool, &JSI_ConfigDB::SetChanges>("ConfigDB_SetChanges"); | scriptInterface.RegisterFunction<bool, std::wstring, bool, &JSI_ConfigDB::SetChanges>("ConfigDB_SetChanges"); | ||||
scriptInterface.RegisterFunction<std::string, std::wstring, std::string, &JSI_ConfigDB::GetValue>("ConfigDB_GetValue"); | scriptInterface.RegisterFunction<std::string, std::wstring, std::string, &JSI_ConfigDB::GetValue>("ConfigDB_GetValue"); | ||||
scriptInterface.RegisterFunction<bool, std::wstring, std::string, std::string, &JSI_ConfigDB::CreateValue>("ConfigDB_CreateValue"); | scriptInterface.RegisterFunction<bool, std::wstring, std::string, std::string, &JSI_ConfigDB::CreateValue>("ConfigDB_CreateValue"); | ||||
scriptInterface.RegisterFunction<bool, std::wstring, std::string, &JSI_ConfigDB::RemoveValue>("ConfigDB_RemoveValue"); | scriptInterface.RegisterFunction<bool, std::wstring, std::string, &JSI_ConfigDB::RemoveValue>("ConfigDB_RemoveValue"); | ||||
scriptInterface.RegisterFunction<bool, std::wstring, Path, &JSI_ConfigDB::WriteFile>("ConfigDB_WriteFile"); | scriptInterface.RegisterFunction<bool, std::wstring, Path, &JSI_ConfigDB::WriteFile>("ConfigDB_WriteFile"); | ||||
scriptInterface.RegisterFunction<bool, std::wstring, std::string, std::string, Path, &JSI_ConfigDB::WriteValueToFile>("ConfigDB_WriteValueToFile"); | scriptInterface.RegisterFunction<bool, std::wstring, std::string, std::string, Path, &JSI_ConfigDB::WriteValueToFile>("ConfigDB_WriteValueToFile"); | ||||
scriptInterface.RegisterFunction<void, std::wstring, std::string, std::string, &JSI_ConfigDB::CreateAndWriteValueToFile>("ConfigDB_CreateAndWriteValueToFile"); | |||||
scriptInterface.RegisterFunction<bool, std::wstring, Path, &JSI_ConfigDB::SetFile>("ConfigDB_SetFile"); | scriptInterface.RegisterFunction<bool, std::wstring, Path, &JSI_ConfigDB::SetFile>("ConfigDB_SetFile"); | ||||
scriptInterface.RegisterFunction<bool, std::wstring, &JSI_ConfigDB::Reload>("ConfigDB_Reload"); | scriptInterface.RegisterFunction<bool, std::wstring, &JSI_ConfigDB::Reload>("ConfigDB_Reload"); | ||||
} | } |
Wildfire Games · Phabricator
The other functions don't hardcode the filename this way, but specify those two strings in the caller (and the filename and cfgNsString play different roles).