Skip to content

Commit 711a186

Browse files
committed
make assets update optional on first run and enable by default for webOS
1 parent b0cd192 commit 711a186

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
@@ -38,10 +38,15 @@
3838

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

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

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

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 "../paths.h"
5455
#include "../tasks/task_content.h"
@@ -3637,7 +3638,7 @@ static void bundle_decompressed(retro_task_t *task,
36373638
command_event(CMD_EVENT_MENU_SAVE_CURRENT_CONFIG, NULL);
36383639
}
36393640

3640-
#if defined(HAVE_ONLINE_UPDATER) && defined(HAVE_NETWORKING) && defined(HAVE_COMPRESSION) && defined(HAVE_ZLIB)
3641+
#if defined(HAVE_ONLINE_UPDATER) && defined(HAVE_NETWORKING) && defined(HAVE_COMPRESSION) && defined(HAVE_ZLIB) && defined(HAVE_UPDATE_ASSETS_FIRST_RUN)
36413642
static void menu_download(enum msg_hash_enums enum_idx)
36423643
{
36433644
char s[PATH_MAX_LENGTH];
@@ -3755,25 +3756,36 @@ static bool rarch_menu_init(
37553756
configuration_set_int(settings,
37563757
settings->uints.bundle_assets_extract_last_version, 1);
37573758
}
3758-
#if defined(HAVE_ONLINE_UPDATER) && defined(HAVE_NETWORKING) && defined(HAVE_ZLIB)
3759+
#if defined(HAVE_ONLINE_UPDATER) && defined(HAVE_NETWORKING) && defined(HAVE_ZLIB) && defined(HAVE_UPDATE_ASSETS_FIRST_RUN)
37593760
else
37603761
{
3762+
#ifdef HAVE_CONFIGFILE
3763+
if (!menu_show_start_screen)
3764+
return true;
3765+
#endif
3766+
37613767
#ifdef HAVE_UPDATE_ASSETS
3762-
if (!path_is_directory(settings->paths.directory_assets))
3763-
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+
}
37643773
#endif
3765-
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))
37663775
menu_download(MENU_ENUM_LABEL_CB_UPDATE_AUTOCONFIG_PROFILES);
37673776
#ifdef HAVE_UPDATE_CORE_INFO
3768-
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))
37693778
menu_download(MENU_ENUM_LABEL_CB_UPDATE_CORE_INFO_FILES);
37703779
#endif
3771-
#ifdef HAVE_LIBRETRODB
3772-
if (!path_is_directory(settings->paths.path_content_database))
3773-
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+
}
37743786
#endif
37753787
#if defined(RARCH_MOBILE) && defined(HAVE_OVERLAY)
3776-
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))
37773789
menu_download(MENU_ENUM_LABEL_CB_UPDATE_OVERLAYS);
37783790
#endif
37793791
}

0 commit comments

Comments
 (0)