using System.Security;
using System.Security.Permissions;
using System.Text;
+using System.Runtime.InteropServices;
namespace System {
+#if NET_2_0
+ [ComVisible (true)]
+#endif
#if NET_2_0
public static class Environment {
#else
* Changes which are already detected at runtime, like the addition
* of icalls, do not require an increment.
*/
- private const int mono_corlib_version = 54;
+ private const int mono_corlib_version = 67;
public enum SpecialFolder
{ // TODO: Determine if these windoze style folder identifiers
public static string StackTrace {
[EnvironmentPermission (SecurityAction.Demand, Unrestricted=true)]
get {
- System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace (1, true);
+ System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace (0, true);
return trace.ToString ();
}
}
return dir;
}
+ private static string ReadXdgUserDir (string config_dir, string home_dir,
+ string key, string fallback)
+ {
+ string env_path = internalGetEnvironmentVariable (key);
+ if (env_path != null && env_path != String.Empty) {
+ return env_path;
+ }
+
+ string user_dirs_path = Path.Combine (config_dir, "user-dirs.dirs");
+
+ if (!File.Exists (user_dirs_path)) {
+ return Path.Combine (home_dir, fallback);
+ }
+
+ try {
+ using(StreamReader reader = new StreamReader (user_dirs_path)) {
+ string line;
+ while ((line = reader.ReadLine ()) != null) {
+ line = line.Trim ();
+ int delim_index = line.IndexOf ('=');
+ if(delim_index > 8 && line.Substring (0, delim_index) == key) {
+ string path = line.Substring (delim_index + 1).Trim ('"');
+ bool relative = false;
+
+ if (path.StartsWith ("$HOME/")) {
+ relative = true;
+ path = path.Substring (6);
+ } else if (!path.StartsWith ("/")) {
+ relative = true;
+ }
+
+ return relative ? Path.Combine (home_dir, path) : path;
+ }
+ }
+ }
+ } catch (FileNotFoundException) {
+ }
+
+ return Path.Combine (home_dir, fallback);
+ }
+
+
// the security runtime (and maybe other parts of corlib) needs the
// information to initialize themselves before permissions can be checked
internal static string InternalGetFolderPath (SpecialFolder folder)
case SpecialFolder.Desktop:
#endif
case SpecialFolder.DesktopDirectory:
- return Path.Combine (home, "Desktop");
+ return ReadXdgUserDir (config, home, "XDG_DESKTOP_DIR", "Desktop");
case SpecialFolder.MyMusic:
- return Path.Combine (home, "Music");
+ return ReadXdgUserDir (config, home, "XDG_MUSIC_DIR", "Music");
+
+ case SpecialFolder.MyPictures:
+ return ReadXdgUserDir (config, home, "XDG_PICTURES_DIR", "Pictures");
// these simply dont exist on Linux
// The spec says if a folder doesnt exist, we
case SpecialFolder.SendTo:
case SpecialFolder.StartMenu:
case SpecialFolder.Startup:
- case SpecialFolder.MyPictures:
case SpecialFolder.Templates:
case SpecialFolder.Cookies:
case SpecialFolder.History:
return GetLogicalDrivesInternal ();
}
- // FIXME: Anyone using this anywhere ?
- static internal string GetResourceString (string s) { return String.Empty; }
-
-
#if NET_2_0
public static string GetEnvironmentVariable (string variable, EnvironmentVariableTarget target)
{
if (!IsRunningOnWindows)
return;
using (Microsoft.Win32.RegistryKey env = Microsoft.Win32.Registry.LocalMachine.OpenSubKey (@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", true)) {
- if (value == null || value.Length == 0)
+ if (String.IsNullOrEmpty (value))
env.DeleteValue (variable, false);
else
env.SetValue (variable, value);
if (!IsRunningOnWindows)
return;
using (Microsoft.Win32.RegistryKey env = Microsoft.Win32.Registry.CurrentUser.OpenSubKey ("Environment", true)) {
- if (value == null || value.Length == 0)
+ if (String.IsNullOrEmpty (value))
env.DeleteValue (variable, false);
else
env.SetValue (variable, value);