@@ -690,14 +690,8 @@ void InitializeSearchPaths()
690690 */
691691string ReadDataFile (const string& relpath)
692692{
693- FILE* fp = NULL ;
694- for (auto dir : g_searchPaths)
695- {
696- string path = dir + " /" + relpath;
697- fp = fopen (path.c_str (), " rb" );
698- if (fp)
699- break ;
700- }
693+ auto abspath = FindDataFile (relpath);
694+ FILE* fp = fopen (abspath.c_str (), " rb" );
701695
702696 if (!fp)
703697 {
@@ -731,14 +725,8 @@ vector<uint32_t> ReadDataFileUint32(const string& relpath)
731725{
732726 vector<uint32_t > buf;
733727
734- FILE* fp = NULL ;
735- for (auto dir : g_searchPaths)
736- {
737- string path = dir + " /" + relpath;
738- fp = fopen (path.c_str (), " rb" );
739- if (fp)
740- break ;
741- }
728+ auto abspath = FindDataFile (relpath);
729+ FILE* fp = fopen (abspath.c_str (), " rb" );
742730
743731 if (!fp)
744732 {
@@ -767,16 +755,18 @@ vector<uint32_t> ReadDataFileUint32(const string& relpath)
767755 */
768756string FindDataFile (const string& relpath)
769757{
758+ // Check relative path first
770759 FILE* fp = fopen (relpath.c_str (), " rb" );
771760 if (fp)
772761 {
773762 fclose (fp);
774763 return relpath;
775764 }
765+
776766 for (auto dir : g_searchPaths)
777767 {
778768 string path = dir + " /" + relpath;
779- FILE* fp = fopen (path.c_str (), " rb" );
769+ fp = fopen (path.c_str (), " rb" );
780770 if (fp)
781771 {
782772 fclose (fp);
0 commit comments