Skip to content

Commit 2ffdbce

Browse files
committed
Merge branch 'dev'
2 parents 1610602 + d6e6d09 commit 2ffdbce

File tree

11 files changed

+108
-145
lines changed

11 files changed

+108
-145
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Retro-Go 1.38.1 (2023-04-02)
2+
- GBC: Added switch to disable RTC sync with system time
3+
- Launcher: Fixed crash when files without extensions were present
4+
5+
16
# Retro-Go 1.38 (2023-03-28)
27
- GBC: Added support for MBC30 (For Pokemon Crystal romhacks)
38
- Launcher: Added a new scroll behavior (Options -> Scroll mode)

components/retro-go/rg_gui.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -492,28 +492,28 @@ void rg_gui_clear(rg_color_t color)
492492

493493
void rg_gui_draw_status_bars(void)
494494
{
495-
int max_len = RG_MIN(gui.screen_width / RG_MAX(gui.style.font->width, 7), 99);
496-
char header[100] = {0};
497-
char footer[100] = {0};
495+
size_t max_len = RG_MIN(gui.screen_width / RG_MAX(gui.style.font->width, 7), 99) + 1;
496+
char header[max_len];
497+
char footer[max_len];
498498

499499
const rg_app_t *app = rg_system_get_app();
500500
rg_stats_t stats = rg_system_get_counters();
501501

502502
if (!app->initialized || app->isLauncher)
503503
return;
504504

505-
snprintf(header, 100, "SPEED: %d%% (%d/%d) / BUSY: %d%%",
505+
snprintf(header, max_len, "SPEED: %d%% (%d/%d) / BUSY: %d%%",
506506
(int)round(stats.totalFPS / app->refreshRate * 100.f),
507507
(int)round(stats.totalFPS - stats.skippedFPS),
508508
(int)round(stats.totalFPS),
509509
(int)round(stats.busyPercent));
510510

511-
if (app->romPath && strlen(app->romPath) > max_len)
512-
snprintf(footer, 100, "...%s", app->romPath + (strlen(app->romPath) - (max_len - 3)));
511+
if (app->romPath && strlen(app->romPath) > max_len - 1)
512+
snprintf(footer, max_len, "...%s", app->romPath + (strlen(app->romPath) - (max_len - 4)));
513513
else if (app->romPath)
514-
snprintf(footer, 100, "%s", app->romPath);
514+
snprintf(footer, max_len, "%s", app->romPath);
515515
else
516-
snprintf(footer, 100, "Retro-Go %s", app->version);
516+
snprintf(footer, max_len, "Retro-Go %s", app->version);
517517

518518
rg_gui_draw_text(0, 0, gui.screen_width, header, C_WHITE, C_BLACK, RG_TEXT_ALIGN_TOP);
519519
rg_gui_draw_text(0, 0, gui.screen_width, footer, C_WHITE, C_BLACK, RG_TEXT_ALIGN_BOTTOM);
@@ -720,7 +720,7 @@ int rg_gui_dialog(const char *title, const rg_gui_option_t *options_const, int s
720720
if (option->update_cb)
721721
option->update_cb(option, RG_DIALOG_INIT);
722722
}
723-
RG_LOGI("text_buffer usage = %d\n", (intptr_t)(text_buffer_ptr - text_buffer));
723+
RG_LOGD("text_buffer usage = %d\n", (intptr_t)(text_buffer_ptr - text_buffer));
724724

725725
rg_gui_draw_status_bars();
726726
rg_gui_draw_dialog(title, options, sel);
@@ -1053,7 +1053,7 @@ static rg_gui_event_t theme_cb(rg_gui_option_t *option, rg_gui_event_t event)
10531053
free(path);
10541054
}
10551055

1056-
sprintf(option->value, "%s", rg_gui_get_theme() ?: "Default");
1056+
strcpy(option->value, rg_gui_get_theme() ?: "Default");
10571057
return RG_DIALOG_VOID;
10581058
}
10591059

