æä¸ç§ç®åçæ¹æ³æ¥æ¾å°å¨Windows Mobile设å¤ä¸çåå¨å¡çè·¯å¾ å½æåå¨å¡åèçFTPè¿æ¥ï¼
æ¬æå°å ï¼CodeGo.net/2314/
-------------------------------------------------------------------------------------------------------------------------Â
1. 请记ä½ï¼â\\åå¨å¡âæ¯è±æ为主ãé对ä¸åçåºååä¸ä¸ªè®¾å¤å¯è½ææç设å¤ä¸çåå¨å¡è·¯å¾ä¸åçæ¯å¦ä½ä¸æä¸åç设å¤ã 以åå¨MSDN表åæåçå ³äºå¦ä½æ£æµæ件系ç»çåå¨å¡åä¸ä¸ªäººå¦ä½å¾å°åå¨å¡ç容éçå 个é®é¢ãæåäºä¸é¢å¯è½æ¯å¯¹è¿äºé®é¢çååºï¼å¹¶è®¤ä¸ºè¿å°æ¯æççå享ãåå¨å¡æ¾ç¤ºå¨æ件系ç»ä¸´æ¶ç®å½ãè¿ä¸ªç¨åºä¼æ£æ¥è®¾å¤ï¼å¹¶å·²ä¸´æ¶å±æ§è¢«è®¤ä¸ºæ¯ä¸ä¸ªç§¯æçå¹é ä»»ä½æ件夹çæ ¹ç®å½ä¸ç对象
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace StorageCardInfo
{
class Program
{
const ulong Megabyte = 1048576;
const ulong Gigabyte = 1073741824;
[DllImport("CoreDLL")]
static extern int GetDiskFreeSpaceEx(
string DirectoryName,
out ulong lpFreeBytesAvailableToCaller,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes
);
static void Main(string[] args)
{
DirectoryInfo root = new DirectoryInfo("\\");
DirectoryInfo[] directoryList = root.GetDirectories();
ulong FreeBytesAvailable;
ulong TotalCapacity;
ulong TotalFreeBytes;
for (int i = 0; i < directoryList.Length; ++i)
{
if ((directoryList.Attributes & FileAttributes.Temporary) != 0)
{
GetDiskFreeSpaceEx(directoryList.FullName, out FreeBytesAvailable, out TotalCapacity, out TotalFreeBytes);
Console.Out.WriteLine("Storage card name: {0}", directoryList.FullName);
Console.Out.WriteLine("Available Bytes : {0}", FreeBytesAvailable);
Console.Out.WriteLine("Total Capacity : {0}", TotalCapacity);
Console.Out.WriteLine("Total Free Bytes : {0}", TotalFreeBytes);
}
}
}
}
2. æè½½ç¹â\\åå¨å¡âï¼ä½å¯ä»¥æ¬å°åä¸ºå ¶ä»è¯è¨ï¼æç±OEMä¿®æ¹ï¼â\\ SDå¡âæå ¶ä»æè½½ç¹ï¼å设å¤æ¯æå¤ç§å®è£ å°ç°æçå¡ CodeGo.netï¼æ好çæ¹æ³æ¯FindFirstFlashCardåFindNextFlashCardã è¿ä¸¤ä¸ªå½æ°å¡«åä¸ä¸ªWIN32_FIND_DATAç»æãæéè¦çé¢åæ¯å°å å«è·¯å¾å¡çæè½½ç¹ï¼å¦â\\åå¨å¡âï¼ã éè¦æ³¨æçæ¯è¯¥è£ ç½®çä¹å°éè¿è¿äºå½æ°ãå¦æä½ åªå¨ä¹å¤å¨å¿½ç¥çå°æ¹æ¯ä¸ä¸ªç©ºå符串çæ åµä¸ï¼ââï¼ã 使ç¨è¿äºå½æ°éè¦ä½ çï¼include <projects.h>ånote_prj.libé¾æ¥ã两è é½å å«å¨Windows Mobileç软件å¼åå·¥å ·å WM 2000åæ´é«çæ¬ãÂ
3. æå·²ç»å¨FindFirstFlashCard / FindNextFlashCardçAPI为æ¯ç®å½æ´å¯é åæ£æ¥ä¸´æ¶æ å¿ï¼å°è¿åèçå ±äº«æ件夹ä¸ï¼ã ä¸é¢ç示ä¾åºç¨ç¨åºæ¼ç¤ºäºå¦ä½åä»ä»¬æéè¦çP / Invoke
using System;
using System.Runtime.InteropServices;
namespace RemovableStorageTest
{
class Program
{
static void Main(string[] args)
{
string removableDirectory = GetRemovableStorageDirectory();
if (removableDirectory != null)
{
Console.WriteLine(removableDirectory);
}
else
{
Console.WriteLine("No removable drive found");
}
}
public static string GetRemovableStorageDirectory()
{
string removableStorageDirectory = null;
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))
{
removableStorageDirectory = findData.cFileName;
break;
}
}
while (FindNextFlashCard(handle, ref findData));
FindClose(handle);
}
return removableStorageDirectory;
}
public static readonly IntPtr INVALID_HANDLE_VALUE = (IntPtr)(-1);
// The CharSet must match the CharSet of the corresponding PInvoke signature
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public 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)]
public struct FILETIME
{
public int dwLowDateTime;
public int dwHighDateTime;
};
[DllImport("note_prj", EntryPoint = "FindFirstFlashCard")]
public extern static IntPtr FindFirstFlashCard(ref WIN32_FIND_DATA findData);
[DllImport("note_prj", EntryPoint = "FindNextFlashCard")]
[return: MarshalAs(UnmanagedType.Bool)]
public extern static bool FindNextFlashCard(IntPtr hFlashCard, ref WIN32_FIND_DATA findData);
[DllImport("coredll")]
public static extern bool FindClose(IntPtr hFindFile);
}
}
4. ä¸è½å¨TreeUKæ·»å åctackeå¦ä¸ï¼ è¿æ¯ä¸è½ä¿è¯æ¾å°ä¸ä¸ª åå¨å¡-许å¤è®¾å¤å®è£ å ç½®flashç¯ï¼å¨æ ¼å °æ¹å¼ï¼å® ä¼åºç°å¨è¿ä¸ªååä¹æ¯å¦æ¤ã- ctacke 5æ8æ¥å¨18:23 è¿æ å ³äºHTCåPsionå ¬å¸è¿ä½è¯å¥½ 设å¤ãä»ä¹è®¾å¤ï¼ä½ ç¥é è¿æ¯è¡ä¸éçï¼å°ä»·å¼ çæ¯å¦æå ¶ä»å±æ§ ä½ å¯ä»¥ææçå¨Flashä¸æ建 å åã-TreeUK 5æ9æ¥22:29 è¦æ¥çå ³äºæ©æç½æMC75ï¼ä»¥åæ¯ç¬¦å·ï¼ï¼è¿çï¼åçï¼ä»£ç çæ³æ³ï¼
WIN32_FIND_DATA cardinfo;
HANDLE card = FindFirstFlashCard(&cardinfo);
if (card != INVALID_HANDLE_VALUE)
{
TCHAR existFile[MAX_PATH];
wprintf(_T("found : %s\n"), cardinfo.cFileName);
while(FindNextFlashCard(card, &cardinfo))
{
wprintf(_T("found : %s\n"), cardinfo.cFileName);
}
}
FindClose(card);
è°è¯è¾åºï¼
cardinfo.dwFileAttributes 0x00000110 unsigned long int
cardinfo.cFileName "Application" wchar_t[260]
cardinfo.dwFileAttributes 0x00000110 unsigned long int
cardinfo.cFileName "Cache Disk" wchar_t[260]
cardinfo.dwFileAttributes 0x00000110 unsigned long int
cardinfo.cFileName "Storage Card" wchar_t[260]
âåºç¨ç¨åºâåâç£çç¼åâæ¯å é¨éªå驱å¨å¨ã âåå¨å¡âå¯ç§»å¨SDå¡ãææ被æ 记为ä¸ä¸ªéªåçä¸ï¼ä»ä»¬æ¯ï¼ï¼ä½åªæâåå¨å¡âæ¯å¯ç§»å¨çãÂ
5. æå¼ è´´å¨è¿éï¼è¦å¾å°çåå¨å¡å®è£ æ¾ç¤ºç®å½ç代ç ã å¨é£éæå¾å°çéªåå¡è·¯å¾çé¨åæ¯ä»Siblyçå¸åæä¸äºåå被å¤å¶ã 主è¦çåºå«æ¯å¨æç»åçææéªåå¡è£ å ¥æ¾ç¤ºç®å½æç´¢åæä¿æä¸ï¼sï¼å¹é ï¼æä»Windowsç注å表ä¸è¯»åé»è®¤çåå¨å¡ã å®è§£å³äºä¸ä¸ªäººå¯¹æ©æç½æçå°æ¹æå¤ä¸ªéªåå¡ï¼åªæä¸ä¸ªSDå¡è¯»å¡å¨ï¼å ¶å®è£ ç®å½çå¯ä»¥ä»é»è®¤çåç¼æ´æ¹ï¼å³è±æçWMç³»ç»æºè½è®¾å¤çé®é¢ï¼âåå¨å¡âï¼âåå¨å¡2 'çï¼ã æç¨WM 6.5çè±è¯æµè¯äºå®å¨æ©æç½ææºåï¼MC75ï¼MC75Aï¼MC90ï¼MC65ï¼ã è¿ä¸ªè§£å³æ¹æ¡åºè¯¥å·¥ä½ä»¥åä¸ä¸åçè¯è¨ï¼ä½æä¸ç¥éå®æ¯å¦è½ä¸é£äºæ¹åå¤ç é»è®¤çåå¨å¡ã è¿ä¸åé½åå³äºè®¾å¤å¶é åæ¯å¦æ´æ°Windows注å表ä¸æ°çé»è®¤ è¿å°æ¯å·¨å¤§çï¼å¦æä½ å¯ä»¥å¨ä¸åççªå£ç®¡çå¨æ设å¤è¿è¡æµè¯ã åé¦
//
// 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<string> GetMountDirs()
{
string key = @"HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\SDMemory";
string storageCardBaseName = Registry.GetValue(key, "Folder", "Storage Card") as String;
List<string> storageCards = new List<string>();
foreach (string flashCard in GetFlashCardMountDirs())
{
string path = flashCard.Trim();
if (path.StartsWith(storageCardBaseName))
{
storageCards.Add(path);
}
}
return storageCards;
}
private static List<string> GetFlashCardMountDirs()
{
List<string> storages = new List<string>();
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);
}
6. å¨Windows CE 5ï¼è¿æ¯åºæ¬çWindows Mobile 6ï¼åå¨å¡å¾å°å®è£ å¨æ ¹æ件系ç»ä¸ºâåå¨å¡\\âï¼âåå¨å¡2 \\âï¼ççã è¦äºè§£ï¼å¦ææ¯å®è£ è°ç¨GetFileAttributesï¼æè¿ç¨çæ¬CeGetFileAttributesæç¸ä¿¡ï¼ä¼ éçå®æ´è·¯å¾ï¼â\\åå¨å¡\\âï¼ãå¦ææ¯é£å°±ä¸æ¯è£ è¿åINVALID_FILE_ATTRIBUTESï¼å¦åæ£æ¥ï¼ä»¥ç¡®ä¿å®çè¿åtrueä¹åçç®å½ãÂ
7. æä¸ä¸ªçº¯Cï¼çæ¹å¼æ¥åå°è¿ä¸ç¹æ²¡ææ¬æºè°ç¨ã åèªè¿éã
//codesnippet:06EE3DE0-D469-44DD-A15F-D8AF629E4E03
public string GetStorageCardFolder()
{
string storageCardFolder = string.Empty;
foreach (string directory in Directory.GetDirectories("\\"))
{
DirectoryInfo dirInfo = new DirectoryInfo(directory);
//Storage cards have temporary attributes do a bitwise check.
// CodeGo.net
if ((dirInfo.Attributes & FileAttributes.Temporary) == FileAttributes.Temporary)
storageCardFolder = directory;
}
return storageCardFolder;
}
8. æä¸æ°ä¸é¢ç解å³æ¹æ¡ï¼ç¹å«æ¯qwliceç代ç ï¼åç°å¨å¤ç§è®¾å¤çSDå¡ã该解å³æ¹æ¡åç°çSDå¡åªï¼æ以æé¤äºææçå é¨âåå¨å¡â设å¤æï¼åçDLLè°ç¨ã 该代ç æç´¢HKEY_LOCAL_MACHINE \\ SYSTEM \\ StorageManager \\ Profilesæ件\\é®å å«âæ æ¸ â为ä¸ç设å¤ç¥æä¸åçé®ï¼æ¾å°é»è®¤çå®è£ ç®å½ï¼ç¶åæ¥æ¾å¼å¤´ä¸ºè¿ä¸ªä¸´æ¶ç®å½ãå®ä¼æ¾å°\\ StorageCard2ï¼\\ StorageCard3ç ææè¿æ ·çä¸ä¸ªèå´åMotorola / Symbol设å¤ï¼è¿æ²¡æä»»ä½é®é¢ãä¸é¢æ¯ä¸é¢ç代ç ï¼
public class StorageCardFinder
{
public static List<string> GetMountDirs()
{
//get default sd card folder name
string key = @"HKEY_LOCAL_MACHINE\System\StorageManager\Profiles";
RegistryKey profiles = Registry.LocalMachine.OpenSubKey(@"System\StorageManager\Profiles");
string sdprofilename = profiles.GetSubKeyNames().FirstOrDefault(k => k.Contains("SD"));
if (sdprofilename == null)
return new List<string>();
key += "\\" + sdprofilename;
string storageCardBaseName = Registry.GetValue(key, "Folder", "Storage Card") as String;
if (storageCardBaseName == null)
return new List<string>();
//find storage card
List<string> cardDirectories = GetFlashCardMountDirs();
List<string> storageCards = new List<string>();
foreach (string flashCard in GetFlashCardMountDirs())
{
string path = flashCard.Trim();
if (path.StartsWith(storageCardBaseName))
{
storageCards.Add("\\" + path);
}
}
return storageCards;
}
private static List<string> GetFlashCardMountDirs()
{
DirectoryInfo root = new DirectoryInfo("\\");
return root.GetDirectories().Where(d => (d.Attributes & FileAttributes.Temporary) != 0)
.Select(d => d.Name).ToList();
}
}
æ¬ææ é¢ ï¼æ¥æ¾åå¨å¡çè·¯å¾å¨WM6
æ¬æå°å ï¼CodeGo.net/2314/