[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System Environment.cs, 1.15,
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System Environment.cs, 1.15, 1.16 |
Date: |
Tue, 19 Aug 2003 23:31:05 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System
In directory subversions:/tmp/cvs-serv19651/runtime/System
Modified Files:
Environment.cs
Log Message:
Clean up the implementation of "Environment.GetFolderPath".
Index: Environment.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Environment.cs,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** Environment.cs 1 Aug 2003 17:53:07 -0000 1.15
--- Environment.cs 20 Aug 2003 03:31:03 -0000 1.16
***************
*** 331,379 ****
}; // enum SpecialFolder
// Get a path to a specific system folder.
public static String GetFolderPath(SpecialFolder folder)
{
! if (Environment.OSVersion.Platform !=
(PlatformID)128/*PlatformID.Unix*/)
{
! // TODO: when auto-selection of
ANSI/Unicode version of DLL functions
! // will be implemented, do not
explicitely call the ANSI/Unicode
! // versions of SHGetFolderPath any more
try
{
! // TODO?: should the allocation
size be multiplied by 2 because of unicode chars ?
! IntPtr pathPtr=
Marshal.AllocHGlobal(260/*MAX_PATH*/ + 1);
! SHGetFolderPathW(IntPtr.Zero,
(Int32)folder, IntPtr.Zero, 0, pathPtr);
! String path=
Marshal.PtrToStringUni(pathPtr);
! Marshal.FreeHGlobal(pathPtr);
! return path;
! }
! catch (System.MissingMethodException e)
! {
! // SHGetFolderPathW could not
be found in the DLL
! try
! {
! IntPtr pathPtr=
Marshal.AllocHGlobal(260/*MAX_PATH*/ + 1);
!
SHGetFolderPathA(IntPtr.Zero, (Int32)folder, IntPtr.Zero, 0, pathPtr);
! String path=
Marshal.PtrToStringAnsi(pathPtr);
!
Marshal.FreeHGlobal(pathPtr);
! return path;
! }
! catch
(System.MissingMethodException e)
{
! // SHGetFolderPathA
could not be found in the DLL
! return String.Empty;
}
}
! catch (System.DllNotFoundException e)
{
! // shell32.dll could not be
found
! return String.Empty;
}
}
! else
{
! // TODO?: try to implement something
similar for non-Win32 platforms
! return String.Empty;
}
}
--- 331,381 ----
}; // enum SpecialFolder
+ // Import the Win32 SHGetFolderPathA function from "shell32.dll"
+ [DllImport("shell32.dll", CallingConvention=CallingConvention.Winapi)]
+ [MethodImpl(MethodImplOptions.PreserveSig)]
+ extern private static Int32 SHGetFolderPathA
+ (IntPtr hwndOwner, int nFolder, IntPtr hToken,
+ uint dwFlags, IntPtr path);
+
// Get a path to a specific system folder.
public static String GetFolderPath(SpecialFolder folder)
{
! // We can use the operating system under Win32.
! if(InfoMethods.GetPlatformID() !=
PlatformID.Unix)
{
! // Allocate a buffer to hold the result
path.
! IntPtr buffer =
Marshal.AllocHGlobal(260 /*MAX_PATH*/ + 1);
!
! // Call "SHGetFolderPath" to retrieve
the path.
try
{
! SHGetFolderPathA(IntPtr.Zero,
(int)folder,
!
IntPtr.Zero, 0, buffer);
! String value =
Marshal.PtrToStringAnsi(buffer);
! if(value != null &&
value.Length != 0)
{
!
Marshal.FreeHGlobal(buffer);
! return value;
}
}
! catch(Exception)
{
! // We weren't able to find the
function in the DLL.
}
+ Marshal.FreeHGlobal(buffer);
}
!
! // Special handling for the
"SpecialFolder.System" case.
! if(folder == SpecialFolder.System)
{
! String dir =
DirMethods.GetSystemDirectory();
! if(dir != null)
! {
! return dir;
! }
}
+
+ // The empty string indicates that the value is
not present.
+ return String.Empty;
}
***************
*** 661,677 ****
};
- // Import the Win32 SHGetFolderPathA function from "shell32.dll"
- [DllImport("shell32.dll",CallingConvention=CallingConvention.Winapi)]
- [MethodImpl(MethodImplOptions.PreserveSig)]
- extern private static Int32 SHGetFolderPathA
- (IntPtr hwndOwner, Int32 nFolder, IntPtr hToken,
- UInt32 dwFlags, IntPtr path);
-
- // Import the Win32 SHGetFolderPathW function from "shell32.dll"
- [DllImport("shell32.dll",CallingConvention=CallingConvention.Winapi)]
- [MethodImpl(MethodImplOptions.PreserveSig)]
- extern private static Int32 SHGetFolderPathW
- (IntPtr hwndOwner, Int32 nFolder, IntPtr hToken,
- UInt32 dwFlags, IntPtr path);
}; // class Environment
--- 663,666 ----
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System Environment.cs, 1.15, 1.16,
Rhys Weatherley <address@hidden> <=