Skip to content

Commit c565b89

Browse files
committed
make assets update optional on first run and enable by default for webOS
1 parent 5e97b18 commit c565b89

5 files changed

Lines changed: 84 additions & 10 deletions

File tree

Makefile.webos

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ HAVE_UPDATE_CORE_INFO = 1
136136
HAVE_USERLAND ?= 0
137137
HAVE_WEBOS_EXTRA_PROTOS ?= 0
138138
HAVE_CORE_INFO_CACHE = 1
139+
HAVE_UPDATE_ASSETS_FIRST_RUN ?= 1
139140
HAVE_WAYLAND ?= 0
140141
HAVE_WAYLAND_BACKPORT ?= 1
141142

@@ -213,6 +214,9 @@ endif
213214
ifeq ($(HAVE_SDL2),1)
214215
DEFINES += -DHAVE_SDL2
215216
endif
217+
ifeq ($(HAVE_UPDATE_ASSETS_FIRST_RUN),1)
218+
DEFINES += -DHAVE_UPDATE_ASSETS_FIRST_RUN
219+
endif
216220

217221
PKG_CONFIG=pkg-config
218222

file_path_special.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ RETRO_BEGIN_DECLS
126126
#define FILE_PATH_CORE_INFO_CACHE "core_info.cache"
127127
#define FILE_PATH_CORE_INFO_CACHE_REFRESH "core_info.refresh"
128128

129+
/* sizes of zip plus decompression space required rounded up to nearest 50MB */
130+
#define ASSETS_ZIP_PLUS_DECOMPRESSION_SIZE 209715200 /* 200MB */
131+
#define DATABASE_RDB_ZIP_PLUS_DECOMPRESSION_SIZE 262144000 /* 250MB */
132+
129133
#ifdef HAVE_LAKKA
130134
#ifdef HAVE_LAKKA_SERVER
131135
#define FILE_PATH_LAKKA_URL HAVE_LAKKA_SERVER

libretro-common/file/file_path_io.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@
3737

3838
#ifdef _WIN32
3939
#include <direct.h>
40+
#include <windows.h>
4041
#else
4142
#include <unistd.h> /* stat() is defined here */
4243
#endif
4344

45+
#if defined(__unix__) || defined(__APPLE__)
46+
#include <sys/statvfs.h>
47+
#endif
48+
4449
/* TODO/FIXME - globals */
4550
static retro_vfs_stat_t path_stat_cb = retro_vfs_stat_impl;
4651
static retro_vfs_mkdir_t path_mkdir_cb = retro_vfs_mkdir_impl;
@@ -78,6 +83,33 @@ bool path_is_directory(const char *path)
7883
return (path_stat_cb(path, NULL) & RETRO_VFS_STAT_IS_DIRECTORY) != 0;
7984
}
8085

86+
bool path_is_empty_directory(const char *dir)
87+
{
88+
struct retro_vfs_dir_handle *d;
89+
const char *name;
90+
91+
d = retro_vfs_opendir_impl(dir, false);
92+
if (!d)
93+
return false;
94+
95+
while (retro_vfs_readdir_impl(d))
96+
{
97+
name = retro_vfs_dirent_get_name_impl(d);
98+
99+
/* Skip . and .. */
100+
if (name &&
101+
strcmp(name, ".") != 0 &&
102+
strcmp(name, "..") != 0)
103+
{
104+
retro_vfs_closedir_impl(d);
105+
return false;
106+
}
107+
}
108+
109+
retro_vfs_closedir_impl(d);
110+
return true;
111+
}
112+
81113
bool path_is_character_special(const char *path)
82114
{
83115
return (path_stat_cb(path, NULL) & RETRO_VFS_STAT_IS_CHARACTER_SPECIAL) != 0;
@@ -146,3 +178,21 @@ bool path_mkdir(const char *dir)
146178
}
147179
return false;
148180
}
181+
182+
int64_t path_get_free_space(const char *path)
183+
{
184+
#if defined(_WIN32)
185+
ULARGE_INTEGER free_bytes_available;
186+
if (GetDiskFreeSpaceExA(path, &free_bytes_available, NULL, NULL))
187+
return (int64_t)free_bytes_available.QuadPart;
188+
return -1;
189+
#elif defined(__unix__) || defined(__APPLE__)
190+
struct statvfs fs;
191+
if (statvfs(path, &fs) == 0)
192+
return (int64_t)fs.f_bavail * (int64_t)fs.f_frsize;
193+
return -1;
194+
#else
195+
/* Unsupported platform */
196+
return -1;
197+
#endif
198+
}

libretro-common/include/file/file_path.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,10 @@ bool path_mkdir(const char *dir);
668668
*/
669669
bool path_is_directory(const char *path);
670670

