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

📄 neroapitest.cpp

📁 NERO sdk,可以对光盘进行编程,刻录
💻 CPP
📖 第 1 页 / 共 3 页
字号:
				| (TAO ? 0 : NBF_DAO) 
				| NBF_DISABLE_ABORT 
				| (speedtest ? NBF_SPEED_TEST : 0)/*| NBF_CLOSE_SESSION*/  /* Write and simulate are not mutually exclusive, we just use either one or the other here. */
				| (no_eject ? NBF_DISABLE_EJECT : 0),
				speed, &NeroProgress);
		}

		/* automatically save a log file */
		FILE *fp = fopen ("neroerr.txt", "w");
		if (fp) {
			char *log = NeroGetErrorLog ();
			fputs (log, fp);
			fclose (fp);
			NeroFreeMem (log);
		}

		switch(res)
		{
		case NEROAPI_BURN_OK:
			break;
		case NEROAPI_BURN_UNKNOWN_CD_FORMAT:
			NeroError ("BurnCD() : unknown CD format");
			break;
		case NEROAPI_BURN_INVALID_DRIVE:
			NeroError ("BurnCD() : invalid drive");
			break;
		case NEROAPI_BURN_FAILED:
			NeroError ("BurnCD() : burn failed");
			break;
		case NEROAPI_BURN_FUNCTION_NOT_ALLOWED:
			NeroError ("BurnCD() : function not allowed");
			break;
		case NEROAPI_BURN_DRIVE_NOT_ALLOWED:
			NeroError ("BurnCD() : drive not allowed");
			break;
		case NEROAPI_BURN_USER_ABORT:
			NeroError ("BurnCD() : aborted by the user");
			break;
		default:
			NeroError ("BurnCD() : unknown error");
		}
	}

	/* done */
	Exit (0);
	return 0;
}


/*
** functions using/implementing the API
*/

static BOOL NERO_CALLBACK_ATTR IdleCallback (void *pUserData)
{
	assert (pUserData == DUMMY_USER_DATA);

	/*
	** Nothing to be done in a Shell application.
	** A GUI might react to messages here:
		static MSG msg;
		while ("not canceled" && ::PeekMessage(&msg,NULL,NULL,NULL,PM_NOREMOVE))
			if (!AfxGetThread()->PumpMessage())
				break;	// All messages "pumped"
	*/

	return Aborted;
}

typedef struct {
	char input;
	NeroUserDlgInOut result;
} Input2DlgOut;
	
static NeroUserDlgInOut CharIO (const Input2DlgOut *CharMapping, const char *prompt) /* array is terminated with input == 0 */
{
	NeroUserDlgInOut res = DLG_RETURN_EXIT;
	BOOL cont = TRUE;
	char buffer[80];
	do {
		puts (prompt);
		fgets (buffer, sizeof(buffer), stdin);
		for (int i = 0; CharMapping[i].input != 0; i++) {
			if (toupper(CharMapping[i].input) == toupper(buffer[0])) {
				res = CharMapping[i].result;
				cont = FALSE;
				break;
			}
		}
	} while (!Aborted && cont);

	return res;
}



