⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogbin2iso.cpp

📁 虚拟光驱程序
💻 CPP
字号:
// DialogBIN2ISO.cpp : implementation file
//

#include "stdafx.h"
#include "Speedcd.h"
#include "DialogBIN2ISO.h"
//#include "bin2iso_new.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDialogBIN2ISO dialog


CDialogBIN2ISO::CDialogBIN2ISO(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogBIN2ISO::IDD, pParent)
{
	cancel_ACT=FALSE;
 	//{{AFX_DATA_INIT(CDialogBIN2ISO)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDialogBIN2ISO::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogBIN2ISO)
	   	DDX_Control(pDX, IDC_PROGRESS, pProgress);
	// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDialogBIN2ISO, CDialog)
	//{{AFX_MSG_MAP(CDialogBIN2ISO)
	ON_WM_TIMER()
	ON_WM_SHOWWINDOW()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogBIN2ISO message handlers



void CDialogBIN2ISO::bin2iso( char* srcFile )
{
	int   seek_header, seek_ecc, sector_size;
	long  i, source_length;
	char  buf[2352], destfilename[_MAX_PATH];
	const char SYNC_HEADER[12] = { (const char)0, (const char)0xFF, (const char)0xFF, (const char)0xFF, (const char)0xFF, 
		                            (const char)0xFF, (const char)0xFF, (const char)0xFF, (const char)0xFF, 
                            		(const char)0xFF, (const char)0xFF, (const char)0 };
	FILE  *fdest, *fsource;

    /*
	if (argc < 2)
	{
   		printf("Error: bad syntax\n\nUsage is: bin2iso image.bin [image.iso]\n");
   		exit(EXIT_FAILURE);
	}
    */
	/*
	if (argc >= 3)
    {
		strcpy(destfilename, argv[2]);
    }
	else
	*/
	{
   		strcpy(destfilename,srcFile);
   		if (strlen(srcFile) < 5 || stricmp(destfilename+strlen(srcFile)-4, ".bin"))
   			strcpy(destfilename+strlen(srcFile), ".iso");
   		else
   			strcpy(destfilename+strlen(srcFile)-4, ".iso");
	}


	fsource = fopen(srcFile,"rb");
	fdest = fopen(destfilename,"wb");

	fread(buf, sizeof(char), 16, fsource);

	if (memcmp(SYNC_HEADER, buf, 12))
	{
		seek_header = 8;		// Mode2/2336    // ** Mac: change to 0
		seek_ecc = 280;
		sector_size = 2336;
	}
	else
	{
	    switch(buf[15])
		{
		   case 2:
			seek_header = 24;	// Mode2/2352    // ** Mac: change to 16
			seek_ecc = 280;
			sector_size = 2352;
			break;
		   case 1:
			seek_header = 16;	// Mode1/2352
			seek_ecc = 288;
			sector_size = 2352;
			break;
		   default:
			  ::MessageBox (m_hWnd,"Convert ISO File","Error: Unsupported track mode",MB_OK);
			  EndDialog(TRUE);

         	//exit(EXIT_FAILURE);
		 }
	}

	fseek(fsource, 0L, SEEK_END);
	source_length = ftell(fsource)/sector_size;
	fseek(fsource, 0L, SEEK_SET);
	pProgress.SetRange(0, source_length-1);
		
    for(i = 0; i < source_length; i++)
	{
		fseek(fsource, seek_header, SEEK_CUR);
		fread(buf, sizeof(char), 2048, fsource);    // ** Mac: change to 2056 for Mode2
		fwrite(buf, sizeof(char), 2048, fdest);     // ** same as above
		fseek(fsource, seek_ecc, SEEK_CUR);
		// Set the range
		// Set the position
		pProgress.SetPos(i);

		if((!CheckMessageQueue()) || (cancel_ACT))
		{   
			fclose(fdest);
			fclose(fsource);
			DeleteFile(LPCTSTR(destfilename));
    		break;
		}
	   //	printf("%d\n",i/source_length);
	}
    if (!cancel_ACT)
	{
	 fclose(fdest);
	 fclose(fsource);
	}
    EndDialog(TRUE);
    return;
//exit(EXIT_SUCCESS);
}


void CDialogBIN2ISO::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CDialog::OnTimer(nIDEvent);
	KillTimer(1);
	bin2iso(  (char* )srcBinFile );
}

void CDialogBIN2ISO::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	SetTimer(1,600,NULL);                //启动定时器
	// TODO: Add your message handler code here
}

void CDialogBIN2ISO::OnCancel() 
{
	// TODO: Add extra cleanup here
	cancel_ACT=TRUE;
	CDialog::OnCancel();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -