Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ducalex committed Apr 2, 2023
2 parents 1610602 + d6e6d09 commit 2ffdbce
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 145 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Retro-Go 1.38.1 (2023-04-02)
- GBC: Added switch to disable RTC sync with system time
- Launcher: Fixed crash when files without extensions were present


# Retro-Go 1.38 (2023-03-28)
- GBC: Added support for MBC30 (For Pokemon Crystal romhacks)
- Launcher: Added a new scroll behavior (Options -> Scroll mode)
Expand Down
30 changes: 10 additions & 20 deletions components/retro-go/rg_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,28 +492,28 @@ void rg_gui_clear(rg_color_t color)

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

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

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

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

if (app->romPath && strlen(app->romPath) > max_len)
snprintf(footer, 100, "...%s", app->romPath + (strlen(app->romPath) - (max_len - 3)));
if (app->romPath && strlen(app->romPath) > max_len - 1)
snprintf(footer, max_len, "...%s", app->romPath + (strlen(app->romPath) - (max_len - 4)));
else if (app->romPath)
snprintf(footer, 100, "%s", app->romPath);
snprintf(footer, max_len, "%s", app->romPath);
else
snprintf(footer, 100, "Retro-Go %s", app->version);
snprintf(footer, max_len, "Retro-Go %s", app->version);

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

rg_gui_draw_status_bars();
rg_gui_draw_dialog(title, options, sel);
Expand Down Expand Up @@ -1053,7 +1053,7 @@ static rg_gui_event_t theme_cb(rg_gui_option_t *option, rg_gui_event_t event)
free(path);
}

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

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

char *rel_hash = strstr(build_ver, "-0-g");
if (rel_hash)
{
rel_hash[0] = ' ';
rel_hash[1] = ' ';
rel_hash[2] = ' ';
rel_hash[3] = '(';
strcat(build_ver, ")");
}

