-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Environment.iOS.cs
148 lines (121 loc) · 4.39 KB
/
Environment.iOS.cs
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
// Copyright 2014 Xamarin Inc.
// note: or older hack to give the Documents (or Library) directories
using System.IO;
using System.Runtime.InteropServices;
namespace System {
public static partial class Environment {
static string ns_document;
static string ns_library;
[DllImport ("__Internal")]
extern static string xamarin_GetFolderPath (int folder);
static string NSDocumentDirectory {
get {
if (ns_document == null) {
#if MONOTOUCH_TV
// The "normal" NSDocumentDirectory is a read-only directory on tvOS
// and that breaks a lot of assumptions in the runtime and the BCL
// to avoid this we relocate the Documents directory under Caches
ns_document = Path.Combine (NSLibraryDirectory, "Caches", "Documents");
if (!Directory.Exists (ns_document))
Directory.CreateDirectory (ns_document);
#else
ns_document = xamarin_GetFolderPath (/* NSDocumentDirectory */ 9);
#endif
}
return ns_document;
}
}
// Various user-visible documentation, support, and configuration files
static string NSLibraryDirectory {
get {
if (ns_library == null)
ns_library = xamarin_GetFolderPath (/* NSLibraryDirectory */ 5);
return ns_library;
}
}
public static string GetFolderPath (SpecialFolder folder, SpecialFolderOption option)
{
return UnixGetFolderPath (folder, option);
}
// needed by our BCL, e.g. IsolatedStorageFile.cs
internal static string UnixGetFolderPath (SpecialFolder folder, SpecialFolderOption option)
{
var dir = iOSGetFolderPath (folder);
if ((option == SpecialFolderOption.Create) && !Directory.Exists (dir))
Directory.CreateDirectory (dir);
return dir;
}
internal static string iOSGetFolderPath (SpecialFolder folder)
{
switch (folder) {
case SpecialFolder.MyComputer:
case SpecialFolder.Programs:
case SpecialFolder.SendTo:
case SpecialFolder.StartMenu:
case SpecialFolder.Startup:
case SpecialFolder.Cookies:
case SpecialFolder.History:
case SpecialFolder.Recent:
case SpecialFolder.CommonProgramFiles:
case SpecialFolder.System:
case SpecialFolder.NetworkShortcuts:
case SpecialFolder.CommonStartMenu:
case SpecialFolder.CommonPrograms:
case SpecialFolder.CommonStartup:
case SpecialFolder.CommonDesktopDirectory:
case SpecialFolder.PrinterShortcuts:
case SpecialFolder.Windows:
case SpecialFolder.SystemX86:
case SpecialFolder.ProgramFilesX86:
case SpecialFolder.CommonProgramFilesX86:
case SpecialFolder.CommonDocuments:
case SpecialFolder.CommonAdminTools:
case SpecialFolder.AdminTools:
case SpecialFolder.CommonMusic:
case SpecialFolder.CommonPictures:
case SpecialFolder.CommonVideos:
case SpecialFolder.LocalizedResources:
case SpecialFolder.CommonOemLinks:
case SpecialFolder.CDBurning:
return String.Empty;
// personal == ~
case SpecialFolder.Personal:
case SpecialFolder.LocalApplicationData:
return NSDocumentDirectory;
case SpecialFolder.ApplicationData:
// note: at first glance that looked like a good place to return NSLibraryDirectory
// but it would break isolated storage for existing applications
return Path.Combine (NSDocumentDirectory, ".config");
case SpecialFolder.Resources:
return NSLibraryDirectory; // older (8.2 and previous) would return String.Empty
case SpecialFolder.Desktop:
case SpecialFolder.DesktopDirectory:
return Path.Combine (NSDocumentDirectory, "Desktop");
case SpecialFolder.MyMusic:
return Path.Combine (NSDocumentDirectory, "Music");
case SpecialFolder.MyPictures:
return Path.Combine (NSDocumentDirectory, "Pictures");
case SpecialFolder.Templates:
return Path.Combine (NSDocumentDirectory, "Templates");
case SpecialFolder.MyVideos:
return Path.Combine (NSDocumentDirectory, "Videos");
case SpecialFolder.CommonTemplates:
return "/usr/share/templates";
case SpecialFolder.Fonts:
return Path.Combine (NSDocumentDirectory, ".fonts");
case SpecialFolder.Favorites:
return Path.Combine (NSLibraryDirectory, "Favorites");
case SpecialFolder.ProgramFiles:
return "/Applications";
case SpecialFolder.InternetCache:
return Path.Combine (NSLibraryDirectory, "Caches");
case SpecialFolder.UserProfile:
return internalGetHome ();
case SpecialFolder.CommonApplicationData:
return "/usr/share";
default:
throw new ArgumentException ("Invalid SpecialFolder");
}
}
}
}