forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTizenIsolatedStorageFile.cs
126 lines (103 loc) · 3.27 KB
/
TizenIsolatedStorageFile.cs
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.IO;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
using TApplication = Tizen.Applications.Application;
namespace Xamarin.Forms.Platform.Tizen
{
internal class TizenIsolatedStorageFile : IIsolatedStorageFile
{
readonly string _rootPath;
internal TizenIsolatedStorageFile()
{
_rootPath = TApplication.Current.DirectoryInfo.Data;
}
public void CreateDirectory(string path)
{
if (path == null)
throw new ArgumentNullException(nameof(path));
Directory.CreateDirectory(Path.Combine(_rootPath, path));
}
public Task CreateDirectoryAsync(string path)
{
CreateDirectory(path);
return Task.FromResult(true);
}
public void MoveFile(string source, string dest)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (dest == null)
throw new ArgumentNullException(nameof(dest));
File.Move(Path.Combine(_rootPath, source), Path.Combine(_rootPath, dest));
}
public void DeleteFile(string path)
{
if (path == null)
throw new ArgumentNullException(nameof(path));
if (path.Trim().Length == 0)
throw new ArgumentException("An empty path is not valid.");
File.Delete(Path.Combine(_rootPath, path));
}
public bool DirectoryExists(string path)
{
if (path == null)
throw new ArgumentNullException(nameof(path));
return Directory.Exists(Path.Combine(_rootPath, path));
}
public Task<bool> GetDirectoryExistsAsync(string path)
{
return Task.FromResult(DirectoryExists(path));
}
public bool FileExists(string path)
{
if (path == null)
throw new ArgumentNullException(nameof(path));
return File.Exists(Path.Combine(_rootPath, path));
}
public Task<bool> GetFileExistsAsync(string path)
{
return Task.FromResult(FileExists(path));
}
public DateTimeOffset GetLastWriteTime(string path)
{
if (path == null)
throw new ArgumentNullException(nameof(path));
if (path.Trim().Length == 0)
throw new ArgumentException("An empty path is not valid.");
string fullPath = Path.Combine(_rootPath, path);
if (File.Exists(fullPath))
return File.GetLastWriteTime(fullPath);
return Directory.GetLastWriteTime(fullPath);
}
public Task<DateTimeOffset> GetLastWriteTimeAsync(string path)
{
return Task.FromResult(GetLastWriteTime(path));
}
public Stream OpenFile(string path, FileMode mode)
{
return OpenFile(path, mode, (mode == FileMode.Append ? FileAccess.Write : FileAccess.ReadWrite));
}
public Stream OpenFile(string path, FileMode mode, FileAccess access)
{
return OpenFile(path, mode, access, FileShare.Read);
}
public Stream OpenFile(string path, FileMode mode, FileAccess access, FileShare share)
{
if (path == null)
throw new ArgumentNullException(nameof(path));
if (path.Trim().Length == 0)
throw new ArgumentException("An empty path is not valid.");
string fullPath = Path.Combine(_rootPath, path);
return new FileStream(fullPath, mode, access, share);
}
public Task<Stream> OpenFileAsync(string path, FileMode mode, FileAccess access)
{
return Task.FromResult(OpenFile(path, mode, access));
}
public Task<Stream> OpenFileAsync(string path, FileMode mode, FileAccess access, FileShare share)
{
return Task.FromResult(OpenFile(path, mode, access, share));
}
}
}