#pragma once #include "export.hpp" #include "compat/macros.hpp" #include #include #include #include namespace options::globals::detail { struct saver_; struct OTR_OPTIONS_EXPORT ini_ctx { std::optional qsettings { std::in_place }; QString pathname; QMutex mtx { QMutex::Recursive }; int refcount = 0; bool modifiedp = false; ini_ctx(); }; struct OTR_OPTIONS_EXPORT saver_ final { ini_ctx& ctx; cc_noinline ~saver_(); explicit cc_noinline saver_(ini_ctx& ini); }; template cc_noinline auto with_settings_object_(ini_ctx& ini, F&& fun) { saver_ saver { ini }; return fun(*ini.qsettings); } OTR_OPTIONS_EXPORT ini_ctx& cur_settings(); OTR_OPTIONS_EXPORT ini_ctx& global_settings(); OTR_OPTIONS_EXPORT bool is_portable_installation(); } // ns options::globals::detail namespace options::globals { OTR_OPTIONS_EXPORT void mark_ini_modified(bool value = true); OTR_OPTIONS_EXPORT bool is_ini_modified(); OTR_OPTIONS_EXPORT QString ini_directory(); OTR_OPTIONS_EXPORT QString ini_filename(); OTR_OPTIONS_EXPORT QString ini_pathname(); OTR_OPTIONS_EXPORT QString ini_combine(const QString& filename); OTR_OPTIONS_EXPORT QStringList ini_list(); template auto with_settings_object(F&& fun) { using namespace detail; return with_settings_object_(cur_settings(), fun); } template auto with_global_settings_object(F&& fun) { using namespace detail; return with_settings_object_(global_settings(), fun); } } // ns options::globals