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

📄 neroapitest.cpp

📁 Nero刻录工具的插件编程SDK
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
|* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|* PARTICULAR PURPOSE.
|* 
|* Copyright 1995-2004 Ahead Software AG. All Rights Reserved.
|*-----------------------------------------------------------------------------
|* NeroSDK / Samples
|*
|* PROGRAM: NeroAPITest.cpp
|*
|* PURPOSE: This command line program demonstrates many things that Nero API can do:
|*			- read information about a CD
|*			- burn audio CD
|*			- burn ISO CD
|*			- burn mixed mode CD
|*			- burn Video and Super Video CD
|*			- burn Nero CD image
|*			- extract CDA tracks
******************************************************************************/

#include "NeroAPIGlue.h"

#include <winbase.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <io.h>
#include <stdio.h>
#include <signal.h>

#include "NeroISODemo.h"


// import the implementation of NeroWaitCDTexts()
#define NERO_WAITCD_TEXTS
#include "NeroUserDialog.h"
#undef NERO_WAITCD_TEXTS

/*
** function declarations
*/
static void NeroError (char *action); /* display Nero error and exit */

/* for the settings */
static BOOL NERO_CALLBACK_ATTR IdleCallback (void *pUserData);
static NeroUserDlgInOut NERO_CALLBACK_ATTR UserDialog (void *pUserData, NeroUserDlgInOut type, void *data);

/* for the progress display */
static BOOL NERO_CALLBACK_ATTR ProgressCallback (void *pUserData, DWORD dwProgressInPercent);
static BOOL NERO_CALLBACK_ATTR AbortedCallback (void *pUserData);
static void NERO_CALLBACK_ATTR AddLogLine (void *pUserData, NERO_TEXT_TYPE type, const char *text);
static void NERO_CALLBACK_ATTR SetPhaseCallback (void *pUserData, const char *text);
static void NERO_CALLBACK_ATTR DisableAbortCallback (void *pUserData,BOOL abortEnabled);
static void NERO_CALLBACK_ATTR SetMajorPhaseCallback(void *pUserData,NERO_MAJOR_PHASE phase,void *reserved);

/* IO callbacks - both take a FILE * as user data */
static DWORD NERO_CALLBACK_ATTR WriteIOCallback (void *pUserData, BYTE *pBuffer, DWORD dwLen);
static DWORD NERO_CALLBACK_ATTR ReadIOCallback (void *pUserData, BYTE *pBuffer, DWORD dwLen);
static BOOL NERO_CALLBACK_ATTR EOFCallback (void *pUserData);
static BOOL NERO_CALLBACK_ATTR ErrorCallback (void *pUserData);

/* parameter parsing */
typedef enum {
	WAV,
	MP3,
	WMA,
	PCM,
	MPEG,
	JPEG,
	AVI,
	IMAGE,
	UNKNOWN
} FileType_t;

/*
** global resources
*/

NERO_DEVICEHANDLE NeroDeviceHandle;
NERO_SCSI_DEVICE_INFOS *NeroDeviceInfos;
NERO_CD_INFO *NeroCDInfo;
#define DUMMY_USER_DATA &NeroSettings 	/* &NeroSettings as user data is only used as illustration */
NERO_SETTINGS NeroSettings =
{
	"NeroFiles",                    /* look for DLLs in sub directory */
	NULL,NULL,
	"Nero.txt",
	{ IdleCallback, DUMMY_USER_DATA },
	{ UserDialog, DUMMY_USER_DATA }
};

NERO_PROGRESS NeroProgress =
{
	ProgressCallback,
	AbortedCallback,
	AddLogLine,
	SetPhaseCallback,
	DUMMY_USER_DATA,
	DisableAbortCallback,
	SetMajorPhaseCallback
};

/*
** CTRL-C handling => remember and return TRUE in IdleCallback to make API abort
*/

BOOL Aborted = FALSE;
static void __cdecl SigCtrlC (int sig)
{
	Aborted = TRUE;
}

/* free resources and exit */
static void Exit (int ret)
{
	/* all of these functions may be called even if NeroAPIGlueInit() failed. */
	NeroCloseDevice (NeroDeviceHandle);
	NeroFreeMem (NeroDeviceInfos);
	NeroFreeMem (NeroCDInfo);
	NeroClearErrors ();
	NeroDone ();

	NeroAPIGlueDone();

	puts ("\npress RETURN to exit");
	getchar ();
	exit (ret);
}



