apple: speed up cloud sync
This commit is contained in:
parent
f30947840e
commit
d5ea842403
|
@ -232,7 +232,9 @@ ACHIEVEMENTS
|
|||
/*============================================================
|
||||
MD5
|
||||
============================================================ */
|
||||
#ifndef __APPLE__
|
||||
#include "../libretro-common/utils/md5.c"
|
||||
#endif
|
||||
|
||||
/*============================================================
|
||||
CHEATS
|
||||
|
|
|
@ -35,6 +35,10 @@
|
|||
|
||||
#include <retro_common_api.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#endif
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
|
@ -51,6 +55,13 @@ int sha1_calculate(const char *path, char *result);
|
|||
|
||||
uint32_t djb2_calculate(const char *str);
|
||||
|
||||
#ifdef __APPLE__
|
||||
typedef CC_MD5_CTX MD5_CTX;
|
||||
#define MD5_Init CC_MD5_Init
|
||||
#define MD5_Update CC_MD5_Update
|
||||
#define MD5_Final CC_MD5_Final
|
||||
#else
|
||||
|
||||
/* Any 32-bit or wider unsigned integer data type will do */
|
||||
typedef unsigned int MD5_u32plus;
|
||||
|
||||
|
@ -90,6 +101,8 @@ void MD5_Init(MD5_CTX *ctx);
|
|||
void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
|
||||
void MD5_Final(unsigned char *result, MD5_CTX *ctx);
|
||||
|
||||
#endif
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
|
@ -225,6 +225,8 @@ int64_t retro_vfs_file_seek_internal(
|
|||
libretro_vfs_implementation_file *stream,
|
||||
int64_t offset, int whence)
|
||||
{
|
||||
int64_t val;
|
||||
|
||||
if (!stream)
|
||||
return -1;
|
||||
|
||||
|
@ -280,10 +282,10 @@ int64_t retro_vfs_file_seek_internal(
|
|||
}
|
||||
#endif
|
||||
|
||||
if (lseek(stream->fd, (off_t)offset, whence) < 0)
|
||||
if ((val = lseek(stream->fd, (off_t)offset, whence)) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -637,6 +639,8 @@ int64_t retro_vfs_file_truncate_impl(libretro_vfs_implementation_file *stream, i
|
|||
|
||||
int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream)
|
||||
{
|
||||
int64_t val;
|
||||
|
||||
if (!stream)
|
||||
return -1;
|
||||
|
||||
|
@ -662,10 +666,10 @@ int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream)
|
|||
RETRO_VFS_FILE_ACCESS_HINT_FREQUENT_ACCESS)
|
||||
return stream->mappos;
|
||||
#endif
|
||||
if (lseek(stream->fd, 0, SEEK_CUR) < 0)
|
||||
if ((val = lseek(stream->fd, 0, SEEK_CUR)) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
return val;
|
||||
}
|
||||
|
||||
int64_t retro_vfs_file_seek_impl(libretro_vfs_implementation_file *stream,
|
||||
|
|
|
@ -491,19 +491,22 @@ static char *task_cloud_sync_md5_rfile(RFILE *file)
|
|||
char *hash = malloc(33);
|
||||
unsigned char buf[4096];
|
||||
unsigned char digest[16];
|
||||
libretro_vfs_implementation_file *hfile = filestream_get_vfs_handle(file);
|
||||
|
||||
if (!hash)
|
||||
return NULL;
|
||||
|
||||
MD5_Init(&md5);
|
||||
|
||||
do
|
||||
{
|
||||
rv = (int)filestream_read(file, buf, sizeof(buf));
|
||||
if (rv > 0)
|
||||
MD5_Update(&md5, buf, rv);
|
||||
} while (rv > 0);
|
||||
|
||||
if (hfile && hfile->mapped)
|
||||
MD5_Update(&md5, hfile->mapped, hfile->size);
|
||||
else
|
||||
do
|
||||
{
|
||||
rv = (int)filestream_read(file, buf, sizeof(buf));
|
||||
if (rv > 0)
|
||||
MD5_Update(&md5, buf, rv);
|
||||
} while (rv > 0);
|
||||
MD5_Final(digest, &md5);
|
||||
|
||||
snprintf(hash, 33, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||
|
@ -748,7 +751,7 @@ static void task_cloud_sync_upload_current_file(task_cloud_sync_state_t *sync_st
|
|||
}
|
||||
|
||||
file = filestream_open(filename,
|
||||
RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
||||
RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_FREQUENT_ACCESS);
|
||||
if (!file)
|
||||
return;
|
||||
|
||||
|
@ -803,7 +806,7 @@ static void task_cloud_sync_check_server_current(task_cloud_sync_state_t *sync_s
|
|||
}
|
||||
|
||||
file = filestream_open(filename,
|
||||
RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
||||
RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_FREQUENT_ACCESS);
|
||||
if (!file)
|
||||
return;
|
||||
|
||||
|
|
Loading…
Reference in New Issue