diff --git a/core/include/DatabaseStorage.h b/core/include/DatabaseStorage.h index b228cd1..4978186 100644 --- a/core/include/DatabaseStorage.h +++ b/core/include/DatabaseStorage.h @@ -51,6 +51,8 @@ namespace sourcetrail void setupDatabase(); void clearDatabase(); + void setProjectSettingsText(const std::string& text); + bool isEmpty() const; bool isCompatible() const; int getLoadedDatabaseVersion() const; diff --git a/core/include/SourcetrailDBWriter.h b/core/include/SourcetrailDBWriter.h index 13538fb..8c7a6a1 100644 --- a/core/include/SourcetrailDBWriter.h +++ b/core/include/SourcetrailDBWriter.h @@ -94,6 +94,7 @@ namespace sourcetrail void setupDatabaseTables(); void clearDatabaseTables(); void createOrResetProjectFile(); + void updateProjectSettingsText(); int addNodeHierarchy(const NameHierarchy& nameHierarchy); int addFile(const std::string& filePath); int addEdge(int sourceId, int targetId, EdgeKind edgeKind); diff --git a/core/src/DatabaseStorage.cpp b/core/src/DatabaseStorage.cpp index af66c29..f502583 100644 --- a/core/src/DatabaseStorage.cpp +++ b/core/src/DatabaseStorage.cpp @@ -86,6 +86,11 @@ namespace sourcetrail setupDatabase(); } + void DatabaseStorage::setProjectSettingsText(const std::string& text) + { + insertOrUpdateMetaValue("project_settings", text); + } + bool DatabaseStorage::isEmpty() const { const std::string tableName = "meta"; diff --git a/core/src/SourcetrailDBWriter.cpp b/core/src/SourcetrailDBWriter.cpp index 5332afb..627857a 100644 --- a/core/src/SourcetrailDBWriter.cpp +++ b/core/src/SourcetrailDBWriter.cpp @@ -81,26 +81,6 @@ namespace sourcetrail } m_projectFilePath += ".srctrlprj"; - try - { - openDatabase(); - } - catch (const SourcetrailException e) - { - m_lastError = e.getMessage(); - return false; - } - - try - { - setupDatabaseTables(); - } - catch (const SourcetrailException e) - { - m_lastError = e.getMessage(); - return false; - } - { bool projectFileExists = false; { @@ -122,6 +102,27 @@ namespace sourcetrail } } + try + { + openDatabase(); + } + catch (const SourcetrailException e) + { + m_lastError = e.getMessage(); + return false; + } + + try + { + setupDatabaseTables(); + updateProjectSettingsText(); + } + catch (const SourcetrailException e) + { + m_lastError = e.getMessage(); + return false; + } + return true; } @@ -145,16 +146,7 @@ namespace sourcetrail try { clearDatabaseTables(); - } - catch (const SourcetrailException e) - { - m_lastError = e.getMessage(); - return false; - } - - try - { - createOrResetProjectFile(); + updateProjectSettingsText(); } catch (const SourcetrailException e) { @@ -661,6 +653,33 @@ namespace sourcetrail } } + void SourcetrailDBWriter::updateProjectSettingsText() + { + try + { + std::ifstream f(m_projectFilePath.c_str()); + if (f.is_open()) + { + std::string line; + std::string text; + while (getline(f, line)) + { + text += line + '\n'; + } + f.close(); + m_storage->setProjectSettingsText(text); + } + else + { + throw SourcetrailException("Unable to open project file."); + } + } + catch (...) + { + throw SourcetrailException("Exception occurred while creating project file."); + } + } + int SourcetrailDBWriter::addNodeHierarchy(const NameHierarchy& nameHierarchy) { if (nameHierarchy.nameElements.size() == 0)