#582: fixed
This commit is contained in:
		@@ -1081,6 +1081,26 @@ static void onConsoleLoadCommandConfirmed(Console* console, const char* param)
 | 
			
		||||
	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 struct
 | 
			
		||||
@@ -3117,7 +3137,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
 | 
			
		||||
	{
 | 
			
		||||
		.tic = tic,
 | 
			
		||||
		.config = config,
 | 
			
		||||
		.load = onConsoleLoadCommandConfirmed,
 | 
			
		||||
		.load = load,
 | 
			
		||||
 | 
			
		||||
#if defined(TIC80_PRO)
 | 
			
		||||
		.loadProject = loadProject,
 | 
			
		||||
 
 | 
			
		||||
@@ -103,7 +103,7 @@ struct Console
 | 
			
		||||
		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);
 | 
			
		||||
	void(*updateProject)(Console*);
 | 
			
		||||
	void(*error)(Console*, const char*);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										39
									
								
								src/fs.c
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								src/fs.c
									
									
									
									
									
								
							@@ -899,6 +899,26 @@ static bool onLoadPublicCart(const char* name, const char* info, s32 id, void* d
 | 
			
		||||
	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)
 | 
			
		||||
{
 | 
			
		||||
	if(isPublic(fs))
 | 
			
		||||
@@ -912,24 +932,7 @@ void* fsLoadFile(FileSystem* fs, const char* name, s32* size)
 | 
			
		||||
		fsEnumFiles(fs, onLoadPublicCart, &loadPublicCartData);
 | 
			
		||||
 | 
			
		||||
		if(strlen(loadPublicCartData.hash))
 | 
			
		||||
		{
 | 
			
		||||
			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;
 | 
			
		||||
		}
 | 
			
		||||
			return fsLoadFileByHash(fs, loadPublicCartData.hash, size);
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								src/fs.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								src/fs.h
									
									
									
									
									
								
							@@ -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 fsSaveRootFile(FileSystem* fs, const char* name, const void* data, size_t size, bool overwrite);
 | 
			
		||||
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 fsMakeDir(FileSystem* fs, const char* name);
 | 
			
		||||
bool fsExistsFile(FileSystem* fs, const char* name);
 | 
			
		||||
 
 | 
			
		||||
@@ -670,7 +670,7 @@ static void onPlayCart(Surf* surf)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
		surf->console->load(surf->console, item->name);
 | 
			
		||||
		surf->console->load(surf->console, item->name, item->hash);
 | 
			
		||||
 | 
			
		||||
	runGameFromSurf();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user