summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/TizenIsolatedStorageFile.cs
blob: ec50c8a403b78457301872166de00986119f8a6e (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
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
	{
		string _rootPath;

		internal TizenIsolatedStorageFile()
		{
			_rootPath = TApplication.Current.DirectoryInfo.Data;
		}

		public void CreateDirectory(string path)
		{
			if (path == null)
				throw new ArgumentNullException("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("source");
			if (dest == null)
				throw new ArgumentNullException("dest");

			File.Move(Path.Combine(_rootPath, source), Path.Combine(_rootPath, dest));
		}

		public void DeleteFile(string path)
		{
			if (path == null)
				throw new ArgumentNullException("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("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("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("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, System.IO.FileMode mode)
		{
			return OpenFile(path, mode, (mode == System.IO.FileMode.Append ? System.IO.FileAccess.Write : System.IO.FileAccess.ReadWrite));
		}

		public Stream OpenFile(string path, System.IO.FileMode mode, System.IO.FileAccess access)
		{
			return OpenFile(path, mode, access, System.IO.FileShare.Read);
		}

		public Stream OpenFile(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share)
		{
			if (path == null)
				throw new ArgumentNullException("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, Internals.FileMode mode, Internals.FileAccess access)
		{
			return Task.FromResult(OpenFile(path, (System.IO.FileMode)mode, (System.IO.FileAccess)access));
		}

		public Task<Stream> OpenFileAsync(string path, Internals.FileMode mode, Internals.FileAccess access, Internals.FileShare share)
		{
			return Task.FromResult(OpenFile(path, (System.IO.FileMode)mode, (System.IO.FileAccess)access, (System.IO.FileShare)share));
		}

	}
}