d722df7936f0981b4c8d847b8c86bd93159cd9db
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Common / Tizen.Applications / DirectoryInfo.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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.ComponentModel;
19 using System.IO;
20
21 namespace Tizen.Applications
22 {
23     /// <summary>
24     /// Represents directory information of the application.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public class DirectoryInfo
28     {
29         private string _dataPath;
30         private string _cachePath;
31         private string _resourcePath;
32
33         private string _sharedDataPath;
34         private string _sharedResourcePath;
35         private string _sharedTrustedPath;
36
37         private string _externalDataPath;
38         private string _externalCachePath;
39         private string _externalSharedDataPath;
40
41         private string _expansionPackageResourcePath;
42
43         internal DirectoryInfo()
44         {
45         }
46
47         /// <summary>
48         /// Gets the absolute path to the application's data directory, which is used to store private data of the application.
49         /// </summary>
50         /// <since_tizen> 3 </since_tizen>
51         public string Data
52         {
53             get
54             {
55                 if (_dataPath == null)
56                     _dataPath = Interop.AppCommon.AppGetDataPath();
57                 return _dataPath;
58             }
59         }
60
61         /// <summary>
62         /// Gets the absolute path to the application's cache directory, which is used to store temporary data of the application.
63         /// </summary>
64         /// <since_tizen> 3 </since_tizen>
65         public string Cache
66         {
67             get
68             {
69                 if (_cachePath == null)
70                     _cachePath = Interop.AppCommon.AppGetCachePath();
71                 return _cachePath;
72             }
73         }
74
75         /// <summary>
76         /// Gets the absolute path to the application resource directory. The resource files are delivered with the application package.
77         /// </summary>
78         /// <since_tizen> 3 </since_tizen>
79         public string Resource
80         {
81             get
82             {
83                 if (_resourcePath == null)
84                     _resourcePath = Interop.AppCommon.AppGetResourcePath();
85                 return _resourcePath;
86             }
87         }
88
89         /// <summary>
90         /// Gets the absolute path to the application's shared data directory, which is used to share data with other applications.
91         /// </summary>
92         /// <since_tizen> 3 </since_tizen>
93         public string SharedData
94         {
95             get
96             {
97                 if (_sharedDataPath == null)
98                     _sharedDataPath = Interop.AppCommon.AppGetSharedDataPath();
99                 return _sharedDataPath;
100             }
101         }
102
103         /// <summary>
104         /// Gets the absolute path to the application's shared resource directory, which is used to share resources with other applications.
105         /// </summary>
106         /// <since_tizen> 3 </since_tizen>
107         public string SharedResource
108         {
109             get
110             {
111                 if (_sharedResourcePath == null)
112                     _sharedResourcePath = Interop.AppCommon.AppGetSharedResourcePath();
113                 return _sharedResourcePath;
114             }
115         }
116
117
118         /// <summary>
119         /// Gets the absolute path to the application's shared trusted directory, which is used to share data with a family of trusted applications.
120         /// </summary>
121         /// <since_tizen> 3 </since_tizen>
122         public string SharedTrusted
123         {
124             get
125             {
126                 if (_sharedTrustedPath == null)
127                     _sharedTrustedPath = Interop.AppCommon.AppGetSharedTrustedPath();
128                 return _sharedTrustedPath;
129             }
130         }
131
132         /// <summary>
133         /// Gets the absolute path to the application's external data directory, which is used to store data of the application.
134         /// </summary>
135         /// <since_tizen> 3 </since_tizen>
136         public string ExternalData
137         {
138             get
139             {
140                 if (_externalDataPath == null)
141                     _externalDataPath = Interop.AppCommon.AppGetExternalDataPath();
142                 return _externalDataPath;
143             }
144         }
145
146         /// <summary>
147         /// Gets the absolute path to the application's external cache directory, which is used to store temporary data of the application.
148         /// </summary>
149         /// <since_tizen> 3 </since_tizen>
150         public string ExternalCache
151         {
152             get
153             {
154                 if (_externalCachePath == null)
155                     _externalCachePath = Interop.AppCommon.AppGetExternalCachePath();
156                 return _externalCachePath;
157             }
158         }
159
160         /// <summary>
161         /// Gets the absolute path to the application's external shared data directory, which is used to share data with other applications.
162         /// </summary>
163         /// <since_tizen> 3 </since_tizen>
164         public string ExternalSharedData
165         {
166             get
167             {
168                 if (_externalSharedDataPath == null)
169                     _externalSharedDataPath = Interop.AppCommon.AppGetExternalSharedDataPath();
170                 return _externalSharedDataPath;
171             }
172         }
173
174         /// <summary>
175         /// Gets the absolute path to the application's TEP(Tizen Expansion Package) directory. The resource files are delivered with the expansion package.
176         /// </summary>
177         /// <since_tizen> 3 </since_tizen>
178         public string ExpansionPackageResource
179         {
180             get
181             {
182                 if (_expansionPackageResourcePath == null)
183                     _expansionPackageResourcePath = Interop.AppCommon.AppGetTepResourcePath();
184                 return _expansionPackageResourcePath;
185             }
186         }
187
188         /// <summary>
189         /// Gets the absolute path to the application's resource control directory, which is used to share the allowed resources of the resource packages.
190         /// </summary>
191         /// <param name="resourceType">The resource type defined in the resource package</param>
192         /// <returns> The absolute path to the application's resource control directory, which is used to share the allowed resources of the resource packages.</returns>
193         /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
194         /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
195         /// <exception cref="DirectoryNotFoundException">Thrown in case of nonexistence of resource.</exception>
196         /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
197         /// <since_tizen> 10 </since_tizen>
198         [EditorBrowsable(EditorBrowsableState.Never)]
199         public string GetResourceControlAllowedResource(string resourceType)
200         {
201             string path = string.Empty;
202             Interop.AppCommon.AppCommonErrorCode err = Interop.AppCommon.AppGetResControlAllowedResourcePath(resourceType, out path);
203             if (err != Interop.AppCommon.AppCommonErrorCode.None)
204             {
205                 switch (err)
206                 {
207                     case Interop.AppCommon.AppCommonErrorCode.InvalidParameter:
208                         throw new ArgumentException("Invalid Arguments");
209                     case Interop.AppCommon.AppCommonErrorCode.OutOfMemory:
210                         throw new OutOfMemoryException("Out of memory");
211                     case Interop.AppCommon.AppCommonErrorCode.InvalidContext:
212                         throw new InvalidOperationException("Invalid app context");
213                     case Interop.AppCommon.AppCommonErrorCode.PermissionDenied:
214                         throw new DirectoryNotFoundException(String.Format("Allowed Resource about {0} is not Found", resourceType));
215                     default:
216                         throw new InvalidOperationException("Invalid Operation");
217                 }
218             }
219
220             return path;
221         }
222
223         /// <summary>
224         /// Gets the absolute path to the application's resource control directory, which is used to share the global resources of the resource packages.
225         /// </summary>
226         /// <param name="resourceType">The resource type defined in the resource package</param>
227         /// <returns> The absolute path to the application's resource control directory, which is used to share the global resources of the resource packages.</returns>
228         /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
229         /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
230         /// <exception cref="DirectoryNotFoundException">Thrown in case of nonexistence of resource.</exception>
231         /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
232         /// <since_tizen> 10 </since_tizen>
233         [EditorBrowsable(EditorBrowsableState.Never)]
234         public string GetResourceControlGlobalResource(string resourceType)
235         {
236             string path = string.Empty;
237             Interop.AppCommon.AppCommonErrorCode err = Interop.AppCommon.AppGetResControlGlobalResourcePath(resourceType, out path);
238             if (err != Interop.AppCommon.AppCommonErrorCode.None)
239             {
240                 switch (err)
241                 {
242                     case Interop.AppCommon.AppCommonErrorCode.InvalidParameter:
243                         throw new ArgumentException("Invalid Arguments");
244                     case Interop.AppCommon.AppCommonErrorCode.OutOfMemory:
245                         throw new OutOfMemoryException("Out of memory");
246                     case Interop.AppCommon.AppCommonErrorCode.InvalidContext:
247                         throw new InvalidOperationException("Invalid app context");
248                     case Interop.AppCommon.AppCommonErrorCode.PermissionDenied:
249                         throw new DirectoryNotFoundException(String.Format("Allowed Resource about {0} is not Found", resourceType));
250                     default:
251                         throw new InvalidOperationException("Invalid Operation");
252                 }
253             }
254
255             return path;
256         }
257     }
258 }