Directory.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "os/c-api/il2cpp-config-platforms.h"
  2. #if !RUNTIME_TINY
  3. #include "os/Directory.h"
  4. #include "os/c-api/Directory-c-api.h"
  5. #include "Allocator.h"
  6. #include "utils/StringUtils.h"
  7. #include "utils/StringViewUtils.h"
  8. #include <string>
  9. extern "C"
  10. {
  11. const char* UnityPalDirectoryGetCurrent(int* error)
  12. {
  13. return Allocator::CopyToAllocatedStringBuffer(il2cpp::os::Directory::GetCurrent(error));
  14. }
  15. UnityPalFindHandle* UnityPalDirectoryFindHandleNew(const char* searchPathWithPattern)
  16. {
  17. Il2CppNativeString pattern(il2cpp::utils::StringUtils::Utf8ToNativeString(searchPathWithPattern));
  18. return new il2cpp::os::Directory::FindHandle(STRING_TO_STRINGVIEW(pattern));
  19. }
  20. void UnityPalDirectoryFindHandleDelete(UnityPalFindHandle* object)
  21. {
  22. IL2CPP_ASSERT(object);
  23. delete object;
  24. }
  25. int32_t UnityPalDirectoryCloseOSHandle(UnityPalFindHandle* object)
  26. {
  27. IL2CPP_ASSERT(object);
  28. return object->CloseOSHandle();
  29. }
  30. UnityPalErrorCode UnityPalDirectoryFindFirstFile(UnityPalFindHandle* findHandle, const char* searchPathWithPattern, char** resultFileName, int32_t* resultAttributes)
  31. {
  32. Il2CppNativeString pattern(il2cpp::utils::StringUtils::Utf8ToNativeString(searchPathWithPattern));
  33. Il2CppNativeString nativeFileName;
  34. UnityPalErrorCode retVal = il2cpp::os::Directory::FindFirstFile(findHandle, STRING_TO_STRINGVIEW(pattern), &nativeFileName, resultAttributes);
  35. *resultFileName = Allocator::CopyToAllocatedStringBuffer(il2cpp::utils::StringUtils::NativeStringToUtf8(nativeFileName));
  36. return retVal;
  37. }
  38. UnityPalErrorCode UnityPalDirectoryFindNextFile(UnityPalFindHandle* findHandle, char** resultFileName, int32_t* resultAttributes)
  39. {
  40. Il2CppNativeString nativeFileName;
  41. UnityPalErrorCode retVal = il2cpp::os::Directory::FindNextFile(findHandle, &nativeFileName, resultAttributes);
  42. *resultFileName = Allocator::CopyToAllocatedStringBuffer(il2cpp::utils::StringUtils::NativeStringToUtf8(nativeFileName));
  43. return retVal;
  44. }
  45. }
  46. #endif