Skip to content

Commit 2b6594d

Browse files
committed
make assets update optional on first run and enable by default for webOS
1 parent b18fe5b commit 2b6594d

File tree

4 files changed

+86
-8
lines changed

4 files changed

+86
-8
lines changed

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
@@ -664,6 +664,10 @@ bool path_mkdir(const char *dir);
664664
*/
665665
bool path_is_directory(const char *path);
666666

667+
bool path_is_empty_directory(const char *dir);
668+
669+
int64_t path_get_free_space(const char *path);
670+
667671
/* Time format strings with AM-PM designation require special
668672
* handling due to platform dependence
669673
* @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"
@@ -3689,6 +3690,9 @@ static bool rarch_menu_init(
36893690
bool menu_show_start_screen = settings->bools.menu_show_start_screen;
36903691
bool config_save_on_exit = settings->bools.config_save_on_exit;
36913692
#endif
3693+
#ifdef HAVE_COMPRESSION
3694+
bool have_bundled_assets = false;
3695+
#endif
36923696

36933697
/* thumbnail initialization */
36943698
if (!(menu_st->thumbnail_path_data = gfx_thumbnail_path_init()))
@@ -3731,6 +3735,7 @@ static bool rarch_menu_init(
37313735
!= settings->uints.bundle_assets_extract_last_version)
37323736
)
37333737
{
3738+
have_bundled_assets = true;
37343739
p_dialog->current_type = MENU_DIALOG_HELP_EXTRACT;
37353740
task_push_decompress(
37363741
settings->paths.bundle_assets_src,
@@ -3750,22 +3755,37 @@ static bool rarch_menu_init(
37503755
#if defined(HAVE_ONLINE_UPDATER) && defined(HAVE_NETWORKING) && defined(HAVE_ZLIB)
37513756
else
37523757
{
3758+
#ifdef HAVE_CONFIGFILE
3759+
if (!menu_show_start_screen)
3760+
return true;
3761+
#endif
3762+
#ifdef HAVE_COMPRESSION
3763+
if (have_bundled_assets)
3764+
return true;
3765+
#endif
3766+
37533767
#ifdef HAVE_UPDATE_ASSETS
3754-
if (!path_is_directory(settings->paths.directory_assets))
3755-
menu_download(MENU_ENUM_LABEL_CB_UPDATE_ASSETS);
3768+
if (!path_is_directory(settings->paths.directory_assets) || path_is_empty_directory(settings->paths.directory_assets))
3769+
{
3770+
if (path_get_free_space(settings->paths.directory_assets) >= ASSETS_ZIP_PLUS_DECOMPRESSION_SIZE)
3771+
menu_download(MENU_ENUM_LABEL_CB_UPDATE_ASSETS);
3772+
}
37563773
#endif
3757-
if (!path_is_directory(settings->paths.directory_autoconfig))
3774+
if (!path_is_directory(settings->paths.directory_autoconfig) || path_is_empty_directory(settings->paths.directory_autoconfig))
37583775
menu_download(MENU_ENUM_LABEL_CB_UPDATE_AUTOCONFIG_PROFILES);
37593776
#ifdef HAVE_UPDATE_CORE_INFO
3760-
if (!path_is_directory(settings->paths.path_libretro_info))
3777+
if (!path_is_directory(settings->paths.path_libretro_info) || path_is_empty_directory(settings->paths.path_libretro_info))
37613778
menu_download(MENU_ENUM_LABEL_CB_UPDATE_CORE_INFO_FILES);
37623779
#endif
3763-
#ifdef HAVE_LIBRETRODB
3764-
if (!path_is_directory(settings->paths.path_content_database))
3765-
menu_download(MENU_ENUM_LABEL_CB_UPDATE_DATABASES);
3780+
#if defined(HAVE_LIBRETRODB)
3781+
if (!path_is_directory(settings->paths.path_content_database) || path_is_empty_directory(settings->paths.path_content_database))
3782+
{
3783+
if (path_get_free_space(settings->paths.path_content_database) >= DATABASE_RDB_ZIP_PLUS_DECOMPRESSION_SIZE)
3784+
menu_download(MENU_ENUM_LABEL_CB_UPDATE_DATABASES);
3785+
}
37663786
#endif
37673787
#if defined(RARCH_MOBILE) && defined(HAVE_OVERLAY)
3768-
if (!path_is_directory(settings->paths.directory_overlay))
3788+
if (!path_is_directory(settings->paths.directory_overlay) || path_is_empty_directory(settings->paths.directory_overlay))
37693789
menu_download(MENU_ENUM_LABEL_CB_UPDATE_OVERLAYS);
37703790
#endif
37713791
}

0 commit comments

Comments
 (0)