6464
6565static const char * PublicDir = TIC_HOST ;
6666
67+ typedef char string [TICNAME_MAX ];
68+
6769struct tic_fs
6870{
69- char dir [ TICNAME_MAX ] ;
70- char work [ TICNAME_MAX ] ;
71+ string dir ;
72+ string work ;
7173 tic_net * net ;
7274};
7375
@@ -85,7 +87,7 @@ void syncfs()
8587
8688const char * tic_fs_pathroot (tic_fs * fs , const char * name )
8789{
88- static char path [ TICNAME_MAX ] ;
90+ static string path ;
8991
9092 snprintf (path , sizeof path , "%s%s" , fs -> dir , name );
9193
@@ -103,14 +105,14 @@ const char* tic_fs_pathroot(tic_fs* fs, const char* name)
103105
104106const char * tic_fs_path (tic_fs * fs , const char * name )
105107{
106- static char path [ TICNAME_MAX + 1 ] ;
108+ static string path ;
107109
108110 if (* name == '/' )
109- strncpy (path , name + 1 , sizeof path );
111+ snprintf (path , sizeof path , "%s" , name + 1 );
110112 else if (strlen (fs -> work ))
111113 snprintf (path , sizeof path , "%s/%s" , fs -> work , name );
112114 else
113- strncpy (path , name , sizeof path );
115+ snprintf (path , sizeof path , "%s" , name );
114116
115117 return tic_fs_pathroot (fs , path );
116118}
@@ -283,8 +285,6 @@ static void onDirResponse(const net_get_data* netData)
283285 {
284286 if (json_parse ((char * )netData -> done .data , netData -> done .size ))
285287 {
286- typedef char string [TICNAME_MAX ];
287-
288288 s32 folders = json_array ("folders" , 0 );
289289 for (s32 i = 0 , size = json_array_size (folders ); i < size ; i ++ )
290290 {
@@ -340,7 +340,7 @@ void fs_enum(const char* path, fs_list_callback callback, void* data)
340340 return ;
341341 }
342342
343- static char path2 [ TICNAME_MAX ] ;
343+ static string path2 ;
344344 strncpy (path2 , path , sizeof path2 );
345345
346346 if (path2 [strlen (path2 ) - 1 ] == '/' ) // one character
@@ -422,7 +422,7 @@ void tic_fs_enum(tic_fs* fs, fs_list_callback onItem, fs_done_callback onDone, v
422422#if defined(BUILD_EDITORS )
423423 if (isPublic (fs ))
424424 {
425- char request [ TICNAME_MAX ] ;
425+ string request ;
426426 snprintf (request , sizeof request , "%s/index.json" , fs -> work + STRLEN (TIC_HOST ));
427427
428428 NetDirData netDirData = { onItem , onDone , data };
@@ -512,15 +512,18 @@ void tic_fs_dir(tic_fs* fs, char* dir)
512512
513513void tic_fs_changedir (tic_fs * fs , const char * dir )
514514{
515- char temp [ TICNAME_MAX + 1 ] ;
515+ string temp ;
516516
517- if (strlen (fs -> work ) > 0 ) {
518- snprintf (temp , TICNAME_MAX + 1 , "%s/%s" , fs -> work , dir );
519- } else {
520- snprintf (temp , TICNAME_MAX , "%s" , dir );
517+ if (strlen (fs -> work ) > 0 )
518+ {
519+ snprintf (temp , sizeof temp , "%s/%s" , fs -> work , dir );
520+ }
521+ else
522+ {
523+ snprintf (temp , sizeof temp , "%s" , dir );
521524 }
522525
523- strncpy (fs -> work , temp , TICNAME_MAX - 1 );
526+ snprintf (fs -> work , sizeof fs -> work , "%s" , temp );
524527
525528#if defined(__TIC_WINDOWS__ )
526529 for (char * ptr = fs -> work , * end = ptr + strlen (ptr ); ptr < end ; ptr ++ )
@@ -769,7 +772,7 @@ typedef struct
769772 tic_fs * fs ;
770773 fs_load_callback done ;
771774 void * data ;
772- char cachePath [ TICNAME_MAX ] ;
775+ string cachePath ;
773776} LoadFileByHashData ;
774777
775778static void fileByHashLoaded (const net_get_data * netData )
@@ -803,27 +806,22 @@ void tic_fs_hashload(tic_fs* fs, const char* name, const char* url, fs_load_call
803806#if defined(BUILD_EDITORS )
804807 LoadFileByHashData loadFileByHashData = { fs , callback , data };
805808
806- const char * hash = strrchr (url , '?' );
809+ const char * hash = md5str (url , strlen (url ));
810+ snprintf (loadFileByHashData .cachePath , sizeof loadFileByHashData .cachePath , TIC_CACHE "%s.tic" , hash );
807811
808- if (hash )
809812 {
810- snprintf (loadFileByHashData .cachePath , sizeof loadFileByHashData .cachePath , TIC_CACHE "%s.tic" , hash + 1 );
811-
813+ s32 size = 0 ;
814+ void * buffer = tic_fs_loadroot (fs , loadFileByHashData .cachePath , & size );
815+ if (buffer )
812816 {
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- }
817+ callback (buffer , size , data );
818+ free (buffer );
819+ return ;
821820 }
822-
823-
824- tic_net_get (fs -> net , url , fileByHashLoaded , MOVE (loadFileByHashData ));
825821 }
826822
823+ tic_net_get (fs -> net , url , fileByHashLoaded , MOVE (loadFileByHashData ));
824+
827825#endif
828826
829827#endif
@@ -967,7 +965,7 @@ tic_fs* tic_fs_create(const char* path, tic_net* net)
967965{
968966 tic_fs * fs = (tic_fs * )calloc (1 , sizeof (tic_fs ));
969967
970- strncpy (fs -> dir , path , TICNAME_MAX );
968+ snprintf (fs -> dir , sizeof fs -> dir , "%s" , path );
971969
972970 if (path [strlen (path ) - 1 ] != SEP [0 ])
973971 strcat (fs -> dir , SEP );
@@ -979,11 +977,11 @@ tic_fs* tic_fs_create(const char* path, tic_net* net)
979977
980978const char * fs_apppath ()
981979{
982- static char apppath [ TICNAME_MAX ] ;
980+ static string apppath ;
983981
984982#if defined(__TIC_WINDOWS__ )
985983 {
986- wchar_t wideAppPath [TICNAME_MAX ];
984+ wchar_t wideAppPath [sizeof apppath ];
987985 GetModuleFileNameW (NULL , wideAppPath , sizeof wideAppPath );
988986 WideCharToMultiByte (CP_UTF8 , 0 , wideAppPath , COUNT_OF (wideAppPath ), apppath , COUNT_OF (apppath ), 0 , 0 );
989987 }
@@ -1000,7 +998,7 @@ const char* fs_apppath()
1000998
1001999const char * fs_appfolder ()
10021000{
1003- static char appfolder [ TICNAME_MAX ] ;
1001+ static string appfolder ;
10041002 strcpy (appfolder , fs_apppath ());
10051003
10061004 char * pos = strrchr (appfolder , SLASH_SYMBOL );
0 commit comments