Skip to content

Commit 6cf0854

Browse files
committed
use hash from url
1 parent 2b43e77 commit 6cf0854

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

src/studio/fs.c

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,17 @@ static void onDirResponse(const net_get_data* netData)
299299
string url;
300300
if(json_tostring(json_array_item(files, i), url, sizeof url))
301301
{
302-
char *base = strrchr(url, '/');
302+
const char *base = strrchr(url, '/');
303303
if(base)
304304
{
305-
netDirData->item(base + 1, base + 1, url, 0, netDirData->data, false);
305+
string name;
306+
const char *hash = strrchr(url, '?');
307+
308+
if(hash)
309+
{
310+
snprintf(name, hash - base, "%s", base + 1);
311+
netDirData->item(name, NULL, url, 0, netDirData->data, false);
312+
}
306313
}
307314
}
308315
}
@@ -762,7 +769,7 @@ typedef struct
762769
tic_fs* fs;
763770
fs_load_callback done;
764771
void* data;
765-
char* cachePath;
772+
char cachePath[TICNAME_MAX];
766773
} LoadFileByHashData;
767774

768775
static void fileByHashLoaded(const net_get_data* netData)
@@ -780,7 +787,6 @@ static void fileByHashLoaded(const net_get_data* netData)
780787
case net_get_done:
781788
case net_get_error:
782789

783-
free(loadFileByHashData->cachePath);
784790
free(loadFileByHashData);
785791
break;
786792
default: break;
@@ -794,25 +800,30 @@ void tic_fs_hashload(tic_fs* fs, const char* name, const char* url, fs_load_call
794800
return;
795801
#else
796802

797-
char cachePath[TICNAME_MAX];
798-
const char *hash = md5str(url, strlen(url));
799-
snprintf(cachePath, sizeof cachePath, TIC_CACHE "%s.tic", hash);
803+
#if defined(BUILD_EDITORS)
804+
LoadFileByHashData loadFileByHashData = { fs, callback, data };
800805

806+
const char *hash = strrchr(url, '?');
807+
808+
if(hash)
801809
{
802-
s32 size = 0;
803-
void* buffer = tic_fs_loadroot(fs, cachePath, &size);
804-
if (buffer)
810+
snprintf(loadFileByHashData.cachePath, sizeof loadFileByHashData.cachePath, TIC_CACHE "%s.tic", hash + 1);
811+
805812
{
806-
callback(buffer, size, data);
807-
free(buffer);
808-
return;
813+
s32 size = 0;
814+
void* buffer = tic_fs_loadroot(fs, loadFileByHashData.cachePath, &size);
815+
if (buffer)
816+
{
817+
callback(buffer, size, data);
818+
free(buffer);
819+
return;
820+
}
809821
}
810-
}
811822

812-
#if defined(BUILD_EDITORS)
813823

814-
LoadFileByHashData loadFileByHashData = { fs, callback, data, strdup(cachePath) };
815-
tic_net_get(fs->net, url, fileByHashLoaded, MOVE(loadFileByHashData));
824+
tic_net_get(fs->net, url, fileByHashLoaded, MOVE(loadFileByHashData));
825+
}
826+
816827
#endif
817828

818829
#endif

src/studio/screens/surf.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,19 +378,22 @@ static void requestCover(Surf* surf, SurfItem* item)
378378
tic_fs_dir(surf->fs, coverLoadingData.dir);
379379

380380
const char *url = item->url;
381-
const char *hash = md5str(item->url, strlen(item->url));
382-
383-
sprintf(coverLoadingData.cachePath, TIC_CACHE "%s.png", hash);
381+
const char *hash = strrchr(url, '?');
384382

383+
if(hash)
385384
{
386-
s32 size = 0;
387-
void* data = tic_fs_loadroot(surf->fs, coverLoadingData.cachePath, &size);
385+
sprintf(coverLoadingData.cachePath, TIC_CACHE "%s.png", hash + 1);
388386

389-
if (data)
390387
{
391-
updateMenuItemCover(surf, surf->menu.pos, data, size);
392-
free(data);
393-
return;
388+
s32 size = 0;
389+
void* data = tic_fs_loadroot(surf->fs, coverLoadingData.cachePath, &size);
390+
391+
if (data)
392+
{
393+
updateMenuItemCover(surf, surf->menu.pos, data, size);
394+
free(data);
395+
return;
396+
}
394397
}
395398
}
396399

0 commit comments

Comments
 (0)