- wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
- Tex2RTFYield(TRUE);
- if (FileExists(OutputFile)) wxRemoveFile(OutputFile);
- wxCopyFile("tmp1.rtf", OutputFile);
- Tex2RTFYield(TRUE);
- wxRemoveFile("tmp1.rtf");
+ wxConcatFiles(_T("header.rtf"), _T("chapters.rtf"), _T("tmp1.rtf"));
+ Tex2RTFYield(true);
+ if (wxFileExists(OutputFile))
+ wxRemoveFile(OutputFile);
+
+ wxChar *cwdStr;
+ cwdStr = wxGetWorkingDirectory();
+
+ wxString outputDirStr;
+ outputDirStr = wxPathOnly(OutputFile);
+
+ // Determine if the temp file and the output file are in the same directory,
+ // and if they are, then just rename the temp file rather than copying
+ // it, as this is much faster when working with large (multi-megabyte files)
+ if ((wxStrcmp(outputDirStr.c_str(),_T("")) == 0) || // no path specified on output file
+ (wxStrcmp(cwdStr,outputDirStr.c_str()) == 0)) // paths do not match
+ {
+ wxRenameFile(_T("tmp1.rtf"), OutputFile);
+ }
+ else
+ {
+ wxCopyFile(_T("tmp1.rtf"), OutputFile);
+ }
+ delete [] cwdStr;
+ Tex2RTFYield(true);
+ wxRemoveFile(_T("tmp1.rtf"));