mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-03-11 01:39:13 +01:00
Simulator - show date, also add NULL checks
This commit is contained in:
@@ -18,10 +18,25 @@ class CProject *CSaveLoad::loadProjectFile(const char *fname) {
|
||||
return 0;
|
||||
}
|
||||
cJSON *n_jProj = cJSON_Parse(jsonData);
|
||||
cJSON *n_jProjCreated = cJSON_GetObjectItemCaseSensitive(n_jProj, "created");
|
||||
cJSON *n_jProjModified = cJSON_GetObjectItemCaseSensitive(n_jProj, "lastModified");
|
||||
p->setCreated(n_jProjCreated->valuestring);
|
||||
p->setLastModified(n_jProjModified->valuestring);
|
||||
if (0==n_jProj) {
|
||||
printf("Warning: failed to parse JSON data %s\n", fname);
|
||||
}
|
||||
else {
|
||||
cJSON *n_jProjCreated = cJSON_GetObjectItemCaseSensitive(n_jProj, "created");
|
||||
cJSON *n_jProjModified = cJSON_GetObjectItemCaseSensitive(n_jProj, "lastModified");
|
||||
if (n_jProjCreated) {
|
||||
p->setCreated(n_jProjCreated->valuestring);
|
||||
}
|
||||
else {
|
||||
printf("Warning: missing 'created' node in %s\n", fname);
|
||||
}
|
||||
if (n_jProjModified) {
|
||||
p->setLastModified(n_jProjModified->valuestring);
|
||||
}
|
||||
else {
|
||||
printf("Warning: missing 'lastModified' node in %s\n", fname);
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
void CSaveLoad::saveProjectToFile(class CProject *projToSave, const char *fname) {
|
||||
|
||||
@@ -57,7 +57,7 @@ void CSimulator::drawWindow() {
|
||||
const char *projectPathDisp = projectPath.c_str();
|
||||
if (*projectPathDisp == 0)
|
||||
projectPathDisp = "none";
|
||||
sprintf(buffer, "OpenBeken Simulator - %s", projectPathDisp);
|
||||
sprintf(buffer, "OpenBeken Simulator " __DATE__ " - %s", projectPathDisp);
|
||||
if (SIM_IsFlashModified()) {
|
||||
strcat(buffer, " (FLASH MODIFIED)");
|
||||
}
|
||||
@@ -288,14 +288,22 @@ bool CSimulator::loadSimulation(const char *s) {
|
||||
printf("CSimulator::loadSimulation: there is no %s\n", memPath.c_str());
|
||||
return true;
|
||||
}
|
||||
printf("CSimulator::loadSimulation: going to load %s\n", s);
|
||||
CProject *newProject = saveLoad->loadProjectFile(s);
|
||||
if (newProject == 0) {
|
||||
printf("CSimulator::loadSimulation: failed reading %s\n", s);
|
||||
return true;
|
||||
}
|
||||
printf("CSimulator::loadSimulation: loaded %s\n", s);
|
||||
CSimulation *newSim = saveLoad->loadSimulationFromFile(simPath.c_str());
|
||||
if (newSim == 0) {
|
||||
printf("CSimulator::loadSimulation: failed reading %s\n", simPath.c_str());
|
||||
return true;
|
||||
}
|
||||
printf("CSimulator::loadSimulation: loaded %s\n", simPath.c_str());
|
||||
projectPath = s;
|
||||
project = newProject;
|
||||
sim = saveLoad->loadSimulationFromFile(simPath.c_str());
|
||||
sim = newSim;
|
||||
recents->registerAndSave(projectPath.c_str());
|
||||
SIM_ClearOBK(memPath.c_str());
|
||||
sim->recalcBounds();
|
||||
|
||||
@@ -169,8 +169,10 @@ char *FS_ReadTextFile(const char *fname) {
|
||||
int len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
char *r = (char*)malloc(len + 1);
|
||||
fread(r, 1, len, f);
|
||||
r[len] = 0;
|
||||
if (r) {
|
||||
fread(r, 1, len, f);
|
||||
r[len] = 0;
|
||||
}
|
||||
fclose(f);
|
||||
return r;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user