?? cdinfo.cpp
字號:
////////////////////////////////////////////////////////////////
// MSDN Magazine -- April 2004
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual Studio .NET on Windows XP. Tab size=3.
//
#include "stdafx.h"
#include "IMAPITools.h"
#include "PropStgEnum.h"
using namespace IMAPITools;
// command-line flags
const enum {
FRI_TERSE = 0,
FRI_LIST_RECORDERS = 0x1,
FRI_LIST_RECORDER_PROPS = 0x2,
FRI_LIST_JOLIET_PROPS = 0x4,
FRI_ALL = 0xFFFF
};
CString FormatRecorderInfo(DWORD flags);
CString FormatRecorderProps(CDiscRecorder& dr);
CString FormatJolietProps(CJolietDiscMaster& jdm);
// check for switch: / or -
inline BOOL isswitch(TCHAR c) { return c==_T('/') || c==_T('-'); }
static void help();
//////////////////
// Main entry point: parse switches before calling FormatRecorderInfo
//
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
DWORD flags = 0;
// Parse command line. Switches can come in any order.
for (int i=1; i<argc; i++) {
if (isswitch(argv[i][0])) {
for (UINT j=1; j<_tcslen(argv[i]); j++) {
switch(argv[i][j]) {
case _T('A'): case _T('a'):
flags |= FRI_LIST_RECORDERS;
break;
case _T('P'): case _T('p'):
flags |= FRI_LIST_RECORDER_PROPS|FRI_LIST_RECORDERS;
break;
case _T('J'): case _T('j'):
flags |= FRI_LIST_JOLIET_PROPS|FRI_LIST_RECORDERS;
break;
case _T('V'): case _T('v'):
flags |= FRI_ALL;
break;
case _T('?'):
default:
help();
return 0;
}
}
} else {
help();
return 0;
}
}
CoInitialize(0); // initialize COM
if (flags) {
_ftprintf(stderr,_T("Please wait...\n"));
}
_tprintf(FormatRecorderInfo(flags));
return 0;
}
//////////////////
// Format information about recorders into a string suitable for printf.
//
CString FormatRecorderInfo(DWORD flags)
{
CString str,temp;
// ICDBurn is the interface to see if writable CD exists
CCDBurn cdb;
if (!cdb.HasRecordableDrive()) {
str += _T("No recordable drive.\n");
return str;
}
// drive letter
CString dl = cdb.GetRecorderDriveLetter();
temp.Format(_T("Default Recorder drive letter = %s\n"),
SUCCEEDED(cdb.m_hr) ? (LPCTSTR)dl : _T("**undefined**"));
str += temp;
// burn path
temp.Format(_T("Burn path = %s\n"), (LPCTSTR)cdb.GetBurnFolderPath());
str += temp;
if (flags==FRI_TERSE) {
return str;
}
CDiscMaster dm; // IDiscMaster
if (!dm.Open()) {
temp.Format(_T("**Can't open DiscMaster: %s.\n"), GetErrorName(dm.m_hr));
str += temp;
return str;
}
// current active format
IID iidActive = dm.GetActiveDiscMasterFormat();
// list supported formats
const MAXNFORMATS = 10; // I've never seen more than 2
IID formats[MAXNFORMATS];
int nFormats = dm.GetSupportedFormats(formats,MAXNFORMATS);
str += _T("Formats supported:\n");
for (int i=0; i<nFormats; i++) {
temp.Format(_T(" %s"), GetFormatName(formats[i]));
str += temp;
if (formats[i] == iidActive)
str += _T(" ACTIVE");
str += _T("\n");
}
if (!(flags & FRI_LIST_RECORDERS))
return str;
int count=1;
CDiscRecorder dr;
CDiscRecorderIterator itr(dm);
while (itr.Next(dr)) {
temp.Format(_T("Recorder #%d: \n"), count);
str += temp;
// Not really a GUID at all, just a long cryptic string.
// temp.Format(_T(" Guid: %s\n"), (LPCTSTR)dr.GetRecorderGUID());
// str += temp;
temp.Format(_T(" PnP ID: %s\n"), (LPCTSTR)dr.GetBasePnPID());
str += temp;
temp.Format(_T(" Type: %s\n"),
(LPCTSTR)GetRecorderTypeName(dr.GetRecorderType()));
str += temp;
temp.Format(_T(" Path: %s\n"), (LPCTSTR)dr.GetPath());
str += temp;
DISPLAYNAMES dn;
dr.GetDisplayNames(dn);
temp.Format(_T(" Vendor: %s\n"),(LPCTSTR)dn.vendor);
str += temp;
temp.Format(_T(" Product: %s\n"),(LPCTSTR)dn.product);
str += temp;
temp.Format(_T(" Revision: %s\n"),(LPCTSTR)dn.revision);
str += temp;
if (dr.OpenExclusive()) {
temp.Format(_T(" State: %s\n"), GetRecorderStateName(dr.GetRecorderState()));
str += temp;
long mtype, mflags;
if (dr.QueryMediaType(mtype, mflags)) {
temp.Format(_T(" Media Type: %s=%d\n"),GetMediaTypeName(mtype),mtype);
str += temp;
temp.Format(_T(" Media Flags: %s=%d\n"),GetMediaFlagsName(mflags),mflags);
str += temp;
} else {
temp.Format(_T(" **Unable to query media type, hr=%s\n"),
GetErrorName(dr.m_hr));
str += temp;
}
MEDIAINFO mi;
if (dr.QueryMediaInfo(mi)) {
temp.Format(_T(" Media Info: nSes=%d LastTrack=%d Start=%d Next=%d Free=%d\n"),
mi.nSessions,
mi.nLastTrack,
mi.nStartAddress,
mi.nNextWritable,
mi.nFreeBlocks);
str += temp;
} else {
temp.Format(_T(" **Unable to query media info, hr=%s\n"),
GetErrorName(dr.m_hr));
str += temp;
}
dr.Close();
} else {
temp.Format(_T(" **Unable to open exclusive, hr=%p\n"), dr.m_hr);
str += temp;
}
if (flags & FRI_LIST_RECORDER_PROPS) {
str += FormatRecorderProps(dr);
}
if (flags & FRI_LIST_JOLIET_PROPS) {
dm.SetActiveDiscRecorder(dr);
CJolietDiscMaster jdm(dm);
str += FormatJolietProps(jdm);
}
count++;
}
return str;
}
//////////////////
// Format recorder information.
//
CString FormatDiscRecorderInfo(CDiscRecorder& dr,DWORD flags)
{
CString str, temp;
// Not really a GUID at all, just a long cryptic string.
// temp.Format(_T(" Guid: %s\n"), (LPCTSTR)dr.GetRecorderGUID());
// str += temp;
temp.Format(_T(" PnP ID: %s\n"), (LPCTSTR)dr.GetBasePnPID());
str += temp;
temp.Format(_T(" Type: %s\n"),
(LPCTSTR)GetRecorderTypeName(dr.GetRecorderType()));
str += temp;
temp.Format(_T(" Path: %s\n"), (LPCTSTR)dr.GetPath());
str += temp;
DISPLAYNAMES dn;
dr.GetDisplayNames(dn);
temp.Format(_T(" Vendor: %s\n"),(LPCTSTR)dn.vendor);
str += temp;
temp.Format(_T(" Product: %s\n"),(LPCTSTR)dn.product);
str += temp;
temp.Format(_T(" Revision: %s\n"),(LPCTSTR)dn.revision);
str += temp;
if (dr.OpenExclusive()) {
temp.Format(_T(" State: %s\n"), GetRecorderStateName(dr.GetRecorderState()));
str += temp;
long mtype, mflags;
if (dr.QueryMediaType(mtype, mflags)) {
temp.Format(_T(" Media Type: %s=%d\n"),GetMediaTypeName(mtype),mtype);
str += temp;
temp.Format(_T(" Media Flags: %s=%d\n"),GetMediaFlagsName(mflags),mflags);
str += temp;
} else {
temp.Format(_T(" **Unable to query media type, hr=%s\n"),
GetErrorName(dr.m_hr));
str += temp;
}
MEDIAINFO mi;
if (dr.QueryMediaInfo(mi)) {
temp.Format(_T(" Media Info: nSes=%d LastTrack=%d Start=%d Next=%d Free=%d\n"),
mi.nSessions,
mi.nLastTrack,
mi.nStartAddress,
mi.nNextWritable,
mi.nFreeBlocks);
str += temp;
} else {
temp.Format(_T(" **Unable to query media info, hr=%s\n"),
GetErrorName(dr.m_hr));
str += temp;
}
dr.Close();
} else {
temp.Format(_T(" **Unable to open exclusive, hr=%s\n"),
GetErrorName(dr.m_hr));
str += temp;
}
if (flags & FRI_LIST_RECORDER_PROPS) {
str += FormatRecorderProps(dr);
}
return str;
}
//////////////////
// Format recorder properties.
// This requires dealing with IEnumSTATPROPSTG--Ugh!
//
CString FormatRecorderProps(CDiscRecorder& dr)
{
CString str,temp;
CComQIPtr<IPropertyStorage> pstg;
if (dr.GetRecorderProperties(&pstg)) {
temp.Format(_T(" Recorder Properties:\n"));
str += temp;
CPropertyStorageIterator it(pstg);
CComVariant val;
while (it.Next(val)) {
CString propname = it.GetPropName();
val.ChangeType(VT_BSTR);
CString strval = val.bstrVal;
temp.Format(_T(" %s=%s\n"), (LPCTSTR)propname, (LPCTSTR)strval);
str += temp;
}
}
return str;
}
CString FormatJolietProps(CJolietDiscMaster& jdm)
{
CString str,temp;
if (jdm) {
temp.Format(_T(" Joilet info:\n"));
str += temp;
temp.Format(_T(" Total data blocks=%d\n"),jdm.GetTotalDataBlocks());
str += temp;
temp.Format(_T(" Used data blocks=%d\n"), jdm.GetUsedDataBlocks());
str += temp;
temp.Format(_T(" Block size=%d\n"),jdm.GetDataBlockSize());
str += temp;
CComQIPtr<IPropertyStorage> pstg;
if (jdm.GetJolietProperties(&pstg)) {
temp.Format(_T(" Joliet Properties:\n"));
str += temp;
CPropertyStorageIterator it(pstg);
CComVariant val;
while (it.Next(val)) {
CString propname = it.GetPropName();
if (propname != _T("BootImage")) { // BootImage is an IStream!
val.ChangeType(VT_BSTR);
CString strval = val.bstrVal;
temp.Format(_T(" %s=%s\n"), (LPCTSTR)propname, (LPCTSTR)strval);
str += temp;
}
}
}
}
return str;
}
void help()
{
_tprintf(
_T("cdinfo: Display information about recordable CD drives.\n")
_T(" Copyright 2003 Paul DiLascia.\n\n")
_T("Format: cdinfo [-apj]\n")
_T("Options:\n")
_T(" None: show active recorder info\n")
_T(" -a all: list all drives\n")
_T(" -p props: list recorder properties\n")
_T(" -j joliet: list joliet properties\n")
_T(" -v verbise: list everything\n")
_T("\n"));
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -