home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / appwiz / customwz / zap.h < prev    next >
C/C++ Source or Header  |  1998-03-05  |  4KB  |  100 lines

  1. // zap.h : declaration of the CZap class.  This class handles zapping the files
  2. //          of a project off of which we're basing the generated custom
  3. //          AppWizard The files are zapped into templates used by the generated
  4. //          custom AppWizard.  Class and file names from the original project
  5. //          are "macroized" so that the generated custom AppWizard will create
  6. //          new projects with class and file names derived from the new
  7. //          projects' names, rather than from the original project's name.
  8. //
  9. // Copyright (c) 1985-1998, Microsoft Corporation. All rights reserved.
  10. //
  11.  
  12. #ifndef __ZAP_H__
  13. #define __ZAP_H__
  14.  
  15. // Each ZRDRootType represents a string derived from the original project
  16. //  name.
  17. #define NUM_ROOT_TYPES 10
  18. enum ZRDRootType
  19. {
  20.     ZRD_ROOT,
  21.     ZRD_ROOT_UPR,
  22.     ZRD_SAFE_ROOT,
  23.     ZRD_CLASS,
  24.     ZRD_FILEBASE,
  25.     ZRD_DOC,
  26.     ZRD_DOC_UPR,
  27.     ZRD_MAC_TYPE,
  28.     ZRD_R_FILE,
  29.     ZRD_R_FILE_UPR,
  30. };
  31.  
  32. // Each instance of this structure contains a recipe for matching one
  33. //  string in the original project, and replacing it with a string
  34. //  to be put in the generated custom AppWizard's templates.
  35. struct ZapRawData
  36. {
  37.     // Strings composing item to match
  38.     LPCTSTR lpszPre;
  39.     ZRDRootType nRootType;
  40.     LPCTSTR lpszPost;
  41.  
  42.     // Strings to replace it with
  43.     LPCTSTR lpszReplace[2];
  44. };
  45.  
  46. class OutputStream;
  47.  
  48. // There is only one CZap instantiated at a time.  It corresponds to the
  49. //  project off of which we're basing the custom AppWizard.  It's capable of
  50. //  macroizing ("zapping") individual filenames (ZapFileName) and
  51. //  template-izing ("zapping") entire files (ZapFile).
  52. class CZap
  53. {
  54. public:
  55.     CZap()
  56.         { m_hFile = NULL; m_hMapping = NULL; m_pStrMatches = NULL; m_bBinary = FALSE; m_posTplName = NULL; }
  57.     ~CZap();
  58.  
  59.     void DefineGeneratedNewprojInfMacro()
  60.         { DefineStringMacro(_T("GENERATED_NEWPROJ_INF_FILES"), m_strGeneratedNewProjInfo); }
  61.  
  62.     LPCTSTR LoadFile(LPCTSTR lpszResource, DWORD& dwSize);
  63.     void ZapFile(LPCTSTR lpszInput, DWORD dwSize, OutputStream* pOutput);
  64.     void ZapFileName(LPCTSTR lpszFileName, CString& rStrZappedFile, int iReplace = 0);
  65.     void UnloadFile();
  66.     void SetRoot(LPCTSTR lpszDir, LPCTSTR lpszRoot);
  67.  
  68. protected:
  69.     void InitMatches();
  70.     void FreeMatches();
  71.     void ZapLine(CString& strLine, int iReplace = 0);
  72.     void AddToNewProjInf();
  73.  
  74.     BOOL m_bBinary;             // Is the file we've loaded binary?
  75.     HANDLE m_hFile;             // Handle to file we're currently zapping
  76.     HANDLE m_hMapping;          // Handle to memory-mapping of that file
  77.     LPCTSTR m_lpszFile;         // Pointer to view of file mapped to memory
  78.     CString m_strRoot;          // Remembers name of project; used for matching
  79.                                 //  strings to replace
  80.     POSITION m_posTplName;      // Current POSITION in the TemplateNames CStringList.
  81.     CString m_strRootDir;       // Remembers root directory of original project;
  82.                                 //  used to preserve nesting from original project
  83.                                 //  files to projects generated by the custom
  84.                                 //  AppWizard we're generating
  85.     CString m_strSubdir;        // Nesting level of file we're currently zapping.
  86.     CString m_strFile;          // Name of file we're currently zapping
  87.     CString m_strBaseFileName;  // Base name (no path/ext) of that file
  88.     CString m_strFileExt;       // Extension of that file
  89.  
  90.     CString m_strGeneratedNewProjInfo;  // Value to set "GENERATED_NEWPROJ_INF_FILES"
  91.                                         //  macro to.
  92.  
  93.     CString* m_pStrMatches;     // Array of strings to search for when zapping a
  94.                                 //  file.  The entries correspond 1-to-1 with
  95.                                 //  entries of the zrdGeneral[] array defined
  96.                                 //  in zap.cpp
  97. };
  98.  
  99. #endif //__ZAP_H__
  100.