4 using System.Diagnostics;
7 using System.Reflection;
8 using SiliconStudio.Core.IO;
10 namespace SiliconStudio.Core
17 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
21 public static readonly
PlatformType Type = PlatformType.Windows;
22 #elif SILICONSTUDIO_PLATFORM_WINDOWS_PHONE
26 public static readonly
PlatformType Type = PlatformType.WindowsPhone;
27 #elif SILICONSTUDIO_PLATFORM_WINDOWS_STORE
31 public static readonly
PlatformType Type = PlatformType.WindowsStore;
32 #elif SILICONSTUDIO_PLATFORM_ANDROID
36 public static readonly
PlatformType Type = PlatformType.Android;
37 #elif SILICONSTUDIO_PLATFORM_IOS
41 public static readonly
PlatformType Type = PlatformType.iOS;
48 public static readonly
bool IsWindowsDesktop = Type == PlatformType.Windows;
53 public static readonly
bool IsRunningDebugAssembly = GetIsRunningDebugAssembly();
58 public static string TemporaryDirectory = GetTemporaryDirectory();
63 public static string ApplicationTemporaryDirectory = GetApplicationTemporaryDirectory();
68 public static readonly
string ApplicationLocalDirectory = GetApplicationLocalDirectory();
73 public static readonly
string ApplicationRoamingDirectory = GetApplicationRoamingDirectory();
78 public static readonly
string ApplicationCacheDirectory = GetApplicationCacheDirectory();
84 public static readonly
string ApplicationDataDirectory = GetApplicationDataDirectory();
90 public static string ApplicationDataSubDirectory
92 get {
return applicationDataSubDirectory; }
95 if (virtualFileSystemInitialized)
96 throw new InvalidOperationException(
"ApplicationDataSubDirectory cannot be modified after the VirtualFileSystem has been initialized.");
98 applicationDataSubDirectory = value;
106 public static readonly
string ApplicationBinaryDirectory = GetApplicationBinaryDirectory();
108 public static readonly
string ApplicationExecutablePath = GetApplicationExecutablePath();
110 private static string applicationDataSubDirectory =
"";
112 private static bool virtualFileSystemInitialized;
113 public static bool IsVirtualFileSystemInitialized
117 return virtualFileSystemInitialized;
121 virtualFileSystemInitialized = value;
125 private static string GetApplicationLocalDirectory()
127 #if SILICONSTUDIO_PLATFORM_ANDROID
128 var directory = Path.Combine(PlatformAndroid.Context.FilesDir.AbsolutePath,
"local");
129 Directory.CreateDirectory(directory);
131 #elif SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
132 return Windows.Storage.ApplicationData.Current.LocalFolder.Path;
133 #elif SILICONSTUDIO_PLATFORM_IOS
134 var directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"..",
"Library",
"Local");
135 Directory.CreateDirectory(directory);
139 var directory = Path.Combine(GetApplicationBinaryDirectory(),
"local");
140 Directory.CreateDirectory(directory);
145 private static string GetApplicationRoamingDirectory()
147 #if SILICONSTUDIO_PLATFORM_ANDROID
148 var directory = Path.Combine(PlatformAndroid.Context.FilesDir.AbsolutePath,
"roaming");
149 Directory.CreateDirectory(directory);
151 #elif SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
152 return Windows.Storage.ApplicationData.Current.RoamingFolder.Path;
153 #elif SILICONSTUDIO_PLATFORM_IOS
154 var directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"..",
"Library",
"Roaming");
155 Directory.CreateDirectory(directory);
159 var directory = Path.Combine(GetApplicationBinaryDirectory(),
"roaming");
160 Directory.CreateDirectory(directory);
165 private static string GetApplicationCacheDirectory()
167 #if SILICONSTUDIO_PLATFORM_ANDROID
168 var directory = Path.Combine(PlatformAndroid.Context.FilesDir.AbsolutePath,
"cache");
169 Directory.CreateDirectory(directory);
171 #elif SILICONSTUDIO_PLATFORM_WINDOWS_STORE
172 var directory = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path,
"cache");
173 NativeFile.DirectoryCreate(directory);
175 #elif SILICONSTUDIO_PLATFORM_WINDOWS_PHONE
176 return Windows.Storage.ApplicationData.Current.LocalCacheFolder.Path;
177 #elif SILICONSTUDIO_PLATFORM_IOS
178 var directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"..",
"Library",
"Caches");
179 Directory.CreateDirectory(directory);
183 var directory = Path.Combine(GetApplicationBinaryDirectory(),
"cache");
184 Directory.CreateDirectory(directory);
189 private static string GetApplicationExecutablePath()
191 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP || SILICONSTUDIO_PLATFORM_MONO_MOBILE
192 return (Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly()).Location;
193 #elif SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
194 return Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path,
"ParadoxGame.exe");
196 throw new NotImplementedException();
200 private static string GetTemporaryDirectory()
202 return GetApplicationTemporaryDirectory();
205 private static string GetApplicationTemporaryDirectory()
207 #if SILICONSTUDIO_PLATFORM_ANDROID
208 return PlatformAndroid.Context.CacheDir.AbsolutePath;
209 #elif SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
210 return Windows.Storage.ApplicationData.Current.TemporaryFolder.Path;
211 #elif SILICONSTUDIO_PLATFORM_IOS
212 return Path.Combine (Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"..",
"tmp");
214 return Path.GetTempPath();
218 private static string GetApplicationBinaryDirectory()
220 var result = Path.GetDirectoryName(GetApplicationExecutablePath());
221 if (result ==
string.Empty)
227 private static string GetApplicationDataDirectory()
229 #if SILICONSTUDIO_PLATFORM_ANDROID
230 return Android.OS.Environment.ExternalStorageDirectory.AbsolutePath +
"/Android/data/" + PlatformAndroid.Context.PackageName +
"/data";
231 #elif SILICONSTUDIO_PLATFORM_IOS
232 return MonoTouch.Foundation.NSBundle.MainBundle.BundlePath +
"/data";
233 #elif SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
234 return Windows.ApplicationModel.Package.Current.InstalledLocation.Path +
@"\data";
236 return Path.Combine(Directory.GetCurrentDirectory(),
"data");
240 private static bool GetIsRunningDebugAssembly()
242 #if SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
245 var entryAssembly = Assembly.GetEntryAssembly();
246 if (entryAssembly != null)
248 var debuggableAttribute = entryAssembly.GetCustomAttributes(typeof(DebuggableAttribute)).OfType<DebuggableAttribute>().FirstOrDefault();
249 if (debuggableAttribute != null)
251 return (debuggableAttribute.DebuggingFlags & DebuggableAttribute.DebuggingModes.DisableOptimizations) != 0;
PlatformType
Describes the platform operating system.