home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / Sessions / Traut / ZStrings / Source / Win32 / Win32ZStringCompareTool.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  3.3 KB  |  123 lines

  1. /*==================================================================
  2.     File:        Win32ZStringCompareTool.cpp
  3.  
  4.     Contains:    Tool for comparing ZString information from
  5.                 a binary on Windows.
  6.  
  7.     Written by:    Hayley Iben
  8.  
  9.     Copyright:    2000-2001 Connectix Corporation
  10.     
  11.     This source has been placed into the public domain by
  12.     Connectix Corporation. You have the right to modify, 
  13.     distribute or use this code without any legal limitations
  14.     or finanicial/licensing requirements. Connectix is not 
  15.     liable for any problems that result from the use of this 
  16.     code.
  17.     
  18.     If you have comments, feedback, questions, or would like
  19.     to submit bug fixes or updates to this code, please email
  20.     opensource@connectix.com.
  21. ==================================================================*/
  22.  
  23. #include "StdAfx.h"
  24. #include "ZStringTool.h"
  25.  
  26. #include "Win32ZString.h"
  27. #include "Win32ZStringTools.h"
  28. #include "Win32ZStringCompareTool.h"
  29.  
  30.  
  31. #ifdef _DEBUG
  32. #undef THIS_FILE
  33. static char THIS_FILE[]=__FILE__;
  34. #define new DEBUG_NEW
  35. #endif
  36.  
  37. //////////////////////////////////////////////////////////////////////
  38. // Construction/Destruction
  39. //////////////////////////////////////////////////////////////////////
  40.  
  41. Win32ZStringCompareTool::Win32ZStringCompareTool()
  42.     : mNewFile(INVALID_HANDLE_VALUE),
  43.     mNewMemFile(0),
  44.     mNewBinaryImage(0),
  45.     mOldFile(INVALID_HANDLE_VALUE),
  46.     mOldMemFile(0),
  47.     mOldBinaryImage(0)
  48. {
  49. }
  50.  
  51. Win32ZStringCompareTool::~Win32ZStringCompareTool()
  52. {
  53.     // CleanUp.
  54.     if (mNewFile != INVALID_HANDLE_VALUE)
  55.         ::CloseFiles(mNewBinaryImage, mNewMemFile, mNewFile);
  56.  
  57.     if (mOldFile != INVALID_HANDLE_VALUE)
  58.         ::CloseFiles(mOldBinaryImage, mOldFile, mOldFile);
  59. }
  60.  
  61.  
  62. /*------------------------------------------------------------------
  63.     CompareZStrings
  64. ------------------------------------------------------------------*/
  65.  
  66. bool
  67. Win32ZStringCompareTool::CompareZStrings(
  68.     CString                    inSrcFile, 
  69.     CString                    inCmpFile,
  70.     CString                    inDestFile,
  71.     ZToolOptions            inOptions)
  72. {
  73.     Z_UInt32            newBinarySize;
  74.     Z_UInt32            oldBinarySize;
  75.  
  76.     // Open as a memory mapped file.
  77.     if (!::OpenMemMappedFile(inSrcFile, mNewFile, mNewMemFile,
  78.             mNewBinaryImage, newBinarySize))
  79.     {
  80.         ::AfxMessageBox("Unable to open the source file.\n Comparison will not be completed.");
  81.         return false;
  82.     }
  83.  
  84.     if (!::OpenMemMappedFile(inCmpFile, mOldFile, mOldMemFile,
  85.         mOldBinaryImage, oldBinarySize))
  86.     {
  87.         ::AfxMessageBox("Unable to open the comparison file.\n Comparison will not be completed.");
  88.         return false;
  89.     }
  90.  
  91.     // Open report file. 
  92.     FILE * reportFile = fopen(inDestFile, "w+");
  93.     if (reportFile == NULL) 
  94.     {
  95.         ::AfxMessageBox("Unable to open the destination file.\n Comparison will not be completed.");
  96.         return false;
  97.     }
  98.     
  99.     CWaitCursor    cursor;
  100.     // Process the data.
  101.     ZStringTool        stringTool;    
  102.  
  103.     CString fileName = inSrcFile;
  104.     fileName.MakeLower();
  105.     inOptions.mHasOTags = (fileName.Find(".dict")!=-1);        // If the file is an override file, it has <O name= tags
  106.  
  107.     stringTool.ProcessBinaries(mNewBinaryImage, newBinarySize, mOldBinaryImage, oldBinarySize, inOptions);
  108.     stringTool.PrintReport(reportFile, inOptions);
  109.  
  110.     fclose(reportFile);
  111.  
  112.     if (mNewFile != INVALID_HANDLE_VALUE)
  113.         ::CloseFiles(mNewBinaryImage, mNewMemFile, mNewFile);
  114.     if (mOldFile != INVALID_HANDLE_VALUE)
  115.         ::CloseFiles(mOldBinaryImage, mOldFile, mOldFile);
  116.  
  117.     ::AfxMessageBox("Comparison report printed successfully.");
  118.     return true;
  119. }
  120.  
  121.  
  122.  
  123.