while (true)
{
switch (rg_gui_dialog("Retro-Go", options, 4))
Expand Down
75 changes: 28 additions & 47 deletions components/retro-go/rg_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,64 +202,49 @@ bool rg_storage_mkdir(const char *dir)
{
RG_ASSERT(dir, "Bad param");

char temp[RG_PATH_MAX + 1];
int ret = mkdir(dir, 0777);

if (ret == -1)
{
if (errno == EEXIST)
return true;
if (mkdir(dir, 0777) == 0)
return true;

strncpy(temp, dir, RG_PATH_MAX);
// FIXME: Might want to stat to see if it's a dir
if (errno == EEXIST)
return true;

for (char *p = temp + strlen(RG_STORAGE_ROOT) + 1; *p; p++)
// Possibly missing some parents, try creating them
char *temp = strdup(dir);
for (char *p = temp + strlen(RG_STORAGE_ROOT) + 1; *p; p++)
{
if (*p == '/')
{
if (*p == '/')
*p = 0;
if (strlen(temp) > 0)
{
*p = 0;
if (strlen(temp) > 0)
{
RG_LOGI("Creating %s\n", temp);
mkdir(temp, 0777);
}
*p = '/';
while (*(p + 1) == '/')
p++;
mkdir(temp, 0777);
}
*p = '/';
while (*(p + 1) == '/')
p++;
}

ret = mkdir(temp, 0777);
}
free(temp);

if (ret == 0)
{
RG_LOGI("Folder created %s\n", dir);
}
// Finally try again
if (mkdir(dir, 0777) == 0)
return true;

return (ret == 0);
return false;
}

bool rg_storage_delete(const char *path)
{
RG_ASSERT(path, "Bad param");
DIR *dir;

if (unlink(path) == 0)
{
RG_LOGI("Deleted file %s\n", path);
// errno has proven to be somewhat unreliable across our targets
// let's use a bruteforce approach...
if (unlink(path) == 0 || rmdir(path) == 0)
return true;
}
else if (errno == ENOENT)
{
// The path already doesn't exist!
return true;
}
else if (rmdir(path) == 0)
{
RG_LOGI("Deleted empty folder %s\n", path);
return true;
}
else if ((dir = opendir(path)))

DIR *dir = opendir(path);
if (dir)
{
char pathbuf[128]; // Smaller than RG_PATH_MAX to prevent issues due to lazy recursion...
struct dirent *ent;
Expand All @@ -272,11 +257,7 @@ bool rg_storage_delete(const char *path)
rg_storage_delete(pathbuf);
}
closedir(dir);
if (rmdir(path) == 0)
{
RG_LOGI("Deleted folder %s\n", path);
return true;
}
return rmdir(path) == 0;
}

return false;
Expand Down
4 changes: 3 additions & 1 deletion components/retro-go/rg_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
#define PRINTF_BINARY_32 PRINTF_BINARY_16 " " PRINTF_BINARY_16
#define PRINTF_BINVAL_32(i) PRINTF_BINVAL_16((i) >> 16), PRINTF_BINVAL_16(i)

size_t strlcpy(char *dst, const char *src, size_t size);
size_t strlcat(char *dst, const char *src, size_t size);

char *rg_strtolower(char *str);
char *rg_strtoupper(char *str);
size_t rg_strlcpy(char *dst, const char *src, size_t size);
const char *rg_dirname(const char *path);
const char *rg_basename(const char *path);
const char *rg_extension(const char *path);
Expand Down
18 changes: 11 additions & 7 deletions launcher/main/applications.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ static int apps_count = 0;
static const char *get_file_path(retro_file_t *file)
{
static char buffer[RG_PATH_MAX + 1];
if (file == NULL) return NULL;
return strcat(strcat(strcpy(buffer, file->folder), "/"), file->name);
RG_ASSERT(file, "Bad param");
snprintf(buffer, RG_PATH_MAX, "%s/%s", file->folder, file->name);
return buffer;
}

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

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

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

if (entry->is_file)
if (entry->is_file && ext != NULL)
{
char buffer[RG_PATH_MAX];
snprintf(buffer, RG_PATH_MAX, " %s ", rg_extension(entry->name));
is_valid = strstr(app->extensions, rg_strtolower(buffer)) != NULL;
snprintf(ext_buf, sizeof(ext_buf), " %s ", ext);
is_valid = strstr(app->extensions, rg_strtolower(ext_buf)) != NULL;
type = 0x00;
}
else if (entry->is_dir)
Expand Down Expand Up @@ -321,7 +323,7 @@ static void tab_refresh(tab_t *tab)
{
retro_file_t *file = &app->files[i];

if (!file->is_valid)
if (!file->is_valid || !file->name)
continue;

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

static void application(const char *desc, const char *name, const char *exts, const char *part, uint16_t crc_offset)
{
RG_ASSERT(desc && name && exts && part, "Bad param");

if (!rg_system_have_app(part))
{
RG_LOGI("Application '%s' (%s) not present, skipping\n", desc, part);
Expand Down
2 changes: 1 addition & 1 deletion launcher/main/applications.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef struct retro_app_s
char description[64];
char short_name[24];
char partition[24];
char extensions[24];
char extensions[32];
struct {
char covers[RG_PATH_MAX];
char saves[RG_PATH_MAX];
Expand Down
9 changes: 8 additions & 1 deletion launcher/main/bookmarks.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ static void book_init(book_type_t book_type, const char *name, const char *desc,

retro_file_t *bookmark_find_by_app(book_type_t book_type, const retro_app_t *app)
{
RG_ASSERT(book_type < BOOK_TYPE_COUNT && app != NULL, "bad param");

book_t *book = &books[book_type];

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

bool bookmark_exists(book_type_t book_type, const retro_file_t *file)
{
RG_ASSERT(book_type < BOOK_TYPE_COUNT && file != NULL, "bad param");

return book_find(&books[book_type], file) != NULL;
}

bool bookmark_add(book_type_t book_type, const retro_file_t *file)
{
RG_ASSERT(file, "bad param");
RG_ASSERT(book_type < BOOK_TYPE_COUNT && file != NULL, "bad param");

book_t *book = &books[book_type];

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

bool bookmark_remove(book_type_t book_type, const retro_file_t *file)
{
RG_ASSERT(book_type < BOOK_TYPE_COUNT && file != NULL, "bad param");

book_t *book = &books[book_type];
size_t found = 0;

Expand Down
2 changes: 2 additions & 0 deletions launcher/main/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void gui_event(gui_event_t event, tab_t *tab)

tab_t *gui_add_tab(const char *name, const char *desc, void *arg, void *event_handler)
{
RG_ASSERT(name && desc, "Bad param");

tab_t *tab = calloc(1, sizeof(tab_t));

snprintf(tab->name, sizeof(tab->name), "%s", name);
Expand Down
22 changes: 15 additions & 7 deletions launcher/main/updater.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,28 @@ void updater_show_dialog(void)
for (int i = 0; i < releases_count; ++i)
{
cJSON *release_json = cJSON_GetArrayItem(releases_json, i);
char *name = cJSON_GetStringValue(cJSON_GetObjectItem(release_json, "name"));
char *date = cJSON_GetStringValue(cJSON_GetObjectItem(release_json, "published_at"));

snprintf(releases[i].name, 32, "%s", name ?: "N/A");
snprintf(releases[i].date, 32, "%s", date ?: "N/A");

cJSON *assets_json = cJSON_GetObjectItem(release_json, "assets");
size_t assets_count = cJSON_GetArraySize(assets_json);

snprintf(releases[i].name, 32, "%s", cJSON_GetStringValue(cJSON_GetObjectItem(release_json, "name")));
snprintf(releases[i].date, 32, "%s", cJSON_GetStringValue(cJSON_GetObjectItem(release_json, "published_at")));
releases[i].assets = calloc(assets_count, sizeof(asset_t));
releases[i].assets_count = assets_count;
releases[i].assets_count = 0;

for (int j = 0; j < assets_count; ++j)
{
cJSON *asset_json = cJSON_GetArrayItem(assets_json, j);
asset_t *asset = &releases[i].assets[j];
snprintf(asset->name, 32, "%s", cJSON_GetStringValue(cJSON_GetObjectItem(asset_json, "name")));
snprintf(asset->url, 256, "%s", cJSON_GetStringValue(cJSON_GetObjectItem(asset_json, "browser_download_url")));
char *name = cJSON_GetStringValue(cJSON_GetObjectItem(asset_json, "name"));
char *url = cJSON_GetStringValue(cJSON_GetObjectItem(asset_json, "browser_download_url"));
if (name && url)
{
asset_t *asset = &releases[i].assets[releases[i].assets_count++];
snprintf(asset->name, 32, "%s", name);
snprintf(asset->url, 256, "%s", url);
}
}
}

Expand Down
Loading

0 comments on commit 2ffdbce

Please sign in to comment.