File.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include "il2cpp-config.h"
  3. #include <stdint.h>
  4. #include <string>
  5. #include "os/ErrorCodes.h"
  6. #include "os/c-api/OSGlobalEnums.h"
  7. #include "utils/Expected.h"
  8. #undef CopyFile
  9. #undef DeleteFile
  10. #undef MoveFile
  11. #undef ReplaceFile
  12. #undef GetFileAttributes
  13. #undef SetFileAttributes
  14. #undef CreatePipe
  15. namespace il2cpp
  16. {
  17. namespace os
  18. {
  19. // File enums and structs
  20. struct FileHandle;
  21. struct FileStat
  22. {
  23. std::string name;
  24. int32_t attributes;
  25. int64_t length;
  26. int64_t creation_time;
  27. int64_t last_access_time;
  28. int64_t last_write_time;
  29. };
  30. class LIBIL2CPP_CODEGEN_API File
  31. {
  32. public:
  33. static utils::Expected<bool> Isatty(FileHandle* fileHandle);
  34. static FileHandle* GetStdInput();
  35. static FileHandle* GetStdOutput();
  36. static FileHandle* GetStdError();
  37. static utils::Expected<bool> CreatePipe(FileHandle** read_handle, FileHandle** write_handle);
  38. static utils::Expected<bool> CreatePipe(FileHandle** read_handle, FileHandle** write_handle, int* error);
  39. static FileType GetFileType(FileHandle* handle);
  40. static UnityPalFileAttributes GetFileAttributes(const std::string& path, int* error);
  41. static bool SetFileAttributes(const std::string& path, UnityPalFileAttributes attributes, int* error);
  42. static bool GetFileStat(const std::string& path, FileStat * stat, int* error);
  43. static bool CopyFile(const std::string& src, const std::string& dest, bool overwrite, int* error);
  44. static bool MoveFile(const std::string& src, const std::string& dest, int* error);
  45. static bool DeleteFile(const std::string& path, int *error);
  46. static bool ReplaceFile(const std::string& sourceFileName, const std::string& destinationFileName, const std::string& destinationBackupFileName, bool ignoreMetadataErrors, int* error);
  47. static FileHandle* Open(const std::string& path, int openMode, int accessMode, int shareMode, int options, int *error);
  48. static bool Close(FileHandle* handle, int *error);
  49. static bool SetFileTime(FileHandle* handle, int64_t creation_time, int64_t last_access_time, int64_t last_write_time, int* error);
  50. static int64_t GetLength(FileHandle* handle, int *error);
  51. static bool SetLength(FileHandle* handle, int64_t length, int *error);
  52. static int64_t Seek(FileHandle* handle, int64_t offset, int origin, int *error);
  53. static int Read(FileHandle* handle, char *dest, int count, int *error);
  54. static int32_t Write(FileHandle* handle, const char* buffer, int count, int *error);
  55. static bool Flush(FileHandle* handle, int* error);
  56. static void Lock(FileHandle* handle, int64_t position, int64_t length, int* error);
  57. static void Unlock(FileHandle* handle, int64_t position, int64_t length, int* error);
  58. static utils::Expected<bool> IsExecutable(const std::string& path);
  59. static bool Truncate(FileHandle* handle, int *error);
  60. static bool Cancel(FileHandle* handle);
  61. static utils::Expected<bool> DuplicateHandle(FileHandle* source_process_handle, FileHandle* source_handle, FileHandle* target_process_handle,
  62. FileHandle** target_handle, int access, int inherit, int options, int* error);
  63. static bool IsHandleOpenFileHandle(intptr_t lookup);
  64. };
  65. }
  66. }