Is there an easy way to find the storage card\'s path on a Windows Mobile device when there is a storage card and a bluetooth ftp connection?
I post here the code that I use to get the mount dirs of the storage cards. The part where I get the flash cards paths is copied from Sibly's post with a few changes.
The main difference is in that I search through the mount dirs of all the flash cards and I keep the one(s) that match the default storage card name that I read from windows' registry.
It solves the problem that one has on motorola's smart devices where there are multiple flash cards and only one sd card reader whose mount dir's name can change from the default by the numeric suffix (ie. in english WM systems: 'Storage Card' , 'Storage Card2' and so on). I tested it on some motorola models (MC75, MC75A, MC90, MC65) with WM 6.5 english.
This solution should work well with different windows mobile's languages but I don't know if it can deal with those that change the default name of the storage cards. It all depends whether the device's manufacturer updates the windows registry with the new default name.
It would be great if you can test it on different WMs or devices. Feedback is welcome.
//
// the storage card is a flash drive mounted as a directory in the root folder
// of the smart device
//
// on english windows mobile systems the storage card is mounted in the directory "/Storage Card",
// if that directory already exists then it's mounted in "/Storage Card2" and so on
//
// the regional name of the mount base dir of the storage card can be found in
// the registry at [HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\SDMemory\Folder]
//
// in order to find the path of the storage card we look for the flash drive that starts
// with the base name
//
public class StorageCard
{
private StorageCard()
{
}
public static List GetMountDirs()
{
string key = @"HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\SDMemory";
string storageCardBaseName = Registry.GetValue(key, "Folder", "Storage Card") as String;
List storageCards = new List();
foreach (string flashCard in GetFlashCardMountDirs())
{
string path = flashCard.Trim();
if (path.StartsWith(storageCardBaseName))
{
storageCards.Add(path);
}
}
return storageCards;
}
private static List GetFlashCardMountDirs()
{
List storages = new List();
WIN32_FIND_DATA findData = new WIN32_FIND_DATA();
IntPtr handle = IntPtr.Zero;
handle = FindFirstFlashCard(ref findData);
if (handle != INVALID_HANDLE_VALUE)
{
do
{
if (!string.IsNullOrEmpty(findData.cFileName))
{
storages.Add(findData.cFileName);
storages.Add(findData.cAlternateFileName);
}
}
while (FindNextFlashCard(handle, ref findData));
FindClose(handle);
}
return storages;
}
private static readonly IntPtr INVALID_HANDLE_VALUE = (IntPtr)(-1);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
private struct WIN32_FIND_DATA
{
public int dwFileAttributes;
public FILETIME ftCreationTime;
public FILETIME ftLastAccessTime;
public FILETIME ftLastWriteTime;
public int nFileSizeHigh;
public int nFileSizeLow;
public int dwOID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string cFileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
public string cAlternateFileName;
}
[StructLayout(LayoutKind.Sequential)]
private struct FILETIME
{
public int dwLowDateTime;
public int dwHighDateTime;
};
[DllImport("note_prj", EntryPoint = "FindFirstFlashCard")]
private extern static IntPtr FindFirstFlashCard(ref WIN32_FIND_DATA findData);
[DllImport("note_prj", EntryPoint = "FindNextFlashCard")]
[return: MarshalAs(UnmanagedType.Bool)]
private extern static bool FindNextFlashCard(IntPtr hFlashCard, ref WIN32_FIND_DATA findData);
[DllImport("coredll")]
private static extern bool FindClose(IntPtr hFindFile);
}