static void Usage (char *descr, void *descr_param)
{
	if (descr) {
		printf (descr, descr_param);
		puts ("");
	}
	puts ("Usage: --listdrives\n"
		  "       --cdinfo --drivename 'xxx'\n"
	      "       --write --drivename 'xxx' [--real] [--TAO] [--bup] [--artist 'artist'] [--title 'title'] [--speed x] [--pause x] [--audioinindex0] 'audio file1' 'audio file2' ... [--cdextra] [--iso 'volume name'] [--iso-no-joliet] [--iso-mode2] 'file/dir1' 'file/dir2' ...\n"
		  "		  --write --drivename 'xxx' --videocd [--real] [--TAO] [--bup] [--speed x] 'mpeg/jpeg file1' ...\n"
		  "		  --write --drivename 'xxx' --svideocd [--real] [--TAO] [--bup] [--speed x] 'mpeg/jpeg file1' ...\n"
		  "		  --write --drivename 'xxx' --image [--real] [--TAO] [--bup] [--speed x] 'nrg file'\n"
		  "       --read --drivename 'xxx' --'xy' 'file1' --'xy' 'file2' ...\n"
		  "		  --erase [--entire] --drivename 'xxx'\n"
		  "		  --eject --drivename 'xxx'\n"
		  "		  --load --drivename 'xxx'\n"
		  "\n"
		  "'xy'       = track number\n"
		  "'file'     = file name including suffix; only .wav and .pcm are supported for audio\n"
		  "'dir/file' = after --iso: file or or directory tree to be added in the root directory\n"
		  );
	Exit (10);
}