static NeroUserDlgInOut NERO_CALLBACK_ATTR UserDialog (void *pUserData, NeroUserDlgInOut type, void *data)
{
	static const Input2DlgOut okay_mapping[] = 
	{
		'O', DLG_RETURN_EXIT,
		0
	};
	static const Input2DlgOut yes_no_mapping[] = 
	{
		'Y', DLG_RETURN_TRUE,
		'N', DLG_RETURN_FALSE,
		0
	};

	assert (pUserData == DUMMY_USER_DATA);

	switch (type) {
	case DLG_AUTO_INSERT:
	{
		static const Input2DlgOut mapping[] = 
		{ 
		  'I', DLG_RETURN_INSTALL_DRIVER,
		  'T', DLG_RETURN_OFF_RESTART,
		  'E', DLG_RETURN_EXIT,
		  'C', DLG_RETURN_CONTINUE,
		  0
		};
		puts ("Auto Insert Notification is turned on in the system configuration.\n"
		      "This may cause serious problems while burning: your CD might be damaged,\n"
		      "or the system might hang up.\n\n"

		      "Nero is able to burn CDs with Auto Insert Notification turned on if all\n"
			  "necessary drivers are installed.\n");

		return CharIO (mapping,
			"[I]nstall drivers and restart Windows\n"
			"[T]urn off Auto Insert Notification and restart Windows\n"
			"[E]xit Nero\n"
			"[C]ontinue at your own risk\n");
		break;
	}
	case DLG_DISCONNECT_RESTART:
	case DLG_DISCONNECT:
	{
		puts ("Disconnect is turned off in the system configuration.\n"
			  "This may cause serious problems while burning: your CD\n"
			  "might be damaged, or the system might hang up.\n");

		if (DLG_DISCONNECT_RESTART == type) {
			static const Input2DlgOut mapping[] = 
			{ 
			  'T', DLG_RETURN_ON_RESTART,
			  'D', DLG_RETURN_RESTART,
			  0
			};

			return CharIO (mapping,
				"[T]urn on Disconnect and restart\n"
				"[D]on't change Disconnect option and restart\n");
		} else {
			static const Input2DlgOut mapping[] = 
			{ 
			  'T', DLG_RETURN_ON_RESTART,
			  'D', DLG_RETURN_RESTART,
			  'C', DLG_RETURN_CONTINUE,
			  0
			};

			return CharIO (mapping,
				"[T]urn on Disconnect and restart\n"
				"[D]on't change Disconnect option and restart\n"
				"[C]ontinue at your own risk\n");
		}
		break;
	}
	case DLG_AUTO_INSERT_RESTART:
		puts ("Auto Insert Notification is now OFF. You should restart Windows.\n");
		return CharIO (okay_mapping, "[O]kay\n");
		break;
	case DLG_RESTART:
		puts ("Please restart Windows now.\n");
		return CharIO (okay_mapping, "[O]kay\n");
		break;
	case DLG_SETTINGS_RESTART: {
		static const Input2DlgOut mapping[] = 
		{ 
		  'R', DLG_RETURN_RESTART,
		  'C', DLG_RETURN_CONTINUE,
		  0
		};

		puts ("Nero detected some modifications of your PC system configuration\n"
		      "and needs to modify some settings. Please restart your PC to make\n"
		      "the changes become effective.\n");
		return CharIO (mapping,
			"[R]estart\n"
			"[C]ontinue at your own risk\n");
		break;
	}
	case DLG_OVERBURN:
		puts ("Sorry, this compilation contains too much data to fit on the CD\n"
		      "with respect to the normal CD capacity. Do you want to try\n"
		      "overburn writing at your own risk (this might cause read\n"
		      "errors at the end of the CD or might even damage your recorder)?\n\n"
		      "Note: It is also possible, that SCSI/Atapi errors occur at the end\n"
		      "of the simulation or burning. Even in this case there is a certain\n"
		      "chance, that the CD is readable.\n");

		return CharIO (yes_no_mapping, "[Y]es\n[N]o\n");
		break;
	case DLG_COPY_QUALITY_LOSS:
		puts( "Disc must be written as 'track at once' ('disc at once' not\n"
			  "supported or not able to write such a disc). This means\n"
			  "there might be some minor quality loss (e.g. lost audio index\n"
			  "or different pause between audio tracks). Do you want to\n"
			  "proceed anyway?\n");
		return CharIO (yes_no_mapping, "[Y]es\n[N]o\n");
		break;
	case DLG_COPY_FULLRISK: 
		puts( "Disc must be written as 'track at once' ('disc at once' not\n"
			  "supported or not able to write such a disc).  Unfortunately\n"
			  "your image has a special format which can most likely only\n"
			  "be written correctly with 'disc at once'. But you may\n"
			  "PROCEED AT YOUR OWN RISK. Do you want to continue\n"
			  "burning?\n");
		return CharIO (yes_no_mapping, "[Y]es\n[N]o\n");
		break;
	case DLG_AUDIO_PROBLEMS:
		if ((INT_PTR)data & AUP_NOTRACK_FOUND) {
			puts ("No tracks given.");
			return DLG_RETURN_EXIT;
		}
		if ((INT_PTR)data == AUP_MEGA_FATAL) {
			puts ("fatal internal problem");
			return DLG_RETURN_EXIT;
		}

		puts ("Nero has detected that the following audio properties are not\n"
		      "supported by your recorder in the current write mode and need\n"
		      "to be modified:");
		if ((INT_PTR)data & AUP_FIRST_TR_PAUSE)    puts ("- CD specification allows only 2-3 Seconds pause for the first track");
		if ((INT_PTR)data & AUP_PAUSE_SETTINGS)    puts ("- Pause length between the tracks not supported");
		if ((INT_PTR)data & AUP_INDEX_SETTINGS)    puts ("- Additional index positions not supported");
		if ((INT_PTR)data & AUP_ISRC_SETTINGS)     puts ("- ISRC codes not supported");
		if ((INT_PTR)data & AUP_COPYPROT_SETTINGS) puts ("- Copy protection bit not supported");

		puts ("Nero can change the audio track settings for you to fit the\n"
		      "capabilities of your recorder. This might cause some audio\n"
			  "properties to be lost. Do you want Nero to change the track\n"
			  "settings for you?\n");
		return CharIO (yes_no_mapping, "[Y]es\n[N]o\n");
		break;
	case DLG_WAITCD:
		{
			char *msg=NeroGetLocalizedWaitCDTexts ((NERO_WAITCD_TYPE) (int)data);
			printf("\n%s\n", msg);
			NeroFreeMem(msg);
		}
		break;
	case DLG_WAITCD_REMINDER:
		printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\b");
		break;
	case DLG_WAITCD_DONE:
		// nothing to be done in the text interface,
		// should close dialog box in a GUI
		break;
	case DLG_FILESEL_IMAGE:
		printf("\nSave image file : ");
		fgets((char *)data,255,stdin);
		// Remove the carriage return
		((char *)data)[strlen((char *)data)-1]=0; 
		return DLG_RETURN_TRUE;
		break;
	case DLG_BURNIMAGE_CANCEL:
		printf("There is not enough space available to burn the image.\n");
		break;
	case DLG_NON_EMPTY_CDRW:
	{
		puts("This CDRW is not empty.");
		static const Input2DlgOut mapping[] = 
		{ 
		  'C', DLG_RETURN_EXIT,
		  'E', DLG_RETURN_CONTINUE,
		  'O', DLG_RETURN_RESTART,
		  0
		};

		NeroUserDlgInOut res=CharIO(mapping,"[E]rase CD\n[O]pen tray\n[C]ancel");
		if (res==DLG_RETURN_CONTINUE)
		{
			// Erase the CDRW
			NEROAPI_CDRW_ERASE_MODE mode=NEROAPI_ERASE_QUICK;
			int time=NeroGetCDRWErasingTime(NeroDeviceHandle,mode);
			if (time==-1)
				NeroError("No CD inserted");
			else if (time==-2)
				NeroError("This CD recorder doesn't support CDRW");
			printf("Erasing CDRW. This will take %d seconds.\n",time);
			int err=NeroEraseCDRW(NeroDeviceHandle,mode);
			if (err)
				NeroError("Error erasing the CDRW");
		}
		return res;
	}
	case DLG_WAITCD_MEDIA_INFO:
		{
			NERO_DLG_WAITCD_MEDIA_INFO *pInfos=(NERO_DLG_WAITCD_MEDIA_INFO *)data;
			printf("Requested media: %s\n",pInfos->ndwmiRequestedMediaName);
			printf("Last detected media: %s\n",pInfos->ndwmiLastDetectedMediaName);
		}
		break;
	default:
		assert (FALSE); // we don't know this type of requester!
		break;
	}
	
	return DLG_RETURN_EXIT;
}

