📄 speedcddlg.cpp
字号:
char strExt[]= "BIN Files(*.bin)|*.bin||";
CFileDialog dlg( TRUE, "*.bin", "*.bin" , OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT
, strExt , this );
if( dlg.DoModal() == IDOK )
{
CDialogBIN2ISO cdBIN2ISO;
//cdBIN2ISO.bin2iso( (char*)(LPCSTR)(dlg.GetPathName()));
memcpy((char*)cdBIN2ISO.srcBinFile,(char*)(LPCSTR)(dlg.GetPathName()),strlen((char*)(LPCSTR)(dlg.GetPathName())));
cdBIN2ISO.srcBinFile[strlen((char*)(LPCSTR)(dlg.GetPathName()))]=0;
cdBIN2ISO.DoModal();
}
}
/////////////////////////////////////////////////////////////////////////////
// DlgNew message handlers
UINT MyControllingFunction( LPVOID pParam )
{
return ((CDialogDemoDlg *)pParam)->StartCopyThread();
}
void CDialogDemoDlg::OnToolsCreateiso()
{
// TODO: Add your command handler code here
//LPDWORD total=0;
//char sPath[_MAX_PATH];
// CString sel;
CenterWindow();
CDialogCreateISO dlg;
if( dlg.DoModal() == IDOK )
{
//strcpy(sPath,(LPCTSTR)dlg.m_strISOFile);
m_sNewPath=dlg.m_strISOFile;
m_bIgnoreErrors=dlg.m_bIgnoreErrors;
cd=dlg.bCDROM;
// if (WimLargeReadLargeIma(m_hWnd, cd, sPath, total, ALL))
// ::MessageBox ( m_hWnd,"Successful!","ISO Studio",MB_ICONINFORMATION |MB_OK);
UpdateData(TRUE);
// start the copy thread
AfxBeginThread( MyControllingFunction, this,THREAD_PRIORITY_BELOW_NORMAL);
// start the modal
m_dlgProgress.m_bCancel = FALSE;
m_dlgProgress.m_sMessage = "Starting... ";
m_dlgProgress.DoModal();
//if (m_bPersistent)
// m_dlgProgress->m_sMessage = "Done";
}
}
int CDialogDemoDlg::StartCopyThread()
{
// this must be larger than 64*1024!!!
#define BLOCK_SIZE (512*1024)
// must be less or equal to BLOCK_SIZE
#define READ_CHUNK_SIZE (512*1024)
// send status messages
//
// The user wants to create a new cdrom image
// We need to show a progress indicator and progress stats
//
// There is no need to talk to the kernel mode driver for this operation
// Get the freespace on the volume that the image is on
// If there is not enough free space then show a warning
// Give chance to abort
// Open the cdrom drive
CString s;
s.Format("\\\\.\\%c:",cd);
s.MakeUpper();
HANDLE h;
h = CreateFile(
s,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL);
if (h == NULL || h == INVALID_HANDLE_VALUE )
{
::MessageBox(m_hWnd,"Could not open CD drive "+s+": for read.\n","ISO Studio",MB_ICONINFORMATION |MB_OK);
m_dlgProgress.SendMessage(WM_COMMAND,IDCANCEL);
return 3;
}
// Open the outfile
CFile f;
DeleteFile(m_sNewPath);
if (!f.Open(m_sNewPath,CFile::modeCreate|CFile::modeWrite|CFile::shareExclusive))
{
::MessageBox(m_hWnd,"Could not create file "+m_sNewPath+".\n"
"You must specify a filename to create in the \"ISO File Path\" box.","ISO Studio",MB_ICONINFORMATION |MB_OK);
m_dlgProgress.SendMessage(WM_COMMAND,IDCANCEL);
return 4;
}
BYTE * buf;
buf = new BYTE[BLOCK_SIZE];
if (!buf)
{
::MessageBox(m_hWnd,"Could not create copy buffer","ISO Studio",MB_ICONINFORMATION |MB_OK);
m_dlgProgress.SendMessage(WM_COMMAND,IDCANCEL);
return 4;
}
// blank the memory
ZeroMemory(buf,BLOCK_SIZE);
DWORD dwBytes;
strcpy((char *)(&(buf[0])),"ISO Studio image file v1.0 Coolqiu");
// save goemetry
DISK_GEOMETRY *dg;
DWORD dwIoCtl = IOCTL_CDROM_GET_DRIVE_GEOMETRY;
dwBytes = 1024;
dg = (DISK_GEOMETRY *)&(buf[1*1024]);
DeviceIoControl(h,dwIoCtl,NULL,0,&(buf[1*1024]),dwBytes,&dwBytes,FALSE);
// save TOC
CDROM_TOC *toc;
dwIoCtl = IOCTL_CDROM_READ_TOC;
dwBytes = 1024;
toc = (CDROM_TOC*)&(buf[2*1024]);
DeviceIoControl(h,dwIoCtl,NULL,0,&(buf[2*1024]),dwBytes,&dwBytes,FALSE);
// save all 64k of data to file
CString s1;
s1 = m_sNewPath;
s1.MakeUpper();
// we skip this for making the ISO images.
if (s1.Right(4) != ".ISO")
f.Write(buf,64*1024);
// read from the cdrom and write to the file until the end of the cd!!!
int count = 0;
int iTotalSize = 1000;
CString sPath;
sPath.Format("%c:\\",cd);
ULARGE_INTEGER ulFreeBytesAvailableToCaller;
ULARGE_INTEGER ulTotalNumberOfBytes;
ULARGE_INTEGER ulTotalNumberOfFreeBytes;
LONGLONG ll =0;
if (GetDiskFreeSpaceEx(
sPath, // pointer to the directory name
&ulFreeBytesAvailableToCaller, // receives the number of bytes on
// disk available to the caller
&ulTotalNumberOfBytes, // receives the number of bytes on disk
&ulTotalNumberOfFreeBytes // receives the free bytes on disk
))
{
ll = ulTotalNumberOfBytes.QuadPart;
iTotalSize = (int)(ll >> 10);
} else
iTotalSize = 0;
CTime tStart = CTime::GetCurrentTime();
LONGLONG lBytesRead = 0;
//Loop
int iRetryCount;
int iBadReads = 0;
while(TRUE)
{
iRetryCount = 0;
CTimeSpan tsLaps = CTime::GetCurrentTime()-tStart;
// Read, Write
count++;
if (m_dlgProgress.m_bCancel)
{
// abort!
f.Close();
// Close CD
CloseHandle(h);
delete []buf;
return 7;
}
if (tsLaps.GetTotalSeconds() < 1)
{
m_dlgProgress.m_sMessage = "";
m_dlgProgress.m_cProgress.SetPos(0);
}else
{
m_dlgProgress.m_cProgress.SetPos(
(count*100*(READ_CHUNK_SIZE/1024))/iTotalSize);
m_dlgProgress.m_sMessage.Format(
// "Count %i\n"
"Currently reading %iMB of total %iMB.\n"
"Seconds laps %is Transfer rate %3.3fMB/s\n"
"Estimated total %is %i%% complete\n"
"%i Read errors",
// count,
count*READ_CHUNK_SIZE/(1024*1024),iTotalSize/1024,
tsLaps.GetTotalSeconds(),
(double)count*READ_CHUNK_SIZE /
((double)tsLaps.GetTotalSeconds()*(1024*1024)),
(int)((iTotalSize/(READ_CHUNK_SIZE/1024))/
((double)count / (double)tsLaps.GetTotalSeconds() )),
(count*100*(READ_CHUNK_SIZE/1024))/iTotalSize,
iBadReads
);
}
// m_dlgProgress->UpdateData();
// m_dlgProgress->UpdateWindow();
DWORD dwBytes = READ_CHUNK_SIZE;
// read one sector at a time!!!
BOOL r = ReadFile(h,buf,dwBytes,&dwBytes,NULL);
if (!r || dwBytes==0)
{
// int error = GetLastError();
// r = ReadFile(h,buf,dwBytes,&dwBytes,NULL);
// if (!r || dwBytes==0)
// {
iBadReads++;
if (!m_bIgnoreErrors)
{
int error1 = GetLastError();
char sError[MAX_PATH];
sprintf(sError,"Error #%i while reading from CD.\n"
"Ignore this error and continue?",error1);
//sError.Format("Error #%i while reading from CD.\n"
// "Ignore this error and continue?",error1);
int r = ::MessageBox(m_hWnd,sError,"ISO Studio",MB_ICONWARNING|MB_OKCANCEL );
if (r != IDOK)
{
break;
}
}
dwBytes = READ_CHUNK_SIZE;
// }
}
lBytesRead += dwBytes;
f.Write(buf,dwBytes);
if (lBytesRead >= ll)
break;
// Update Progress
}
// Close Outfile
f.Close();
// Close CD
CloseHandle(h);
// send message to enable the end of the modal
//::MessageBox ( m_hWnd,"Successful!","ISO Studio",MB_ICONINFORMATION |MB_OK);
// AfxMessageBox("Create file "+m_sNewPath+"Successful!\n");
m_dlgProgress.SendMessage(WM_COMMAND,IDCANCEL);
delete []buf;
return 0;
}
void CDialogDemoDlg::OnFILEAddVirtual()
{
// TODO: Add your command handler code here C~Z
UpdateData(TRUE);
CString m_sMountLetter;
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_sMountLetter=s;
break;
}
}
if (m_sMountLetter.GetLength()<1)
{
AfxMessageBox("Select drive to mount.");
return;
}
CString m_sMountPath;
int i=-1;
if (m_ctlList1.GetItemCount())
i=m_ctlList1.GetNextItem(-1,LVNI_SELECTED);
if (i>=0)
m_sMountPath=m_ctlList1.GetItemText(i,0);
else
{
char strExt[]= "CD ISO Files(*.iso)|*.iso||";
CFileDialog dlg( TRUE, "*.iso", "*.iso" , OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT
, strExt , this );
if( dlg.DoModal() == IDOK )
{
m_sMountPath=dlg.GetPathName();
}
}
if (m_sMountPath!="")
{
HANDLE h = AttachToDriver();
if (h == INVALID_HANDLE_VALUE )
{
AfxMessageBox("Could not open driver. You must be running as Administrator to mount CDs.");
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
{
// 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.
int itmCNT=m_ctlList1.GetItemCount();
for (i=0;i<itmCNT;i++)
{
if (m_ctlList1.GetItemText(i,0)==m_sMountPath)
break;
}
if (i==itmCNT||itmCNT==0)
{
m_ctlList1.InsertItem(m_ctlList1.GetItemCount(),m_sMountPath);
CString s;
s.Format("%ld", i);
inifile.SetValue("ISOFILE",s,m_sMountPath);
inifile.WriteFile();
// SaveHistory();
}
inifile.SetValue("ISOCD",m_sMountLetter,m_sMountPath);
inifile.WriteFile();
hi1 = m_ctlTree1.InsertItem(m_sMountLetter+":", 1, 2, m_hi );
hi2 = m_ctlTree1.InsertItem( m_sMountPath, 3, 3, hi1 );
m_ctlTree1.SetItemData(hi1,3); //Have CD ISO FILE
m_ctlTree1.SetItemData(hi2,2);
//
// 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\\SPEEDCD\\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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -