This commit is contained in:
Vadim Grigoruk 2018-08-03 15:20:32 +03:00
parent 5e90d56635
commit 69f8c30ef4
5 changed files with 45 additions and 21 deletions

View File

@ -1081,6 +1081,26 @@ static void onConsoleLoadCommandConfirmed(Console* console, const char* param)
commandDone(console); commandDone(console);
} }
static void load(Console* console, const char* path, const char* hash)
{
s32 size = 0;
const char* name = getCartName(path);
void* data = fsLoadFileByHash(console->fs, hash, &size);
if(data)
{
console->showGameMenu = true;
loadRom(console->tic, data, size, true);
onCartLoaded(console, name);
free(data);
}
commandDone(console);
}
typedef void(*ConfirmCallback)(Console* console, const char* param); typedef void(*ConfirmCallback)(Console* console, const char* param);
typedef struct typedef struct
@ -3117,7 +3137,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
{ {
.tic = tic, .tic = tic,
.config = config, .config = config,
.load = onConsoleLoadCommandConfirmed, .load = load,
#if defined(TIC80_PRO) #if defined(TIC80_PRO)
.loadProject = loadProject, .loadProject = loadProject,

View File

@ -103,7 +103,7 @@ struct Console
bool crtMonitor; bool crtMonitor;
}; };
void(*load)(Console*, const char* name); void(*load)(Console*, const char* path, const char* hash);
bool(*loadProject)(Console*, const char* name, const char* data, s32 size, tic_cartridge* dst); bool(*loadProject)(Console*, const char* name, const char* data, s32 size, tic_cartridge* dst);
void(*updateProject)(Console*); void(*updateProject)(Console*);
void(*error)(Console*, const char*); void(*error)(Console*, const char*);

View File

@ -899,6 +899,26 @@ static bool onLoadPublicCart(const char* name, const char* info, s32 id, void* d
return true; return true;
} }
void* fsLoadFileByHash(FileSystem* fs, const char* hash, s32* size)
{
char cachePath[FILENAME_MAX] = {0};
sprintf(cachePath, TIC_CACHE "%s.tic", hash);
{
void* data = fsLoadRootFile(fs, cachePath, size);
if(data) return data;
}
char path[FILENAME_MAX] = {0};
sprintf(path, "/cart/%s/cart.tic", hash);
void* data = getSystem()->getUrlRequest(path, size);
if(data)
fsSaveRootFile(fs, cachePath, data, *size, false);
return data;
}
void* fsLoadFile(FileSystem* fs, const char* name, s32* size) void* fsLoadFile(FileSystem* fs, const char* name, s32* size)
{ {
if(isPublic(fs)) if(isPublic(fs))
@ -912,24 +932,7 @@ void* fsLoadFile(FileSystem* fs, const char* name, s32* size)
fsEnumFiles(fs, onLoadPublicCart, &loadPublicCartData); fsEnumFiles(fs, onLoadPublicCart, &loadPublicCartData);
if(strlen(loadPublicCartData.hash)) if(strlen(loadPublicCartData.hash))
{ return fsLoadFileByHash(fs, loadPublicCartData.hash, size);
char cachePath[FILENAME_MAX] = {0};
sprintf(cachePath, TIC_CACHE "%s.tic", loadPublicCartData.hash);
{
void* data = fsLoadRootFile(fs, cachePath, size);
if(data) return data;
}
char path[FILENAME_MAX] = {0};
sprintf(path, "/cart/%s/cart.tic", loadPublicCartData.hash);
void* data = getSystem()->getUrlRequest(path, size);
if(data)
fsSaveRootFile(fs, cachePath, data, *size, false);
return data;
}
} }
else else
{ {

View File

@ -57,6 +57,7 @@ bool fsDeleteDir(FileSystem* fs, const char* name);
bool fsSaveFile(FileSystem* fs, const char* name, const void* data, size_t size, bool overwrite); bool fsSaveFile(FileSystem* fs, const char* name, const void* data, size_t size, bool overwrite);
bool fsSaveRootFile(FileSystem* fs, const char* name, const void* data, size_t size, bool overwrite); bool fsSaveRootFile(FileSystem* fs, const char* name, const void* data, size_t size, bool overwrite);
void* fsLoadFile(FileSystem* fs, const char* name, s32* size); void* fsLoadFile(FileSystem* fs, const char* name, s32* size);
void* fsLoadFileByHash(FileSystem* fs, const char* hash, s32* size);
void* fsLoadRootFile(FileSystem* fs, const char* name, s32* size); void* fsLoadRootFile(FileSystem* fs, const char* name, s32* size);
void fsMakeDir(FileSystem* fs, const char* name); void fsMakeDir(FileSystem* fs, const char* name);
bool fsExistsFile(FileSystem* fs, const char* name); bool fsExistsFile(FileSystem* fs, const char* name);

View File

@ -670,7 +670,7 @@ static void onPlayCart(Surf* surf)
} }
} }
else else
surf->console->load(surf->console, item->name); surf->console->load(surf->console, item->name, item->hash);
runGameFromSurf(); runGameFromSurf();
} }