Revert "Add Test cases for app shortcut, managedapps"
[profile/tv/apps/dotnet/home.git] / LibTVRefCommonPortable / Utils / FileSystemUtils.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd
3  *
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
7  *
8  *     http://floralicense.org/license/
9  *
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.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using System.IO;
20 using System.Linq;
21 using System.Text;
22 using System.Threading.Tasks;
23 using Xamarin.Forms;
24
25 namespace LibTVRefCommonPortable.Utils
26 {
27     /// <summary>
28     /// A class for file system control function.
29     /// </summary>
30     class FileSystemUtils
31     {
32         /// <summary>
33         /// A instance of file system port layer
34         /// </summary>
35         private static IFileSystemAPIs fileSystemAPIs;
36
37         /// <summary>
38         /// A instance of FileSystemUtils
39         /// </summary>
40         private static readonly FileSystemUtils instance = new FileSystemUtils();
41
42         /// <summary>
43         /// A property of FileSystemUtils instance
44         /// </summary>
45         public static FileSystemUtils Instance
46         {
47             get
48             {
49                 return instance;
50             }
51         }
52
53         /// <summary>
54         /// A unit test stub for FileSystemUtils
55         /// </summary>
56         private class TestStub : IFileSystemAPIs
57         {
58             /// <summary>
59             /// A directory path which should be used for app data storing.
60             /// </summary>
61             public string AppDataStorage
62             {
63                 get
64                 {
65                     return "test_app_data_path/";
66                 }
67             }
68
69             /// <summary>
70             /// A directory path which should be used for app resource storing.
71             /// </summary>
72             public string AppResourceStorage
73             {
74                 get
75                 {
76                     return "test_app_resource_path/";
77                 }
78             }
79
80             /// <summary>
81             /// A directory path which should be used for sharing between apps.
82             /// </summary>
83             public string PlatformShareStorage
84             {
85                 get
86                 {
87                     return "test_platform_share_path/";
88                 }
89             }
90
91             /// <summary>
92             /// A method closes the file.
93             /// </summary>
94             /// <param name="stream">A file descriptor</param>
95             public void CloseFile(Stream stream)
96             {
97             }
98
99             /// <summary>
100             /// A method flushing the stream to write remains.
101             /// </summary>
102             /// <param name="stream">A file descriptor</param>
103             public void Flush(Stream stream)
104             {
105             }
106
107             /// <summary>
108             /// A method checks if a file existence in the file system.
109             /// </summary>
110             /// <param name="filePath">A file path</param>
111             /// <returns>An existence of the file</returns>
112             public bool IsFileExist(string filePath)
113             {
114                 return true;
115             }
116
117             /// <summary>
118             /// A method checks if file is read to use.
119             /// </summary>
120             /// <param name="filePath">A file path</param>
121             /// <returns>A status of ready</returns>
122             public bool IsFileReady(string filePath)
123             {
124                 return true;
125             }
126
127             /// <summary>
128             /// A method opens a file on the given mode.
129             /// </summary>
130             /// <param name="filePath">A file path</param>
131             /// <param name="mode">An opening mode</param>
132             /// <returns>A file descriptor</returns>
133             public Stream OpenFile(string filePath, UtilFileMode mode)
134             {
135                 throw new NotImplementedException();
136             }
137         }
138
139         /// <summary>
140         /// A constructor
141         /// </summary>
142         private FileSystemUtils()
143         {
144             fileSystemAPIs = new TestStub();
145
146             try
147             {
148                 if (DependencyService.Get<IFileSystemAPIs>() != null)
149                 {
150                     fileSystemAPIs = DependencyService.Get<IFileSystemAPIs>();
151                 }
152             }
153             catch (InvalidOperationException e)
154             {
155                 DebuggingUtils.Err(e.Message);
156             }
157         }
158
159         /// <summary>
160         /// A directory path which should be used for app data storing.
161         /// </summary>
162         public string AppDataStorage
163         {
164             get
165             {
166                 return fileSystemAPIs.AppDataStorage;
167             }
168         }
169
170         /// <summary>
171         /// A directory path which should be used for app resource storing.
172         /// </summary>
173         public string AppResourceStorage
174         {
175             get
176             {
177                 return fileSystemAPIs.AppResourceStorage;
178             }
179         }
180
181         /// <summary>
182         /// A directory path which should be used for sharing between apps.
183         /// </summary>
184         public string PlatformShareStorage
185         {
186             get
187             {
188                 return fileSystemAPIs.PlatformShareStorage;
189             }
190         }
191
192         /// <summary>
193         /// A method opens a file on the given mode.
194         /// </summary>
195         /// <param name="filePath">A file path</param>
196         /// <param name="mode">An opening mode</param>
197         /// <returns>A file descriptor</returns>
198         public Stream OpenFile(string filePath, UtilFileMode mode)
199         {
200             return fileSystemAPIs.OpenFile(filePath, mode);
201         }
202
203         /// <summary>
204         /// A method flushing the stream to write remains.
205         /// </summary>
206         /// <param name="stream">A file descriptor</param>
207         public void Flush(Stream stream)
208         {
209             fileSystemAPIs.Flush(stream);
210         }
211
212         /// <summary>
213         /// A method closes the file.
214         /// </summary>
215         /// <param name="stream">A file descriptor</param>
216         public void CloseFile(Stream stream)
217         {
218             fileSystemAPIs.CloseFile(stream);
219         }
220
221         /// <summary>
222         /// A method checks if a file existence in the file system.
223         /// </summary>
224         /// <param name="filePath">A file path</param>
225         /// <returns>An existence of the file</returns>
226         public bool IsFileExist(String filePath)
227         {
228             return fileSystemAPIs.IsFileExist(filePath);
229         }
230
231         /// <summary>
232         /// A method checks if file is read to use.
233         /// </summary>
234         /// <param name="filePath">A file path</param>
235         /// <returns>A status of ready</returns>
236         public bool IsFileReady(String filePath)
237         {
238             return fileSystemAPIs.IsFileReady(filePath);
239         }
240
241
242     }
243 }