home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OProfile.cpp < prev    next >
C/C++ Source or Header  |  1996-10-21  |  5KB  |  207 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OProfile.cpp
  5.  
  6. // Profile Actions (INI-Handling)
  7.  
  8.  
  9. /*
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  16.  *    endorse or promote products derived from this software
  17.  *    without specific prior written permission.
  18.  * 3. See OCL.INF for a detailed copyright notice.
  19.  *
  20.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  21.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30.  * SUCH DAMAGE.
  31.  */
  32.  
  33. // $Header: W:/Projects/OCL/Source/rcs/OProfile.cpp 1.50 1996/08/11 23:49:29 B.STEIN Release $
  34.  
  35. #define __OCL_SOURCE__
  36.  
  37. #define OINCL_OSTRING
  38. #define OINCL_BASE
  39.  
  40. #include <ocl.hpp>
  41. #include <OApp.hpp>
  42. #include <OProfile.hpp>
  43.  
  44.  
  45. // members of OProfile
  46.  
  47.  
  48. OProfile::OProfile() 
  49.   : hini(NULLHANDLE)
  50.   {}
  51.  
  52.  
  53. OProfile::OProfile(const HINI iniHandle)
  54.   : hini(iniHandle)
  55.   {}
  56.  
  57.  
  58. OProfile::OProfile(PSZ iniName)
  59. {
  60.  hini = PrfOpenProfile(OApp::current().anchor(), iniName);
  61. }
  62.  
  63.  
  64. BOOL OProfile::open(PSZ iniName)
  65. {
  66.  hini = PrfOpenProfile(OApp::current().anchor(), (PSZ) iniName);
  67.  return(hini != NULLHANDLE);
  68. }
  69.  
  70.  
  71. OProfile::~OProfile()
  72. {
  73.  list.reset();
  74.  PrfCloseProfile(hini);
  75. }
  76.  
  77.  
  78. PSZ OProfile::isOfType() const
  79.  return("OProfile"); 
  80. }
  81.  
  82.  
  83. void OProfile::close()
  84. {
  85.  PrfCloseProfile(hini);
  86. }
  87.  
  88.  
  89. BOOL OProfile::write(PSZ App, PSZ Key, PVOID Value, ULONG len)
  90. {
  91.  return(PrfWriteProfileData(hini, (PSZ) App, (PSZ) Key, Value, len));
  92. }
  93.  
  94.  
  95. BOOL OProfile::deleteApp(PSZ App)
  96. {
  97.  return(PrfWriteProfileData(hini, App, NULL, NULL, 0));
  98. }
  99.  
  100.  
  101. BOOL OProfile::deleteKey(PSZ App, PSZ Key)
  102. {
  103.  return(PrfWriteProfileData(hini, App, Key, NULL, 0));
  104. }
  105.  
  106. BOOL OProfile::getApps()
  107. {
  108.  return(getKeys(NULL));
  109. }
  110.  
  111.  
  112. BOOL OProfile::getKeys(PSZ App)
  113. {
  114.  UCHAR  *DatTemp;
  115.  ULONG  Size = 0x0000ffffL;
  116.  
  117.  if (DosAllocMem((PPVOID) &DatTemp,  0x0000ffffL, PAG_READ | PAG_WRITE | PAG_COMMIT))
  118.    return(FALSE);
  119.  
  120.  if (getData(App, NULL, DatTemp, &Size))
  121.   return(setupList(DatTemp));
  122.  else
  123.   return(FALSE);
  124. }
  125.  
  126.  
  127. BOOL OProfile::getStr(PSZ App, PSZ Key)
  128. {
  129.  UCHAR  *DatTemp;
  130.  ULONG  Size = 0x0000ffffL;
  131.  
  132.  if (DosAllocMem((PPVOID) &DatTemp,  0x0000ffffL, PAG_READ | PAG_WRITE | PAG_COMMIT))
  133.    return(FALSE);
  134.  
  135.  if (!getData(App, Key, DatTemp, &Size))
  136.    return(FALSE);
  137.  else
  138.    val << (PSZ) DatTemp;
  139.  
  140.  DosFreeMem(DatTemp);
  141.  return(TRUE);
  142. }
  143.  
  144.  
  145. BOOL OProfile::getData(PSZ App, PSZ Key, PVOID Buffer, PULONG Size)
  146. {
  147.  return(PrfQueryProfileData(hini, App, Key, Buffer, Size));
  148. }
  149.  
  150.  
  151. BOOL OProfile::setupList(UCHAR *DatTemp)
  152. {
  153.  ULONG x, len;
  154.  UCHAR *Buffer;
  155.  
  156.  if (DosAllocMem((PPVOID) &Buffer,  0x0000ffffL, PAG_READ | PAG_WRITE | PAG_COMMIT))
  157.    return(FALSE);
  158.  
  159.  list.reset();
  160.  
  161.  x = 0;
  162.  do
  163.    {
  164.     len = 0;
  165.     while (DatTemp[x+len] != '\0')
  166.       {
  167.        Buffer[len] = DatTemp[x+len];
  168.        ++len;
  169.       }
  170.     Buffer[len] = '\0';
  171.     if (len != 0)
  172.       {
  173.        list << (PSZ) Buffer;
  174.        x += (len+1);
  175.       }
  176.    }
  177.    while (DatTemp[x] != '\0');
  178.  
  179.  DosFreeMem(Buffer);
  180.  DosFreeMem(DatTemp);
  181.  return(TRUE);
  182. }
  183.  
  184.  
  185. BOOL OProfile::insert(const HWND hwnd, const ULONG id)
  186. {
  187.  OListItem<OString> *tmp = list.first();
  188.  
  189.  while((tmp) && (tmp->item) && (tmp->item->getText()))
  190.   {
  191.    if (LIT_MEMERROR == (LONG)WinSendDlgItemMsg(hwnd, id, LM_INSERTITEM,
  192.                             MPFROM2SHORT(LIT_SORTASCENDING, 0),
  193.                             MPFROMP(tmp->item->getText())))
  194.      return(FALSE);
  195.    tmp = tmp->next;
  196.   }
  197.  
  198.  tmp = list.first();
  199.  if ((tmp) && (tmp->item) && (tmp->item->getText()))
  200.     WinSetDlgItemText(hwnd, id, tmp->item->getText());
  201.  return(TRUE);
  202. }
  203.  
  204.  
  205. // end of source
  206.