📄 dlgmount.cpp
字号:
/*
VaporCD CD-ROM Volume Emulation for Windows NT/2000
Copyright (C) 2000 Brad Johnson
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
http://vaporcd.sourceforge.net/
Brad Johnson
3305 2nd PL #222
Lubbock, TX 79415
*/
// DlgMount.cpp : implementation file
//
#include "stdafx.h"
#include "VaporCD.h"
#include "DlgMount.h"
#include "DlgProgress.h"
#include "vaporcd_mfc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DlgMount property page
IMPLEMENT_DYNCREATE(DlgMount, CPropertyPage)
DlgMount::DlgMount() : CPropertyPage(DlgMount::IDD)
{
//{{AFX_DATA_INIT(DlgMount)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_psp.dwFlags &= ~PSP_HASHELP;
m_bPersistent = FALSE;
}
DlgMount::~DlgMount()
{
}
void DlgMount::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgMount)
DDX_Control(pDX, IDC_MOUNT_PATH, m_cMountPath);
DDX_Check(pDX, IDC_PERSISTENT, m_bPersistent);
DDX_Control(pDX, IDC_MOUNT_LETTER, m_cMountLetter);
DDX_CBString(pDX, IDC_MOUNT_LETTER, m_sMountLetter);
DDX_CBString(pDX, IDC_MOUNT_PATH, m_sMountPath);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DlgMount, CPropertyPage)
//{{AFX_MSG_MAP(DlgMount)
ON_BN_CLICKED(IDC_MOUNT, OnMount)
ON_BN_CLICKED(IDC_MOUNT_BROWSE, OnMountBrowse)
ON_CBN_DROPDOWN(IDC_MOUNT_PATH, OnDropdownMountPath)
ON_CBN_DROPDOWN(IDC_MOUNT_LETTER, OnDropdownMountLetter)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DlgMount message handlers
CString GetErrorMessage()
{
CString s;
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Free the buffer.
s = (char *)lpMsgBuf;
LocalFree( lpMsgBuf );
return s;
}
void DlgMount::OnMount()
{
UpdateData(TRUE);
if (m_sMountLetter.GetLength()<1)
{
AfxMessageBox("Select drive to mount.");
return;
}
SaveHistory();
HANDLE h = AttachToDriver();
if (h == INVALID_HANDLE_VALUE )
{
AfxMessageBox("Could not open driver. You must be running as Administrator to mount CDs.");
return;
}
ULONG ulDriverVer = GetVaporCDDriverVer(h);
if (ulDriverVer != VAPOR_CD_VERSION_NUMBER)
{
CString s;
s.Format("The VaporCD driver version (%i) is incorrect. Please check that VaporCD\n"
"is correctly installed and that you have rebooted since you installed.",
ulDriverVer);
AfxMessageBox(s);
CloseHandle(h);
h = NULL;
return;
}
m_sMountLetter.MakeUpper();
// report errors
if (m_sMountLetter.GetLength() < 1 || Mount(h,m_sMountPath,m_sMountLetter[0], FALSE) == 0)
{
CString s;
s.Format("Error while mounting: \n%s",GetErrorMessage());
AfxMessageBox(s);
}else
{
UINT nIndex;
nIndex = m_cMountLetter.FindStringExact(-1,m_sMountLetter);
if (nIndex!=CB_ERR)
m_cMountLetter.DeleteString(nIndex);
//
// Okay the drive is mounted.
// If it was a persistent connection we need
// to save the settings in the registry so that
// we can mount the drive on boot from now on.
// So we save the full path to the image file in a registry value that
// has the ordinal base 0 of the drive letter. A=0 Z=25
// It is saved in the registry as Unicode so there is no need
// to convert the value while in kernel mode.
// TODO:
//
// Add or replace the value in the registry.
//
if (m_bPersistent)
{
HKEY hkResult;
LONG r1 = RegCreateKeyEx(
HKEY_LOCAL_MACHINE, // handle to open key
"SYSTEM\\CurrentControlSet\\Services\\VaporCD\\Parameters", // address of name of subkey to open
0,
NULL,
0, // options
KEY_ALL_ACCESS, // reserved REGSAM samDesired, // security access mask
NULL, // security discriptor
&hkResult, // result
NULL //disp
);
if (r1 !=ERROR_SUCCESS)
{
AfxMessageBox("Cannot open registry key");
if (h != NULL)
CloseHandle(h);
return;
}
// delete the key with the matching ordinal
//LONG r = RegDeleteValue(hkResult,m_sUnmountLetter);
LONG r= RegSetValueEx(hkResult,m_sMountLetter,0, REG_SZ,
(const unsigned char *)m_sMountPath.GetBuffer(1), m_sMountPath.GetLength());
m_sMountPath.ReleaseBuffer();
if (r != ERROR_SUCCESS)
{
// error deleting key
AfxMessageBox("Error creating key");
}
RegCloseKey(hkResult);
}
}
if (h != NULL)
CloseHandle(h);
}
void DlgMount::OnMountBrowse()
{
static char BASED_CODE szFilter[] =
"VaporCD Image Files (*.VaporCD)|*.VaporCD|"
"ISO CD Image Files(*.ISO)|*.ISO|"
"All Files (*.*)|*.*||";
CFileDialog d(TRUE,NULL,m_sMountPath,OFN_HIDEREADONLY,szFilter);
UpdateData(TRUE);
if (d.DoModal() == IDOK)
{
m_sMountPath = d.GetPathName();
UpdateData(FALSE);
}
}
BOOL DlgMount::OnInitDialog()
{
CPropertyPage::OnInitDialog();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void DlgMount::OnDropdownMountPath()
{
// Fill the list box with strings from the registry
m_cMountPath.ResetContent();
for (int i=0; i < 10; i++)
{
CString s;
CString val;
val.Format("hist%i",i);
s = ((CVaporCDApp *)AfxGetApp())->GetProfileString("Mount",val,"");
if (s != "")
m_cMountPath.AddString(s);
}
}
BOOL DlgMount::SaveHistory()
{
if (m_sMountPath == "")
return TRUE; // Add to the front of the list, remove from other if already in list
int ind = m_cMountPath.FindStringExact(-1,m_sMountPath);
if (ind == CB_ERR)
{
m_cMountPath.InsertString(0,m_sMountPath);
}else
{
m_cMountPath.DeleteString(ind);
m_cMountPath.InsertString(0,m_sMountPath);
}
// Save the contents of the listbox
for (int i=0; i < 10; i++)
{
CString val,value;
val.Format("hist%i",i);
if (i < m_cMountPath.GetCount())
m_cMountPath.GetLBText(i, value);
else
value = "";
((CVaporCDApp *)AfxGetApp())-> WriteProfileString("Mount",val, value);
}
return TRUE;
}
//
// Update the registry
//
BOOL DlgMount::SaveMount(char cLetter)
{
/* CString t;
CString s = ((CVaporCDApp *)AfxGetApp())->GetProfileString("Mount","Mounted","");
if (s.Find(cLetter) == -1)
{
// not found then we add it
t.Format("%s%c",s,cLetter);
((CVaporCDApp *)AfxGetApp())-> WriteProfileString("Mount","Mounted", t);
}*/
return TRUE;
}
void DlgMount::OnDropdownMountLetter()
{
m_cMountLetter.ResetContent();
for (char c= 'A'; c<= 'Z' ;c++)
{
CString s,s1;
s.Format("%c",c);
s1.Format("%c:\\",c);
int iType = GetDriveType(s1);
if (iType == DRIVE_NO_ROOT_DIR)
m_cMountLetter.AddString(s);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -