From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Export/Windows/WindowsFile.txt | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Runtime/Export/Windows/WindowsFile.txt (limited to 'Runtime/Export/Windows/WindowsFile.txt') 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 buffer; + buffer.resize(file.GetFileLength()); + file.Read(&buffer[0], buffer.size()); + file.Close(); + return CreateScriptingArray(&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(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 +} -- cgit v1.1-26-g67d0