//------------------------------------------------------------------------------
//
// System.Environment.cs
//
// Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
//
// Author: Jim Richardson, develop@wtfo-guru.com
// Dan Lewis (dihlewis@yahoo.co.uk)
// Created: Saturday, August 11, 2001
//
//------------------------------------------------------------------------------
using System;
using System.IO;
//using System.Diagnostics;
using System.Collections;
using System.Security;
using System.Security.Permissions;
using System.Runtime.CompilerServices;
namespace System
{
public sealed class Environment
{
private Environment () {}
[MonoTODO]
public enum SpecialFolder
{ // TODO: Determine if these windoze style folder identifiers
// have unix/linux counterparts
Programs = 0x02,
Personal = 0x05,
Favorites = 0x06,
Startup = 0x07,
Recent = 0x08,
SendTo = 0x09,
StartMenu = 0x0b,
DesktopDirectory = 0x10,
Templates = 0x15,
ApplicationData = 0x1a,
LocalApplicationData = 0x1c,
InternetCache = 0x20,
Cookies = 0x21,
History = 0x22,
CommonApplicationData = 0x23,
System = 0x25,
ProgramFiles = 0x26,
CommonProgramFiles = 0x2b,
}
// TODO: Make sure the security attributes do what I expect
///
/// Gets the command line for this process
///
public static string CommandLine
{ // TODO: Coordinate with implementor of EnvironmentPermissionAttribute
// [EnvironmentPermissionAttribute(SecurityAction.Demand, Read = "COMMANDLINE")]
get
{
// FIXME: we may need to quote, but any sane person
// should use GetCommandLineArgs () instead.
return String.Join (" ", GetCommandLineArgs ());
}
}
///
/// Gets or sets the current directory. Actually this is supposed to get
/// and/or set the process start directory acording to the documentation
/// but actually test revealed at beta2 it is just Getting/Setting the CurrentDirectory
///
public static string CurrentDirectory
{
// originally it was my thought that the external call would be made in
// the directory class however that class has additional security requirements
// so the Directory class will call this class for its get/set current directory
// [EnvironmentPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
get
{
return MonoIO.GetCurrentDirectory ();
}
[MonoTODO("disabled because of compile error. Need mcs magic.")]
//[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
set
{
MonoIO.SetCurrentDirectory (value);
}
}
///
/// Gets or sets the exit code of this process
///
[MonoTODO]
public static int ExitCode
{ // TODO: find a way to implement this property
get
{
throw new NotImplementedException ();
}
set
{
throw new NotImplementedException ();
}
}
///
/// Gets the name of the local computer
///
public extern static string MachineName {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
get;
}
///
/// Gets the standard new line value
///
public extern static string NewLine {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
get;
}
///
/// Gets the current OS version information
///
[MonoTODO]
public static OperatingSystem OSVersion {
get
{
return null;
}
}
///
/// Get StackTrace
///
public static string StackTrace {
get {
try {
throw new Exception ();
} catch (Exception e) {
return e.StackTrace;
}
}
}
///
/// Get a fully qualified path to the system directory
///
public static string SystemDirectory
{
get
{
return GetFolderPath(SpecialFolder.System);
}
}
///
/// Get the number of milliseconds that have elapsed since the system was booted
///
public extern static int TickCount {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
get;
}
///
/// Get UserDomainName
///
[MonoTODO]
public static string UserDomainName {
get {
return MachineName;
}
}
///
/// Gets a flag indicating whether the process is in interactive mode
///
[MonoTODO]
public static bool UserInteractive
{
get
{
return false;
}
}
///
/// Get the user name of current process is running under
///
[MonoTODO]
public static string UserName
{
get
{
// TODO: needs more research/work/thought
string result = GetEnvironmentVariable("USERNAME");
if(result == null || result.Equals(string.Empty))
{
result = GetEnvironmentVariable("USER");
}
return result;
}
}
///
/// Get the version of the common language runtime
///
[MonoTODO]
public static Version Version {
get {
return new Version();
}
}
///
/// Get the amount of physical memory mapped to process
///
[MonoTODO]
public static long WorkingSet
{
get
{
return 0;
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static void Exit(int exitCode);
///
/// Substitute environment variables in the argument "name"
///
[MonoTODO]
public static string ExpandEnvironmentVariables(string name)
{
return name;
}
///
/// Return an array of the command line arguments of the current process
///
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static string[] GetCommandLineArgs();
///
/// Return a string containing the value of the environment
/// variable identifed by parameter "variable"
///
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static string GetEnvironmentVariable (string name);
///
/// Return a set of all environment variables and their values
///
public static IDictionary GetEnvironmentVariables()
{
Hashtable vars = new Hashtable ();
foreach (string name in GetEnvironmentVariableNames ())
vars [name] = GetEnvironmentVariable (name);
return vars;
}
///
/// Returns the fully qualified path of the
/// folder specified by the "folder" parameter
///
[MonoTODO]
public static string GetFolderPath(SpecialFolder folder)
{
return null;
}
///
/// Returns an array of the logical drives
///
[MonoTODO]
public static string[] GetLogicalDrives()
{
return null;
}
// private methods
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static string [] GetEnvironmentVariableNames ();
}
}