2 * Copyright (c) 2017 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using LibTVRefCommonPortable.Stubs;
22 namespace LibTVRefCommonPortable.Utils
25 /// A class for file system control function.
30 /// A instance of file system port layer
32 private static IFileSystemAPIs fileSystemAPIs;
35 /// A instance of file system watcher port layer
37 private static IFileSystemWatcherAPIs fileSystemWatcherAPIs;
40 /// A instance of FileSystemUtils
42 private static readonly FileSystemUtils instance = new FileSystemUtils();
45 /// A property of FileSystemUtils instance
47 public static FileSystemUtils Instance
56 /// A property of file system watcher instance
58 public IFileSystemWatcherAPIs FileSysteamWatcherInstance
62 return fileSystemWatcherAPIs;
69 private FileSystemUtils()
71 fileSystemAPIs = new FileSystemAPITestStub();
72 fileSystemWatcherAPIs = new FileWatcherAPITestStub();
76 if (DependencyService.Get<IFileSystemAPIs>() != null)
78 fileSystemAPIs = DependencyService.Get<IFileSystemAPIs>();
81 if (DependencyService.Get<IFileSystemWatcherAPIs>() != null)
83 fileSystemWatcherAPIs = DependencyService.Get<IFileSystemWatcherAPIs>();
86 catch (InvalidOperationException e)
88 DebuggingUtils.Err(e.Message);
93 /// A directory path which should be used for app data storing.
95 public string AppDataStorage
99 return fileSystemAPIs.AppDataStorage;
104 /// A directory path which should be used for app resource storing.
106 public string AppResourceStorage
110 return fileSystemAPIs.AppResourceStorage;
115 /// A directory path which should be used for sharing between apps.
117 public string PlatformShareStorage
121 return fileSystemAPIs.PlatformShareStorage;
126 /// A method opens a file on the given mode.
128 /// <param name="filePath">A file path</param>
129 /// <param name="mode">An opening mode</param>
130 /// <returns>A file descriptor</returns>
131 public Stream OpenFile(string filePath, UtilFileMode mode)
133 return fileSystemAPIs.OpenFile(filePath, mode);
137 /// A method flushing the stream to write remains.
139 /// <param name="stream">A file descriptor</param>
140 public void Flush(Stream stream)
142 fileSystemAPIs.Flush(stream);
146 /// A method closes the file.
148 /// <param name="stream">A file descriptor</param>
149 public void CloseFile(Stream stream)
151 fileSystemAPIs.CloseFile(stream);
155 /// A method checks if a file existence in the file system.
157 /// <param name="filePath">A file path</param>
158 /// <returns>An existence of the file</returns>
159 public bool IsFileExist(String filePath)
161 return fileSystemAPIs.IsFileExist(filePath);
165 /// A method checks if file is read to use.
167 /// <param name="filePath">A file path</param>
168 /// <returns>A status of ready</returns>
169 public bool IsFileReady(String filePath)
171 return fileSystemAPIs.IsFileReady(filePath);