[
] 一山還有一山高,一部還比一部糟
如果你看到 Chiru 的 Golimar 或《油內褲》,就已經在心中為印度電影(或是比較精確的說,Telugu 電影)貼上了某種標籤,給了某種評價…這只代表一件事情—你還沒有看過芭樂克利希那(Balakrishna)的作品啊!
] 一山還有一山高,一部還比一部糟
如果你看到 Chiru 的 Golimar 或《油內褲》,就已經在心中為印度電影(或是比較精確的說,Telugu 電影)貼上了某種標籤,給了某種評價…這只代表一件事情—你還沒有看過芭樂克利希那(Balakrishna)的作品啊!
] 在使用 .Net Framwork 時讀取 MediaPath 目錄中的內容(續)
(續前篇)Windows 系統中,關於系統音效檔案位置的相關資訊,是寫在 Registry 中,不過,如果是照著前篇實作,應該(會像我一樣)很快就會發現一個問題:在 Windows Vista 裡頭,這段資訊的寫法,與 Windows XP 不太一樣:Windows XP 寫在 MediaPath 這個字串值裡頭,Windows Vista 則是寫在 MediaPathUnexpanded 裡頭。
所以,要抓取 Windows Vista 的系統音效目錄,要用下面這段 code:
RegistryKey registryKey = Registry.LocalMachine;
registryKey = registryKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion", false);
string MediaPathUnexpanded = registryKey.GetValue("MediaPathUnexpanded").ToString();
m_mediaPath = Environment.ExpandEnvironmentVariables(MediaPathUnexpanded);
另外,就是要判斷現在到底是在 Windows Vista 上,還是 XP 上:
public static bool IsVistaOrLater
{
get
{
return Environment.OSVersion.Platform ==
PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6;
}
}public static bool IsXp
{
get
{
return Environment.OSVersion.Platform ==
PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 5;
}
}
] 在使用 .Net framwork 時讀取 MediaPath 目錄中的內容
在 Windows 作業系統中,會將一些預設的系統音效檔案,裝在 Windows 安裝目錄下的 Media 目錄裡頭—比方說,如果你將 WIndows XP 裝在C:\Windows 目錄下,那麼,就是 C:\Windows\media 這個目錄。如果您想要使用一些系統內建的音效檔案,除了 System.Media.SystemSounds 之外,大概就得往這個目錄找。
然而這個目錄不一定會是在同一個位置,因為 WIndows 系統很有可能安裝在其他的地方,System.Environment.SpecialFolder 所提供的幾個提供特殊目錄的路徑 Class Method 中,又剛好沒有提供 Media 這個目錄的路徑位置。
在 .Net Framework 中,想要知道這個路徑究竟該是哪個位置,就只能夠往 registry 動腦筋,至少我們可以從 registry 設定中,找到這筆資料。如果要透過 C# 實做,首先我們要引入 Microsoft.Win32 這個 name space:
using Microsoft.Win32;
然後使用 RegistryKey 這個類別,讀取 registry。
RegistryKey registryKey = Registry.LocalMachine;
registryKey = registryKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion", false);
string m_mediaPath = registryKey.GetValue("MediaPath").ToString();
最後就可以取得音效檔案的列表了。
DirectoryInfo dirInfo = new DirectoryInfo(m_mediaPath);
FileInfo[] fileInfo = dirInfo.GetFiles("*.wav");