OSBasics.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyString.h"
  22. struct PHYSFS_File;
  23. class _PolyExport OSFileEntry : public PolyBase {
  24. public:
  25. OSFileEntry() {};
  26. OSFileEntry(const Polycode::String& fullPath, int type);
  27. OSFileEntry(const Polycode::String& path, const Polycode::String& name, int type);
  28. void init(const Polycode::String& path, const Polycode::String& name, int type);
  29. Polycode::String name;
  30. Polycode::String extension;
  31. Polycode::String nameWithoutExtension;
  32. Polycode::String basePath;
  33. Polycode::String fullPath;
  34. int type;
  35. static const int TYPE_FILE = 0;
  36. static const int TYPE_FOLDER = 1;
  37. };
  38. class _PolyExport OSFILE : public PolyBase {
  39. public:
  40. OSFILE(){}
  41. void debugDump();
  42. int fileType;
  43. FILE *file;
  44. PHYSFS_File *physFSFile;
  45. static const int TYPE_FILE = 0;
  46. static const int TYPE_ARCHIVE_FILE = 1;
  47. };
  48. class _PolyExport OSBasics : public PolyBase {
  49. public:
  50. static OSFILE *open(const Polycode::String& filename, const Polycode::String& opts);
  51. static int close(OSFILE *file);
  52. static size_t read( void * ptr, size_t size, size_t count, OSFILE * stream );
  53. static size_t write( const void * ptr, size_t size, size_t count, OSFILE * stream );
  54. static int seek(OSFILE * stream, long int offset, int origin );
  55. static long tell(OSFILE * stream);
  56. static std::vector<OSFileEntry> parsePhysFSFolder(const Polycode::String& pathString, bool showHidden);
  57. static std::vector<OSFileEntry> parseFolder(const Polycode::String& pathString, bool showHidden);
  58. static bool fileExists(const Polycode::String& pathString);
  59. static bool isFolder(const Polycode::String& pathString);
  60. static void createFolder(const Polycode::String& pathString);
  61. static void removeItem(const Polycode::String& pathString);
  62. static time_t getFileTime(const Polycode::String& pathString);
  63. private:
  64. };