platformVolume.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  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
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "console/console.h"
  23. #include "platform/platform.h"
  24. #if defined(TORQUE_OS_WIN)
  25. #include <sys/utime.h>
  26. #else
  27. #include <sys/time.h>
  28. #endif
  29. #include "platform/platformVolume.h"
  30. #include "core/util/zip/zipVolume.h"
  31. using namespace Torque;
  32. using namespace Torque::FS;
  33. namespace Platform
  34. {
  35. namespace FS
  36. {
  37. bool MountDefaults()
  38. {
  39. String path = getAssetDir();
  40. bool mounted = Mount( "game", createNativeFS( path ));
  41. if ( !mounted )
  42. return false;
  43. #ifdef TORQUE_SECURE_VFS
  44. mounted = Mount("/", createNativeFS(path));
  45. if (!mounted)
  46. {
  47. return false;
  48. }
  49. #endif
  50. // Always mount the data dir so scripts work in either configuration. This is used for eg. preferences storage.
  51. Path dataDirectory = Platform::getUserDataDirectory();
  52. Path appDataDirectory;
  53. appDataDirectory.setPath(dataDirectory.getFileName());
  54. dataDirectory.appendPath(appDataDirectory);
  55. dataDirectory.setFileName(TORQUE_APP_NAME);
  56. mounted = Mount("data", Platform::FS::createNativeFS(dataDirectory.getFullPath()));
  57. if (!mounted)
  58. {
  59. return false;
  60. }
  61. #ifndef TORQUE_DISABLE_VIRTUAL_MOUNT_SYSTEM
  62. // Note that the VirtualMountSystem must be enabled in volume.cpp for zip support to work.
  63. return MountZips("game");
  64. #else
  65. return true;
  66. #endif
  67. }
  68. bool MountZips(const String &root)
  69. {
  70. Path basePath;
  71. basePath.setRoot(root);
  72. Vector<String> outList;
  73. S32 num = FindByPattern(basePath, "*.zip", true, outList);
  74. if(num == 0)
  75. return true; // not an error
  76. S32 mounted = 0;
  77. for(S32 i = 0;i < outList.size();++i)
  78. {
  79. String &zipfile = outList[i];
  80. #ifdef TORQUE_ZIP_DISK_LAYOUT
  81. mounted += (S32)Mount(root, new ZipFileSystem(zipfile, false));
  82. #else
  83. mounted += (S32)Mount(root, new ZipFileSystem(zipfile, true));
  84. #endif
  85. }
  86. return mounted == outList.size();
  87. }
  88. //-----------------------------------------------------------------------------
  89. bool Touch( const Path &path )
  90. {
  91. #if defined(TORQUE_OS_WIN)
  92. return( utime( path.getFullPath(), 0 ) != -1 );
  93. #else
  94. return( utimes( path.getFullPath(), NULL) == 0 ); // utimes returns 0 on success.
  95. #endif
  96. }
  97. } // namespace FS
  98. } // namespace Platform