just save

This commit is contained in:
Gerhard Hoffmann 2024-03-21 16:57:53 +01:00
parent 65f72eca79
commit 73340cbb7a
4 changed files with 86 additions and 8 deletions

View File

@ -31,11 +31,13 @@ int main(int argc, char *argv[])
//TariffCalculatorHandle handle = NewTariffCalculator(); //TariffCalculatorHandle handle = NewTariffCalculator();
//DeleteTariffCalculator(handle); //DeleteTariffCalculator(handle);
if (InitGitLibrary() > 0) { //if (InitGitLibrary() > 0) {
qCritical() << CloneRepository("https://git.mimbach49.de/GerhardHoffmann/customer_999.git", "C:\\tmp\\customer_999"); // qCritical() << CloneRepository("https://git.mimbach49.de/GerhardHoffmann/customer_999.git", "C:\\tmp\\customer_999");
qCritical() << CheckoutLocalBranch("C:\\tmp\\customer_999", "master"); // qCritical() << CheckoutLocalBranch("C:\\tmp\\customer_999", "master");
ShutdownGitLibrary(); // ShutdownGitLibrary();
} // }
qCritical() << GetFileMenuSize("customer_999");
#else #else
QLibrary library("C:\\build-ATBTariffCalculator-Desktop_Qt_6_5_0_MinGW_64_bit-Release\\CalculatorCInterface\\release\\CalculatorCInterface.dll"); QLibrary library("C:\\build-ATBTariffCalculator-Desktop_Qt_6_5_0_MinGW_64_bit-Release\\CalculatorCInterface\\release\\CalculatorCInterface.dll");
if (library.load()) { if (library.load()) {

View File

@ -28,12 +28,14 @@ CONFIG += c++20 console
SOURCES += \ SOURCES += \
calculator_c_interface_lib.cpp \ calculator_c_interface_lib.cpp \
tariff_calculator.cpp tariff_calculator.cpp \
local_git_repository.cpp
HEADERS += \ HEADERS += \
calculator_c_interface_lib.h \ calculator_c_interface_lib.h \
calculator_c_interface_lib_global.h \ calculator_c_interface_lib_global.h \
tariff_calculator.h tariff_calculator.h \
local_git_repository.h
# Default rules for deployment. # Default rules for deployment.
unix { unix {

View File

@ -5,12 +5,17 @@
#include <QMap> #include <QMap>
#include <QString> #include <QString>
#include <QDir> #include <QDir>
#include <QFile>
#include <QByteArray>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include <mutex> #include <mutex>
#include <git2.h> #include <git2.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <algorithm>
static QMap<QString, git_repository *> customerRepoMap; static QMap<QString, git_repository *> customerRepoMap;
static std::mutex m; static std::mutex m;
@ -589,7 +594,67 @@ int PushLocalRepository(char const *local_path, char const *branch_name, char co
return error; return error;
} }
#include <local_git_repository.h>
static QMap<QString, LocalGitRepository *> localGitRepos;
int32_t GetFileMenuSize(char const *localGitRepo) {
if (localGitRepos.count(localGitRepo) == 0) {
localGitRepos.insert(localGitRepo,
new LocalGitRepository(localGitRepo));
}
return localGitRepos[localGitRepo]->GetFileMenuSize();
}
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()) {
memcpy(json, a.constData(), std::min(len, (int)a.size()));
}
}
return json;
}
char const *GetFileName(char const *localGitRepo, char const *fileId) {
QByteArray const &a = localGitRepos[localGitRepo]->GetFileName(fileId);
if (a.isValidUtf8()) {
char *c = new char[a.size() + 1];
memset(c, 0x00, a.size() + 1);
memcpy(c, a.constData(), a.size());
return c;
}
return nullptr;
}
int32_t GetFileSize(char const *localGitRepo, char const *fileId) {
return localGitRepos[localGitRepo]->GetFileSize(fileId);
}
char const *GetFile(char const *localGitRepo, char const *fileId) {
QByteArray const &a = localGitRepos[localGitRepo]->GetFile(fileId);
if (a.isValidUtf8()) {
char *c = new char[a.size() + 1];
memset(c, 0x00, a.size() + 1);
memcpy(c, a.constData(), a.size());
return c;
}
return nullptr;
}
void DeleteMem(char *p) {
if (p) {
// fprintf(stderr, "delete pointer %p\n", p);
delete p;
}
}
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,6 +1,5 @@
#ifndef CALCULATOR_C_INTERFACE_LIB_H_INCLUDED #ifndef CALCULATOR_C_INTERFACE_LIB_H_INCLUDED
#define CALCULATOR_C_INTERFACE_LIB_H_INCLUDED #define CALCULATOR_C_INTERFACE_LIB_H_INCLUDED
#include "calculator_c_interface_lib_global.h" #include "calculator_c_interface_lib_global.h"
#include "tariff_calculator.h" #include "tariff_calculator.h"
@ -10,6 +9,16 @@ typedef TariffCalculator *TariffCalculatorHandle;
extern "C" { extern "C" {
#endif #endif
void DeleteMem(char *p) CALCULATOR_C_INTERFACE_LIB_EXPORT;
// interface for menu of webpage
char const *GetFileMenu(char const *localRepo) CALCULATOR_C_INTERFACE_LIB_EXPORT;
int32_t GetFileMenuSize(char const *localRepo) CALCULATOR_C_INTERFACE_LIB_EXPORT;
char const *GetFileName(char const *localRepo, char const *fileId) CALCULATOR_C_INTERFACE_LIB_EXPORT;
int32_t GetFileSize(char const *localRepo, char const *fileId) CALCULATOR_C_INTERFACE_LIB_EXPORT;
char const *GetFile(char const *localRepo, char const *fileId) CALCULATOR_C_INTERFACE_LIB_EXPORT;
bool SetFile(char const *localRepo, char const *fileId, char const *json) CALCULATOR_C_INTERFACE_LIB_EXPORT;
TariffCalculatorHandle NewTariffCalculator(void) CALCULATOR_C_INTERFACE_LIB_EXPORT; TariffCalculatorHandle NewTariffCalculator(void) CALCULATOR_C_INTERFACE_LIB_EXPORT;
void DeleteTariffCalculator(TariffCalculatorHandle handle) CALCULATOR_C_INTERFACE_LIB_EXPORT; void DeleteTariffCalculator(TariffCalculatorHandle handle) CALCULATOR_C_INTERFACE_LIB_EXPORT;