platformVolume.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #include "core/memVolume.h"
  32. using namespace Torque;
  33. using namespace Torque::FS;
  34. namespace Platform
  35. {
  36. namespace FS
  37. {
  38. bool MountDefaults()
  39. {
  40. String path = getAssetDir();
  41. bool mounted = Mount( "game", createNativeFS( path ));
  42. if ( !mounted )
  43. return false;
  44. #ifdef TORQUE_SECURE_VFS
  45. // Set working directory to where the executable is
  46. StringTableEntry executablePath = Platform::getExecutablePath();
  47. SetCwd(executablePath);
  48. // FIXME: Should we use the asset path here as well?
  49. mounted = Mount("/", createNativeFS(executablePath));
  50. if (!mounted)
  51. {
  52. return false;
  53. }
  54. #endif
  55. // Always mount the data dir so scripts work in either configuration. This is used for eg. preferences storage.
  56. Path dataDirectory = Platform::getUserDataDirectory();
  57. Path appDataDirectory;
  58. appDataDirectory.setPath(dataDirectory.getFileName());
  59. dataDirectory.appendPath(appDataDirectory);
  60. dataDirectory.setFileName(TORQUE_APP_NAME);
  61. Con::errorf("RAW DATA: %s", dataDirectory.getFullPath().c_str());
  62. mounted = Mount("data", Platform::FS::createNativeFS(dataDirectory.getFullPath()));
  63. if (!mounted)
  64. {
  65. return false;
  66. }
  67. #ifndef TORQUE_DISABLE_VIRTUAL_MOUNT_SYSTEM
  68. // Note that the VirtualMountSystem must be enabled in volume.cpp for zip support to work.
  69. return MountZips("game");
  70. #else
  71. return true;
  72. #endif
  73. }
  74. bool MountZips(const String &root)
  75. {
  76. Path basePath;
  77. basePath.setRoot(root);
  78. Vector<String> outList;
  79. S32 num = FindByPattern(basePath, "*.zip", true, outList);
  80. if(num == 0)
  81. return true; // not an error
  82. S32 mounted = 0;
  83. for(S32 i = 0;i < outList.size();++i)
  84. {
  85. String &zipfile = outList[i];
  86. #ifdef TORQUE_ZIP_DISK_LAYOUT
  87. mounted += (S32)Mount(root, new ZipFileSystem(zipfile, false));
  88. #else
  89. mounted += (S32)Mount(root, new ZipFileSystem(zipfile, true));
  90. #endif
  91. }
  92. return mounted == outList.size();
  93. }
  94. //-----------------------------------------------------------------------------
  95. bool Touch( const Path &path )
  96. {
  97. #if defined(TORQUE_OS_WIN)
  98. return( utime( path.getFullPath(), 0 ) != -1 );
  99. #else
  100. return( utimes( path.getFullPath(), NULL) == 0 ); // utimes returns 0 on success.
  101. #endif
  102. }
  103. } // namespace FS
  104. } // namespace Platform