www.pudn.com > NEROSDK5582.ZIP > getopt.cpp
/******************************************************************************
|* 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-2002 Ahead Software AG. All Rights Reserved.
|*-----------------------------------------------------------------------------
|* NeroSDK / NeroCmd
|*
|* PROGRAM: getopt.cpp
|*
|* PURPOSE: Constructors for PARAMETERS class
|* Decoding of argument list
|* Help function
|* Parsing of parameter file
******************************************************************************/
#include "stdafx.h"
#include "getopt.h"
#include "parameters.h"
// forward declarations
static void Usage (void);
static bool ReadParameterFile (PARAMETERS & params, LPCSTR psFilename);
// These are error strings that correspond to the error codes above.
static LPCSTR s_cle[CLE_MAX] = {
"Everything fine.",
"Multiple commands were specified from the following set: listdrives, cdinfo, read, write, erase, eject, load. Only one command is allowed at one time.",
"Missing drive name parameter after --drivename.",
"Missing artist parameter after --artist.",
"Missing title parameter after --title.",
"Missing speed parameter after --speed.",
"Supplied speed parameter is invalid.",
"Missing volume name parameter after --iso.",
"Invalid -- parameter.",
"Multiple burn types were specified from the following set: iso/audio, videocd, svideocd, image. Only one burn type is allowed at one time.",
"Missing file name after --XX parameter.",
"Maximum number of 99 tracks has been reached.",
"Parameter file was already processed. It cannot be done recursively!",
"Missing image filename parameter after --image.",
"Missing error log filename parameter after --error_log.",
"Missing import session parameter after --import.",
"Supplied import session parameter is invalid.",
"Iso/Audio and (S)VideoCD need at least one track!",
"Burn type was not specified! Use a proper combination of --audio, --videocd, --svideocd and --iso.",
};
// This function decodes the argument list.
bool getopt (PARAMETERS & params, int argc, char ** argv)
{
if ((0 == argc) && (params.GetProcessedParameterFile() == false))
{
Usage ();
return false;
}
COMMAND_LINE_ERRORS ecl = CLE_NO_ERROR;
try
{
for (; argc; argc--, argv++)
{
if (CLE_NO_ERROR != ecl)
{
throw ecl;
}
else if (!stricmp (*argv, "--listdrives"))
{
ecl = params.SetCommand(COMMAND_LISTDRIVES);
}
else if (!stricmp (*argv, "--version"))
{
ecl = params.SetCommand(COMMAND_VERSION);
}
else if (!stricmp (*argv, "--cdinfo"))
{
ecl = params.SetCommand(COMMAND_CDINFO);
}
else if (!stricmp (*argv, "--read"))
{
ecl = params.SetCommand(COMMAND_READ);
}
else if (!stricmp (*argv, "--write"))
{
ecl = params.SetCommand(COMMAND_WRITE);
}
else if (!stricmp (*argv, "--erase"))
{
ecl = params.SetCommand(COMMAND_ERASE);
}
else if (!stricmp (*argv, "--eject"))
{
ecl = params.SetCommand(COMMAND_EJECT);
}
else if (!stricmp (*argv, "--load"))
{
ecl = params.SetCommand(COMMAND_LOAD);
}
else if (!stricmp (*argv, "--drivename"))
{
ecl = params.SetDriveName(argc, argv);
}
else if (!stricmp (*argv, "--real"))
{
ecl = params.SetUseReal();
}
else if (!stricmp (*argv, "--tao"))
{
ecl = params.SetUseTAO();
}
else if (!stricmp (*argv, "--underrun_prot"))
{
ecl = params.SetUseUnderRunProt();
}
else if (!stricmp (*argv, "--no_error_log"))
{
ecl = params.SetWriteErrorLog();
}
else if (!stricmp (*argv, "--speedtest"))
{
ecl = params.SetSpeedTest();
}
else if (!stricmp (*argv, "--enable_abort"))
{
ecl = params.SetEnableAbort();
}
else if (!stricmp (*argv, "--close_session"))
{
ecl = params.SetCloseSession();
}
else if (!stricmp (*argv, "--detect_non_empty_cdrw"))
{
ecl = params.SetDetectNonEmptyCDRW();
}
else if (!stricmp (*argv, "--cd_text"))
{
ecl = params.SetUseCDText();
}
else if (!stricmp (*argv, "--use_rockridge"))
{
ecl = params.SetUseRockridge();
}
else if (!stricmp (*argv, "--create_iso_fs"))
{
ecl = params.SetCreateIsoFs();
}
else if (!stricmp (*argv, "--create_udf_fs"))
{
ecl = params.SetCreateUdfFs();
}
else if (!stricmp (*argv, "--import_rockridge"))
{
ecl = params.SetImportRockridge();
}
else if (!stricmp (*argv, "--import_iso_only"))
{
ecl = params.SetImportIsoOnly();
}
else if (!stricmp (*argv, "--prefer_rockridge"))
{
ecl = params.SetPreferRockridge();
}
else if (!stricmp (*argv, "--disable_eject"))
{
ecl = params.SetDisableEject();
}
else if (!stricmp (*argv, "--verify"))
{
ecl = params.SetVerify();
}
else if (!stricmp (*argv, "--error_log"))
{
ecl = params.SetErrorLogName(argc, argv);
}
else if (!stricmp (*argv, "--artist"))
{
ecl = params.SetArtist(argc, argv);
}
else if (!stricmp (*argv, "--title"))
{
ecl = params.SetTitle(argc, argv);
}
else if (!stricmp (*argv, "--speed"))
{
ecl = params.SetSpeed(argc, argv);
}
else if (!stricmp (*argv, "--import"))
{
ecl = params.SetSessionToImport(argc, argv);
}
else if (!stricmp (*argv, "--cdextra"))
{
params.SetCDExtra();
}
else if (!stricmp (*argv, "--iso"))
{
ecl = params.SetISOSelected(argc, argv);
}
else if (!stricmp (*argv, "--iso-no-joliet"))
{
params.SetUseJoliet();
}
else if (!stricmp (*argv, "--iso-mode2"))
{
params.SetUseMode2();
}
else if (!stricmp (*argv, "--audio"))
{
ecl = params.SetAudioSelected();
}
else if (!stricmp (*argv, "--videocd"))
{
ecl = params.SetBurnType(BURNTYPE_VIDEOCD);
}
else if (!stricmp (*argv, "--svideocd"))
{
ecl = params.SetBurnType(BURNTYPE_SVIDEOCD);
}
else if (!stricmp (*argv, "--image"))
{
params.SetImageBurnType(argc, argv);
}
else if (!stricmp (*argv, "--freestyle_mode1") ||
!stricmp (*argv, "--freestyle_mode2") ||
!stricmp (*argv, "--freestyle_audio"))
{
params.SetFreestyleBurnType(argc, argv);
}
else if (!stricmp (*argv, "--entire"))
{
ecl = params.SetEraseMode(NEROAPI_ERASE_ENTIRE);
}
else if (!stricmp (*argv, "--dvd"))
{
ecl = params.SetUseDVD();
}
else if (!stricmp (*argv, "--nero_log_timestamp"))
{
ecl = params.SetNeroLogTimestamp();
}
else if (!stricmp (*argv, "--force_erase_cdrw"))
{
ecl = params.SetForceEraseCDRW();
}
else if ((*argv)[0] == '@')
{
if (params.GetProcessedParameterFile() == true)
{
throw CLE_PARAMETER_FILE_ALREADY_PROCESSED;
}
ecl = params.SetProcessedParameterFile();
if (CLE_NO_ERROR != ecl)
{
throw ecl;
}
if (!ReadParameterFile (params, &(*argv)[1]))
{
return false;
}
}
else if (!strncmp (*argv, "--", 2))
{
ecl = params.AddAudioReadTrack(argc, argv);
}
else
{
ecl = params.AddAudioIsoFreestyleWriteTrack(argc, argv);
}
}
// Make sure we had no error during
// the last loop execution.
if (CLE_NO_ERROR != ecl)
{
throw ecl;
}
if (params.GetCommand() == COMMAND_WRITE && params.GetBurnType() == BURNTYPE_UNKNOWN)
{
throw CLE_BURN_TYPE_NOT_SPECIFIED;
}
if ((params.GetBurnType() == BURNTYPE_ISOAUDIO ||
params.GetBurnType() == BURNTYPE_SVIDEOCD ||
params.GetBurnType() == BURNTYPE_VIDEOCD) &&
params.GetNumberOfTracks() <= 0 && params.GetFileListSize() == 0)
{
throw CLE_NEED_TRACKS;
}
}
catch (COMMAND_LINE_ERRORS e)
{
printf ("%s\n", s_cle[e]);
Usage ();
return false;
}
return true;
}
// This function displays usage information after the user enters incorrect parameters.
// It always displays only as many lines of text as there are visible lines.
static void Usage (void)
{
LPCSTR psMessage =
"\nUsage:\n"
" _______________\n"
" | list available| --listdrives\n"
" | drives |\n"
" |_______________|\n"
" | obtain cd info| --cdinfo --drivename \n"
" |_______________|\n"
" | write | --write --drivename [--real] [--tao]\n"
" | iso/audio cd | [--artist ] [--title ] [--speed ]\n"
" | | [--audio]