From 6c472660a16620713f12d457ec602740d5469c9b Mon Sep 17 00:00:00 2001 From: Deve Date: Fri, 3 Mar 2017 21:57:55 +0100 Subject: [PATCH] Some additional checks for android assets manager. If data was already extracted somewhere, then use this directory as preferred path. This is to avoid a situation that we have data extracted in two different places after STK upgrade. --- src/io/assets_android.cpp | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/io/assets_android.cpp b/src/io/assets_android.cpp index 726c9d73d..f8de5c8a0 100644 --- a/src/io/assets_android.cpp +++ b/src/io/assets_android.cpp @@ -75,25 +75,55 @@ void AssetsAndroid::init() paths.push_back("/storage/sdcard1/"); paths.push_back("/data/data/org.supertuxkart.stk/files/"); - // Check if STK data is available somewhere + // Check if STK data for current version is available somewhere for (std::string path : paths) { Log::info("AssetsAndroid", "Check data files in: %s", path.c_str()); if (m_file_manager->fileExists(path + "/stk/data/" + version)) { - Log::info("AssetsAndroid", "Data files found in: %s", path.c_str()); m_stk_dir = path + "/stk"; break; } if (m_file_manager->fileExists(path + "/supertuxkart/data/" + version)) { - Log::info("AssetsAndroid", "Data files found in: %s", path.c_str()); m_stk_dir = path + "/supertuxkart"; break; } } + + // If data for current version is not available, then try to find any other + // version, so that we won't accidentaly create second STK directory in + // different place + if (m_stk_dir.size() == 0) + { + for (std::string path : paths) + { + Log::info("AssetsAndroid", "Check data files for different STK " + "version in: %s", path.c_str()); + + if (m_file_manager->fileExists(path + "/stk/.extracted")) + { + m_stk_dir = path + "/stk"; + needs_extract_data = true; + break; + } + + if (m_file_manager->fileExists(path + "/supertuxkart/.extracted")) + { + m_stk_dir = path + "/supertuxkart"; + needs_extract_data = true; + break; + } + } + } + + if (m_stk_dir.size() > 0) + { + Log::info("AssetsAndroid", "Data files found in: %s", + m_stk_dir.c_str()); + } // Create data dir if it's not available anywhere if (m_stk_dir.size() == 0)