save for the weekend
This commit is contained in:
parent
73340cbb7a
commit
f3680754ec
@ -607,19 +607,22 @@ int32_t GetFileMenuSize(char const *localGitRepo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char const *GetFileMenu(const char *localGitRepo) {
|
char const *GetFileMenu(const char *localGitRepo) {
|
||||||
static char j[] = "{}";
|
if (localGitRepos.count(localGitRepo) == 0) {
|
||||||
char *json = j;
|
localGitRepos.insert(localGitRepo,
|
||||||
int const len = GetFileMenuSize(localGitRepo);
|
new LocalGitRepository(localGitRepo));
|
||||||
if (len > 0) {
|
}
|
||||||
json = new char [len+1];
|
QByteArray const &a = localGitRepos[localGitRepo]->GetFileMenu().constData();
|
||||||
// fprintf(stderr, "allocate pointer %p\n", json);
|
if (a.isValidUtf8()) {
|
||||||
memset(json, 0x00, len+1);
|
int const len = GetFileMenuSize(localGitRepo);
|
||||||
QByteArray const &a = localGitRepos[localGitRepo]->GetFileMenu().constData();
|
if (len > 0) {
|
||||||
if (a.isValidUtf8()) {
|
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()));
|
memcpy(json, a.constData(), std::min(len, (int)a.size()));
|
||||||
|
return json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return json;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,14 +16,11 @@ LocalGitRepository::LocalGitRepository(QString const &localRepository)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t LocalGitRepository::GetFileMenuSize() const {
|
int32_t LocalGitRepository::GetFileMenuSize() const {
|
||||||
if (m_fileMenuSize == -1) {
|
|
||||||
GetFileMenu();
|
|
||||||
}
|
|
||||||
return m_fileMenuSize;
|
return m_fileMenuSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray const &LocalGitRepository::GetFileMenu() const {
|
QByteArray const &LocalGitRepository::GetFileMenu() const {
|
||||||
if (m_fileMenu.toStdString() == "{}") {
|
if (m_fileMenuSize == -1) {
|
||||||
QFile f(QDir::cleanPath(QString(baseDir) + m_localRepository + QDir::separator()
|
QFile f(QDir::cleanPath(QString(baseDir) + m_localRepository + QDir::separator()
|
||||||
+ "etc/psa_webinterface/menu_config.json"));
|
+ "etc/psa_webinterface/menu_config.json"));
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
@ -98,7 +95,7 @@ bool LocalGitRepository::SetFile(QString const &fId, QByteArray const &json) {
|
|||||||
QFile fn(a);
|
QFile fn(a);
|
||||||
if (fn.exists()) {
|
if (fn.exists()) {
|
||||||
if (fn.open(QIODevice::WriteOnly)) {
|
if (fn.open(QIODevice::WriteOnly)) {
|
||||||
quint64 bytesWritten = 0;
|
qint64 bytesWritten = 0;
|
||||||
qint64 bytesToWrite = a.size();
|
qint64 bytesToWrite = a.size();
|
||||||
while (bytesToWrite > 0 &&
|
while (bytesToWrite > 0 &&
|
||||||
(bytesWritten = fn.write(json.constData(), bytesToWrite)) != -1) {
|
(bytesWritten = fn.write(json.constData(), bytesToWrite)) != -1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user