Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed script LocalStorage data (race times etc...) not being written #2968

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions source/main/scripting/LocalStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ LocalStorage::LocalStorage(AngelScript::asIScriptEngine *engine_in, std::string

sectionName = sectionName_in.substr(0, sectionName_in.find(".", 0));

this->filename = fileName_in + ".asdata";
m_filename = fileName_in + ".asdata";
this->separators = "=";
this->resource_group_name = RGN_CACHE;
loadDict();

saved = true;
Expand Down Expand Up @@ -101,7 +100,7 @@ void LocalStorage::ReleaseAllReferences(AngelScript::asIScriptEngine * /*engine*

LocalStorage &LocalStorage::operator =(LocalStorage &other)
{
filename = other.getFilename();
m_filename = other.getFilename();
sectionName = other.getSection();
SettingsBySection::iterator secIt;
SettingsBySection osettings = other.getSettings();
Expand Down Expand Up @@ -251,28 +250,28 @@ void LocalStorage::saveDict()

try
{
this->saveImprovedCfg();
this->saveImprovedCfg(m_filename, RGN_CACHE);
this->saved = true;
}
catch (std::exception& e)
{
RoR::LogFormat("[RoR|Scripting|LocalStorage]"
"Error saving file '%s' (resource group '%s'), message: '%s'",
this->filename, RGN_CACHE, e.what());
m_filename, RGN_CACHE, e.what());
}
}

bool LocalStorage::loadDict()
{
try
{
this->loadImprovedCfg();
this->loadImprovedCfg(m_filename, RGN_CACHE);
}
catch (std::exception& e)
{
RoR::LogFormat("[RoR|Scripting|LocalStorage]"
"Error reading file '%s' (resource group '%s'), message: '%s'",
this->filename, RGN_CACHE, e.what());
m_filename, RGN_CACHE, e.what());
return false;
}
saved = true;
Expand Down
3 changes: 2 additions & 1 deletion source/main/scripting/LocalStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ class LocalStorage : public ImprovedConfigFile
void ReleaseAllReferences(AngelScript::asIScriptEngine* engine);

SettingsBySection getSettings() { return mSettingsPtr; }
std::string getFilename() { return filename; }
std::string getFilename() { return m_filename; }
std::string getSection() { return sectionName; }

protected:
std::string m_filename;
bool saved; //!< Inverted 'dirty flag'
std::string sectionName;

Expand Down
12 changes: 5 additions & 7 deletions source/main/utils/ImprovedConfigFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class ImprovedConfigFile : public RoR::ConfigFile
{
public:
ImprovedConfigFile() : separators("="), filename()
ImprovedConfigFile() : separators("=")
{
ConfigFile();
}
Expand All @@ -45,21 +45,21 @@ class ImprovedConfigFile : public RoR::ConfigFile
{
}

void loadImprovedCfg()
void loadImprovedCfg(std::string const& filename, std::string const& resource_group_name)
{
ConfigFile::load(this->filename, this->resource_group_name, this->separators, /*trimWhitespace*/true);
ConfigFile::load(filename, resource_group_name, this->separators, /*trimWhitespace*/true);
}

bool hasSetting(Ogre::String key, Ogre::String section = "")
{
return (mSettingsPtr.find(section) != mSettingsPtr.end() && mSettingsPtr[section]->find(key) != mSettingsPtr[section]->end());
}

bool saveImprovedCfg()
bool saveImprovedCfg(std::string const& filename, std::string const& resource_group_name)
{
Ogre::DataStreamPtr stream
= Ogre::ResourceGroupManager::getSingleton().createResource(
this->filename, this->resource_group_name, /*overwrite=*/true);
filename, resource_group_name, /*overwrite=*/true);

const size_t BUF_LEN = 2000;
char buf[BUF_LEN];
Expand Down Expand Up @@ -231,6 +231,4 @@ class ImprovedConfigFile : public RoR::ConfigFile

protected:
Ogre::String separators;
Ogre::String filename;
Ogre::String resource_group_name;
};