2017-10-30 17:41:50 +00:00
|
|
|
#ifndef slic3r_AppConfig_hpp_
|
|
|
|
#define slic3r_AppConfig_hpp_
|
|
|
|
|
2018-03-28 09:36:36 +00:00
|
|
|
#include <set>
|
2017-10-30 17:41:50 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2018-03-28 09:36:36 +00:00
|
|
|
#include "libslic3r/Config.hpp"
|
2018-04-11 11:12:08 +00:00
|
|
|
#include "slic3r/Utils/Semver.hpp"
|
2018-03-28 09:36:36 +00:00
|
|
|
|
2017-10-30 17:41:50 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
class AppConfig
|
|
|
|
{
|
|
|
|
public:
|
2018-05-17 14:19:40 +00:00
|
|
|
AppConfig() :
|
|
|
|
m_dirty(false),
|
|
|
|
m_orig_version(Semver::invalid()),
|
|
|
|
m_legacy_datadir(false)
|
|
|
|
{
|
|
|
|
this->reset();
|
|
|
|
}
|
2017-10-30 17:41:50 +00:00
|
|
|
|
|
|
|
// Clear and reset to defaults.
|
|
|
|
void reset();
|
|
|
|
// Override missing or keys with their defaults.
|
|
|
|
void set_defaults();
|
|
|
|
|
2017-11-01 18:30:05 +00:00
|
|
|
// Load the slic3r.ini from a user profile directory (or a datadir, if configured).
|
2017-10-30 17:41:50 +00:00
|
|
|
void load();
|
2017-11-01 18:30:05 +00:00
|
|
|
// Store the slic3r.ini into a user profile directory (or a datadir, if configured).
|
2017-10-30 17:41:50 +00:00
|
|
|
void save();
|
|
|
|
|
|
|
|
// Does this config need to be saved?
|
|
|
|
bool dirty() const { return m_dirty; }
|
|
|
|
|
|
|
|
// Const accessor, it will return false if a section or a key does not exist.
|
|
|
|
bool get(const std::string §ion, const std::string &key, std::string &value) const
|
|
|
|
{
|
|
|
|
value.clear();
|
|
|
|
auto it = m_storage.find(section);
|
|
|
|
if (it == m_storage.end())
|
|
|
|
return false;
|
|
|
|
auto it2 = it->second.find(key);
|
|
|
|
if (it2 == it->second.end())
|
|
|
|
return false;
|
|
|
|
value = it2->second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
std::string get(const std::string §ion, const std::string &key) const
|
|
|
|
{ std::string value; this->get(section, key, value); return value; }
|
|
|
|
std::string get(const std::string &key) const
|
|
|
|
{ std::string value; this->get("", key, value); return value; }
|
|
|
|
void set(const std::string §ion, const std::string &key, const std::string &value)
|
|
|
|
{
|
|
|
|
std::string &old = m_storage[section][key];
|
|
|
|
if (old != value) {
|
|
|
|
old = value;
|
|
|
|
m_dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void set(const std::string &key, const std::string &value)
|
|
|
|
{ this->set("", key, value); }
|
|
|
|
bool has(const std::string §ion, const std::string &key) const
|
|
|
|
{
|
|
|
|
auto it = m_storage.find(section);
|
|
|
|
if (it == m_storage.end())
|
|
|
|
return false;
|
|
|
|
auto it2 = it->second.find(key);
|
|
|
|
return it2 != it->second.end() && ! it2->second.empty();
|
|
|
|
}
|
|
|
|
bool has(const std::string &key) const
|
|
|
|
{ return this->has("", key); }
|
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
void erase(const std::string §ion, const std::string &key)
|
|
|
|
{
|
|
|
|
auto it = m_storage.find(section);
|
|
|
|
if (it != m_storage.end()) {
|
|
|
|
it->second.erase(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-01 18:30:05 +00:00
|
|
|
void clear_section(const std::string §ion)
|
|
|
|
{ m_storage[section].clear(); }
|
|
|
|
|
2018-04-12 18:04:48 +00:00
|
|
|
typedef std::map<std::string, std::map<std::string, std::set<std::string>>> VendorMap;
|
2018-04-06 10:15:28 +00:00
|
|
|
bool get_variant(const std::string &vendor, const std::string &model, const std::string &variant) const;
|
|
|
|
void set_variant(const std::string &vendor, const std::string &model, const std::string &variant, bool enable);
|
|
|
|
void set_vendors(const AppConfig &from);
|
2018-04-12 18:04:48 +00:00
|
|
|
void set_vendors(const VendorMap &vendors) { m_vendors = vendors; m_dirty = true; }
|
|
|
|
void set_vendors(VendorMap &&vendors) { m_vendors = std::move(vendors); m_dirty = true; }
|
|
|
|
const VendorMap& vendors() const { return m_vendors; }
|
2018-03-28 09:36:36 +00:00
|
|
|
|
2017-10-30 17:41:50 +00:00
|
|
|
// return recent/skein_directory or recent/config_directory or empty string.
|
|
|
|
std::string get_last_dir() const;
|
|
|
|
void update_config_dir(const std::string &dir);
|
|
|
|
void update_skein_dir(const std::string &dir);
|
|
|
|
|
|
|
|
std::string get_last_output_dir(const std::string &alt) const;
|
|
|
|
void update_last_output_dir(const std::string &dir);
|
|
|
|
|
2018-03-14 12:29:50 +00:00
|
|
|
// reset the current print / filament / printer selections, so that
|
|
|
|
// the PresetBundle::load_selections(const AppConfig &config) call will select
|
|
|
|
// the first non-default preset when called.
|
|
|
|
void reset_selections();
|
|
|
|
|
2017-10-30 17:41:50 +00:00
|
|
|
// Get the default config path from Slic3r::data_dir().
|
|
|
|
static std::string config_path();
|
2018-04-25 15:43:01 +00:00
|
|
|
|
|
|
|
// Returns true if the user's data directory comes from before Slic3r 1.40.0 (no updating)
|
2018-04-16 14:52:11 +00:00
|
|
|
bool legacy_datadir() const { return m_legacy_datadir; }
|
2018-05-18 06:46:33 +00:00
|
|
|
void set_legacy_datadir(bool value) { m_legacy_datadir = value; }
|
2017-10-30 17:41:50 +00:00
|
|
|
|
2018-04-25 15:43:01 +00:00
|
|
|
// Get the Slic3r version check url.
|
|
|
|
// This returns a hardcoded string unless it is overriden by "version_check_url" in the ini file.
|
|
|
|
std::string version_check_url() const;
|
|
|
|
|
2018-05-17 14:19:40 +00:00
|
|
|
// Returns the original Slic3r version found in the ini file before it was overwritten
|
|
|
|
// by the current version
|
|
|
|
Semver orig_version() const { return m_orig_version; }
|
|
|
|
|
2017-10-30 17:41:50 +00:00
|
|
|
// Does the config file exist?
|
|
|
|
static bool exists();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Map of section, name -> value
|
|
|
|
std::map<std::string, std::map<std::string, std::string>> m_storage;
|
2018-03-28 09:36:36 +00:00
|
|
|
// Map of enabled vendors / models / variants
|
2018-04-12 18:04:48 +00:00
|
|
|
VendorMap m_vendors;
|
2017-10-30 17:41:50 +00:00
|
|
|
// Has any value been modified since the config.ini has been last saved or loaded?
|
|
|
|
bool m_dirty;
|
2018-05-17 14:19:40 +00:00
|
|
|
// Original version found in the ini file before it was overwritten
|
|
|
|
Semver m_orig_version;
|
2018-04-16 14:52:11 +00:00
|
|
|
// Whether the existing version is before system profiles & configuration updating
|
|
|
|
bool m_legacy_datadir;
|
2017-10-30 17:41:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}; // namespace Slic3r
|
|
|
|
|
|
|
|
#endif /* slic3r_AppConfig_hpp_ */
|