Skip to content

Commit 0db66ec

Browse files
committed
make assets update optional on first run and enable by default for webOS
1 parent a02188b commit 0db66ec

4 files changed

Lines changed: 86 additions & 8 deletions

File tree

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_stat32_cb = retro_vfs_stat_impl;
4651
static retro_vfs_stat_64_t path_stat64_cb = retro_vfs_stat_64_impl;
@@ -88,6 +93,33 @@ bool path_is_directory(const char *path)
8893
return (path_stat32_cb(path, NULL) & RETRO_VFS_STAT_IS_DIRECTORY) != 0;
8994
}
9095

96+
bool path_is_empty_directory(const char *dir)
97+
{
98+
struct retro_vfs_dir_handle *d;
99+
const char *name;
100+
101+
d = retro_vfs_opendir_impl(dir, false);
102+
if (!d)
103+
return false;
104+
105+
while (retro_vfs_readdir_impl(d))
106+
{
107+
name = retro_vfs_dirent_get_name_impl(d);
108+
109+
/* Skip . and .. */
110+
if (name &&
111+
strcmp(name, ".") != 0 &&
112+
strcmp(name, "..") != 0)
113+
{
114+
retro_vfs_closedir_impl(d);
115+
return false;
116+
}
117+
}
118+
119+
retro_vfs_closedir_impl(d);
120+
return true;
121+
}
122+
91123
bool path_is_character_special(const char *path)
92124
{
93125
if (path_stat64_cb)
@@ -166,3 +198,21 @@ bool path_mkdir(const char *dir)
166198
}
167199
return false;
168200
}
201+
202+
int64_t path_get_free_space(const char *path)
203+
{
204+
#if defined(_WIN32)
205+
ULARGE_INTEGER free_bytes_available;
206+
if (GetDiskFreeSpaceExA(path, &free_bytes_available, NULL, NULL))
207+
return (int64_t)free_bytes_available.QuadPart;
208+
return -1;
209+
#elif defined(__unix__) || defined(__APPLE__)
210+
struct statvfs fs;
211+
if (statvfs(path, &fs) == 0)
212+
return (int64_t)fs.f_bavail * (int64_t)fs.f_frsize;
213+
return -1;
214+
#else
215+
/* Unsupported platform */
216+
return -1;
217+
#endif
218+
}

libretro-common/include/file/file_path.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,10 @@ bool path_mkdir(const char *dir);
665665
*/
666666
bool path_is_directory(const char *path);
667667

668+
bool path_is_empty_directory(const char *dir);
669+
670+
int64_t path_get_free_space(const char *path);
671+
668672
/* Time format strings with AM-PM designation require special
669673
* handling due to platform dependence
670674
* @return Length of the string written to @s

menu/menu_driver.c

Lines changed: 28 additions & 8 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 "../msg_hash_lbl_str.h"
5455
#include "../paths.h"
@@ -3687,6 +3688,9 @@ static bool rarch_menu_init(
36873688
bool menu_show_start_screen = settings->bools.menu_show_start_screen;
36883689
bool config_save_on_exit = settings->bools.config_save_on_exit;
36893690
#endif
3691+
#ifdef HAVE_COMPRESSION
3692+
bool have_bundled_assets = false;
3693+
#endif
36903694

36913695
/* thumbnail initialization */
36923696
if (!(menu_st->thumbnail_path_data = gfx_thumbnail_path_init()))
@@ -3729,6 +3733,7 @@ static bool rarch_menu_init(
37293733
!= settings->uints.bundle_assets_extract_last_version)
37303734
)
37313735
{
3736+
have_bundled_assets = true;
37323737
p_dialog->current_type = MENU_DIALOG_HELP_EXTRACT;
37333738
task_push_decompress(
37343739
settings->paths.bundle_assets_src,
@@ -3748,22 +3753,37 @@ static bool rarch_menu_init(
37483753
#if defined(HAVE_ONLINE_UPDATER) && defined(HAVE_NETWORKING) && defined(HAVE_ZLIB)
37493754
else
37503755
{
3756+
#ifdef HAVE_CONFIGFILE
3757+
if (!menu_show_start_screen)
3758+
return true;
3759+
#endif
3760+
#ifdef HAVE_COMPRESSION
3761+
if (have_bundled_assets)
3762+
return true;
3763+
#endif
3764+
37513765
#ifdef HAVE_UPDATE_ASSETS
3752-
if (!path_is_directory(settings->paths.directory_assets))
3753-
menu_download(MENU_ENUM_LABEL_CB_UPDATE_ASSETS);
3766+
if (!path_is_directory(settings->paths.directory_assets) || path_is_empty_directory(settings->paths.directory_assets))
3767+
{
3768+
if (path_get_free_space(settings->paths.directory_assets) >= ASSETS_ZIP_PLUS_DECOMPRESSION_SIZE)
3769+
menu_download(MENU_ENUM_LABEL_CB_UPDATE_ASSETS);
3770+
}
37543771
#endif
3755-
if (!path_is_directory(settings->paths.directory_autoconfig))
3772+
if (!path_is_directory(settings->paths.directory_autoconfig) || path_is_empty_directory(settings->paths.directory_autoconfig))
37563773
menu_download(MENU_ENUM_LABEL_CB_UPDATE_AUTOCONFIG_PROFILES);
37573774
#ifdef HAVE_UPDATE_CORE_INFO
3758-
if (!path_is_directory(settings->paths.path_libretro_info))
3775+
if (!path_is_directory(settings->paths.path_libretro_info) || path_is_empty_directory(settings->paths.path_libretro_info))
37593776
menu_download(MENU_ENUM_LABEL_CB_UPDATE_CORE_INFO_FILES);
37603777
#endif
3761-
#ifdef HAVE_LIBRETRODB
3762-
if (!path_is_directory(settings->paths.path_content_database))
3763-
menu_download(MENU_ENUM_LABEL_CB_UPDATE_DATABASES);
3778+
#if defined(HAVE_LIBRETRODB)
3779+
if (!path_is_directory(settings->paths.path_content_database) || path_is_empty_directory(settings->paths.path_content_database))
3780+
{
3781+
if (path_get_free_space(settings->paths.path_content_database) >= DATABASE_RDB_ZIP_PLUS_DECOMPRESSION_SIZE)
3782+
menu_download(MENU_ENUM_LABEL_CB_UPDATE_DATABASES);
3783+
}
37643784
#endif
37653785
#if defined(RARCH_MOBILE) && defined(HAVE_OVERLAY)
3766-
if (!path_is_directory(settings->paths.directory_overlay))
3786+
if (!path_is_directory(settings->paths.directory_overlay) || path_is_empty_directory(settings->paths.directory_overlay))
37673787
menu_download(MENU_ENUM_LABEL_CB_UPDATE_OVERLAYS);
37683788
#endif
37693789
}

0 commit comments

Comments
 (0)