home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Source / lang.h < prev    next >
C/C++ Source or Header  |  2004-01-20  |  7KB  |  309 lines

  1. #ifndef ___NLF___H_____
  2. #define ___NLF___H_____
  3.  
  4. #include "exehead/fileform.h"
  5.  
  6. struct NLFRef {
  7.   int iRef;
  8.   int iUnRef;
  9. };
  10.  
  11. struct langstring {
  12.   int name;
  13.   int sn;
  14.   int index;
  15.   int uindex;
  16.   int process;
  17. };
  18.  
  19. class LangStringList : public SortedStringListND<struct langstring>
  20. {
  21.   public:
  22.     LangStringList() {
  23.       count = 0;
  24.     }
  25.     ~LangStringList() { }
  26.  
  27.     int add(const char *name, int *sn=0)
  28.     {
  29.       int pos = SortedStringListND<struct langstring>::add(name);
  30.       if (pos == -1) return -1;
  31.  
  32.       ((struct langstring*)gr.get())[pos].sn = count;
  33.       if (sn) *sn = count;
  34.       count++;
  35.       ((struct langstring*)gr.get())[pos].index = -1;
  36.       ((struct langstring*)gr.get())[pos].uindex = -1;
  37.       ((struct langstring*)gr.get())[pos].process = 1;
  38.  
  39.       return pos;
  40.     }
  41.  
  42.     int get(char *name, int *sn=0, int *index=0, int *uindex=0, int *process=0)
  43.     {
  44.       if (index) *index = -1;
  45.       if (uindex) *uindex = -1;
  46.       if (sn) *sn = -1;
  47.       int v=SortedStringListND<struct langstring>::find(name);
  48.       if (v==-1) return -1;
  49.       if (index) *index = ((struct langstring*)gr.get())[v].index;
  50.       if (uindex) *uindex = ((struct langstring*)gr.get())[v].uindex;
  51.       if (sn) *sn = ((struct langstring*)gr.get())[v].sn;
  52.       if (process) *process = ((struct langstring*)gr.get())[v].process;
  53.       return v;
  54.     }
  55.  
  56.     void set(int pos, int index=-1, int uindex=-1, int process=-1)
  57.     {
  58.       if ((unsigned int)pos > (gr.getlen() / sizeof(struct langstring)))
  59.         return;
  60.  
  61.       struct langstring *data=(struct langstring *)gr.get();
  62.  
  63.       if (index >= 0)
  64.         data[pos].index = index;
  65.       if (uindex >= 0)
  66.         data[pos].uindex = uindex;
  67.       if (process >= 0)
  68.         data[pos].process = process;
  69.     }
  70.  
  71.     void set(char *name, int index, int uindex=-1, int process=-1)
  72.     {
  73.       set(get(name), index, uindex, process);
  74.     }
  75.  
  76.     const char *pos2name(int pos)
  77.     {
  78.       struct langstring *data=(struct langstring *)gr.get();
  79.  
  80.       if ((unsigned int)pos > (gr.getlen() / sizeof(struct langstring)))
  81.         return 0;
  82.  
  83.       return ((const char*)strings.get() + data[pos].name);
  84.     }
  85.  
  86.     const char *offset2name(int name)
  87.     {
  88.       if ((unsigned int)name > (unsigned int)strings.getlen())
  89.         return 0;
  90.  
  91.       return (const char*)strings.get() + name;
  92.     }
  93.  
  94.     int getnum()
  95.     {
  96.       return gr.getlen() / sizeof(struct langstring);
  97.     }
  98.  
  99.     static int compare_index(const void *item1, const void *item2)
  100.     {
  101.       struct langstring *ls1 = (struct langstring *)item1;
  102.       struct langstring *ls2 = (struct langstring *)item2;
  103.  
  104.       return ls1->index - ls2->index;
  105.     }
  106.  
  107.     struct langstring *sort_index(int *num)
  108.     {
  109.       if (!num) return 0;
  110.       sortbuf.resize(0);
  111.       sortbuf.add(gr.get(), gr.getlen());
  112.       *num = sortbuf.getlen() / sizeof(struct langstring);
  113.       qsort(sortbuf.get(), *num, sizeof(struct langstring), compare_index);
  114.       return (struct langstring*) sortbuf.get();
  115.     }
  116.  
  117.     static int compare_uindex(const void *item1, const void *item2)
  118.     {
  119.       struct langstring *ls1 = (struct langstring *)item1;
  120.       struct langstring *ls2 = (struct langstring *)item2;
  121.  
  122.       return ls1->uindex - ls2->uindex;
  123.     }
  124.  
  125.     struct langstring *sort_uindex(int *num)
  126.     {
  127.       if (!num) return 0;
  128.       sortbuf.resize(0);
  129.       sortbuf.add(gr.get(), gr.getlen());
  130.       *num = sortbuf.getlen() / sizeof(struct langstring);
  131.       qsort(sortbuf.get(), *num, sizeof(struct langstring), compare_uindex);
  132.       return (struct langstring*) sortbuf.get();
  133.     }
  134.  
  135.   private:
  136.     int count;
  137.     TinyGrowBuf sortbuf;
  138. };
  139.  
  140. class StringsArray
  141. {
  142.   private:
  143.     TinyGrowBuf offsets;
  144.     GrowBuf strings;
  145.  
  146.   public:
  147.     StringsArray()
  148.     {
  149.       offsets.set_zeroing(1);
  150.  
  151.       strings.add("", sizeof(""));
  152.     }
  153.  
  154.     ~StringsArray() { }
  155.  
  156.     void resize(int num)
  157.     {
  158.       offsets.resize(num * sizeof(int));
  159.     }
  160.  
  161.     int set(int idx, char *str)
  162.     {
  163.       if (idx < 0)
  164.         return 0;
  165.  
  166.       if (idx >= (int)(offsets.getlen() / sizeof(int)))
  167.         resize(idx+1);
  168.  
  169.       int old = ((int*)offsets.get())[idx];
  170.  
  171.       ((int*)offsets.get())[idx] = strings.add(str, strlen(str) + 1);
  172.  
  173.       return old;
  174.     }
  175.  
  176.     const char *get(int idx)
  177.     {
  178.       if ((unsigned int)idx >= (offsets.getlen() / sizeof(int)))
  179.         return 0;
  180.  
  181.       return (const char *)strings.get() + ((int*)offsets.get())[idx];
  182.     }
  183. };
  184.  
  185. #define NLF_VERSION 6
  186.  
  187. enum {
  188.   NLF_BRANDING,
  189.   NLF_CAPTION,
  190.   NLF_UCAPTION,
  191.   NLF_SUBCAPTION_LICENSE,
  192.   NLF_SUBCAPTION_OPTIONS,
  193.   NLF_SUBCAPTION_DIR,
  194.   NLF_SUBCAPTION_INSTFILES,
  195.   NLF_SUBCAPTION_COMPLETED,
  196.   NLF_USUBCAPTION_OPTIONS,
  197.   NLF_USUBCAPTION_DIR,
  198.   NLF_USUBCAPTION_CONFIRM,
  199.   NLF_USUBCAPTION_INSTFILES,
  200.   NLF_USUBCAPTION_COMPLETED,
  201.   NLF_BTN_BACK,
  202.   NLF_BTN_NEXT,
  203.   NLF_BTN_LICENSE,
  204.   NLF_BTN_LICENSE_AGREE,
  205.   NLF_BTN_LICENSE_DISAGREE,
  206.   NLF_BTN_INSTALL,
  207.   NLF_BTN_UNINSTALL,
  208.   NLF_BTN_CANCEL,
  209.   NLF_BTN_CLOSE,
  210.   NLF_BTN_BROWSE,
  211.   NLF_BTN_DETAILS,
  212.   NLF_CLICK_NEXT,
  213.   NLF_CLICK_INSTALL,
  214.   NLF_CLICK_UNINSTALL,
  215.   NLF_NAME,
  216.   NLF_NAME_DA, // name with doubled ampersands - virtual
  217.   NLF_COMPLETED,
  218.   NLF_LICENSE_TEXT,
  219.   NLF_LICENSE_TEXT_FSCB,
  220.   NLF_LICENSE_TEXT_FSRB,
  221.   NLF_ULICENSE_TEXT,
  222.   NLF_ULICENSE_TEXT_FSCB,
  223.   NLF_ULICENSE_TEXT_FSRB,
  224.   NLF_LICENSE_DATA, // virtual
  225.   NLF_COMP_CUSTOM,
  226.   NLF_COMP_TEXT,
  227.   NLF_COMP_SUBTEXT1,
  228.   NLF_COMP_SUBTEXT1_NO_INST_TYPES,
  229.   NLF_COMP_SUBTEXT2,
  230.   NLF_UCOMP_TEXT,
  231.   NLF_UCOMP_SUBTEXT1,
  232.   NLF_UCOMP_SUBTEXT1_NO_INST_TYPES,
  233.   NLF_UCOMP_SUBTEXT2,
  234.   NLF_DIR_TEXT,
  235.   NLF_DIR_SUBTEXT,
  236.   NLF_DIR_BROWSETEXT,
  237.   NLF_UDIR_TEXT,
  238.   NLF_UDIR_SUBTEXT,
  239.   NLF_UDIR_BROWSETEXT,
  240.   NLF_SPACE_AVAIL,
  241.   NLF_SPACE_REQ,
  242.   NLF_UNINST_TEXT,
  243.   NLF_UNINST_SUBTEXT,
  244.   NLF_FILE_ERROR,
  245.   NLF_FILE_ERROR_NOIGNORE,
  246.   NLF_CANT_WRITE,
  247.   NLF_COPY_FAILED,
  248.   NLF_COPY_TO,
  249.   NLF_REGISTERING,
  250.   NLF_UNREGISTERING,
  251.   NLF_SYMBOL_NOT_FOUND,
  252.   NLF_COULD_NOT_LOAD,
  253.   NLF_CREATE_DIR,
  254.   NLF_CREATE_SHORTCUT,
  255.   NLF_CREATED_UNINST,
  256.   NLF_DEL_FILE,
  257.   NLF_DEL_ON_REBOOT,
  258.   NLF_ERR_CREATING_SHORTCUT,
  259.   NLF_ERR_CREATING,
  260.   NLF_ERR_DECOMPRESSING,
  261.   NLF_ERR_REG_DLL,
  262.   NLF_EXEC_SHELL,
  263.   NLF_EXEC,
  264.   NLF_EXTRACT,
  265.   NLF_ERR_WRITING,
  266.   NLF_INST_CORRUPTED,
  267.   NLF_NO_OLE,
  268.   NLF_OUTPUT_DIR,
  269.   NLF_REMOVE_DIR,
  270.   NLF_RENAME_ON_REBOOT,
  271.   NLF_RENAME,
  272.   NLF_SKIPPED,
  273.   NLF_COPY_DETAILS,
  274.   NLF_LOG_INSTALL_PROCESS,
  275.   NLF_BYTE,
  276.   NLF_KILO,
  277.   NLF_MEGA,
  278.   NLF_GIGA,
  279.  
  280.   NLF_FONT,
  281.   NLF_FONTSIZE,
  282.   NLF_RTL,
  283.  
  284.   NLF_STRINGS
  285. };
  286.  
  287. struct NLF {
  288.     bool          m_bLoaded;
  289.     char         *m_szName;
  290.     char         *m_szFont;
  291.     int           m_iFontSize;
  292.     unsigned int  m_uCodePage;
  293.     bool          m_bRTL;
  294.  
  295.     char         *m_szStrings[NLF_STRINGS];
  296. };
  297.  
  298. struct LanguageTable {
  299.   LANGID lang_id;
  300.  
  301.   int dlg_offset;
  302.  
  303.   StringsArray *lang_strings;
  304.  
  305.   NLF nlf;
  306. };
  307.  
  308. #endif
  309.