CCFileUtils-tizen.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /****************************************************************************
  2. Copyright (c) 2014-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #include "platform/CCPlatformConfig.h"
  21. #if CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN
  22. #include "platform/tizen/CCFileUtils-tizen.h"
  23. #include <app.h>
  24. #include <sys/stat.h>
  25. using namespace std;
  26. NS_CC_BEGIN
  27. FileUtils* FileUtils::getInstance()
  28. {
  29. if (s_sharedFileUtils == nullptr)
  30. {
  31. s_sharedFileUtils = new FileUtilsTizen();
  32. if(!s_sharedFileUtils->init())
  33. {
  34. delete s_sharedFileUtils;
  35. s_sharedFileUtils = nullptr;
  36. CCLOG("ERROR: Could not init FileUtilsTizen");
  37. }
  38. }
  39. return s_sharedFileUtils;
  40. }
  41. FileUtilsTizen::FileUtilsTizen()
  42. {
  43. }
  44. bool FileUtilsTizen::init()
  45. {
  46. _defaultResRootPath = app_get_resource_path();
  47. _writablePath = app_get_data_path();
  48. return FileUtils::init();
  49. }
  50. string FileUtilsTizen::getWritablePath() const
  51. {
  52. return _writablePath;
  53. }
  54. bool FileUtilsTizen::isFileExistInternal(const std::string& strFilePath) const
  55. {
  56. if (strFilePath.empty())
  57. {
  58. return false;
  59. }
  60. std::string strPath = strFilePath;
  61. if (!isAbsolutePath(strPath))
  62. { // Not absolute path, add the default root path at the beginning.
  63. strPath.insert(0, _defaultResRootPath);
  64. }
  65. struct stat sts;
  66. return (stat(strPath.c_str(), &sts) != -1) ? true : false;
  67. }
  68. NS_CC_END
  69. #endif // CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN