diff options
Diffstat (limited to 'apps/plugins/open_plugins.c')
-rw-r--r-- | apps/plugins/open_plugins.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/apps/plugins/open_plugins.c b/apps/plugins/open_plugins.c index b8d11d2ae5..3a0c34d8d6 100644 --- a/apps/plugins/open_plugins.c +++ b/apps/plugins/open_plugins.c | |||
@@ -49,7 +49,8 @@ | |||
49 | static int fd_dat; | 49 | static int fd_dat; |
50 | static struct gui_synclist lists; | 50 | static struct gui_synclist lists; |
51 | struct open_plugin_entry_t op_entry; | 51 | struct open_plugin_entry_t op_entry; |
52 | const off_t op_entry_sz = sizeof(struct open_plugin_entry_t); | 52 | static const uint32_t open_plugin_csum = OPEN_PLUGIN_CHECKSUM; |
53 | static const off_t op_entry_sz = sizeof(struct open_plugin_entry_t); | ||
53 | 54 | ||
54 | /* we only need the names for the first menu so don't bother reading paths yet */ | 55 | /* we only need the names for the first menu so don't bother reading paths yet */ |
55 | const off_t op_name_sz = OPEN_PLUGIN_NAMESZ + (op_entry.name - (char*)&op_entry); | 56 | const off_t op_name_sz = OPEN_PLUGIN_NAMESZ + (op_entry.name - (char*)&op_entry); |
@@ -101,6 +102,15 @@ static bool op_entry_read_name(int fd, int selected_item) | |||
101 | return op_entry_read(fd, selected_item, op_name_sz); | 102 | return op_entry_read(fd, selected_item, op_name_sz); |
102 | } | 103 | } |
103 | 104 | ||
105 | static int op_entry_checksum(void) | ||
106 | { | ||
107 | if (op_entry.checksum != open_plugin_csum) | ||
108 | { | ||
109 | return 0; | ||
110 | } | ||
111 | return 1; | ||
112 | } | ||
113 | |||
104 | static int op_entry_read_opx(const char *path) | 114 | static int op_entry_read_opx(const char *path) |
105 | { | 115 | { |
106 | int ret = -1; | 116 | int ret = -1; |
@@ -112,13 +122,14 @@ static int op_entry_read_opx(const char *path) | |||
112 | if(len > OP_LEN && rb->strcasecmp(&((path)[len-OP_LEN]), "." OP_EXT) == 0) | 122 | if(len > OP_LEN && rb->strcasecmp(&((path)[len-OP_LEN]), "." OP_EXT) == 0) |
113 | { | 123 | { |
114 | fd_opx = rb->open(path, O_RDONLY); | 124 | fd_opx = rb->open(path, O_RDONLY); |
115 | if (fd_opx) | 125 | if (fd_opx >= 0) |
116 | { | 126 | { |
117 | filesize = rb->filesize(fd_opx); | 127 | filesize = rb->filesize(fd_opx); |
118 | ret = filesize; | 128 | ret = filesize; |
119 | if (filesize == op_entry_sz && !op_entry_read(fd_opx, 0, op_entry_sz)) | 129 | if (filesize == op_entry_sz && !op_entry_read(fd_opx, 0, op_entry_sz)) |
120 | ret = 0; | 130 | ret = 0; |
121 | 131 | else if (op_entry_checksum() <= 0) | |
132 | ret = 0; | ||
122 | rb->close(fd_opx); | 133 | rb->close(fd_opx); |
123 | } | 134 | } |
124 | } | 135 | } |
@@ -131,7 +142,7 @@ static void op_entry_export(int selection) | |||
131 | int fd = -1; | 142 | int fd = -1; |
132 | char filename [MAX_PATH + 1]; | 143 | char filename [MAX_PATH + 1]; |
133 | 144 | ||
134 | if (!op_entry_read(fd_dat, selection, op_entry_sz)) | 145 | if (!op_entry_read(fd_dat, selection, op_entry_sz) || op_entry_checksum() <= 0) |
135 | goto failure; | 146 | goto failure; |
136 | 147 | ||
137 | rb->snprintf(filename, MAX_PATH, "%s/%s", PLUGIN_APPS_DIR, op_entry.name); | 148 | rb->snprintf(filename, MAX_PATH, "%s/%s", PLUGIN_APPS_DIR, op_entry.name); |
@@ -161,6 +172,11 @@ failure: | |||
161 | 172 | ||
162 | } | 173 | } |
163 | 174 | ||
175 | static void op_entry_set_checksum(void) | ||
176 | { | ||
177 | op_entry.checksum = open_plugin_csum; | ||
178 | } | ||
179 | |||
164 | static void op_entry_set_name(void) | 180 | static void op_entry_set_name(void) |
165 | { | 181 | { |
166 | char tmp_buf[OPEN_PLUGIN_NAMESZ+1]; | 182 | char tmp_buf[OPEN_PLUGIN_NAMESZ+1]; |
@@ -277,12 +293,12 @@ static int op_entry_transfer(int fd, int fd_tmp, | |||
277 | void *data) | 293 | void *data) |
278 | { | 294 | { |
279 | int entries = -1; | 295 | int entries = -1; |
280 | if (fd_tmp && fd && rb->lseek(fd, 0, SEEK_SET) == 0) | 296 | if (fd_tmp >= 0 && fd >= 0 && rb->lseek(fd, 0, SEEK_SET) == 0) |
281 | { | 297 | { |
282 | entries = 0; | 298 | entries = 0; |
283 | while (rb->read(fd, &op_entry, op_entry_sz) == op_entry_sz) | 299 | while (rb->read(fd, &op_entry, op_entry_sz) == op_entry_sz) |
284 | { | 300 | { |
285 | if (compfn && compfn(&op_entry, entries, data) > 0) | 301 | if (compfn && compfn(&op_entry, entries, data) > 0 && op_entry_checksum() > 0) |
286 | { | 302 | { |
287 | rb->write(fd_tmp, &op_entry, op_entry_sz); | 303 | rb->write(fd_tmp, &op_entry, op_entry_sz); |
288 | entries++; | 304 | entries++; |
@@ -359,7 +375,7 @@ static uint32_t op_entry_add_path(const char *key, const char *plugin, const cha | |||
359 | op_entry.hash = newhash; | 375 | op_entry.hash = newhash; |
360 | } | 376 | } |
361 | } | 377 | } |
362 | 378 | op_entry_set_checksum(); | |
363 | rb->write(fd_tmp, &op_entry, op_entry_sz); /* add new entry first */ | 379 | rb->write(fd_tmp, &op_entry, op_entry_sz); /* add new entry first */ |
364 | } | 380 | } |
365 | else if(op_entry_read_opx(plugin) == op_entry_sz) | 381 | else if(op_entry_read_opx(plugin) == op_entry_sz) |
@@ -374,13 +390,13 @@ static uint32_t op_entry_add_path(const char *key, const char *plugin, const cha | |||
374 | open_plugin_get_hash(op_entry.path, &hash); | 390 | open_plugin_get_hash(op_entry.path, &hash); |
375 | 391 | ||
376 | op_entry.hash = hash; | 392 | op_entry.hash = hash; |
377 | 393 | op_entry_set_checksum(); | |
378 | rb->write(fd_tmp, &op_entry, op_entry_sz); /* add new entry first */ | 394 | rb->write(fd_tmp, &op_entry, op_entry_sz); /* add new entry first */ |
379 | } | 395 | } |
380 | else | 396 | else |
381 | { | 397 | { |
382 | if (op_entry.lang_id != LANG_SHORTCUTS) | 398 | if (op_entry.lang_id != LANG_SHORTCUTS) |
383 | rb->splashf(HZ / 2, rb->str(LANG_OPEN_PLUGIN_NOT_A_PLUGIN), pos); | 399 | rb->splashf(HZ * 2, rb->str(LANG_OPEN_PLUGIN_NOT_A_PLUGIN), pos); |
384 | return 0; | 400 | return 0; |
385 | } | 401 | } |
386 | } | 402 | } |
@@ -845,7 +861,7 @@ reopen_datfile: | |||
845 | synclist_set(MENU_ID_MAIN, selection, items, 1); | 861 | synclist_set(MENU_ID_MAIN, selection, items, 1); |
846 | rb->gui_synclist_draw(&lists); | 862 | rb->gui_synclist_draw(&lists); |
847 | 863 | ||
848 | while (!exit) | 864 | while (!exit && fd_dat >= 0) |
849 | { | 865 | { |
850 | action = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); | 866 | action = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); |
851 | 867 | ||