From: Carl Hetherington Date: Fri, 16 Dec 2016 12:02:51 +0000 (+0000) Subject: Use boost::optional for Config::_default_directory. X-Git-Tag: v2.10.5-test~16 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=396c26415da57f42271ddcf56c1169a437d5a981 Use boost::optional for Config::_default_directory. --- diff --git a/src/lib/config.cc b/src/lib/config.cc index 9222d8498..30ed1243b 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -160,7 +160,11 @@ try optional version = f.optional_number_child ("Version"); _num_local_encoding_threads = f.number_child ("NumLocalEncodingThreads"); - _default_directory = f.string_child ("DefaultDirectory"); + _default_directory = f.optional_string_child ("DefaultDirectory"); + if (_default_directory && _default_directory->empty ()) { + /* We used to store an empty value for this to mean "none set" */ + _default_directory = boost::optional (); + } boost::optional b = f.optional_number_child ("ServerPort"); if (!b) { @@ -374,7 +378,9 @@ Config::write_config_xml () const root->add_child("Version")->add_child_text ("2"); root->add_child("NumLocalEncodingThreads")->add_child_text (raw_convert (_num_local_encoding_threads)); - root->add_child("DefaultDirectory")->add_child_text (_default_directory.string ()); + if (_default_directory) { + root->add_child("DefaultDirectory")->add_child_text (_default_directory->string ()); + } root->add_child("ServerPortBase")->add_child_text (raw_convert (_server_port_base)); root->add_child("UseAnyServers")->add_child_text (_use_any_servers ? "1" : "0"); @@ -495,17 +501,17 @@ Config::write_cinemas_xml () const boost::filesystem::path Config::default_directory_or (boost::filesystem::path a) const { - if (_default_directory.empty()) { + if (!_default_directory) { return a; } boost::system::error_code ec; - bool const e = boost::filesystem::exists (_default_directory, ec); + bool const e = boost::filesystem::exists (*_default_directory, ec); if (ec || !e) { return a; } - return _default_directory; + return *_default_directory; } void diff --git a/src/lib/config.h b/src/lib/config.h index a38fb129c..c50846707 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -52,7 +52,7 @@ public: return _num_local_encoding_threads; } - boost::filesystem::path default_directory () const { + boost::optional default_directory () const { return _default_directory; } @@ -290,7 +290,11 @@ public: } void set_default_directory (boost::filesystem::path d) { - maybe_set (_default_directory, d); + if (_default_directory && *_default_directory == d) { + return; + } + _default_directory = d; + changed (); } /** @param p New server port */ @@ -558,7 +562,7 @@ private: /** number of threads to use for J2K encoding on the local machine */ int _num_local_encoding_threads; /** default directory to put new films in */ - boost::filesystem::path _default_directory; + boost::optional _default_directory; /** base port number to use for J2K encoding servers; * this port and the two above it will be used. */