diff --git a/src/guiengine/event_handler.cpp b/src/guiengine/event_handler.cpp index 1aadc8cb5..fca73f350 100644 --- a/src/guiengine/event_handler.cpp +++ b/src/guiengine/event_handler.cpp @@ -19,7 +19,6 @@ #ifdef ANDROID #include "addons/addons_manager.hpp" -#include "io/file_manager.hpp" #endif #include "audio/music_manager.hpp" #include "audio/sfx_manager.hpp" @@ -191,10 +190,6 @@ bool EventHandler::OnEvent (const SEvent &event) PlayerManager::get()->save(); if (addons_manager->hasDownloadedIcons()) addons_manager->saveInstalled(); - // Clean temp files manually as destructor of file manager - // won't be called at all in mobile if user just press home - // button - file_manager->cleanTempFiles(); } } else if (cmd == APP_CMD_RESUME || cmd == APP_CMD_GAINED_FOCUS) diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index a1623ae5a..874095566 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -408,6 +408,53 @@ void FileManager::init() addAssetsSearchPath(); m_cert_bundle_location = m_file_system->getAbsolutePath( getAsset("cacert.pem").c_str()).c_str(); + + // Clean up left-over files in addons/tmp that are older than 24h + // ============================================================== + // (The 24h delay is useful when debugging a problem with a zip file) + // We do when starting STK because for mobile STK destructor of file + // manager may never be called if only home button is pressed + std::set allfiles; + std::string tmp=getAddonsFile("tmp"); + listFiles(allfiles, tmp); + for(std::set::iterator i=allfiles.begin(); + i!=allfiles.end(); i++) + { + if((*i)=="." || (*i)=="..") continue; + // For now there should be only zip files or .part files + // (not fully downloaded files) in tmp. Warn about any + // other files. + std::string full_path=tmp+"/"+*i; + if(StringUtils::getExtension(*i)!="zip" && + StringUtils::getExtension(*i)!="part" ) + { + Log::warn("[FileManager]", "Unexpected tmp file '%s' found.", + full_path.c_str()); + continue; + } + if(isDirectory(full_path)) + { + // Gee, a .zip file which is a directory - stay away from it + Log::warn("[FileManager]", "'%s' is a directory and will not be deleted.", + full_path.c_str()); + continue; + } + struct stat mystat; + FileUtils::statU8Path(full_path, &mystat); + StkTime::TimeType current = StkTime::getTimeSinceEpoch(); + if(current - mystat.st_ctime <24*3600) + { + if(UserConfigParams::logAddons()) + Log::verbose("[FileManager]", "'%s' is less than 24h old " + "and will not be deleted.", + full_path.c_str()); + continue; + } + if(UserConfigParams::logAddons()) + Log::verbose("[FileManager]", "Deleting tmp file'%s'.",full_path.c_str()); + removeFile(full_path); + + } // for i in all files in tmp } // init //----------------------------------------------------------------------------- @@ -454,7 +501,6 @@ void FileManager::reinitAfterDownloadAssets() //----------------------------------------------------------------------------- FileManager::~FileManager() { - cleanTempFiles(); // Clean up rest of file manager // ============================= popMusicSearchPath(); @@ -465,55 +511,6 @@ FileManager::~FileManager() m_file_system = NULL; } // ~FileManager -// ---------------------------------------------------------------------------- -void FileManager::cleanTempFiles() -{ - // Clean up left-over files in addons/tmp that are older than 24h - // ============================================================== - // (The 24h delay is useful when debugging a problem with a zip file) - std::set allfiles; - std::string tmp=getAddonsFile("tmp"); - listFiles(allfiles, tmp); - for(std::set::iterator i=allfiles.begin(); - i!=allfiles.end(); i++) - { - if((*i)=="." || (*i)=="..") continue; - // For now there should be only zip files or .part files - // (not fully downloaded files) in tmp. Warn about any - // other files. - std::string full_path=tmp+"/"+*i; - if(StringUtils::getExtension(*i)!="zip" && - StringUtils::getExtension(*i)!="part" ) - { - Log::warn("[FileManager]", "Unexpected tmp file '%s' found.", - full_path.c_str()); - continue; - } - if(isDirectory(full_path)) - { - // Gee, a .zip file which is a directory - stay away from it - Log::warn("[FileManager]", "'%s' is a directory and will not be deleted.", - full_path.c_str()); - continue; - } - struct stat mystat; - FileUtils::statU8Path(full_path, &mystat); - StkTime::TimeType current = StkTime::getTimeSinceEpoch(); - if(current - mystat.st_ctime <24*3600) - { - if(UserConfigParams::logAddons()) - Log::verbose("[FileManager]", "'%s' is less than 24h old " - "and will not be deleted.", - full_path.c_str()); - continue; - } - if(UserConfigParams::logAddons()) - Log::verbose("[FileManager]", "Deleting tmp file'%s'.",full_path.c_str()); - removeFile(full_path); - - } // for i in all files in tmp -} // cleanTempFiles - // ---------------------------------------------------------------------------- /** Returns true if the specified file exists. */ diff --git a/src/io/file_manager.hpp b/src/io/file_manager.hpp index a3f9d8dd6..5226f357c 100644 --- a/src/io/file_manager.hpp +++ b/src/io/file_manager.hpp @@ -245,8 +245,7 @@ public: // ------------------------------------------------------------------------ const std::string& getCertBundleLocation() const { return m_cert_bundle_location; } - // ------------------------------------------------------------------------ - void cleanTempFiles(); + }; // FileManager extern FileManager* file_manager; diff --git a/src/main_loop.cpp b/src/main_loop.cpp index faf49cd23..0b950f3cf 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -137,10 +137,6 @@ float MainLoop::getLimitedDt() PlayerManager::get()->save(); if (addons_manager->hasDownloadedIcons()) addons_manager->saveInstalled(); - // Clean temp files manually as destructor of file manager - // won't be called at all in mobile if user just press home - // button - file_manager->cleanTempFiles(); } dev->run(); win_active = dev->isWindowActive();