mxsZipPackage.h

Go to the documentation of this file.
00001 /*  
00002  *      MSZipPackage.h - MAXScript Zip Module file classes & utilities
00003  *
00004  *          Copyright (c) Autodesk, Inc, 2000.  John Wainwright.
00005  *
00006  */
00007 
00008 #pragma once
00009 
00010 #include "..\compiler\parser.h"
00011 
00012 class MSZipPackage;
00013 class DotRunParser;
00014 class MZPExtraction;
00015 class TabMZPExtraction;
00016 
00017 // MZPExtraction & TabMZPExtraction, for maintaing a table of
00018 //   file extractions so far giving name in .zip and local extracted name
00019 class MZPExtraction
00020 {
00021 public:
00022     MSTR zip_name;
00023     MSTR extracted_name;
00024 
00025     MZPExtraction(const MCHAR* zip_name, const MCHAR* extracted_name) :
00026         zip_name(zip_name), extracted_name(extracted_name) { }
00027 };
00028 
00029 class TabMZPExtraction : public Tab<MZPExtraction*>
00030 {
00031 public:
00032     ~TabMZPExtraction();
00033 
00034     MCHAR* find(const MCHAR* zip_name);
00035     void   add(const MCHAR* zip_name, const MCHAR* extracted_name);
00036 };
00037 
00038 // MSZipPackage: instances represent open .mzp module files
00039 class MSZipPackage : public Value
00040 {
00041 public:
00042     enum clear_modes { CLEAR_NOW, CLEAR_ON_MAX_EXIT, CLEAR_ON_RESET, KEEP, };   // clear temp modes
00043 
00044     MSTR    file_name;          // zip module file name
00045     MSTR    package_name;       // parsed from mzp.run file...
00046     MSTR    description;
00047     int     version;
00048     MSTR    extract_dir;        // current extract dir
00049     MSTR    drop_file;          // primary drop file (if any in found)
00050     TabMZPExtraction extractions; // currently extracted files
00051     clear_modes clear_mode;
00052     WORD    flags;              // flag bits
00053 
00054     MSZipPackage(const MCHAR* file_name) : file_name(file_name), flags(0), clear_mode(CLEAR_ON_MAX_EXIT) { tag = INTERNAL_CLASS_TAG; } 
00055 
00056     void    collect() { delete this; }
00057 
00058     // main zip module file in function
00059     ScripterExport static bool file_in_package(const MCHAR* file_name, MSTR* extract_dir=NULL);
00060     static int WINAPI output_callback(char far *buf, unsigned long size);
00061 
00062     // module SearchFile
00063     ScripterExport static BOOL search_current_package(const MCHAR* file_name, MCHAR* found_path);
00064 
00065     // extraction
00066     bool    extract_to(const MCHAR* dir);
00067     MCHAR*  find_extraction(const MCHAR* zip_name) { return extractions.find(zip_name); }
00068     void    add_extraction(const MCHAR* zip_name, const MCHAR* extracted_name);
00069 
00070     // directory & file manipulation
00071     ScripterExport static MSTR  expand_dir(const MCHAR* dir);
00072     ScripterExport static MSTR  expand_file(const MCHAR* file_name);
00073     MSTR    expand_dir_for_extraction(const MCHAR* dir);
00074     MSTR    expand_file_for_extraction(const MCHAR* file_name);
00075 
00076     // running
00077     void    run_all_scripts();
00078     bool    run_script(const MCHAR* zip_name);
00079 };
00080 
00081 // MZP flags
00082 #define MZP_DONT_RUN        0x0001      // just loading, don't run any scripts
00083 #define MZP_HAVE_DROPFILE   0x0002      // 'drop' command encountered
00084 #define MZP_HAVE_OPEN       0x0004      // 'open' command encountered
00085 
00086 // interpret copy() function type bits...
00087 #define MZP_COPY        0x00
00088 #define MZP_MOVE        0x01
00089 #define MZP_FILES       0x00
00090 #define MZP_TREE        0x02
00091 #define MZP_NOREPLACE   0x04
00092 
00093 // parser specialization to parse & run mzp.run control file
00094 class DotRunParser : public Parser
00095 {
00096     MSZipPackage* mzp;
00097 
00098 public:
00099 
00100     DotRunParser (MSZipPackage* mzp) : mzp(mzp) { }
00101 
00102     // parse & run mzp.run file
00103     bool    interpret(const MCHAR* src);
00104 
00105     // parser production functions
00106     void    name();
00107     void    version();
00108     void    description();
00109     void    extract();
00110     void    run();
00111     void    drop();
00112     void    open();
00113     void    merge();
00114     void    xref();
00115     void    import();
00116     void    copy(BYTE type);
00117     void    clear();
00118     void    keep();
00119 
00120     // utils
00121     void    copy_files(const MCHAR* from, const MCHAR* to, BYTE type);
00122     ScripterExport static bool  create_dir(const MCHAR* dir);
00123 };
00124