forked from 400plus/400plus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
persist.c
62 lines (45 loc) · 1.3 KB
/
persist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <vxworks.h>
#include <ioLib.h>
#include "firmware.h"
#include "firmware/fio.h"
#include "main.h"
#include "exposure.h"
#include "scripts.h"
#include "persist.h"
persist_t persist = {
ev_comp : EC_ZERO,
last_script : SCRIPT_NONE,
};
int persist_read(void) {
int result = FALSE;
int file = -1;
int version = 0;
persist_t persistent_buffer;
if ((file = FIO_OpenFile(MKPATH_NEW(PERSIST_FILENAME), O_RDONLY)) == -1)
if ((file = FIO_OpenFile(MKPATH_OLD(PERSIST_FILENAME), O_RDONLY)) == -1)
goto end;
if (FIO_ReadFile(file, &version, sizeof(version)) != sizeof(version))
goto end;
if (version != PERSIST_VERSION)
goto end;
if (FIO_ReadFile(file, &persistent_buffer, sizeof(persistent_buffer)) != sizeof(persistent_buffer))
goto end;
persist = persistent_buffer;
result = TRUE;
end:
if (file != -1)
FIO_CloseFile(file);
return result;
}
void persist_write(void) {
const int version = PERSIST_VERSION;
int file = -1;
if ((file = FIO_OpenFile(MKPATH_NEW(PERSIST_FILENAME), O_CREAT | O_WRONLY)) == -1)
if (status.folder_exists || (file = FIO_OpenFile(MKPATH_OLD(PERSIST_FILENAME), O_CREAT | O_WRONLY)) == -1)
goto end;
FIO_WriteFile(file, (void*)&version, sizeof(version));
FIO_WriteFile(file, &persist, sizeof(persist));
end:
if (file != -1)
FIO_CloseFile(file);
}