Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: PlayActivityUI to use most recent img for game #1305

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions src/playActivity/playActivityDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/stat.h>

#include "utils/file.h"
#include "utils/str.h"
#include "utils/log.h"

#include "./cacheDB.h"
Expand Down Expand Up @@ -47,6 +48,31 @@ struct PlayActivities {

sqlite3 *play_activity_db = NULL;

char * get_rom_image_path(char *rom_file) {

if(str_endsWith(rom_file, ".p8") || str_endsWith(rom_file, ".png")) {
char * path[STR_MAX];
concat(path, "/mnt/SDCARD/Roms/", rom_file);
return strdup(path);
};

char *clean_rom_name = file_removeExtension(basename(rom_file));
char *rom_path = str_replace(rom_file, basename(rom_file), "");
Aemiii91 marked this conversation as resolved.
Show resolved Hide resolved

char base_path[STR_MAX];
concat(base_path, "/mnt/SDCARD/Roms/",rom_path);

char img_path[STR_MAX];
concat(img_path, base_path, "Imgs/");
char png_name[STR_MAX];
concat(png_name, clean_rom_name, ".png");

char ret[STR_MAX];
concat(ret, img_path, png_name);

return is_file(ret) ? strdup(ret) : NULL;
}

void play_activity_db_close()
{
sqlite3_close(play_activity_db);
Expand Down Expand Up @@ -140,7 +166,7 @@ PlayActivities *play_activity_find_all(void)
PlayActivities *play_activities = NULL;
char *sql =
"SELECT * FROM ("
" SELECT rom.id, rom.type, rom.name, rom.file_path, rom.image_path, "
" SELECT rom.id, rom.type, rom.name, rom.file_path, "
" COUNT(play_activity.ROWID) AS play_count_total, "
" SUM(play_activity.play_time) AS play_time_total, "
" SUM(play_activity.play_time)/COUNT(play_activity.ROWID) AS play_time_average, "
Expand Down Expand Up @@ -179,19 +205,17 @@ PlayActivities *play_activity_find_all(void)
rom->name = strdup((const char *)sqlite3_column_text(stmt, 2));
if (sqlite3_column_text(stmt, 3) != NULL) {
rom->file_path = strdup((const char *)sqlite3_column_text(stmt, 3));
}
if (sqlite3_column_text(stmt, 4) != NULL) {
rom->image_path = strdup((const char *)sqlite3_column_text(stmt, 4));
rom->image_path = get_rom_image_path(rom->file_path);
}

entry->play_count = sqlite3_column_int(stmt, 5);
entry->play_time_total = sqlite3_column_int(stmt, 6);
entry->play_time_average = sqlite3_column_int(stmt, 7);
entry->play_count = sqlite3_column_int(stmt, 4);
entry->play_time_total = sqlite3_column_int(stmt, 5);
entry->play_time_average = sqlite3_column_int(stmt, 6);
if (sqlite3_column_text(stmt, 8) != NULL) {
entry->first_played_at = strdup((const char *)sqlite3_column_text(stmt, 8));
entry->first_played_at = strdup((const char *)sqlite3_column_text(stmt, 7));
}
if (sqlite3_column_text(stmt, 9) != NULL) {
entry->last_played_at = strdup((const char *)sqlite3_column_text(stmt, 9));
entry->last_played_at = strdup((const char *)sqlite3_column_text(stmt, 8));
}

play_activities->play_time_total += entry->play_time_total;
Expand Down
Loading