forked from focus-creative-games/il2cpp_plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectory.cpp
More file actions
110 lines (89 loc) · 3.87 KB
/
Directory.cpp
File metadata and controls
110 lines (89 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "os/c-api/il2cpp-config-platforms.h"
#if !RUNTIME_TINY
#include "os/Directory.h"
#include "os/c-api/Directory-c-api.h"
#include "Allocator.h"
#include "utils/StringUtils.h"
#include "utils/StringViewUtils.h"
#include <string>
extern "C"
{
const char* UnityPalDirectoryGetCurrent(int* error)
{
return Allocator::CopyToAllocatedStringBuffer(il2cpp::os::Directory::GetCurrent(error));
}
int32_t UnityPalDirectorySetCurrent(const char* path, int* error)
{
return il2cpp::os::Directory::SetCurrent(path, error);
}
int32_t UnityPalDirectoryCreate(const char* path, int *error)
{
return il2cpp::os::Directory::Create(path, error);
}
int32_t UnityPalDirectoryRemove(const char* path, int *error)
{
return il2cpp::os::Directory::Remove(path, error);
}
void UnityPalDirectoryGetFileSystemEntries(const char* path, const char* pathWithPattern, int32_t attrs, int32_t mask, int* error, char*** entries, int32_t* numEntries)
{
std::set<std::string> localSet = il2cpp::os::Directory::GetFileSystemEntries(path, pathWithPattern, attrs, mask, error);
if (localSet.empty())
{
*numEntries = 0;
(*entries) = NULL;
return;
}
// First allocate a new array that can hold all of the entries in the std::set
char** entryArray = NULL;
*numEntries = static_cast<int32_t>(localSet.size());
entryArray = (char**)Allocator::Allocate(*numEntries * sizeof(char*));
IL2CPP_ASSERT(entryArray);
// Copy each string in the std::set into a newly allocated char* slot of the
// array.
std::set<std::string>::const_iterator it;
int arrayIndex = 0;
for (it = localSet.begin(); it != localSet.end(); ++it, ++arrayIndex)
{
entryArray[arrayIndex] = (char*)Allocator::Allocate(it->length() * sizeof(char) + 1);
IL2CPP_ASSERT(entryArray[arrayIndex]);
strncpy(entryArray[arrayIndex], it->c_str(), it->length() + 1);
}
(*entries) = entryArray;
}
UnityPalFindHandle* UnityPalDirectoryFindHandleNew(const char* searchPathWithPattern)
{
Il2CppNativeString pattern(il2cpp::utils::StringUtils::Utf8ToNativeString(searchPathWithPattern));
return new il2cpp::os::Directory::FindHandle(STRING_TO_STRINGVIEW(pattern));
}
void UnityPalDirectoryFindHandleDelete(UnityPalFindHandle* object)
{
IL2CPP_ASSERT(object);
delete object;
}
int32_t UnityPalDirectoryCloseOSHandle(UnityPalFindHandle* object)
{
IL2CPP_ASSERT(object);
return object->CloseOSHandle();
}
void* UnityPalDirectoryGetOSHandle(UnityPalFindHandle* object)
{
IL2CPP_ASSERT(object);
return object->osHandle;
}
UnityPalErrorCode UnityPalDirectoryFindFirstFile(UnityPalFindHandle* findHandle, const char* searchPathWithPattern, char** resultFileName, int32_t* resultAttributes)
{
Il2CppNativeString pattern(il2cpp::utils::StringUtils::Utf8ToNativeString(searchPathWithPattern));
Il2CppNativeString nativeFileName;
UnityPalErrorCode retVal = il2cpp::os::Directory::FindFirstFile(findHandle, STRING_TO_STRINGVIEW(pattern), &nativeFileName, resultAttributes);
*resultFileName = Allocator::CopyToAllocatedStringBuffer(il2cpp::utils::StringUtils::NativeStringToUtf8(nativeFileName));
return retVal;
}
UnityPalErrorCode UnityPalDirectoryFindNextFile(UnityPalFindHandle* findHandle, char** resultFileName, int32_t* resultAttributes)
{
Il2CppNativeString nativeFileName;
UnityPalErrorCode retVal = il2cpp::os::Directory::FindNextFile(findHandle, &nativeFileName, resultAttributes);
*resultFileName = Allocator::CopyToAllocatedStringBuffer(il2cpp::utils::StringUtils::NativeStringToUtf8(nativeFileName));
return retVal;
}
}
#endif