Skip to content

Commit 04e4399

Browse files
committed
Wed 26 Feb 2020 00:45:29 EST - working on favorites
1 parent 9fba546 commit 04e4399

File tree

1 file changed

+48
-10
lines changed
  • Launchers/retro-esp32/main

1 file changed

+48
-10
lines changed

Launchers/retro-esp32/main/main.c

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -959,9 +959,10 @@
959959
i = 0;
960960
offset = ROM.favorite?40:35;
961961
int option = SAVED ? 3 : 1;
962+
draw_mask(x,y-1,80,9);
962963
for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) {
963964
buffer[i] = icons[r+offset][c] == WHITE ? OPTION == option ? WHITE : GUI.fg : GUI.bg;i++;
964-
}}
965+
}}
965966
ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
966967
draw_text(x+10,y,ROM.favorite?"Unfavorite":"Favorite",false,OPTION == option?true:false, false);
967968
}
@@ -1249,12 +1250,7 @@
12491250
f = fopen(file, "rb");
12501251
if(f == NULL) {
12511252
f = fopen(file, "w+");
1252-
printf("\nCREATING: %s", file);
1253-
/*
1254-
Castlevania Adventure, The (U).gb
1255-
Legend of Zelda, The - Oracle of Seasons (USA).gbc
1256-
Mega Man 2 (USA).nes
1257-
*/
1253+
printf("\nCREATING: %s", file);
12581254
} else {
12591255
read_favorites();
12601256
}
@@ -1300,6 +1296,49 @@
13001296

13011297
void delete_favorite(char *favorite) {
13021298
printf("\n----- %s START -----", __func__);
1299+
1300+
int n = 0;
1301+
int count = 0;
1302+
1303+
free(FAVORITES);
1304+
FAVORITES = (char**)malloc(50 * sizeof(void*));
1305+
1306+
char file[256] = "/sd/odroid/data";
1307+
sprintf(file, "%s/%s", file, FAVFILE);
1308+
1309+
FILE *f;
1310+
f = fopen(file, "rb");
1311+
if(f) {
1312+
printf("\nCHECKING: %s\n", favorite);
1313+
char line[256];
1314+
while (fgets(line, sizeof(line), f)) {
1315+
char *ep = &line[strlen(line)-1];
1316+
while (*ep == '\n' || *ep == '\r'){*ep-- = '\0';}
1317+
if(strcmp(favorite, line) != 0) {
1318+
size_t len = strlen(line);
1319+
FAVORITES[n] = (char*)malloc(len + 1);
1320+
strcpy(FAVORITES[n], line);
1321+
n++;
1322+
count++;
1323+
}
1324+
}
1325+
}
1326+
fclose(f);
1327+
struct stat st;
1328+
if (stat(file, &st) == 0) {
1329+
unlink(file);
1330+
create_favorites();
1331+
for(n = 0; n < count; n++) {
1332+
size_t len = strlen(FAVORITES[n]);
1333+
if(len > 0) {
1334+
add_favorite(FAVORITES[n]);
1335+
printf("\n%s - %d" , FAVORITES[n], len);
1336+
}
1337+
}
1338+
} else {
1339+
printf("\nUNABLE TO UNLINK\n");
1340+
}
1341+
13031342
printf("\n----- %s END -----\n", __func__);
13041343
}
13051344

@@ -1319,7 +1358,6 @@
13191358
while (fgets(line, sizeof(line), f)) {
13201359
char *ep = &line[strlen(line)-1];
13211360
while (*ep == '\n' || *ep == '\r'){*ep-- = '\0';}
1322-
printf("\nfavorite:%s line:%s match:%d", favorite, line, strcmp(favorite, line));
13231361
if(strcmp(favorite, line) == 0) {
13241362
ROM.favorite = true;
13251363
}
@@ -1948,14 +1986,14 @@
19481986
SAVED ? rom_resume() : rom_run(false);
19491987
break;
19501988
case 1:
1951-
SAVED ? rom_run(true) : add_favorite(ROM.name);
1989+
SAVED ? rom_run(true) : ROM.favorite ? delete_favorite(ROM.name) : add_favorite(ROM.name);
19521990
if(!SAVED) {draw_launcher_options();}
19531991
break;
19541992
case 2:
19551993
rom_delete_save();
19561994
break;
19571995
case 3:
1958-
add_favorite(ROM.name);
1996+
ROM.favorite ? delete_favorite(ROM.name) : add_favorite(ROM.name);
19591997
draw_launcher_options();
19601998
break;
19611999
}

0 commit comments

Comments
 (0)