diff options
Diffstat (limited to 'Runtime/Export/Windows/WindowsFile.txt')
-rw-r--r-- | Runtime/Export/Windows/WindowsFile.txt | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/Runtime/Export/Windows/WindowsFile.txt b/Runtime/Export/Windows/WindowsFile.txt new file mode 100644 index 0000000..9c63bd6 --- /dev/null +++ b/Runtime/Export/Windows/WindowsFile.txt @@ -0,0 +1,69 @@ +C++RAW + +#include "UnityPrefix.h" +#include "Runtime/Mono/MonoManager.h" +#include "Runtime/Scripting/ScriptingUtility.h" +#include "Runtime/Scripting/ScriptingExportUtility.h" +#include "Runtime/Utilities/File.h" + +using namespace Unity; + +using namespace std; + +CSRAW +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using UnityEngineInternal; + +namespace UnityEngine.Windows +{ +CONDITIONAL UNITY_WINRT_API +CLASS File + CUSTOM public static byte[] ReadAllBytes(string path) + { + File file; + if (file.Open(path.AsUTF8(), File::kReadPermission)) + { + std::vector<UInt8> buffer; + buffer.resize(file.GetFileLength()); + file.Read(&buffer[0], buffer.size()); + file.Close(); + return CreateScriptingArray<UInt8>(&buffer[0], buffer.size(), GetMonoManager().GetCommonClasses().byte); + } + else + { + ErrorStringMsg("File.ReadAllBytes - failed to open %s for reading", path.AsUTF8().c_str()); + } + return SCRIPTING_NULL; + } + + CUSTOM public static void WriteAllBytes(string path, byte[] bytes) + { + File file; + if (file.Open(path.AsUTF8(), File::kWritePermission)) + { + int size = GetScriptingArraySize(bytes); + UInt8* rawBytes = Scripting::GetScriptingArrayStart<UInt8>(bytes); + file.Write(rawBytes, size); + file.Close(); + } + else + { + ErrorStringMsg("File.WriteAllBytes - failed to open %s for writing", path.AsUTF8().c_str()); + } + } + CUSTOM public static bool Exists(string path) + { + return IsFileCreated(path.AsUTF8()); + } + CUSTOM public static void Delete(string path) + { + if (IsFileCreated(path.AsUTF8())) + DeleteFileOrDirectory(path.AsUTF8()); + } +CSRAW +END + +CSRAW +} |