//From my game
public static class Vista
{
public static bool IsVista = (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6);
public static readonly Guid SavedGames = new Guid("4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4");
//You could add more, but most of them are natively supported by Environment.SpecialFolder.
public static string GetKnownFolderPath(Guid target)
{
if (!IsVista)
return null;
string ret = null;
IntPtr pPath;
try
{
if (SafeNativeMethods.SHGetKnownFolderPath(SavedGames, 0, IntPtr.Zero, out pPath) == 0)
{
ret = System.Runtime.InteropServices.Marshal.PtrToStringUni(pPath);
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(pPath);
}
return ret;
}
catch (DllNotFoundException)
{
return null;
}
}
}
internal static class SafeNativeMethods
{
[DllImport("shell32.dll")]
public static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, IntPtr hToken, out IntPtr pszPath);
}
//Untested -- savePath will be "Saved Games\foo", "AppData\Local\foo", or "~/.config/foo" depending on the OS.
savePath = Path.Combine(Vista.GetKnownFolderPath(Vista.SavedGames) ?? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), gameName);