summaryrefslogtreecommitdiff
path: root/Runtime/Export/Windows/WindowsFile.txt
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-14 22:50:43 +0800
committerchai <chaifix@163.com>2019-08-14 22:50:43 +0800
commit15740faf9fe9fe4be08965098bbf2947e096aeeb (patch)
treea730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Export/Windows/WindowsFile.txt
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/Export/Windows/WindowsFile.txt')
-rw-r--r--Runtime/Export/Windows/WindowsFile.txt69
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
+}