From f3680754ece5a677c02db8f13c420293c7300678 Mon Sep 17 00:00:00 2001 From: Hoffmann Gerhard Date: Fri, 22 Mar 2024 13:46:54 +0100 Subject: [PATCH] save for the weekend --- .../calculator_c_interface_lib.cpp | 23 +++++++++++-------- CalculatorCInterface/local_git_repository.cpp | 7 ++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CalculatorCInterface/calculator_c_interface_lib.cpp b/CalculatorCInterface/calculator_c_interface_lib.cpp index f1b97ef..11f068d 100644 --- a/CalculatorCInterface/calculator_c_interface_lib.cpp +++ b/CalculatorCInterface/calculator_c_interface_lib.cpp @@ -607,19 +607,22 @@ int32_t GetFileMenuSize(char const *localGitRepo) { } char const *GetFileMenu(const char *localGitRepo) { - static char j[] = "{}"; - char *json = j; - int const len = GetFileMenuSize(localGitRepo); - if (len > 0) { - json = new char [len+1]; - // fprintf(stderr, "allocate pointer %p\n", json); - memset(json, 0x00, len+1); - QByteArray const &a = localGitRepos[localGitRepo]->GetFileMenu().constData(); - if (a.isValidUtf8()) { + if (localGitRepos.count(localGitRepo) == 0) { + localGitRepos.insert(localGitRepo, + new LocalGitRepository(localGitRepo)); + } + QByteArray const &a = localGitRepos[localGitRepo]->GetFileMenu().constData(); + if (a.isValidUtf8()) { + int const len = GetFileMenuSize(localGitRepo); + if (len > 0) { + char *json = new char [len+1]; + // fprintf(stderr, "allocate pointer %p\n", json); + memset(json, 0x00, len+1); memcpy(json, a.constData(), std::min(len, (int)a.size())); + return json; } } - return json; + return nullptr; } diff --git a/CalculatorCInterface/local_git_repository.cpp b/CalculatorCInterface/local_git_repository.cpp index 3ad89f4..6016a68 100644 --- a/CalculatorCInterface/local_git_repository.cpp +++ b/CalculatorCInterface/local_git_repository.cpp @@ -16,14 +16,11 @@ LocalGitRepository::LocalGitRepository(QString const &localRepository) } int32_t LocalGitRepository::GetFileMenuSize() const { - if (m_fileMenuSize == -1) { - GetFileMenu(); - } return m_fileMenuSize; } QByteArray const &LocalGitRepository::GetFileMenu() const { - if (m_fileMenu.toStdString() == "{}") { + if (m_fileMenuSize == -1) { QFile f(QDir::cleanPath(QString(baseDir) + m_localRepository + QDir::separator() + "etc/psa_webinterface/menu_config.json")); if (f.exists()) { @@ -98,7 +95,7 @@ bool LocalGitRepository::SetFile(QString const &fId, QByteArray const &json) { QFile fn(a); if (fn.exists()) { if (fn.open(QIODevice::WriteOnly)) { - quint64 bytesWritten = 0; + qint64 bytesWritten = 0; qint64 bytesToWrite = a.size(); while (bytesToWrite > 0 && (bytesWritten = fn.write(json.constData(), bytesToWrite)) != -1) {