-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO.cs
More file actions
66 lines (58 loc) · 1.75 KB
/
IO.cs
File metadata and controls
66 lines (58 loc) · 1.75 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
using System;
using System.IO;
using UnityEngine;
using System.Collections;
namespace dpull
{
public class DirectoryEx
{
public static void CreateDirectory(string path)
{
path = Path.GetFullPath(path);
CreateDirectory(new DirectoryInfo(path));
}
public static void CreateDirectory(DirectoryInfo path)
{
if (path.Exists)
return;
while (true)
{
var parent = path.Parent;
if (parent == null || parent.Exists)
break;
CreateDirectory(parent);
}
path.Create();
}
public static void DeleteDirectory(string path)
{
path = Path.GetFullPath(path);
if (Directory.Exists(path))
Directory.Delete(path, true);
}
}
public class FileEx
{
public static Stream OpenRead(string sourceFileName)
{
#if UNITY_ANDROID
if (sourceFileName.StartsWith(Application.streamingAssetsPath))
{
var startIndex = Application.streamingAssetsPath.Length;
if (!PathEx.EndWithDirectorySeparatorChar(Application.streamingAssetsPath))
startIndex++;
sourceFileName = sourceFileName.Substring(startIndex);
return new AndroidAssetStream(sourceFileName);
}
#endif
return File.OpenRead(sourceFileName);
}
}
public class PathEx
{
public static bool EndWithDirectorySeparatorChar(string path)
{
return path.EndsWith("\\") || path.EndsWith("/");
}
}
}