home *** CD-ROM | disk | FTP | other *** search
- /*==================================================================
- File: Win32ZStringExtractTool.cpp
-
- Contains: Tool for creating override libraries for
- ZStrings on the Windows
-
- Written by: Nalini Prakash
-
- Copyright: 2000-2001 Connectix Corporation
-
- This source has been placed into the public domain by
- Connectix Corporation. You have the right to modify,
- distribute or use this code without any legal limitations
- or finanicial/licensing requirements. Connectix is not
- liable for any problems that result from the use of this
- code.
-
- If you have comments, feedback, questions, or would like
- to submit bug fixes or updates to this code, please email
- opensource@connectix.com.
- ==================================================================*/
-
- #include "StdAfx.h"
-
- #include "ZStringTypes.h"
- #include "ZStringTool.h"
-
- #include "Win32ZStringTools.h"
- #include "Win32ZStringOverrideTool.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
-
-
- char * Win32ZStringOverrideTool::sNewBinaryTitle = "Please Select New Binary File";
- char * Win32ZStringOverrideTool::sReportFileTitle = "Please Select Report File";
-
-
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
-
- Win32ZStringOverrideTool::Win32ZStringOverrideTool()
- {
- }
-
- Win32ZStringOverrideTool::~Win32ZStringOverrideTool()
- {
- }
-
-
- bool
- Win32ZStringOverrideTool::CreateOverrideDictionary(
- CString inSrcFile,
- CString inDestFile,
- ZToolOptions inOptions)
- {
- HANDLE overrideFile = INVALID_HANDLE_VALUE;
- HANDLE memOverride = NULL;
- char * overrideFileImage = NULL;
- Z_UInt32 overrideFileSize = 0;
-
- // Open as a memory mapped file.
- if (!::OpenMemMappedFile(inSrcFile, overrideFile, memOverride,
- overrideFileImage, overrideFileSize))
- {
- ::AfxMessageBox("Unable to open the source file.\n Override will not be completed.");
- return false;
- }
-
- CWaitCursor wait;
-
- // Process the data.
- ZStringTool stringTool;
- stringTool.ProcessBinaries(overrideFileImage, overrideFileSize, NULL, 0, inOptions);
-
- FILE * errorFile = fopen("errors.html", "w+");
- if (errorFile == NULL)
- ::AfxMessageBox("Unable to open the error file.\n Any errors will not be reported.");
- else {
- Z_Boolean isOk = stringTool.PrintReport(errorFile, inOptions);
- fclose(errorFile);
-
- if (!isOk) {
- ::ShellExecute(NULL, "open", "errors.html", NULL, NULL, SW_SHOWNORMAL);
- ::AfxMessageBox("Errors have been found. These need fixed before the override dictionary will print.\n");
- return false;
- }
- }
-
- if (overrideFile != INVALID_HANDLE_VALUE)
- ::CloseFiles(overrideFileImage, memOverride, overrideFile);
-
- char * dictionary = NULL;
- Z_UInt32 dictLength;
-
- Z_Boolean success = stringTool.CreateOverrideDictionary(dictionary, dictLength);
-
- if (!success)
- {
- ::AfxMessageBox("Unable to allocate the dictionary.\n Override will not be completed.");
- return false;
- }
-
- char * newResHandle = new char[dictLength];
-
- if (newResHandle == NULL)
- {
- ::AfxMessageBox("Unable to allocate a new resource.\n Override will not be completed.");
- return false;
- }
-
- memcpy(newResHandle, dictionary, dictLength);
-
- try
- {
- CFile reportFile;
- CString reportFileName = inDestFile;
-
- // Delete any existing file, and create a new override file.
- reportFile.Open(reportFileName, CFile::modeCreate |
- CFile::modeReadWrite);
-
- reportFile.Write(newResHandle, dictLength);
-
- reportFile.Close(); // if omitted, destuctor will close.
- }
- catch (CFileException * exp)
- {
- // Display error message.
- exp->ReportError();
- exp->Delete();
- if (dictionary != NULL)
- free(dictionary);
- delete [] newResHandle;
- return false;
- }
-
- ::AfxMessageBox("Override dictionary printed successfully.\n");
-
- delete [] dictionary;
- delete [] newResHandle;
-
- return true;
- }
-
-
-