@@ -1169,16 +1169,6 @@ void rg_gui_about_menu(const rg_gui_option_t *extra_options)
11691169
snprintf(build_date, 30, "%s %s", app->buildDate, app->buildTime);
11701170
snprintf(build_user, 30, "%s", app->buildUser);
11711171

1172-
char *rel_hash = strstr(build_ver, "-0-g");
1173-
if (rel_hash)
1174-
{
1175-
rel_hash[0] = ' ';
1176-
rel_hash[1] = ' ';
1177-
rel_hash[2] = ' ';
1178-
rel_hash[3] = '(';
1179-
strcat(build_ver, ")");
1180-
}
1181-
11821172
while (true)
11831173
{
11841174
switch (rg_gui_dialog("Retro-Go", options, 4))

components/retro-go/rg_storage.c

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -202,64 +202,49 @@ bool rg_storage_mkdir(const char *dir)
202202
{
203203
RG_ASSERT(dir, "Bad param");
204204

205-
char temp[RG_PATH_MAX + 1];
206-
int ret = mkdir(dir, 0777);
207-
208-
if (ret == -1)
209-
{
210-
if (errno == EEXIST)
211-
return true;
205+
if (mkdir(dir, 0777) == 0)
206+
return true;
212207

213-
strncpy(temp, dir, RG_PATH_MAX);
208+
// FIXME: Might want to stat to see if it's a dir
209+
if (errno == EEXIST)
210+
return true;
214211

215-
for (char *p = temp + strlen(RG_STORAGE_ROOT) + 1; *p; p++)
212+
// Possibly missing some parents, try creating them
213+
char *temp = strdup(dir);
214+
for (char *p = temp + strlen(RG_STORAGE_ROOT) + 1; *p; p++)
215+
{
216+
if (*p == '/')
216217
{
217-
if (*p == '/')
218+
*p = 0;
219+
if (strlen(temp) > 0)
218220
{
219-
*p = 0;
220-
if (strlen(temp) > 0)
221-
{
222-
RG_LOGI("Creating %s\n", temp);
223-
mkdir(temp, 0777);
224-
}
225-
*p = '/';
226-
while (*(p + 1) == '/')
227-
p++;
221+
mkdir(temp, 0777);
228222
}
223+
*p = '/';
224+
while (*(p + 1) == '/')
225+
p++;
229226
}
230-
231-
ret = mkdir(temp, 0777);
232227
}
228+
free(temp);
233229

234-
if (ret == 0)
235-
{
236-
RG_LOGI("Folder created %s\n", dir);
237-
}
230+
// Finally try again
231+
if (mkdir(dir, 0777) == 0)
232+
return true;
238233

239-
return (ret == 0);
234+
return false;
240235
}
241236

242237
bool rg_storage_delete(const char *path)
243238
{
244239
RG_ASSERT(path, "Bad param");
245-
DIR *dir;
246240

247-
if (unlink(path) == 0)
248-
{
249-
RG_LOGI("Deleted file %s\n", path);
241+
// errno has proven to be somewhat unreliable across our targets
242+
// let's use a bruteforce approach...
243+
if (unlink(path) == 0 || rmdir(path) == 0)
250244
return true;
251-
}
252-
else if (errno == ENOENT)
253-
{
254-
// The path already doesn't exist!
255-
return true;
256-
}
257-
else if (rmdir(path) == 0)
258-
{
259-
RG_LOGI("Deleted empty folder %s\n", path);
260-
return true;
261-
}
262-
else if ((dir = opendir(path)))
245+
246+
DIR *dir = opendir(path);
247+
if (dir)
263248
{
264249
char pathbuf[128]; // Smaller than RG_PATH_MAX to prevent issues due to lazy recursion...
265250
struct dirent *ent;
@@ -272,11 +257,7 @@ bool rg_storage_delete(const char *path)
272257
rg_storage_delete(pathbuf);
273258
}
274259
closedir(dir);
275-
if (rmdir(path) == 0)
276-
{
277-
RG_LOGI("Deleted folder %s\n", path);
278-
return true;
279-
}
260+
return rmdir(path) == 0;
280261
}
281262

282263
return false;

components/retro-go/rg_utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@
4040
#define PRINTF_BINARY_32 PRINTF_BINARY_16 " " PRINTF_BINARY_16
4141
#define PRINTF_BINVAL_32(i) PRINTF_BINVAL_16((i) >> 16), PRINTF_BINVAL_16(i)
4242

43+
size_t strlcpy(char *dst, const char *src, size_t size);
44+
size_t strlcat(char *dst, const char *src, size_t size);
45+
4346
char *rg_strtolower(char *str);
4447
char *rg_strtoupper(char *str);
45-
size_t rg_strlcpy(char *dst, const char *src, size_t size);
4648
const char *rg_dirname(const char *path);
4749
const char *rg_basename(const char *path);
4850
const char *rg_extension(const char *path);

launcher/main/applications.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ static int apps_count = 0;
3131
static const char *get_file_path(retro_file_t *file)
3232
{
3333
static char buffer[RG_PATH_MAX + 1];
34-
if (file == NULL) return NULL;
35-
return strcat(strcat(strcpy(buffer, file->folder), "/"), file->name);
34+
RG_ASSERT(file, "Bad param");
35+
snprintf(buffer, RG_PATH_MAX, "%s/%s", file->folder, file->name);
36+
return buffer;
3637
}
3738

3839
static void scan_folder(retro_app_t *app, const char* path, void *parent)
@@ -43,17 +44,18 @@ static void scan_folder(retro_app_t *app, const char* path, void *parent)
4344

4445
const char *folder = const_string(path);
4546
rg_scandir_t *files = rg_storage_scandir(path, NULL, false);
47+
char ext_buf[32];
4648

4749
for (rg_scandir_t *entry = files; entry && entry->is_valid; ++entry)
4850
{
51+
const char *ext = rg_extension(entry->name);
4952
uint8_t is_valid = false;
5053
uint8_t type = 0x00;
5154

52-
if (entry->is_file)
55+
if (entry->is_file && ext != NULL)
5356
{
54-
char buffer[RG_PATH_MAX];
55-
snprintf(buffer, RG_PATH_MAX, " %s ", rg_extension(entry->name));
56-
is_valid = strstr(app->extensions, rg_strtolower(buffer)) != NULL;
57+
snprintf(ext_buf, sizeof(ext_buf), " %s ", ext);
58+
is_valid = strstr(app->extensions, rg_strtolower(ext_buf)) != NULL;
5759
type = 0x00;
5860
}
5961
else if (entry->is_dir)
@@ -321,7 +323,7 @@ static void tab_refresh(tab_t *tab)
321323
{
322324
retro_file_t *file = &app->files[i];
323325

324-
if (!file->is_valid)
326+
if (!file->is_valid || !file->name)
325327
continue;
326328

327329
if (file->folder != folder && strcmp(file->folder, folder) != 0)
@@ -649,6 +651,8 @@ void application_show_file_menu(retro_file_t *file, bool advanced)
649651

650652
static void application(const char *desc, const char *name, const char *exts, const char *part, uint16_t crc_offset)
651653
{
654+
RG_ASSERT(desc && name && exts && part, "Bad param");
655+
652656
if (!rg_system_have_app(part))
653657
{
654658
RG_LOGI("Application '%s' (%s) not present, skipping\n", desc, part);

launcher/main/applications.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typedef struct retro_app_s
2323
char description[64];
2424
char short_name[24];
2525
char partition[24];
26-
char extensions[24];
26+
char extensions[32];
2727
struct {
2828
char covers[RG_PATH_MAX];
2929
char saves[RG_PATH_MAX];

launcher/main/bookmarks.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ static void book_init(book_type_t book_type, const char *name, const char *desc,
210210

211211
retro_file_t *bookmark_find_by_app(book_type_t book_type, const retro_app_t *app)
212212
{
213+
RG_ASSERT(book_type < BOOK_TYPE_COUNT && app != NULL, "bad param");
214+
213215
book_t *book = &books[book_type];
214216

215217
// Find the last entry (most recent)
@@ -226,12 +228,15 @@ retro_file_t *bookmark_find_by_app(book_type_t book_type, const retro_app_t *app
226228

227229
bool bookmark_exists(book_type_t book_type, const retro_file_t *file)
228230
{
231+
RG_ASSERT(book_type < BOOK_TYPE_COUNT && file != NULL, "bad param");
232+
229233
return book_find(&books[book_type], file) != NULL;
230234
}
231235

232236
bool bookmark_add(book_type_t book_type, const retro_file_t *file)
233237
{
234-
RG_ASSERT(file, "bad param");
238+
RG_ASSERT(book_type < BOOK_TYPE_COUNT && file != NULL, "bad param");
239+
235240
book_t *book = &books[book_type];
236241

237242
for (retro_file_t *item; (item = book_find(book, file));)
@@ -246,6 +251,8 @@ bool bookmark_add(book_type_t book_type, const retro_file_t *file)
246251

247252
bool bookmark_remove(book_type_t book_type, const retro_file_t *file)
248253
{
254+
RG_ASSERT(book_type < BOOK_TYPE_COUNT && file != NULL, "bad param");
255+
249256
book_t *book = &books[book_type];
250257
size_t found = 0;
251258

launcher/main/gui.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ void gui_event(gui_event_t event, tab_t *tab)
6868

6969
tab_t *gui_add_tab(const char *name, const char *desc, void *arg, void *event_handler)
7070
{
71+
RG_ASSERT(name && desc, "Bad param");
72+
7173
tab_t *tab = calloc(1, sizeof(tab_t));
7274

7375
snprintf(tab->name, sizeof(tab->name), "%s", name);

launcher/main/updater.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,28 @@ void updater_show_dialog(void)
151151
for (int i = 0; i < releases_count; ++i)
152152
{
153153
cJSON *release_json = cJSON_GetArrayItem(releases_json, i);
154+
char *name = cJSON_GetStringValue(cJSON_GetObjectItem(release_json, "name"));
155+
char *date = cJSON_GetStringValue(cJSON_GetObjectItem(release_json, "published_at"));
156+
157+
snprintf(releases[i].name, 32, "%s", name ?: "N/A");
158+
snprintf(releases[i].date, 32, "%s", date ?: "N/A");
159+
154160
cJSON *assets_json = cJSON_GetObjectItem(release_json, "assets");
155161
size_t assets_count = cJSON_GetArraySize(assets_json);
156-
157-
snprintf(releases[i].name, 32, "%s", cJSON_GetStringValue(cJSON_GetObjectItem(release_json, "name")));
158-
snprintf(releases[i].date, 32, "%s", cJSON_GetStringValue(cJSON_GetObjectItem(release_json, "published_at")));
159162
releases[i].assets = calloc(assets_count, sizeof(asset_t));
160-
releases[i].assets_count = assets_count;
163+
releases[i].assets_count = 0;
161164

162165
for (int j = 0; j < assets_count; ++j)
163166
{
164167
cJSON *asset_json = cJSON_GetArrayItem(assets_json, j);
165-
asset_t *asset = &releases[i].assets[j];
166-
snprintf(asset->name, 32, "%s", cJSON_GetStringValue(cJSON_GetObjectItem(asset_json, "name")));
167-
snprintf(asset->url, 256, "%s", cJSON_GetStringValue(cJSON_GetObjectItem(asset_json, "browser_download_url")));
168+
char *name = cJSON_GetStringValue(cJSON_GetObjectItem(asset_json, "name"));
169+
char *url = cJSON_GetStringValue(cJSON_GetObjectItem(asset_json, "browser_download_url"));
170+
if (name && url)
171+
{
172+
asset_t *asset = &releases[i].assets[releases[i].assets_count++];
173+
snprintf(asset->name, 32, "%s", name);
174+
snprintf(asset->url, 256, "%s", url);
175+
}
168176
}
169177
}
170178

0 commit comments

Comments
 (0)