static BOOL NERO_CALLBACK_ATTR ProgressCallback (void *pUserData, DWORD dwProgressInPercent)
{
	printf ("%03d%%\r", dwProgressInPercent);

	return IdleCallback (pUserData);
}

static BOOL NERO_CALLBACK_ATTR AbortedCallback (void *pUserData)
{
//	printf("Abort ?\n");

	return Aborted;
}

static void NERO_CALLBACK_ATTR AddLogLine (void *pUserData, NERO_TEXT_TYPE type, const char *text)
{
	char *header = "  ";
	const char *start;

	switch (type) {
	case NERO_TEXT_INFO:        /* informative text                     */
		header = "i ";
		break;
	case NERO_TEXT_STOP:        /* some operation stopped prematurely   */
		header = "# ";
		break;
	case NERO_TEXT_EXCLAMATION: /* important information                */
		header = "! ";
		break;
	case NERO_TEXT_QUESTION:    /* a question which requires an answer  */
		header = "? ";
		break;
	case NERO_TEXT_DRIVE:		/* a message concerning a CD-ROM drive or recorder */
		header = "- ";
		break;
	default:
		break;
	}

	start = text;
	while (start) {
		char *end = strchr (start, '\n');
		int len = end ? (int)(end - start) : strlen (start);

		fputs (header, stdout);
		fwrite (start, 1, len, stdout);
		// clear rest of line
		len = 79 - strlen (header) - len;
		while (--len >= 0) {
			putchar (' ');
		}

		puts ("");

		start = end ? end + 1 : NULL;
	}
}

static void NERO_CALLBACK_ATTR SetPhaseCallback (void *pUserData, const char *text)
{
	int len;

	printf ("     %s", text);
	// clear rest of line
	len = 79 - strlen (text) - 5;
	while (--len >= 0) {
		putchar (' ');
	}
	putchar ('\r');
}

static void NERO_CALLBACK_ATTR DisableAbortCallback (void *pUserData, BOOL enableAbort)
{
	if (!enableAbort)
		puts("The current process cannot be interrupted");
	else puts("The process can be interrupted again");
}

static void NERO_CALLBACK_ATTR SetMajorPhaseCallback(void *pUserData,NERO_MAJOR_PHASE phase,void *reserved)
{
}

static DWORD NERO_CALLBACK_ATTR WriteIOCallback (void *pUserData, BYTE *pBuffer, DWORD dwLen)
{
	return fwrite (pBuffer, 1, dwLen, (FILE *)pUserData);
}
static BOOL NERO_CALLBACK_ATTR EOFCallback (void *pUserData)
{
	return feof ((FILE *)pUserData);
}
static BOOL NERO_CALLBACK_ATTR ErrorCallback (void *pUserData)
{
	return ferror ((FILE *)pUserData);
}
static DWORD NERO_CALLBACK_ATTR ReadIOCallback (void *pUserData, BYTE *pBuffer, DWORD dwLen)
{
	return fread (pBuffer, 1, dwLen, (FILE *)pUserData);
}

static void NeroError (char *action) /* display Nero error and exit */
{
	char *error = NeroGetLastError ();

	puts (action);
	puts (error ? error : "failed");

	NeroFreeMem (error);
	Exit (10);
}

⌨️ 快捷键说明

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