From 7b571de39552dc71df66fe0b35636145ec87123d Mon Sep 17 00:00:00 2001
From: Benau <Benau@users.noreply.github.com>
Date: Fri, 25 Aug 2017 16:39:34 +0800
Subject: [PATCH] Fix the wrong "misuse"

Now you can play hot.ogg
---
 src/graphics/material.cpp |  8 ++++----
 src/io/file_manager.cpp   | 34 ++++++++++++++++++++++++++--------
 src/io/file_manager.hpp   |  2 ++
 3 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/src/graphics/material.cpp b/src/graphics/material.cpp
index 57878c9bc..21776ff7d 100644
--- a/src/graphics/material.cpp
+++ b/src/graphics/material.cpp
@@ -618,10 +618,10 @@ void Material::initCustomSFX(const XMLNode *sfx)
     {
 
         // The directory for the track was added to the model search path
-        // so just misuse the getModelFile function
-        const std::string full_path = file_manager->getAsset(FileManager::MODEL,
-                                                             filename);
-        SFXBuffer* buffer = SFXManager::get()->loadSingleSfx(sfx, full_path);
+        // so just misuse the searchModel function
+        std::string path = file_manager->searchModel(filename);
+        path = StringUtils::getPath(path);
+        SFXBuffer* buffer = SFXManager::get()->loadSingleSfx(sfx, path);
 
         if (buffer != NULL)
         {
diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp
index 8e29049cc..8aea5e793 100644
--- a/src/io/file_manager.cpp
+++ b/src/io/file_manager.cpp
@@ -601,14 +601,14 @@ bool FileManager::findFile(std::string& full_path,
     return false;
 }   // findFile
 
-    //-----------------------------------------------------------------------------
-    /** Tries to find the specified file in any of the given search paths.
-    *  \param full_path On return contains the full path of the file, or
-    *         "" if the file is not found.
-    *  \param file_name The name of the file to look for.
-    *  \param search_path The list of paths to search for the file.
-    *  \return True if the file is found, false otherwise.
-    */
+//-----------------------------------------------------------------------------
+/** Tries to find the specified file in any of the given search paths.
+*  \param full_path On return contains the full path of the file, or
+*         "" if the file is not found.
+*  \param file_name The name of the file to look for.
+*  \param search_path The list of paths to search for the file.
+*  \return True if the file is found, false otherwise.
+*/
 bool FileManager::findFile(std::string& full_path,
     const std::string& file_name,
     const std::vector<TextureSearchPath>& search_path) const
@@ -1231,6 +1231,24 @@ std::string FileManager::searchMusic(const std::string& file_name) const
     return path;
 }   // searchMusic
 
+//-----------------------------------------------------------------------------
+/** Returns the full path of a model file by searching all model search paths.
+ *  It throws an exception if the file is not found.
+ *  \param file_name File name to search for.
+ */
+std::string FileManager::searchModel(const std::string& file_name) const
+{
+    std::string path;
+    bool success = findFile(path, file_name, m_model_search_path);
+    if (!success)
+    {
+        throw std::runtime_error(
+            "[FileManager::searchModel] Cannot find model file '"
+            +file_name+"'.");
+    }
+    return path;
+}   // searchModel
+
 //-----------------------------------------------------------------------------
 /** Returns true if the given name is a directory.
  *  \param path File name to test.
diff --git a/src/io/file_manager.hpp b/src/io/file_manager.hpp
index 26e56f165..6c766e3de 100644
--- a/src/io/file_manager.hpp
+++ b/src/io/file_manager.hpp
@@ -162,6 +162,8 @@ public:
     }
     // ------------------------------------------------------------------------
     std::string searchMusic(const std::string& file_name) const;
+    // ------------------------------------------------------------------------
+    std::string searchModel(const std::string& file_name) const;
     std::string searchTexture(const std::string& fname) const;
     std::string getUserConfigFile(const std::string& fname) const;
     bool        fileExists(const std::string& path) const;