int __cdecl main(int argc, char* argv[])
{
	/* parse args */
	BOOL listdrives = FALSE,
		cdinfo = FALSE,
		write = FALSE,
		read = FALSE,
		real = FALSE,
		CDExtra = FALSE,
		TAO = FALSE,
		data = FALSE,
		videocd = FALSE,
		svideocd = FALSE,
		image = FALSE,
		speedtest = FALSE,
		eject = FALSE,
		no_eject = FALSE,
		load = FALSE,
		erase = FALSE,
		entire = FALSE,
		bup = FALSE,
		dvd = FALSE,
		verify = FALSE,
		listspeed = FALSE,
		bAudioInIndex0 = FALSE;
	int writebuffersize=0,iPauseLength=-1;
	float speed = 0;  /* maximum */
	char *drivename = NULL;
	char *artist = NULL, *title = NULL, *pPauseLenStr = NULL;
	char *files[99]; /* maximum number of tracks per CD */
	char *tempdir=NULL;
	unsigned int tracks[99];
	FileType_t type[99];
	unsigned int num_files = 0;
	unsigned int i;
	CDemoIsoTrack IsoTrack;

	/* skip program name */
	argc--;
	argv++;
	while (argc > 0) {
		BOOL had_parameter = FALSE; /* this argument had a parameter */
		if (!strncmp(*argv, "--", 2)) {
			/* option */
			if (!stricmp(*argv, "--listdrives")) {
				listdrives = TRUE;
			} else if (!stricmp(*argv, "--cdinfo")) {
				cdinfo = TRUE;
			} else if (!stricmp(*argv, "--drivename")) {
				if (argc <= 1) {
					Usage ("no drive name specified", 0);
				}
				drivename = argv[1];
				had_parameter = TRUE;
			} else if (!stricmp(*argv, "--write")) {
				write = TRUE;	
			} else if (!stricmp(*argv, "--real")) {
				real = TRUE;
			} else if (!stricmp(*argv, "--speedtest")) 
			{
				speedtest = TRUE;
			} else if (!stricmp(*argv, "--TAO")) {
				TAO = TRUE;
			} else if (!stricmp(*argv, "--bup")) 
			{
				bup = TRUE;
			} else if (!stricmp(*argv, "--read")) 
			{
				read = TRUE;
			} else if (!stricmp(*argv, "--speed")) {
				if (argc <= 1) {
					Usage ("missing argument for --speed", 0);
				}
				speed = atof (argv[1]);
				had_parameter = TRUE;
			} else if (!stricmp(*argv, "--artist"))
			{
				if (argc<=1)
					Usage("Missing argument for --artist", 0);
				artist=argv[1];
				had_parameter=TRUE;
			} else if (!stricmp(*argv, "--title"))
			{
				if (argc<=1)
					Usage("Missing argument for --title", 0);
				title=argv[1];
				had_parameter=TRUE;
			} else if (!stricmp(*argv, "--audioinindex0"))
			{
				bAudioInIndex0 = TRUE;
			} else if (!stricmp(*argv, "--pause"))
			{
				if(argc<=1)
					Usage("Missing argument for --pause", 0);
				pPauseLenStr=argv[1];
				had_parameter=TRUE;
			}
			else if (!stricmp(*argv, "--iso") || !stricmp(*argv, "--udf") || !stricmp(*argv, "--isoudf")) 
			{
				data = TRUE;
				if (argc > 1) {
					IsoTrack.SetVolumeName (argv[1]);
					had_parameter = TRUE;
				}
				IsoTrack.SetISO(!stricmp(*argv, "--iso") || !stricmp(*argv, "--isoudf"));
				IsoTrack.SetUDF(!stricmp(*argv, "--udf") || !stricmp(*argv, "--isoudf"));
			} 
			else if (!stricmp(*argv, "--dvd"))
			{
				dvd=TRUE;
			} 
			else if (!stricmp(*argv, "--dvdvideo"))
			{
				dvd=TRUE;
				IsoTrack.SetReallocDVDVideoFiles(TRUE);
			}
			else if (!stricmp (*argv, "--iso-no-joliet")) {
				IsoTrack.SetJoliet (FALSE);
			} else if (!stricmp (*argv, "--iso-mode2")) {
				IsoTrack.SetMode2 (TRUE);
			} else if (!stricmp (*argv, "--cdextra")) {
				CDExtra = TRUE;
			} else if (!stricmp (*argv, "--videocd"))
			{
				videocd = TRUE;
			} else if (!stricmp (*argv, "--svideocd"))
			{
				svideocd = TRUE;
			} else if (!stricmp (*argv, "--image"))
			{
				image = TRUE;
			} else if (!stricmp (*argv, "--eject"))
			{
				eject = TRUE;
			} else if (!stricmp (*argv, "--no_eject"))
			{
				no_eject = TRUE;
			} else if (!stricmp (*argv, "--load"))
			{
				load = TRUE;
			} else if (!stricmp (*argv, "--erase"))
			{
				erase = TRUE;
			} else if (!stricmp (*argv, "--entire"))
			{
				entire = TRUE;
			} else if (!stricmp( *argv, "--writebuffersize"))
			{
				if (argc<=1)
					Usage("Missing buffer size",0);
				else
				{
					writebuffersize=atoi(argv[1])*1024;
					had_parameter = TRUE;
				}
			} else if (!stricmp( *argv, "--tempdir"))
			{
				if (argc<=1)
					Usage("Missing temp directory",0);
				else
				{
					tempdir=argv[1];
					had_parameter = TRUE;
				}
			} else if (!stricmp( *argv, "--verify"))
			{
				verify = TRUE;
			} else if (!stricmp( *argv, "--listspeed"))
			{
				listspeed = TRUE;
			}
			else if (atoi(&argv[0][2])) {
				/* file with track number */
				int track_number = atoi(&argv[0][2]);
				if (argc <= 1) {
					Usage ("no file specified after track number %ld", (void *)track_number);
				}
				if (num_files < sizeof(files) / sizeof(files[0])) {
					tracks[num_files] = track_number;
					files[num_files++] = argv[1];
				} else {
					Usage ("Number of files limited to 99.", 0);
				}
				had_parameter = TRUE;
			} else {
				Usage ("Unknown parameter %s", argv[0]);
			}
		} else {
			/* file - either ISO or audio */
			if (data) {
				IsoTrack.AddEntry (*argv);
			} 
			else if (write)
			{
				if (num_files < sizeof(files) / sizeof(files[0])) {
					tracks[num_files] = 0;
					files[num_files++] = argv[0];
				} else {
					Usage ("Number of files limited to 99.", 0);
				}
			} else
			{
				Usage("",0);
				Exit(0);
			}
		}
		argc--;
		argv++;
		if (had_parameter) {
			argc--;
			argv++;
		}
	}

	/* verify args */
	if(TAO && bAudioInIndex0)
		Usage ("--TAO and --audioinindex0 are mutually exclusive", 0);
	if(pPauseLenStr != NULL)
	{
		iPauseLength = atoi(pPauseLenStr);
		if((iPauseLength<0) || (iPauseLength>7500))
			Usage ("invalid pause length specified (valid: 0-7500)", 0);
	}
	if(iPauseLength < 0)				/* Pause length unspecified -> set it to the default pause length of 2 seconds */
		iPauseLength = 2 * 75;
	if(TAO && (iPauseLength!=2*75))		/* In TAO only default pause length is supported */
	{
		Usage ("a pause length other than 150 blocks is not supported in TAO mode", 0);
	}
	if (read && write) {
		Usage ("--read and --write are mutually exclusive", 0);
	}
	if (read || write) {
		if (!drivename) {
			Usage ("required drive name not specified", 0);
		}
		if (!num_files && !data) {
			Usage ("no files specified", 0);
		}
		unsigned int i;
		for (i = 0; i < num_files; i++) {
			char *ext = strrchr (files[i], '.');

			if (ext && !stricmp (ext, ".wav") && !videocd && !svideocd) 
			{
				type[i] = WAV;
			} else if (ext && !stricmp (ext, ".mp3") && !videocd && !svideocd) 
			{
				type[i] = MP3;
			} else if (ext && !stricmp (ext, ".wma") && !videocd && !svideocd) 
			{
				type[i] = WMA;
			} else if (ext && !stricmp (ext, ".pcm") && !videocd && !svideocd)
			{
				type[i] = PCM;
			} else if (ext && (!stricmp (ext, ".mpg") || !stricmp (ext, ".mpeg")) && (videocd || svideocd))
			{
				type[i] = MPEG;
			} else if (ext && !stricmp (ext, ".avi") && (videocd || svideocd))
			{
				type[i] = AVI;
			} else if (ext && (!stricmp (ext, ".jpg") || !stricmp (ext, ".jpeg")) && (videocd || svideocd))
			{
				type[i] = JPEG;
			} else if (ext && (!stricmp (ext, ".nrg") || !stricmp (ext, ".iso") || !stricmp (ext, ".cue"))  && image)
			{
				type[i] = IMAGE;
			}
			else {
				type[i] = UNKNOWN;
				Usage ("unknown file type %s", files[i]);

⌨️ 快捷键说明

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