From 5338c30e79dc04869f6316b1e0f792e50f26e1b6 Mon Sep 17 00:00:00 2001 From: Hoffmann Gerhard Date: Wed, 27 Mar 2024 08:40:16 +0100 Subject: [PATCH] saving ... --- .../calculator_c_interface_lib.cpp | 16 ++++++++++++++++ .../calculator_c_interface_lib.h | 3 +++ CalculatorCInterface/local_git_repository.cpp | 18 +++++++++++++++--- CalculatorCInterface/local_git_repository.h | 15 ++++++++++++--- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/CalculatorCInterface/calculator_c_interface_lib.cpp b/CalculatorCInterface/calculator_c_interface_lib.cpp index f21ad2f..5ffbeb3 100644 --- a/CalculatorCInterface/calculator_c_interface_lib.cpp +++ b/CalculatorCInterface/calculator_c_interface_lib.cpp @@ -598,6 +598,22 @@ int PushLocalRepository(char const *local_path, char const *branch_name, char co static QMap localGitRepos; +void SetReposRootDirectoryInternal(char const *p) { + LocalGitRepository::SetReposRootDirectory(QString::fromUtf8(p)); +} + +char const *GetReposRootDirectoryInternal() { + return LocalGitRepository::GetReposRootDirectory().toUtf8().constData(); +} + +char const *GetLocalRepositoryPathInternal(char const *localGitRepo) { + if (localGitRepos.count(localGitRepo) == 0) { + localGitRepos.insert(localGitRepo, + new LocalGitRepository(localGitRepo)); + } + return localGitRepos[localGitRepo]->localRepositoryPath().toUtf8().constData(); +} + int32_t GetFileMenuSizeInternal(char const *localGitRepo) { if (localGitRepos.count(localGitRepo) == 0) { localGitRepos.insert(localGitRepo, diff --git a/CalculatorCInterface/calculator_c_interface_lib.h b/CalculatorCInterface/calculator_c_interface_lib.h index 30b865f..404ccc5 100644 --- a/CalculatorCInterface/calculator_c_interface_lib.h +++ b/CalculatorCInterface/calculator_c_interface_lib.h @@ -10,6 +10,9 @@ extern "C" { #endif void DeleteMem(char *p) CALCULATOR_C_INTERFACE_LIB_EXPORT; +void SetReposRootDirectoryInternal(char const *p) CALCULATOR_C_INTERFACE_LIB_EXPORT; +char const *GetReposRootDirectoryInternal() CALCULATOR_C_INTERFACE_LIB_EXPORT; +char const *GetLocalRepositoryPathInternal(char const *localRepo) CALCULATOR_C_INTERFACE_LIB_EXPORT; // interface for menu of webpage char const *GetFileMenuInternal(char const *localRepo) CALCULATOR_C_INTERFACE_LIB_EXPORT; diff --git a/CalculatorCInterface/local_git_repository.cpp b/CalculatorCInterface/local_git_repository.cpp index f38feca..8f6a3e4 100644 --- a/CalculatorCInterface/local_git_repository.cpp +++ b/CalculatorCInterface/local_git_repository.cpp @@ -9,6 +9,17 @@ #include #include + +QString LocalGitRepository::m_repoRootDirectory = "H:\\"; + +void LocalGitRepository::SetReposRootDirectory(QString s) { + m_repoRootDirectory = s; +} + +QString LocalGitRepository::GetReposRootDirectory() { + return m_repoRootDirectory; +} + LocalGitRepository::LocalGitRepository(QString const &localRepository) : m_localRepository(localRepository) , m_fileMenu("{}") @@ -21,8 +32,9 @@ int32_t LocalGitRepository::GetFileMenuSizeInternal() const { QByteArray LocalGitRepository::GetFileMenuInternal() { if (m_fileMenuSize == -1) { - QFile f(QDir::cleanPath(QString(baseDir) + m_localRepository + QDir::separator() - + "etc/psa_webinterface/menu_config.json")); + QFile f(QDir::cleanPath(m_repoRootDirectory + QDir::separator() + + m_localRepository + QDir::separator() + + "etc/psa_webinterface/menu_config.json")); if (f.exists()) { if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { m_fileMenu = QTextStream(&f).readAll().toUtf8(); @@ -51,7 +63,7 @@ QByteArray LocalGitRepository::GetFileNameInternal(QString const &fId) { if (s != "master") { if (fId.contains("psa_tariff")) { QString fn(QDir::cleanPath( - QString(baseDir) + QDir::separator() + + m_repoRootDirectory + QDir::separator() + QString(m_localRepository) + QDir::separator() + path + QDir::separator() + QString("tariff%1.json").arg(s.toUInt(), 2, 10, QChar('0')))); diff --git a/CalculatorCInterface/local_git_repository.h b/CalculatorCInterface/local_git_repository.h index 0fa0c8b..2211ccd 100644 --- a/CalculatorCInterface/local_git_repository.h +++ b/CalculatorCInterface/local_git_repository.h @@ -3,20 +3,29 @@ #include #include - #include #include #include +#include class LocalGitRepository { QString m_localRepository; mutable QByteArray m_fileMenu; mutable int32_t m_fileMenuSize; + + static QString m_repoRootDirectory; public: + static void SetReposRootDirectory(QString s); + static QString GetReposRootDirectory(); + LocalGitRepository(QString const &localRepository); - static char const constexpr *baseDir = "H:\\"; - QString gitRepository() const { return m_localRepository; } + QString localRepository() const { return m_localRepository; } + + QString localRepositoryPath() { + return QDir::cleanPath( + m_repoRootDirectory + QDir::separator() + m_localRepository); + } QByteArray GetFileMenuInternal(); int32_t GetFileMenuSizeInternal() const;