blob: 9c63bd681c5f3c43ab4aee62f2b478066630d5e7 (
plain)
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
|
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
}
|