671+
bool path_is_empty_directory(const char *dir);
672+
673+
int64_t path_get_free_space(const char *path);
674+
671675
/* Time format strings with AM-PM designation require special
672676
* handling due to platform dependence
673677
* @return Length of the string written to @s

menu/menu_driver.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "menu_driver.h"
5050
#include "menu_cbs.h"
5151
#include "../driver.h"
52+
#include "../file_path_special.h"
5253
#include "../list_special.h"
5354
#include "../intl/msg_hash_lbl_str.h"
5455
#include "../paths.h"
@@ -3629,7 +3630,7 @@ static void bundle_decompressed(retro_task_t *task,
36293630
command_event(CMD_EVENT_MENU_SAVE_CURRENT_CONFIG, NULL);
36303631
}
36313632

3632-
#if defined(HAVE_ONLINE_UPDATER) && defined(HAVE_NETWORKING) && defined(HAVE_COMPRESSION) && defined(HAVE_ZLIB)
3633+
#if defined(HAVE_ONLINE_UPDATER) && defined(HAVE_NETWORKING) && defined(HAVE_COMPRESSION) && defined(HAVE_ZLIB) && defined(HAVE_UPDATE_ASSETS_FIRST_RUN)
36333634
static void menu_download(enum msg_hash_enums enum_idx)
36343635
{
36353636
char s[PATH_MAX_LENGTH];
@@ -3747,25 +3748,36 @@ static bool rarch_menu_init(
37473748
configuration_set_int(settings,
37483749
settings->uints.bundle_assets_extract_last_version, 1);
37493750
}
3750-
#if defined(HAVE_ONLINE_UPDATER) && defined(HAVE_NETWORKING) && defined(HAVE_ZLIB)
3751+
#if defined(HAVE_ONLINE_UPDATER) && defined(HAVE_NETWORKING) && defined(HAVE_ZLIB) && defined(HAVE_UPDATE_ASSETS_FIRST_RUN)
37513752
else
37523753
{
3754+
#ifdef HAVE_CONFIGFILE
3755+
if (!menu_show_start_screen)
3756+
return true;
3757+
#endif
3758+
37533759
#ifdef HAVE_UPDATE_ASSETS
3754-
if (!path_is_directory(settings->paths.directory_assets))
3755-
menu_download(MENU_ENUM_LABEL_CB_UPDATE_ASSETS);
3760+
if (!path_is_directory(settings->paths.directory_assets) || path_is_empty_directory(settings->paths.directory_assets))
3761+
{
3762+
if (path_get_free_space(settings->paths.directory_assets) >= ASSETS_ZIP_PLUS_DECOMPRESSION_SIZE)
3763+
menu_download(MENU_ENUM_LABEL_CB_UPDATE_ASSETS);
3764+
}
37563765
#endif
3757-
if (!path_is_directory(settings->paths.directory_autoconfig))
3766+
if (!path_is_directory(settings->paths.directory_autoconfig) || path_is_empty_directory(settings->paths.directory_autoconfig))
37583767
menu_download(MENU_ENUM_LABEL_CB_UPDATE_AUTOCONFIG_PROFILES);
37593768
#ifdef HAVE_UPDATE_CORE_INFO
3760-
if (!path_is_directory(settings->paths.path_libretro_info))
3769+
if (!path_is_directory(settings->paths.path_libretro_info) || path_is_empty_directory(settings->paths.path_libretro_info))
37613770
menu_download(MENU_ENUM_LABEL_CB_UPDATE_CORE_INFO_FILES);
37623771
#endif
3763-
#ifdef HAVE_LIBRETRODB
3764-
if (!path_is_directory(settings->paths.path_content_database))
3765-
menu_download(MENU_ENUM_LABEL_CB_UPDATE_DATABASES);
3772+
#if defined(HAVE_LIBRETRODB)
3773+
if (!path_is_directory(settings->paths.path_content_database) || path_is_empty_directory(settings->paths.path_content_database))
3774+
{
3775+
if (path_get_free_space(settings->paths.path_content_database) >= DATABASE_RDB_ZIP_PLUS_DECOMPRESSION_SIZE)
3776+
menu_download(MENU_ENUM_LABEL_CB_UPDATE_DATABASES);
3777+
}
37663778
#endif
37673779
#if defined(RARCH_MOBILE) && defined(HAVE_OVERLAY)
3768-
if (!path_is_directory(settings->paths.directory_overlay))
3780+
if (!path_is_directory(settings->paths.directory_overlay) || path_is_empty_directory(settings->paths.directory_overlay))
37693781
menu_download(MENU_ENUM_LABEL_CB_UPDATE_OVERLAYS);
37703782
#endif
37713783
}

0 commit comments

Comments
 (0)