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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
using System;
using System.Configuration;
using System.IO;
using System.Reflection;
namespace MediaBrowser.Common.Kernel
{
/// <summary>
/// Provides a base class to hold common application paths used by both the Ui and Server.
/// This can be subclassed to add application-specific paths.
/// </summary>
public abstract class BaseApplicationPaths
{
/// <summary>
/// The _program data path
/// </summary>
private string _programDataPath;
/// <summary>
/// Gets the path to the program data folder
/// </summary>
/// <value>The program data path.</value>
public string ProgramDataPath
{
get
{
return _programDataPath ?? (_programDataPath = GetProgramDataPath());
}
}
/// <summary>
/// The _data directory
/// </summary>
private string _dataDirectory;
/// <summary>
/// Gets the folder path to the data directory
/// </summary>
/// <value>The data directory.</value>
public string DataPath
{
get
{
if (_dataDirectory == null)
{
_dataDirectory = Path.Combine(ProgramDataPath, "data");
if (!Directory.Exists(_dataDirectory))
{
Directory.CreateDirectory(_dataDirectory);
}
}
return _dataDirectory;
}
}
/// <summary>
/// The _image cache path
/// </summary>
private string _imageCachePath;
/// <summary>
/// Gets the image cache path.
/// </summary>
/// <value>The image cache path.</value>
public string ImageCachePath
{
get
{
if (_imageCachePath == null)
{
_imageCachePath = Path.Combine(CachePath, "images");
if (!Directory.Exists(_imageCachePath))
{
Directory.CreateDirectory(_imageCachePath);
}
}
return _imageCachePath;
}
}
/// <summary>
/// The _plugins path
/// </summary>
private string _pluginsPath;
/// <summary>
/// Gets the path to the plugin directory
/// </summary>
/// <value>The plugins path.</value>
public string PluginsPath
{
get
{
if (_pluginsPath == null)
{
_pluginsPath = Path.Combine(ProgramDataPath, "plugins");
if (!Directory.Exists(_pluginsPath))
{
Directory.CreateDirectory(_pluginsPath);
}
}
return _pluginsPath;
}
}
/// <summary>
/// The _plugin configurations path
/// </summary>
private string _pluginConfigurationsPath;
/// <summary>
/// Gets the path to the plugin configurations directory
/// </summary>
/// <value>The plugin configurations path.</value>
public string PluginConfigurationsPath
{
get
{
if (_pluginConfigurationsPath == null)
{
_pluginConfigurationsPath = Path.Combine(PluginsPath, "configurations");
if (!Directory.Exists(_pluginConfigurationsPath))
{
Directory.CreateDirectory(_pluginConfigurationsPath);
}
}
return _pluginConfigurationsPath;
}
}
private string _tempUpdatePath;
/// <summary>
/// Gets the path to where temporary update files will be stored
/// </summary>
/// <value>The plugin configurations path.</value>
public string TempUpdatePath
{
get
{
if (_tempUpdatePath == null)
{
_tempUpdatePath = Path.Combine(ProgramDataPath, "Updates");
if (!Directory.Exists(_tempUpdatePath))
{
Directory.CreateDirectory(_tempUpdatePath);
}
}
return _tempUpdatePath;
}
}
/// <summary>
/// The _log directory path
/// </summary>
private string _logDirectoryPath;
/// <summary>
/// Gets the path to the log directory
/// </summary>
/// <value>The log directory path.</value>
public string LogDirectoryPath
{
get
{
if (_logDirectoryPath == null)
{
_logDirectoryPath = Path.Combine(ProgramDataPath, "logs");
if (!Directory.Exists(_logDirectoryPath))
{
Directory.CreateDirectory(_logDirectoryPath);
}
}
return _logDirectoryPath;
}
}
/// <summary>
/// The _configuration directory path
/// </summary>
private string _configurationDirectoryPath;
/// <summary>
/// Gets the path to the application configuration root directory
/// </summary>
/// <value>The configuration directory path.</value>
public string ConfigurationDirectoryPath
{
get
{
if (_configurationDirectoryPath == null)
{
_configurationDirectoryPath = Path.Combine(ProgramDataPath, "config");
if (!Directory.Exists(_configurationDirectoryPath))
{
Directory.CreateDirectory(_configurationDirectoryPath);
}
}
return _configurationDirectoryPath;
}
}
/// <summary>
/// The _system configuration file path
/// </summary>
private string _systemConfigurationFilePath;
/// <summary>
/// Gets the path to the system configuration file
/// </summary>
/// <value>The system configuration file path.</value>
public string SystemConfigurationFilePath
{
get
{
return _systemConfigurationFilePath ?? (_systemConfigurationFilePath = Path.Combine(ConfigurationDirectoryPath, "system.xml"));
}
}
/// <summary>
/// The _cache directory
/// </summary>
private string _cachePath;
/// <summary>
/// Gets the folder path to the cache directory
/// </summary>
/// <value>The cache directory.</value>
public string CachePath
{
get
{
if (_cachePath == null)
{
_cachePath = Path.Combine(ProgramDataPath, "cache");
if (!Directory.Exists(_cachePath))
{
Directory.CreateDirectory(_cachePath);
}
}
return _cachePath;
}
}
/// <summary>
/// The _temp directory
/// </summary>
private string _tempDirectory;
/// <summary>
/// Gets the folder path to the temp directory within the cache folder
/// </summary>
/// <value>The temp directory.</value>
public string TempDirectory
{
get
{
if (_tempDirectory == null)
{
_tempDirectory = Path.Combine(CachePath, "temp");
if (!Directory.Exists(_tempDirectory))
{
Directory.CreateDirectory(_tempDirectory);
}
}
return _tempDirectory;
}
}
/// <summary>
/// Gets the path to the application's ProgramDataFolder
/// </summary>
/// <returns>System.String.</returns>
public static string GetProgramDataPath()
{
#if DEBUG
string programDataPath = ConfigurationManager.AppSettings["DebugProgramDataPath"];
#else
string programDataPath = Path.Combine(ConfigurationManager.AppSettings["ReleaseProgramDataPath"], ConfigurationManager.AppSettings["ProgramDataFolderName"]);
#endif
programDataPath = programDataPath.Replace("%CommonApplicationData%", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
// If it's a relative path, e.g. "..\"
if (!Path.IsPathRooted(programDataPath))
{
var path = Assembly.GetExecutingAssembly().Location;
path = Path.GetDirectoryName(path);
programDataPath = Path.Combine(path, programDataPath);
programDataPath = Path.GetFullPath(programDataPath);
}
if (!Directory.Exists(programDataPath))
{
Directory.CreateDirectory(programDataPath);
}
return programDataPath;
}
}
}
|