isotrack.cpp
来自「把doc文档转成pdf后刻录成CD,用VC++开发,用了Nero的SDK和CXI」· C++ 代码 · 共 719 行 · 第 1/2 页
CPP
719 行
// Compare entry names...
//
if ((*ppItemFirst)->isDirectory == (*ppItemSecond)->isDirectory &&
0 == stricmp (GetFilename (*ppItemFirst), GetFilename (*ppItemSecond)))
{
bool bReplace = true;
// The items point to the same file/directory. We need
// to remove one of them. Which one is removed depends
// on whether "--backup" is specified on command line.
// If it is a directory, make sure to recurse anyway
// because the trees below may not be identical.
//
if ((*ppItemFirst)->isDirectory)
{
bSuccess = MergeIsoTrack (params, &(*ppItemFirst)->subDirFirstItem, (*ppItemSecond)->subDirFirstItem);
(*ppItemSecond)->subDirFirstItem = NULL;
if (!bSuccess)
{
break;
}
// Since the item is a directory, we won't replace
// the old one as it doesn't matter which one we
// keep. Directory is just a name. It has no file
// access time stamp.
//
bReplace = false;
}
else
{
// If there is a file name conflict between iso items
// that don't belong to imported sessions, ask the user
// what to do.
//
if (!(*ppItemFirst)->isReference)
{
printf ("\nThere is a file name conflict!\n"
"%s\n"
"%s\n"
"Do you want to use the first or second file, or to exit?\n",
GetFilenameSourcePath (*ppItemFirst),
GetFilenameSourcePath (*ppItemSecond));
static const CResponsePairs mapping[] = {
"First", DLG_RETURN_TRUE,
"Second", DLG_RETURN_FALSE,
"Exit", DLG_RETURN_CANCEL,
NULL};
CResponse response (mapping, 0);
NeroUserDlgInOut result = response;
// If the user chose to quit, then obey and quit.
//
if (result == DLG_RETURN_CANCEL)
{
bSuccess = false;
break;
}
else
{
// Otherwise, choose between first and second
// file.
//
bReplace = (result == DLG_RETURN_FALSE);
}
}
else
{
// If no "--backup" was specified, always replace
// the old files.
//
if (!params.GetBackup ())
{
bReplace = true;
}
else
{
// If there is a "--backup" command line,
// replace the old one only if older in terms
// of access times.
//
time_t timeOld = mktime (&(*ppItemFirst)->entryTime);
time_t timeNew = mktime (&(*ppItemSecond)->entryTime);
bReplace = timeOld < timeNew;
}
}
}
if (bReplace)
{
// We will now switch places of items in the first and
// second tree. Since one of the items has to be deleted
// eventually, this operation will essentially keep
// the item from the second tree and delete the item
// from the first tree.
//
NERO_ISO_ITEM * pTempItem = *ppItemSecond;
*ppItemSecond = *ppItemFirst;
*ppItemFirst = pTempItem;
pTempItem = (*ppItemSecond)->nextItem;
(*ppItemSecond)->nextItem = (*ppItemFirst)->nextItem;
(*ppItemFirst)->nextItem = pTempItem;
}
// Remove the item from the second tree.
//
NERO_ISO_ITEM * pTempItem = *ppItemSecond;
*ppItemSecond = pTempItem->nextItem;
pTempItem->nextItem = NULL;
DeleteIsoItemTree (pTempItem);
}
else
{
// No match, advance to the next item.
//
ppItemSecond = &(*ppItemSecond)->nextItem;
}
}
}
// Attach whatever is left of the new tree to the main tree.
//
*ppItemFirst = pItemToAdd;
// Returning true means, everything is fine, continue.
//
return bSuccess;
}
// This function deletes the iso tree recursively.
void CBurnContext::DeleteIsoItemTree (NERO_ISO_ITEM * pItem)
{
// First free our own long filename strings, then free the whole tree.
//
FreeOurOwnResources (pItem);
NeroFreeIsoItemTree (pItem);
}
void CBurnContext::FreeOurOwnResources (NERO_ISO_ITEM * pItem)
{
// Step through the tree until the
// ISO item tree pointer becomes NULL
while (NULL != pItem)
{
NERO_ISO_ITEM* pNextItem = pItem->nextItem;
if (pItem->isDirectory)
{
// We have encountered another ISO item tree;
// recurse another level.
FreeOurOwnResources (pItem->subDirFirstItem);
}
// It the item is not a reference, free its associated long
// filenames, if any.
//
if (!pItem->isReference)
{
delete pItem->longFileName;
delete (char *) pItem->longSourceFilePath;
}
pItem = pNextItem;
}
}
// This function searches for a specified path and recursively adds
// all files and directories that are found.
CExitCode CBurnContext::CreateIsoTree (const PARAMETERS & params, LPCSTR psFilename, NERO_ISO_ITEM ** ppItem, int iLevel)
{
// CFindFiles is a helper class for file and subdirectory handling
CFindFiles ff (psFilename);
*ppItem = NULL;
if (!ff.IsValidEntry())
{
if (0 == iLevel)
{
// If we haven't found any entries and we are on the
// first level of recursion then this should be
// reported as an error.
m_ErrorLog.printf ("File specification '%s' resulted in no matches!\n", psFilename);
return EXITCODE_FILE_NOT_FOUND;
}
else
{
// If we are on a level other than first, it is ok
// not to find any entries. This simply means we
// stumbled upon an empty directory somewhere in a tree.
return EXITCODE_OK;
}
}
char sPath[MAX_PATH];
// Make sure that we have no relative path names, but only absolute paths
if (NULL == _fullpath (sPath, psFilename, sizeof (sPath)))
{
// Our path buffer is too small. Bail out!
return EXITCODE_INTERNAL_ERROR;
}
// Find the last blackslash and remove it if found.
// This will leave us with a root directory.
LPSTR psBackslash = strrchr (sPath, '\\');
if (NULL != psBackslash)
{
*psBackslash = '\0';
}
do
{
std::string sNewPath;
sNewPath = sPath;
sNewPath += "\\";
sNewPath += ff.GetName ();
if (ff.IsSubDir())
{
// Here we handle subdirectories
// strcmp returns 0 on equal strings.
// Proceed if name contains none of "." or ".."
if ((0 != strcmp (ff.GetName (), ".")) && (0 != strcmp (ff.GetName (), "..")))
{
// Append a wildcard to the path and do a recursive search.
sNewPath += "\\";
sNewPath += ff.GetWildcard ();
NERO_ISO_ITEM * pNewItem = NeroCreateIsoItem ();
if (NULL == pNewItem)
{
DeleteIsoItemTree (*ppItem);
return EXITCODE_OUT_OF_MEMORY;
}
// Attach this item to the beginning of the list.
if (*ppItem != NULL)
{
pNewItem->nextItem = *ppItem;
}
*ppItem = pNewItem;
pNewItem->isDirectory = TRUE;
time_t t = ff.GetCreateTime ();
pNewItem->entryTime = *localtime (&t);
StoreFileName (pNewItem->fileName, pNewItem->longFileName, ff.GetName ());
// If we the user wants recursive search, only then do we
// actually recurse at deeper levels otherwise ignore directories
// alltogether.
//
if (params.GetRecursive ())
{
// Create an ISO item tree at a deeper level
EXITCODE code = CreateIsoTree (params, sNewPath.c_str (), &pNewItem->subDirFirstItem, iLevel + 1);
if (EXITCODE_OK != code)
{
DeleteIsoItemTree (*ppItem);
return code;
}
// We don't allow empty directories. This should probably
// be regulated by a command line switch.
//
if (pNewItem->subDirFirstItem == NULL)
{
// If the newly added directory is empty, remove it!
// We first detach it from the list and then
// deallocate it.
//
*ppItem = pNewItem->nextItem;
pNewItem->nextItem = NULL;
DeleteIsoItemTree (pNewItem);
}
}
}
}
else
{
// Here we handle regular files
NERO_ISO_ITEM * pNewItem = NeroCreateIsoItem ();
if (NULL == pNewItem)
{
DeleteIsoItemTree (*ppItem);
return EXITCODE_OUT_OF_MEMORY;
}
StoreFileName (pNewItem->sourceFilePath, (char *) pNewItem->longSourceFilePath, sNewPath.c_str ());
pNewItem->isDirectory = FALSE;
time_t t = ff.GetCreateTime ();
pNewItem->entryTime = *localtime (&t);
StoreFileName (pNewItem->fileName, pNewItem->longFileName, ff.GetName ());
// Attach this item to the beginning of the list.
if (*ppItem != NULL)
{
pNewItem->nextItem = *ppItem;
}
*ppItem = pNewItem;
}
ff.FindNext ();
}
while (ff.IsValidEntry ());
return EXITCODE_OK;
}
void CBurnContext::StoreFileName (char (& shortFilename) [252], char * psLongFilename, LPCSTR psFilename)
{
// If filename can fit in the old field, store it there
// to prevent unnecessary allocation. If not, allocate
// a sufficient buffer to hold the string.
//
int iLen = strlen (psFilename);
if (iLen < sizeof (shortFilename))
{
strcpy (shortFilename, psFilename);
}
else
{
psLongFilename = new char [iLen + 1];
if (psLongFilename != NULL)
{
strcpy (psLongFilename, psFilename);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?