logic: only prefill application settings once

This commit is contained in:
mlangkabel
2018-07-24 11:55:44 +02:00
parent 86b0583b6b
commit f715e5c99e
3 changed files with 84 additions and 15 deletions
+18 -5
View File
@@ -60,8 +60,9 @@ void setupLogging()
void prefillJavaRuntimePath()
{
std::shared_ptr<ApplicationSettings> settings = ApplicationSettings::getInstance();
if (settings->getJavaPath().empty())
if (!settings->getHasPrefilledJavaPath() && settings->getJavaPath().empty())
{
LOG_INFO("Prefilling Java path");
std::shared_ptr<CombinedPathDetector> javaPathDetector = utility::getJavaRuntimePathDetector();
std::vector<FilePath> paths = javaPathDetector->getPaths();
if (!paths.empty())
@@ -76,13 +77,15 @@ void prefillJavaRuntimePath()
MessageStatus(L"Ran Java runtime path detection, no path found.").dispatch();
}
}
settings->setHasPrefilledJavaPath(true);
}
void prefillJreSystemLibraryPaths()
{
std::shared_ptr<ApplicationSettings> settings = ApplicationSettings::getInstance();
if (settings->getJreSystemLibraryPaths().empty())
if (!settings->getHasPrefilledJreSystemLibraryPaths() && settings->getJreSystemLibraryPaths().empty())
{
LOG_INFO("Prefilling JRE system library path");
std::shared_ptr<CombinedPathDetector> jreSystemLibraryPathsDetector = utility::getJreSystemLibraryPathsDetector();
std::vector<FilePath> paths = jreSystemLibraryPathsDetector->getPaths();
if (!paths.empty())
@@ -97,13 +100,15 @@ void prefillJreSystemLibraryPaths()
MessageStatus(L"Ran JRE system library path detection, no path found.").dispatch();
}
}
settings->setHasPrefilledJreSystemLibraryPaths(true);
}
void prefillMavenExecutablePath()
{
std::shared_ptr<ApplicationSettings> settings = ApplicationSettings::getInstance();
if (settings->getMavenPath().empty())
if (!settings->getHasPrefilledMavenPath() && settings->getMavenPath().empty())
{
LOG_INFO("Prefilling Maven path");
std::shared_ptr<CombinedPathDetector> mavenPathDetector = utility::getMavenExecutablePathDetector();
std::vector<FilePath> paths = mavenPathDetector->getPaths();
if (!paths.empty())
@@ -118,13 +123,15 @@ void prefillMavenExecutablePath()
MessageStatus(L"Ran Maven executable path detection, no path found.").dispatch();
}
}
settings->setHasPrefilledMavenPath(true);
}
void prefillCxxHeaderPaths()
{
std::shared_ptr<ApplicationSettings> settings = ApplicationSettings::getInstance();
if (settings->getHeaderSearchPaths().empty())
if (!settings->getHasPrefilledHeaderSearchPaths() && settings->getHeaderSearchPaths().empty())
{
LOG_INFO("Prefilling header search paths");
std::shared_ptr<CombinedPathDetector> cxxHeaderDetector = utility::getCxxHeaderPathDetector();
std::vector<FilePath> paths = cxxHeaderDetector->getPaths();
@@ -137,13 +144,15 @@ void prefillCxxHeaderPaths()
settings->save();
}
}
settings->setHasPrefilledHeaderSearchPaths(true);
}
void prefillCxxFrameworkPaths()
{
std::shared_ptr<ApplicationSettings> settings = ApplicationSettings::getInstance();
if (settings->getFrameworkSearchPaths().empty())
if (!settings->getHasPrefilledFrameworkSearchPaths() && settings->getFrameworkSearchPaths().empty())
{
LOG_INFO("Prefilling framework search paths");
std::shared_ptr<CombinedPathDetector> cxxFrameworkDetector = utility::getCxxFrameworkPathDetector();
std::vector<FilePath> paths = cxxFrameworkDetector->getPaths();
if (!paths.empty())
@@ -155,6 +164,7 @@ void prefillCxxFrameworkPaths()
settings->save();
}
}
settings->setHasPrefilledFrameworkSearchPaths(true);
}
void prefillPaths()
@@ -164,6 +174,9 @@ void prefillPaths()
prefillJreSystemLibraryPaths();
prefillCxxHeaderPaths();
prefillCxxFrameworkPaths();
std::shared_ptr<ApplicationSettings> settings = ApplicationSettings::getInstance();
settings->save();
}
void addLanguagePackages()
+50 -8
View File
@@ -27,14 +27,6 @@ std::shared_ptr<ApplicationSettings> ApplicationSettings::getInstance()
return s_instance;
}
ApplicationSettings::ApplicationSettings()
{
}
ApplicationSettings::~ApplicationSettings()
{
}
bool ApplicationSettings::load(const FilePath& filePath, bool readOnly)
{
bool loaded = Settings::load(filePath, readOnly);
@@ -352,6 +344,16 @@ void ApplicationSettings::setJavaPath(const FilePath& path)
setValue<std::wstring>("indexing/java/java_path", path.wstr());
}
bool ApplicationSettings::getHasPrefilledJavaPath() const
{
return getValue<bool>("indexing/java/has_prefilled_java_path", false);
}
void ApplicationSettings::setHasPrefilledJavaPath(bool v)
{
setValue<bool>("indexing/java/has_prefilled_java_path", v);
}
int ApplicationSettings::getJavaMaximumMemory() const
{
return getValue<int>("indexing/java/java_maximum_memory", -1);
@@ -377,6 +379,16 @@ bool ApplicationSettings::setJreSystemLibraryPaths(const std::vector<FilePath>&
return setPathValues("indexing/java/jre_system_library_paths/jre_system_library_path", jreSystemLibraryPaths);
}
bool ApplicationSettings::getHasPrefilledJreSystemLibraryPaths() const
{
return getValue<bool>("indexing/java/has_prefilled_jre_system_library_paths", false);
}
void ApplicationSettings::setHasPrefilledJreSystemLibraryPaths(bool v)
{
setValue<bool>("indexing/java/has_prefilled_jre_system_library_paths", v);
}
FilePath ApplicationSettings::getMavenPath() const
{
return FilePath(getValue<std::wstring>("indexing/java/maven_path", L""));
@@ -387,6 +399,16 @@ void ApplicationSettings::setMavenPath(const FilePath& path)
setValue<std::wstring>("indexing/java/maven_path", path.wstr());
}
bool ApplicationSettings::getHasPrefilledMavenPath() const
{
return getValue<bool>("indexing/java/has_prefilled_maven_path", false);
}
void ApplicationSettings::setHasPrefilledMavenPath(bool v)
{
setValue<bool>("indexing/java/has_prefilled_maven_path", v);
}
std::vector<FilePath> ApplicationSettings::getHeaderSearchPaths() const
{
return getPathValues("indexing/cxx/header_search_paths/header_search_path");
@@ -402,6 +424,16 @@ bool ApplicationSettings::setHeaderSearchPaths(const std::vector<FilePath>& head
return setPathValues("indexing/cxx/header_search_paths/header_search_path", headerSearchPaths);
}
bool ApplicationSettings::getHasPrefilledHeaderSearchPaths() const
{
return getValue<bool>("indexing/cxx/has_prefilled_header_search_paths", false);
}
void ApplicationSettings::setHasPrefilledHeaderSearchPaths(bool v)
{
setValue<bool>("indexing/cxx/has_prefilled_header_search_paths", v);
}
std::vector<FilePath> ApplicationSettings::getFrameworkSearchPaths() const
{
return getPathValues("indexing/cxx/framework_search_paths/framework_search_path");
@@ -417,6 +449,16 @@ bool ApplicationSettings::setFrameworkSearchPaths(const std::vector<FilePath>& f
return setPathValues("indexing/cxx/framework_search_paths/framework_search_path", frameworkSearchPaths);
}
bool ApplicationSettings::getHasPrefilledFrameworkSearchPaths() const
{
return getValue<bool>("indexing/cxx/has_prefilled_framework_search_paths", false);
}
void ApplicationSettings::setHasPrefilledFrameworkSearchPaths(bool v)
{
setValue<bool>("indexing/cxx/has_prefilled_framework_search_paths", v);
}
int ApplicationSettings::getCodeTabWidth() const
{
return getValue<int>("code/tab_width", 4);
+16 -2
View File
@@ -17,8 +17,7 @@ public:
static const size_t VERSION;
ApplicationSettings();
~ApplicationSettings();
ApplicationSettings() = default;
bool load(const FilePath& filePath, bool readOnly = false);
@@ -97,6 +96,9 @@ public:
FilePath getJavaPath() const;
void setJavaPath(const FilePath& path);
bool getHasPrefilledJavaPath() const;
void setHasPrefilledJavaPath(bool v);
int getJavaMaximumMemory() const;
void setJavaMaximumMemory(int size);
@@ -104,17 +106,29 @@ public:
std::vector<FilePath> getJreSystemLibraryPathsExpanded() const;
bool setJreSystemLibraryPaths(const std::vector<FilePath>& jreSystemLibraryPaths);
bool getHasPrefilledJreSystemLibraryPaths() const;
void setHasPrefilledJreSystemLibraryPaths(bool v);
FilePath getMavenPath() const;
void setMavenPath(const FilePath& path);
bool getHasPrefilledMavenPath() const;
void setHasPrefilledMavenPath(bool v);
std::vector<FilePath> getHeaderSearchPaths() const;
std::vector<FilePath> getHeaderSearchPathsExpanded() const;
bool setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths);
bool getHasPrefilledHeaderSearchPaths() const;
void setHasPrefilledHeaderSearchPaths(bool v);
std::vector<FilePath> getFrameworkSearchPaths() const;
std::vector<FilePath> getFrameworkSearchPathsExpanded() const;
bool setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths);
bool getHasPrefilledFrameworkSearchPaths() const;
void setHasPrefilledFrameworkSearchPaths(bool v);
// code
int getCodeTabWidth() const;
void setCodeTabWidth(int codeTabWidth);