- wxRemoveFile(_T("chapters.rtf"));
- wxRemoveFile(_T("header.rtf"));
-
- if (winHelp)
- {
- wxRemoveFile(_T("sections.rtf"));
- wxRemoveFile(_T("subsections.rtf"));
- wxRemoveFile(_T("subsubsections.rtf"));
- wxRemoveFile(_T("popups.rtf"));
+ wxString 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 ((outputDirStr.empty()) || // no path specified on output file
+ (cwdStr != outputDirStr)) // paths do not match
+ {
+ wxRenameFile(_T("tmp1.rtf"), OutputFile);
+ }
+ else
+ {
+ wxCopyFile(_T("tmp1.rtf"), OutputFile);
+ }
+ Tex2RTFYield(true);
+ wxRemoveFile(_T("tmp1.rtf"));
+ }
+
+ if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName);
+
+ if (!wxRenameFile(TmpContentsName, ContentsName))
+ {
+ wxCopyFile(TmpContentsName, ContentsName);
+ wxRemoveFile(TmpContentsName);
+ }
+
+ wxRemoveFile(_T("chapters.rtf"));
+ wxRemoveFile(_T("header.rtf"));
+
+ if (winHelp)
+ {
+ wxRemoveFile(_T("sections.rtf"));
+ wxRemoveFile(_T("subsections.rtf"));
+ wxRemoveFile(_T("subsubsections.rtf"));
+ wxRemoveFile(_T("popups.rtf"));
+ }
+ if (winHelp && generateHPJ)
+ WriteHPJ(OutputFile);
+ return true;