save for the weekend
This commit is contained in:
parent
73340cbb7a
commit
f3680754ec
@ -607,20 +607,23 @@ 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);
|
||||
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 nullptr;
|
||||
}
|
||||
|
||||
|
||||
char const *GetFileName(char const *localGitRepo, char const *fileId) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user