home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / xwphescr.zip / XWPH0208.ZIP / include / helpers / xprf.h < prev    next >
C/C++ Source or Header  |  2001-10-23  |  9KB  |  238 lines

  1.  
  2. /*
  3.  *@@sourcefile xprf.h:
  4.  *      header file for xprf.c. See remarks there.
  5.  *
  6.  *      This file was new with V0.9.5 (?).
  7.  *
  8.  *      Note: Version numbering in this file relates to XWorkplace version
  9.  *            numbering.
  10.  *
  11.  *@@include #define INCL_WINSHELLDATA
  12.  *@@include #include <os2.h>
  13.  *@@include #include "helpers\xprf.h"
  14.  */
  15.  
  16. /*      Copyright (C) 2000 Ulrich Möller.
  17.  *      This file is part of the "XWorkplace helpers" source package.
  18.  *      This is free software; you can redistribute it and/or modify
  19.  *      it under the terms of the GNU General Public License as published
  20.  *      by the Free Software Foundation, in version 2 as it comes in the
  21.  *      "COPYING" file of the XWorkplace main distribution.
  22.  *      This program is distributed in the hope that it will be useful,
  23.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  24.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  25.  *      GNU General Public License for more details.
  26.  */
  27.  
  28. #if __cplusplus
  29. extern "C" {
  30. #endif
  31.  
  32. #ifndef XPRF_HEADER_INCLUDED
  33.     #define XPRF_HEADER_INCLUDED
  34.  
  35.     /* ******************************************************************
  36.      *
  37.      *   OS/2 INI file layout
  38.      *
  39.      ********************************************************************/
  40.  
  41.     #pragma pack(1)
  42.  
  43.     /*
  44.      *@@ INIFILE_HEADER:
  45.      *      header of OS/2 INI file. This is
  46.      *      what an OS/2 .INI file starts with
  47.      *      at byte 0.
  48.      *
  49.      *      An OS/2 INI file has the following layout:
  50.      *
  51.      *      -- INIFILE_HEADER
  52.      *      -- first INIFILE_APP, if any
  53.      *      -- name of first application (zero-terminated),
  54.      *              of which the first INIFILE_APP.offAppName
  55.      *              has the offset
  56.      *          -- first INIFILE_KEY of first app
  57.      *          -- name of first key (zero-terminated),
  58.      *              of which the first INIFILE_KEY.offKeyName
  59.      *              has the offset
  60.      *          -- data block of first key, of which the first
  61.      *              INIFILE_KEY.offKeyData has the offset;
  62.      *              the length is in INIFILE_KEY.lenKeyData
  63.      *
  64.      *          -- subsequent INIFILE_KEY's, names, data, if any
  65.      *
  66.      *      -- subsequent INIFILE_APP's, if any
  67.      *              ...
  68.      *
  69.      *@@added V0.9.5 (2000-08-10) [umoeller]
  70.      */
  71.  
  72.     typedef struct _INIFILE_HEADER
  73.     {
  74.         ULONG magic;       // Magic Footprint, Always $FFFFFFFF (?)
  75.         ULONG offFirstApp; // Offset of First Application in File
  76.         ULONG lenFile;     // Length of INI File
  77.         ULONG filler1;     // Always $00000000 (?)
  78.         ULONG filler2;     // Always $00000000 (?)
  79.     } INIFILE_HEADER, *PINIFILE_HEADER;
  80.  
  81.     /*
  82.      *@@ INIFILE_APP:
  83.      *      application entry in OS/2 INI file.
  84.      *      The first application comes right after
  85.      *      INIFILE_HEADER. After INIFILE_APP, the
  86.      *      Prf* functions store the app name and
  87.      *      the keys which belong to this application
  88.      *      (INIFILE_KEY).
  89.      *
  90.      *@@added V0.9.5 (2000-08-10) [umoeller]
  91.      */
  92.  
  93.     typedef struct _INIFILE_APP
  94.     {
  95.         ULONG  offNextApp;       // Offset of Next Application in File
  96.                                  // (0 No More Apps)
  97.         ULONG  offFirstKeyInApp; // Offset of Application's First Key Entry
  98.         ULONG  filler1;          // Always $00000000 (?)
  99.         USHORT lenAppName;       // Length of Application Name
  100.                                  // (incl. terminating \0)
  101.         USHORT _lenAppName;      // Always same as above (?)
  102.         ULONG  offAppName;       // Offset of ASCIIZ Application Name
  103.     } INIFILE_APP, *PINIFILE_APP;
  104.  
  105.     /*
  106.      *@@ INIFILE_KEY:
  107.      *      key entry in OS/2 INI file.
  108.      *      The first key in an application comes right after
  109.      *      its INIFILE_APP. After INIFILE_KEY, the Prf*
  110.      *      functions store the key name and finally the
  111.      *      data for that key.
  112.      *
  113.      *@@added V0.9.5 (2000-08-10) [umoeller]
  114.      */
  115.  
  116.     typedef struct _INIFILE_KEY
  117.     {
  118.         ULONG  offNextKeyInApp; // Offset of Next Key in Application
  119.                                 // (0 = No More Keys)
  120.         ULONG  filler1;         // Always $00000000 (?)
  121.         USHORT lenKeyName;      // Length of Key Name (incl. terminating \0)
  122.         USHORT _lenKeyName;     // Always same as above (?)
  123.         ULONG  offKeyName;      // Offset of ASCIIZ Key Name
  124.         USHORT lenKeyData;      // Length of Key Data
  125.         USHORT _lenKeyData;     // Always same as above (?)
  126.         ULONG  offKeyData;      // Offset of Key Data (ASCII(Z) or Binary)
  127.     } INIFILE_KEY, *PINIFILE_KEY;
  128.  
  129.     #pragma pack()
  130.  
  131.     /* ******************************************************************
  132.      *
  133.      *   API Functions
  134.      *
  135.      ********************************************************************/
  136.  
  137.     #define XINI_MAGIC_BYTES    "hjba78j,"
  138.  
  139.     #ifdef LINKLIST_HEADER_INCLUDED
  140.         /*
  141.          *@@ XINI:
  142.          *      open INI file. Returned by xprfOpenProfile
  143.          *      and is used in place of HINI by the replacement
  144.          *      INI functions.
  145.          *
  146.          *      Do not modify any data in here.
  147.          */
  148.  
  149.         typedef struct _XINI
  150.         {
  151.             CHAR    acMagic[sizeof(XINI_MAGIC_BYTES)];
  152.                                 // magic bytes for security
  153.             CHAR    szFilename[CCHMAXPATH];
  154.             HFILE   hFile;      // returned by DosProtectOpen
  155.             FHLOCK  hLock;      // lock ID of DosProtectOpen
  156.             BOOL    fDirty;     // TRUE if changed and needs to be flushed
  157.                                 // on close
  158.  
  159.             // applications list
  160.             LINKLIST    llApps;             // contains PXINIAPPDATA items
  161.             ULONG       cApps;              // count of items on list
  162.         } XINI, *PXINI;
  163.     #else
  164.         typedef void* PXINI;
  165.     #endif
  166.  
  167.     APIRET xprfOpenProfile(const char *pcszFilename,
  168.                            PXINI *ppxini);
  169.  
  170.     BOOL xprfCloseProfile(PXINI hIni);
  171.  
  172.     /* BOOL xprfQueryProfileData(PXINI hIni,
  173.                        const char *pcszApp,
  174.                        const char *pcszKey,
  175.                        PVOID pBuffer,
  176.                        PULONG pulBufferMax); */
  177.  
  178.     BOOL xprfWriteProfileData(PXINI hIni,
  179.                        const char *pcszApp,
  180.                        const char *pcszKey,
  181.                        PVOID pData,
  182.                        ULONG ulDataLen);
  183.  
  184.     /* ******************************************************************
  185.      *
  186.      *   Copy API Functions
  187.      *
  188.      ********************************************************************/
  189.  
  190.     /*
  191.      *@@ FN_PRF_PROGRESS:
  192.      *      prototype for a progress callback used with
  193.      *      xprfCopyProfile and xprfSaveINIs.
  194.      *
  195.      *      Declare your callback like this:
  196.      +          BOOL _Optlink fnProgress(ULONG ulUser,
  197.      +                                         // in: use param specified with
  198.      +                                         // xprfCopyProfile and xprfSaveINIs
  199.      +                                   ULONG ulProgressNow,
  200.      +                                         // in: current progress
  201.      +                                   ULONG ulProgressMax)
  202.      +                                         // in: maximum progress
  203.      *
  204.      *      If this returns FALSE, processing is aborted.
  205.      */
  206.  
  207.     typedef BOOL (_Optlink FN_PRF_PROGRESS)(ULONG, ULONG, ULONG);
  208.     typedef FN_PRF_PROGRESS *PFN_PRF_PROGRESS;
  209.  
  210.     APIRET xprfCopyKey(HINI hiniSource,
  211.                        PSZ pszSourceApp,
  212.                        PSZ pszKey,
  213.                        PXINI hiniTarget,
  214.                        PSZ pszTargetApp);
  215.  
  216.     APIRET xprfCopyApp(HINI hiniSource,
  217.                        PSZ pszSourceApp,
  218.                        PXINI hiniTarget,
  219.                        PSZ pszTargetApp,
  220.                        PSZ pszErrorKey);
  221.  
  222.     APIRET xprfCopyProfile(HINI hOld,
  223.                            PSZ pszNew,
  224.                            PFN_PRF_PROGRESS pfnProgressCallback,
  225.                            ULONG ulUser,
  226.                            ULONG ulCount,
  227.                            ULONG ulMax);
  228.  
  229.     APIRET xprfSaveINIs(HAB hab,
  230.                         PFN_PRF_PROGRESS pfnProgressCallback,
  231.                         ULONG ulUser);
  232. #endif
  233.  
  234. #if __cplusplus
  235. }
  236. #endif
  237.  
  238.