Changeset 1536 for trunk/gsinstaller


Ignore:
Timestamp:
2000-09-11T17:29:32+12:00 (24 years ago)
Author:
sjboddie
Message:

Changes to get compiling on VC++ and gcc

Location:
trunk/gsinstaller
Files:
3 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsinstaller/FilePath.cpp

    r1498 r1536  
    66#include <stdarg.h>
    77#include <stdio.h>
    8 #include <dir.h>
     8//#include <dir.h>
     9#include <direct.h>
    910
    1011static char divider = '\\';
     
    1213
    1314bool __pathIsAValidRoot(string path)
    14 {   DWORD driveMask;
    15     int     driveNum;
     15{
     16  DWORD driveMask;
     17  int driveNum;
    1618
    1719  if (path.length() > 3)
    18   { return false;
    19   }
    20 
    21     if (path[1] != ':' || !isalpha(path[0]))
    22   { return false;
    23   }
     20  {
     21    return false;
     22  }
     23 
     24  if (path[1] != ':' || !isalpha(path[0]))
     25    {
     26      return false;
     27    }
     28 
    2429  if (isupper(path[0]))
    25   { driveNum = path[0] - 'A';
    26   }
    27   else
    28   { driveNum = path[0] - 'a';
    29   }
     30  {
     31    driveNum = path[0] - 'A';
     32  }
     33
     34  else
     35    {
     36      driveNum = path[0] - 'a';
     37    }
     38
    3039  if (driveNum > 25)
    31   { return false;
    32   }
     40  {
     41    return false;
     42  }
     43
    3344  driveMask = GetLogicalDrives();
     45
    3446  if ((driveMask & (1 << driveNum)) != (1 << driveNum))
    35   { return false;
    36   }
     47    {
     48      return false;
     49    }
     50
    3751  return true;
    3852}
    3953
    40 FilePath::FilePath()
    41 {
    42 }
     54FilePath::FilePath() {}
    4355
    4456FilePath::FilePath(int npaths, ...)
    45 {   va_list list;
    46     string* pathArray;
    47 
    48   pathArray = new string[npaths];
     57{
     58  va_list list;
     59  string* pathArray;
     60
     61  pathArray = new string[npaths];
    4962
    5063  // initialise use of variable parameters
     
    5265
    5366  if (pathArray)
    54   { for (int i = 0; i < npaths; i ++)
    55     { // get next parameter (guaranteed to be a char * by caller!!!)
    56         pathArray[i] = va_arg(list, char *);
    57 
    58       // discount leading slashes
    59       if (pathArray[i][0] == divider)
    60       { pathArray[i] = pathArray[i].substr(1);
    61       }
    62 
    63       // get rid of terminating slashes if present
    64       if (pathArray[i][pathArray[i].length() - 1] == divider)
    65       { pathArray[i] = pathArray[i].substr(0, pathArray[i].length() - 1);
    66       }
    67     }
    68   }
     67    {
     68      for (int i = 0; i < npaths; i ++)
     69    {
     70      // get next parameter (guaranteed to be a char * by caller!!!)
     71      pathArray[i] = va_arg(list, char *);
     72
     73      // discount leading slashes
     74      if (pathArray[i][0] == divider)
     75        {
     76          pathArray[i] = pathArray[i].substr(1);
     77        }
     78
     79      // get rid of terminating slashes if present
     80      if (pathArray[i][pathArray[i].length() - 1] == divider)
     81        {
     82          pathArray[i] = pathArray[i].substr(0, pathArray[i].length() - 1);
     83        }
     84    }
     85    }
    6986
    7087  // end of variable arguments
    71     va_end(list);
     88  va_end(list);
    7289
    7390  // construct path in the usual manner
    7491  if (npaths > 0)
    75   { this->path = pathArray[0];
    76   }
     92    {
     93      this->path = pathArray[0];
     94    }
     95
    7796  for (int i = 1; i < npaths; i ++)
    78   { // don't add slashes if suppressed
    79     if (pathArray[i][0] != '!')
    80     {   this->path.append("\\");
    81         this->path.append(pathArray[i]);
    82     }
    83     // if slashes suppressed, skip the magic character
    84     else
    85     { this->path.append(pathArray[i].substr(1));
    86     }
    87   }
     97    {
     98      // don't add slashes if suppressed
     99      if (pathArray[i][0] != '!')
     100    {
     101      this->path.append("\\");
     102      this->path.append(pathArray[i]);
     103    }
     104
     105      // if slashes suppressed, skip the magic character
     106      else
     107    {
     108      this->path.append(pathArray[i].substr(1));
     109    }
     110    }
    88111
    89112  // destroy temporary array
    90113  if (pathArray)
    91   { delete[] pathArray;
    92   }
     114    {
     115      delete[] pathArray;
     116    }
    93117
    94118  // set if this is a valid root (unlikely in this circumstance)
     
    97121
    98122void FilePath::_init(string filePath, string subPath)
    99 { // copy the directory path
     123{
     124  // copy the directory path
    100125  this->path = filePath;
    101126
     
    103128  // filePath is empty, we're not actually going to add any divider at
    104129  // all
     130
    105131  if (filePath.length() > 0 &&
    106132      this->path[filePath.length()-1] != divider)
    107   { this->path.append(dividerStr);
     133  {
     134    this->path.append(dividerStr);
    108135  }
    109136
    110137  // copy in the subdirectory path, eliminating any leading divider
    111138  if (subPath[0] != divider)
    112   { this->path.append(subPath);
    113   }
    114   else
    115   { this->path.append(subPath.substr(1));
    116   }
    117 
    118     // set if this is a valid root (unlikely when joining two paths)
     139  {
     140    this->path.append(subPath);
     141  }
     142  else
     143  {
     144    this->path.append(subPath.substr(1));
     145  }
     146
     147  // set if this is a valid root (unlikely when joining two paths)
    119148  this->is_aRoot = __pathIsAValidRoot(this->path);
    120149}
     
    123152 * Construct a Filepath from a directory and a sub-directory path
    124153 */
     154
    125155FilePath::FilePath(string filePath, string subPath)
    126 { this->_init(filePath, subPath);
     156{
     157  this->_init(filePath, subPath);
    127158}
    128159
    129160FilePath::FilePath(FilePath &path, string subPath)
    130 { this->_init(path.pathString(), subPath);
     161{
     162  this->_init(path.pathString(), subPath);
    131163}
    132164
    133165FilePath::FilePath(string filePath)
    134 { if (filePath.length() < 3)
    135     { this->path    = filePath;
    136     this->path.append("\\");
    137   }
    138   else
    139   { this->path  = filePath;
    140 
    141     // trim trailing directory separators
    142     if (this->path[this->path.length() - 1] == '\\')
    143     {   this->path = this->path.substr(0, this->path.length() - 1);
    144     }
    145   }
     166{
     167  if (filePath.length() < 3)
     168    {
     169      this->path = filePath;
     170      this->path.append("\\");
     171    }
     172  else
     173    {
     174    this->path = filePath;
     175
     176    // trim trailing directory separators
     177    if (this->path[this->path.length() - 1] == '\\')
     178      {
     179    this->path = this->path.substr(0, this->path.length() - 1);
     180      }
     181    }
    146182
    147183  // check for a valid root
     
    150186
    151187bool FilePath::isEmpty()
    152 {   return this->path.length() == 0;
     188{
     189  return this->path.length() == 0;
    153190}
    154191
    155192bool FilePath::isRoot()
    156 {   return this->is_aRoot;
     193{
     194  return this->is_aRoot;
    157195}
    158196
    159197bool FilePath::equals(FilePath &other)
    160 {   if (this->path.compare(other.path) == 0)
    161     {   return true;
    162   }
     198{
     199  if (this->path.compare(other.path) == 0)
     200    {
     201      return true;
     202    }
     203
    163204  return false;
    164205}
    165206
    166207bool FilePath::equals(const char *other)
    167 {   if (strcmp(this->path.c_str(), other) == 0)
    168     {   return true;
    169   }
     208{
     209  if (strcmp(this->path.c_str(), other) == 0)
     210    {
     211      return true;
     212    }
     213
    170214  return false;
    171215}
     
    175219 */
    176220FilePath *FilePath::rootDrive()
    177 {   FilePath *reply = this->root();
    178 
    179     if (reply->path.length() >= 2 &&
    180         reply->path[1] == ':' &&
     221{
     222  FilePath *reply = this->root();
     223
     224  if (reply->path.length() >= 2 &&
     225      reply->path[1] == ':' &&
    181226      isalpha(reply->path[0])) // if this is a drive letter destination
    182   { reply->path = reply->path.substr(0, 2);
    183   }
    184   else
    185   { reply->path = "";
     227  {
     228    reply->path = reply->path.substr(0, 2);
     229  }
     230  else
     231  {
     232    reply->path = "";
    186233  }
    187234  return reply;
     
    192239 */
    193240FilePath *FilePath::root()
    194 { // TODO: cope with network destinations
    195     FilePath *reply = new FilePath(this->path);
     241{
     242  // TODO: cope with network destinations
     243  FilePath *reply = new FilePath(this->path);
    196244
    197245  unsigned int truncate = reply->path.find(divider);
    198246  if (truncate != -1) // if it's got a divider then skip past it;
    199                                         // we will assume that it's a drive letter first
    200   { truncate ++;
    201     reply->path = reply->path.substr(0, truncate);
    202   }
     247                      // we will assume that it's a drive letter first
     248  {
     249    truncate ++;
     250    reply->path = reply->path.substr(0, truncate);
     251  }
     252
    203253  // if we've got a drive, then we'll use it plus the divider
    204254  else if (reply->path[1] == ':' && reply->path.length() == 2 &&
    205                  isalpha(reply->path[0]))
    206   { reply->path = reply->path + dividerStr;
    207   }
    208   else
    209   { reply->path = "";
    210   }
     255       isalpha(reply->path[0]))
     256    {
     257      reply->path = reply->path + dividerStr;
     258    }
     259  else
     260    {
     261      reply->path = "";
     262    }
    211263  return reply;
    212264}
     
    216268 */
    217269bool FilePath::exists()
    218 { File f(this->path);
    219 
    220     return f.exists();
     270{
     271  File f(this->path);
     272  return f.exists();
    221273}
    222274
     
    225277 */
    226278FilePath *FilePath::parent()
    227 { // TODO: cope with network roots
    228     FilePath *reply = new FilePath(this->path);
    229 
    230     // get the last divider
    231     unsigned int truncate   =   reply->path.find_last_of(divider);
     279{
     280  // TODO: cope with network roots
     281  FilePath *reply = new FilePath(this->path);
     282
     283  // get the last divider
     284  unsigned int truncate = reply->path.find_last_of(divider);
    232285
    233286  // if it exists, then we can do a normal get parent
    234287  if (truncate != -1)
    235   { // if it's the leftmost one as well then we'll skip it to
    236     // give a parent of <drive>:\ as this patches some problems
    237     // with windows calls!  Note that a parent call to the returned
    238     // object in this case will return itself
    239     if (truncate == reply->path.find(divider))
    240     {   truncate ++;
    241     }
    242     reply->path = reply->path.substr(0, truncate);
    243   }
     288    {
     289      // if it's the leftmost one as well then we'll skip it to
     290      // give a parent of <drive>:\ as this patches some problems
     291      // with windows calls!  Note that a parent call to the returned
     292      // object in this case will return itself
     293      if (truncate == reply->path.find(divider))
     294    {
     295      truncate ++;
     296    }
     297      reply->path = reply->path.substr(0, truncate);
     298    }
     299
    244300  // if we've got a drive letter only, then append the divider to
    245301  // patch problematic windows calls;  again subsequent parent
    246302  // calls to our returned object would in effect return itself
    247303  else if (reply->path[1] == ':' && reply->path.length() == 2 &&
    248                  isalpha(reply->path[0]))
    249   { reply->path = reply->path + dividerStr;
    250   }
     304       isalpha(reply->path[0]))
     305    {
     306      reply->path = reply->path + dividerStr;
     307    }
     308
    251309  // a non-rooted object; return blank
    252310  else
    253   { reply->path = "";
    254   }
    255     reply->is_aRoot = __pathIsAValidRoot(reply->path);
     311    {
     312      reply->path = "";
     313    }
     314
     315  reply->is_aRoot = __pathIsAValidRoot(reply->path);
    256316  return reply;
    257317}
    258318
    259319FilePath *FilePath::append(FilePath &subPath)
    260 {   return new FilePath(this->path, subPath.path);
     320{
     321  return new FilePath(this->path, subPath.path);
    261322}
    262323
    263324FilePath *FilePath::append(char *subPath)
    264 {   return new FilePath(this->path, subPath);
     325{
     326  return new FilePath(this->path, subPath);
    265327}
    266328
    267329const char *FilePath::cString()
    268 {   return this->path.c_str();
     330{
     331  return this->path.c_str();
    269332}
    270333
    271334string FilePath::pathString()
    272 {   return this->path;
     335{
     336  return this->path;
    273337}
    274338
    275339bool FilePath::ensureWriteablePath()
    276 { //TODO: don't assume that all roots are writeable!
    277     if (this->isRoot())
    278   { return true;
    279   }
    280 
    281     // does this path exist?
    282     File thisFile(this->path);
     340{
     341  //TODO: don't assume that all roots are writeable!
     342  if (this->isRoot())
     343    {
     344      return true;
     345    }
     346
     347  // does this path exist?
     348  File thisFile(this->path);
    283349  bool reply = false;
    284350
    285     // if not, ensure writeable parent
     351  // if not, ensure writeable parent
    286352  if (thisFile.exists() == false)
    287   { FilePath    *parent;
    288 
    289     // create parent reference
    290     parent  = this->parent();
    291     if (parent->equals(thisFile.getFileName()))
    292     { delete parent;
    293         return true;
    294     }
    295 
    296     // if parent is writeable then try to make the directory
    297     if (parent->ensureWriteablePath())
    298     { // make this directory; if it succeeded we reply positively
    299         if (mkdir(this->path.c_str()) == 0)
    300       { reply = true;
    301       }
    302     }
    303     // destroy parent reference
    304     delete parent;
    305   }
     353    {
     354      FilePath *parent;
     355
     356      // create parent reference
     357      parent = this->parent();
     358
     359      if (parent->equals(thisFile.getFileName()))
     360    {
     361      delete parent;
     362      return true;
     363    }
     364
     365      // if parent is writeable then try to make the directory
     366      if (parent->ensureWriteablePath())
     367    {
     368      // make this directory; if it succeeded we reply positively
     369      if (_mkdir(this->path.c_str()) == 0)
     370        {
     371          reply = true;
     372        }
     373    }
     374
     375      // destroy parent reference
     376      delete parent;
     377    }
     378
    306379  else if (thisFile.isDirectory() == true)
    307   { // is this writeable by user?; if so we're okay
    308     if (thisFile.isWriteable())
    309     {   reply = true;
    310     }
    311   }
    312 
     380    {
     381      // is this writeable by user?; if so we're okay
     382      if (thisFile.isWriteable())
     383    {
     384      reply = true;
     385    }
     386    }
    313387  return reply;
    314388}
  • trunk/gsinstaller/FilePath.h

    r1498 r1536  
    55
    66class FilePath
    7 {   private:
    8         string path;            // full path of this item
    9     bool     is_aRoot;  // indicates whether this directory/file is a file root
    10     void   _init(string path, string subPath);
    11     public:
    12     FilePath();
    13     FilePath(string filePath);
    14     FilePath(string filePath, string filePath2);
    15     FilePath(int nPaths, ...);
    16     FilePath(FilePath &path, string subPath);
    17     bool      equals(FilePath &path);
    18     bool      equals(const char *path);
    19     bool            isRoot();
    20     bool            isEmpty();
    21     FilePath *append(FilePath &path);
    22     FilePath *append(char *path);
    23     FilePath *parent();
    24     FilePath *root();
    25     FilePath *rootDrive();
    26     bool ensureWriteablePath();
    27     bool exists();
    28     const char *cString();
    29     string      pathString();
    30     bool operator==(const FilePath &b) { return this->path == b.path; }
    31     bool operator!=(const FilePath &b) { return this->path != b.path; }
    32     bool operator<(const FilePath &b) { return this->path < b.path; }
     7{
     8private:
     9  string path;                  // full path of this item
     10  bool is_aRoot;                // indicates whether this directory/file is a file root
     11  void _init(string path, string subPath);
     12public:
     13  FilePath();
     14  FilePath(string filePath);
     15  FilePath(string filePath, string filePath2);
     16  FilePath(int nPaths, ...);
     17  FilePath(FilePath &path, string subPath);
     18  bool equals(FilePath &path);
     19  bool equals(const char *path);
     20  bool isRoot();
     21  bool isEmpty();
     22  FilePath *append(FilePath &path);
     23  FilePath *append(char *path);
     24  FilePath *parent();
     25  FilePath *root();
     26  FilePath *rootDrive();
     27  bool ensureWriteablePath();
     28  bool exists();
     29  const char *cString();
     30  string pathString();
     31  bool operator==(const FilePath &b) const { return this->path == b.path; }
     32  bool operator!=(const FilePath &b) const { return this->path != b.path; }
     33  bool operator<(const FilePath &b) const { return this->path < b.path; }
    3334};
    3435#endif
  • trunk/gsinstaller/copyProgress.cpp

    r1475 r1536  
    77
    88extern HINSTANCE app_instance;
    9 extern gsInstall_getDesktopExt(int *x, int *y);
     9extern void gsInstall_getDesktopExt(int *x, int *y);
    1010
    11 LRESULT CALLBACK copyProgressBar_windowProc(    HWND window, UINT message,
    12                                                                                             WPARAM wParam, LPARAM lParam)
    13 {   switch (message)
    14     {   case WM_CREATE:
    15     {   CREATESTRUCT *createStruct = (CREATESTRUCT *) lParam;
     11LRESULT CALLBACK copyProgressBar_windowProc(HWND window, UINT message,
     12                        WPARAM wParam, LPARAM lParam)
     13{   
     14  switch (message)
     15    {   
     16    case WM_CREATE:
     17      {
     18    CREATESTRUCT *createStruct = (CREATESTRUCT *) lParam;
    1619        long *createParams;
    1720        copyProgressBar *progressBar;
    1821
    19       createParams = (long *) createStruct->lpCreateParams;
     22    createParams = (long *) createStruct->lpCreateParams;
     23   
     24    SetWindowLong(window, GWL_USERDATA, createParams[0]);
     25    progressBar = (copyProgressBar *) GetWindowLong(window, GWL_USERDATA);
     26    if (progressBar == NULL)
     27      {
     28        MessageBox(0, "A", "A", MB_OK);
     29      }
    2030
    21             SetWindowLong(window, GWL_USERDATA, createParams[0]);
    22       progressBar = (copyProgressBar *) GetWindowLong(window, GWL_USERDATA);
    23         if (progressBar == NULL)
    24       { MessageBox(0, "A", "A", MB_OK);
     31    CreateWindowEx( 0, "STATIC", (char *) createParams[1], WS_CHILD | WS_VISIBLE,
     32            10, 5, 180, 20, window, (HMENU) 0,
     33            app_instance, NULL);
    2534      }
     35      break;
    2636
    27       CreateWindowEx( 0, "STATIC", (char *) createParams[1], WS_CHILD | WS_VISIBLE,
    28                                          10, 5, 180, 20, window, (HMENU) 0,
    29                          app_instance, NULL);
     37    default:
     38      return(DefWindowProc(window, message, wParam, lParam));
     39    }
    3040
    31     }
    32     break;
    33 
    34         default:
    35             return(DefWindowProc(window, message, wParam, lParam));
    36   }
    37 
    38     return 0;
     41  return 0;
    3942}
    4043
  • trunk/gsinstaller/dirSelector.cpp

    r1397 r1536  
    9292
    9393void dirSelector::requestPath(HWND parent, LPSTR message)
    94 { OPENFILENAME  openStr;
    95     char                    fileName[256] = "dir.dir\0";
    96   DWORD                 error;
    97   BROWSEINFO    bInfo;
    98   int                       image;
     94{
     95  OPENFILENAME openStr;
     96  char fileName[256] = "dir.dir\0";
     97  DWORD error;
     98  BROWSEINFO bInfo;
     99  int image;
    99100
    100101  bInfo.hwndOwner = parent;
    101   bInfo.pidlRoot                = NULL;
    102   bInfo.pszDisplayName  = fileName;
    103   bInfo.lpszTitle               = message;
    104   bInfo.ulFlags                 = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
    105   bInfo.lpfn                        = initSelect;
    106   bInfo.lParam                  = (LONG) this;
    107   bInfo.iImage                  = image = 0;
     102  bInfo.pidlRoot = NULL;
     103  bInfo.pszDisplayName = fileName;
     104  bInfo.lpszTitle = message;
     105  bInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
     106  bInfo.lpfn = initSelect;
     107  bInfo.lParam = (LONG) this;
     108  bInfo.iImage = image = 0;
    108109  LPITEMIDLIST itemList = SHBrowseForFolder(&bInfo);
    109110  if (itemList != NULL)
    110   { SHGetPathFromIDList(itemList, fileName);
    111     this->setPath(fileName);
    112   }
     111    {
     112      SHGetPathFromIDList(itemList, fileName);
     113      this->setPath(fileName);
     114    }
    113115  return;
    114116
    115     openStr.lStructSize = sizeof(OPENFILENAME);
    116   openStr.hwndOwner     = parent;
    117   openStr.hInstance     = 0;// app_instance; //this->dlgBlock;
    118   openStr.lpstrFilter               = NULL;
    119   openStr.lpstrCustomFilter = NULL;
    120   openStr.nMaxCustFilter        = NULL;
    121   openStr.nFilterIndex          = 0;
    122   openStr.lpstrFile                 = fileName;
    123   openStr.nMaxFile                  = 255;
    124   openStr.lpstrFileTitle        = NULL;
    125   openStr.lpstrInitialDir       = NULL;
    126   openStr.lpstrTitle                = message;
    127   openStr.Flags                         = OFN_ENABLEHOOK | OFN_NOTESTFILECREATE | OFN_NOVALIDATE | OFN_EXPLORER; //  || OFN_ENABLETEMPLATE | OFN_EXPLORER;
    128   openStr.nFileOffset               = 0;
    129   openStr.nFileExtension        = 4;
    130   openStr.lpstrDefExt               = NULL;
    131   openStr.lCustData                 = NULL;
    132   openStr.lpfnHook                  = hookProc;
    133   openStr.lpTemplateName        = 0; // "MySaveAsDlg";
     117  openStr.lStructSize = sizeof(OPENFILENAME);
     118  openStr.hwndOwner = parent;
     119  openStr.hInstance = 0; // app_instance; //this->dlgBlock;
     120  openStr.lpstrFilter = NULL;
     121  openStr.lpstrCustomFilter = NULL;
     122  //  openStr.nMaxCustFilter = NULL;
     123  openStr.nMaxCustFilter = 0;
     124  openStr.nFilterIndex = 0;
     125  openStr.lpstrFile = fileName;
     126  openStr.nMaxFile = 255;
     127  openStr.lpstrFileTitle = NULL;
     128  openStr.lpstrInitialDir = NULL;
     129  openStr.lpstrTitle = message;
     130  openStr.Flags = OFN_ENABLEHOOK | OFN_NOTESTFILECREATE | OFN_NOVALIDATE | OFN_EXPLORER; //  || OFN_ENABLETEMPLATE | OFN_EXPLORER;
     131  openStr.nFileOffset = 0;
     132  openStr.nFileExtension = 4;
     133  openStr.lpstrDefExt = NULL;
     134  //  openStr.lCustData = NULL;
     135  openStr.lCustData = 0;
     136  openStr.lpfnHook = hookProc;
     137  openStr.lpTemplateName = 0; // "MySaveAsDlg";
    134138  if (GetSaveFileName(&openStr) == 0)
    135   { error = CommDlgExtendedError();
    136   }
     139    {
     140      error = CommDlgExtendedError();
     141    }
    137142  else
    138   { if (this->path != NULL)
    139     { free(this->path);
     143    {
     144      if (this->path != NULL)
     145    {
     146      free(this->path);
     147    }
     148      this->path = (char *) malloc (strlen(openStr.lpstrFile) + 1);
     149      strcpy(this->path, openStr.lpstrFile);
    140150    }
    141     this->path = (char *) malloc (strlen(openStr.lpstrFile) + 1);
    142     strcpy(this->path, openStr.lpstrFile);
    143   }
    144151}
    145152
    146153char *dirSelector::selectedPath()
    147 {   return this->path;
     154{
     155  return this->path;
    148156}
  • trunk/gsinstaller/dirent.cpp

    r1524 r1536  
    11#include <string.h>
    22#include <windows.h>
     3#include <malloc.h>
    34
    45#include "dirent.h"
    56
    67void _getFileName(DIRSTR *dirlist, WIN32_FIND_DATA *winFileData)
    7 { // get leaf if directory name is given
    8     char *leafname = strrchr(winFileData->cFileName, '\\');
     8{
     9  // get leaf if directory name is given
     10  char *leafname = strrchr(winFileData->cFileName, '\\');
    911
    10     if (leafname)
    11   { leafname ++;
     12  if (leafname)
     13  {
     14    leafname ++;
    1215  }
    1316  else
    14   { leafname = winFileData->cFileName;
     17  {
     18    leafname = winFileData->cFileName;
    1519  }
    16     strcpy(dirlist->fileData.d_name, leafname);
     20  strcpy(dirlist->fileData.d_name, leafname);
    1721}
    1822
    1923DIRSTR *opendir(const char *name)
    20 { char buffer[MAX_PATH];
     24{
     25  char buffer[MAX_PATH];
    2126  WIN32_FIND_DATA winFileData;
    22 
    23     DIRSTR *newlist = (DIRSTR *) malloc(sizeof(DIRSTR));
     27  DIRSTR *newlist = (DIRSTR *) malloc(sizeof(DIRSTR));
    2428
    2529  strcpy(buffer, name);
    2630  if (buffer[strlen(buffer)-1] != '\\')
    27   { strcat(buffer, "\\*");
    28   }
     31    {
     32      strcat(buffer, "\\*");
     33    }
    2934  else
    30   { strcat(buffer, "*");
    31   }
     35    {
     36      strcat(buffer, "*");
     37    }
    3238
    3339  newlist->searchHandle = FindFirstFile(buffer, &winFileData);
    3440  if (newlist->searchHandle == INVALID_HANDLE_VALUE)
    35   { DWORD error = GetLastError();
    36     if (error == ERROR_NO_MORE_FILES)
    37     { newlist->first = 2;
     41    {
     42      DWORD error = GetLastError();
     43      if (error == ERROR_NO_MORE_FILES)
     44    {
     45      newlist->first = 2;
     46    }
     47      else
     48    {
     49      free(newlist);
     50      newlist = NULL;
     51    }
    3852    }
    39     else
    40     {   free(newlist);
    41       newlist = NULL;
     53  else
     54    {
     55      _getFileName(newlist, &winFileData);
     56      newlist->first = 1;
    4257    }
    43   }
    44   else
    45   { _getFileName(newlist, &winFileData);
    46     newlist->first = 1;
    47   }
    4858  return newlist;
    4959}
    5060
    5161dirent *readdir(DIRSTR *dirlist)
    52 { if (dirlist->first == 2)
    53     { // empty directory
    54     return NULL;
    55   }
    56     else if (dirlist->first != 1)
    57     { WIN32_FIND_DATA winFileData;
    58 
    59     if (FindNextFile(dirlist->searchHandle, &winFileData) == 0)
    60     { DWORD error = GetLastError();
    61 
    62         return NULL;
     62{
     63  if (dirlist->first == 2)
     64    {
     65      // empty directory
     66      return NULL;
    6367    }
    64     else
    65     { _getFileName(dirlist, &winFileData);
     68  else if (dirlist->first != 1)
     69    {
     70      WIN32_FIND_DATA winFileData;
     71   
     72      if (FindNextFile(dirlist->searchHandle, &winFileData) == 0)
     73    {
     74      DWORD error = GetLastError();
     75      return NULL;
     76    }
     77      else
     78    {
     79      _getFileName(dirlist, &winFileData);
     80    }
    6681    }
    67   }
    6882  else
    69   { dirlist->first = 0;
    70   }
     83    {   
     84      dirlist->first = 0;
     85    }
    7186
    7287  return &dirlist->fileData;
     
    7489
    7590void closedir(DIRSTR *dirlist)
    76 { free(dirlist);
     91{
     92  free(dirlist);
    7793}
    78 
    79 
    80 
  • trunk/gsinstaller/file.h

    r1397 r1536  
    77
    88class File
    9 {   private:
    10     string              name;
    11     unsigned long size;
    12         vector<File>    children;
    13     bool                    is_dir;
    14     bool                    does_exist;
    15     bool          is_writable;
     9{
     10private:
     11  string name;
     12  unsigned long size;
     13  vector<File> children;
     14  bool is_dir;
     15  bool does_exist;
     16  bool is_writable;
    1617
    17         void _getDetails();
    18     void getChildren();
    19     protected:
    20   public:
    21     File();
    22     File(string filename, unsigned long filesize);
    23     File(string filename);
    24     void copy(char *destination);
    25     bool isDirectory();
    26     bool isWriteable();
    27     bool exists();
    28     unsigned long getRawFileSize();
    29     unsigned long getFileSize();
    30     const char *getFileName();
    31     unsigned long getDiskSpace(DiskSpace &diskSpace);
    32     vector<File>::iterator childBegin();
    33     vector<File>::iterator childEnd();
     18  void _getDetails();
     19  void getChildren();
     20protected:
     21public:
     22  File();
     23  File(string filename, unsigned long filesize);
     24  File(string filename);
     25  void copy(char *destination);
     26  bool isDirectory();
     27  bool isWriteable();
     28  bool exists();
     29  unsigned long getRawFileSize();
     30  unsigned long getFileSize();
     31  const char *getFileName();
     32  unsigned long getDiskSpace(DiskSpace &diskSpace);
     33  vector<File>::iterator childBegin();
     34  vector<File>::iterator childEnd();
    3435};
    3536
  • trunk/gsinstaller/fileCopier.cpp

    r1498 r1536  
    33#include <stdlib.h>
    44#include <stdio.h>
    5 #include <dir.h>
     5//#include <dir.h>
     6#include <direct.h>
    67
    78fileCopySet::fileCopySet()
    8 {   this->sourceDir = NULL;
    9     this->destDir       = NULL;
     9{
     10  // do we need this - they're FilePath's, not pointers
     11  //  this->sourceDir = NULL;
     12  //  this->destDir = NULL;
    1013}
    1114
    1215fileCopySet::fileCopySet(FileVector files, FilePath &from, FilePath &to)
    13 {   this->fileList  = files;
    14     this->sourceDir = from;
    15   this->destDir     = to;
    16   this->dataSize    = 0;
    17 
    18     FileVector::iterator here   = files.begin();
    19   FileVector::iterator end  = files.end();
    20 
    21   while (here != end)
    22   { this->dataSize  +=  here->getFileSize();
    23     here ++;
    24   }
     16{
     17  this->fileList = files;
     18  this->sourceDir = from;
     19  this->destDir = to;
     20  this->dataSize = 0;
     21
     22  FileVector::iterator here = files.begin();
     23  FileVector::iterator end = files.end();
     24
     25  while (here != end)
     26    {
     27      this->dataSize += here->getFileSize();
     28      here ++;
     29    }
    2530}
    2631
     
    3035 */
    3136char *fileCopySet::destination(File *file)
    32 {   const char *oldname = file->getFileName();
    33     char *newname = (char *) malloc(strlen(oldname) - strlen(this->sourceDir.cString()) + strlen(this->destDir.cString()) + 1);
     37{
     38  const char *oldname = file->getFileName();
     39  char *newname = (char *) malloc(strlen(oldname) - strlen(this->sourceDir.cString()) + strlen(this->destDir.cString()) + 1);
    3440
    3541  if (newname != NULL)
    36   { strcpy(newname, this->destDir.cString());
    37     strcat(newname, &oldname[strlen(this->sourceDir.cString())]);
    38   }
     42    {
     43      strcpy(newname, this->destDir.cString());
     44      strcat(newname, &oldname[strlen(this->sourceDir.cString())]);
     45    }
    3946
    4047  return newname;
     
    4552 */
    4653bool fileCopySet::copyFile(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar)
    47 { unsigned long copied = 0;
    48     unsigned long bytes_read, bytes_written;
    49     unsigned char buffer[65536];
     54{
     55  unsigned long copied = 0;
     56  unsigned long bytes_read, bytes_written;
     57  unsigned char buffer[65536];
    5058  FILE *read_handle, *write_handle;
    5159  char *destination;
    5260
    5361  // get destination as a char[] block; will free it later
    54   destination   = this->destination(file);
     62  destination = this->destination(file);
    5563
    5664  // get read and write file handles
    57   read_handle   = fopen(file->getFileName(), "rb");
     65  read_handle = fopen(file->getFileName(), "rb");
    5866  if (read_handle == NULL)
    59   { return false;
    60   }
    61     write_handle    = fopen(destination, "wb");
     67    {
     68      return false;
     69    }
     70  write_handle = fopen(destination, "wb");
    6271  if (write_handle == NULL)
    63   { fclose(read_handle);
    64     return false;
    65   }
     72    {
     73      fclose(read_handle);
     74      return false;
     75    }
    6676
    6777  while (copied < file->getFileSize())
    68   { // TODO: lock
    69 
    70         // read so many bytes
    71     if (file->getFileSize() - copied < 65536)
    72     {   bytes_read = file->getFileSize() - copied;
    73     }
    74     else
    75     {   bytes_read  = 65536;
    76     }
    77     bytes_read = fread((void *) buffer, 1, bytes_read, read_handle);
    78 
    79     // write so many bytes
    80     bytes_written   =   fwrite((void *) buffer, 1, bytes_read, write_handle);
    81 
    82     // TODO: unlock
    83 
    84     // note new bytes copied
    85     copied                  +=  bytes_written;
    86     this->dataSize  += bytes_written;
    87   }
     78    {
     79      // TODO: lock
     80      // read so many bytes
     81      if (file->getFileSize() - copied < 65536)
     82    {
     83      bytes_read = file->getFileSize() - copied;
     84    }
     85      else
     86    {
     87      bytes_read = 65536;
     88    }
     89      bytes_read = fread((void *) buffer, 1, bytes_read, read_handle);
     90
     91      // write so many bytes
     92      bytes_written = fwrite((void *) buffer, 1, bytes_read, write_handle);
     93
     94      // TODO: unlock
     95
     96      // note new bytes copied
     97      copied += bytes_written;
     98      this->dataSize += bytes_written;
     99    }
    88100  fclose(read_handle);
    89101  fclose(write_handle);
     
    91103  // free destination filename text
    92104  if (monitor != NULL)
    93   { monitor->copied(file->getFileName(), destination, false);
    94   }
     105    {
     106      monitor->copied(file->getFileName(), destination, false);
     107    }
    95108  delete destination;
    96109  return true;
     
    102115 */
    103116void fileCopySet::copy(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar)
    104 { // just skip this file if it doesn't exist
    105     if (file->exists() == false)
    106     {   return;
    107   }
     117{
     118  // just skip this file if it doesn't exist
     119  if (file->exists() == false)
     120    {
     121      return;
     122    }
    108123
    109124  // if a directory, scan it.
    110     if (file->isDirectory())
    111     { // create directory
    112     char *thisDestDir   = this->destination(file);
    113     mkdir(thisDestDir);
    114 
    115     // note amount of data copied
    116     // this->copied += file->getRawFileSize();
    117 
    118     // note for uninstall the action done
    119       if (monitor != NULL)
    120     {   monitor->copied(file->getFileName(), thisDestDir, true);
     125  if (file->isDirectory())
     126    {
     127      // create directory
     128      char *thisDestDir = this->destination(file);
     129      _mkdir(thisDestDir);
     130
     131      // note amount of data copied
     132      // this->copied += file->getRawFileSize();
     133
     134      // note for uninstall the action done
     135      if (monitor != NULL)
     136    {
     137      monitor->copied(file->getFileName(), thisDestDir, true);
    121138    }
    122139
    123     // copy children
    124     vector<File>::iterator here = file->childBegin();
    125     vector<File>::iterator end  = file->childEnd();
    126     while (here != end)
    127     {   this->copy(here, monitor, progressBar);
    128         here ++;
    129     }
    130 
    131     // delete constructed destination name
    132     delete thisDestDir;
    133   }
     140      // copy children
     141      vector<File>::iterator here = file->childBegin();
     142      vector<File>::iterator end = file->childEnd();
     143      while (here != end)
     144    {
     145      this->copy(here, monitor, progressBar);
     146      here ++;
     147    }
     148
     149      // delete constructed destination name
     150      delete thisDestDir;
     151    }
     152
    134153  // not a directory; just copy the file
    135154  else
    136   { // copy file itself
    137     this->copyFile(file, monitor, progressBar);
    138   }
     155    {
     156      // copy file itself
     157      this->copyFile(file, monitor, progressBar);
     158    }
     159
    139160  progressBar.done(file->getRawFileSize());
    140161}
    141162
    142163void fileCopySet::copy(fileCopyMonitor *monitor, copyProgressBar &progressBar)
    143 {   FileVector::iterator here = fileList.begin();
    144     FileVector::iterator end    = fileList.end();
    145 
    146   while (here != end)
    147   { this->copy(here, monitor, progressBar);
    148     here ++;
    149   }
     164{
     165  FileVector::iterator here = fileList.begin();
     166  FileVector::iterator end = fileList.end();
     167  while (here != end)
     168    {
     169      this->copy(here, monitor, progressBar);
     170      here ++;
     171    }
    150172}
    151173
    152174unsigned long fileCopySet::getCopiedSize(DiskSpace &space)
    153 { // initialise counters for size
    154     unsigned long copiedSize        = 0;
     175{
     176  // initialise counters for size
     177  unsigned long copiedSize = 0;
    155178
    156179  // iterate through our list of files to obtain total space requirement
    157180  FileVector::iterator here = fileList.begin();
    158     FileVector::iterator end    = fileList.end();
    159 
    160   while (here != end)
    161   { copiedSize += here->getDiskSpace(space);
    162     here ++;
    163   }
    164 
     181  FileVector::iterator end = fileList.end();
     182  while (here != end)
     183    {
     184      copiedSize += here->getDiskSpace(space);
     185      here ++;
     186    }
    165187  return copiedSize;
    166188}
    167189
    168190unsigned long fileCopySet::getOriginalSize()
    169 { // initialise counters for size
    170     return this->dataSize;
     191{
     192  // initialise counters for size
     193  return this->dataSize;
    171194}
    172195
     
    176199 */
    177200bool fileCopier::checkSpace()
    178 { fileCopySetList localSet = this->list;
    179 
    180     do
    181   { unsigned int i = 0;
    182 
    183     // get destination root and use it to obtain space check information
    184         FilePath *destRoot = localSet[0].destDir.root();
    185         DiskSpace space(destRoot->cString());
    186 
    187       // check that diskspace checking is functional
    188       if (space.initialisedOk() == false)
    189     { delete destRoot;
    190         return false;
     201{
     202  fileCopySetList localSet = this->list;
     203
     204  do
     205    {
     206      unsigned int i = 0;
     207
     208      // get destination root and use it to obtain space check information
     209      FilePath *destRoot = localSet[0].destDir.root();
     210      DiskSpace space(destRoot->cString());
     211
     212      // check that diskspace checking is functional
     213      if (space.initialisedOk() == false)
     214    {
     215      delete destRoot;
     216      return false;
    191217    }
    192218
    193     // get size of the first set
    194     unsigned long copiedSize = localSet[0].getCopiedSize(space);
    195 
    196     // dispose of the first set
    197     localSet.erase(localSet.begin());
    198 
    199     // get all remaining sets and in turn if they share the root with
    200     // the first root, add their size to the count and remove them from
    201     // the local list of sets; otherwise skip
    202     while (i < localSet.size())
    203     { // get a new root object for this set's destination
    204         FilePath *p = localSet[i].destDir.root();
    205 
    206         if (*destRoot == *p)
    207       { copiedSize  +=  localSet[i].getCopiedSize(space);
    208         localSet.erase(localSet.begin() + i);
    209       }
    210       else
    211       { i ++;
    212       }
    213 
    214       // delete the constructed root
    215       delete p;
    216     }
    217 
    218     // dispose of destination root
    219     delete destRoot;
    220 
    221       // return false if not enough space
    222     if (space.totalFreeSpace() < copiedSize)
    223     { return false;
     219      // get size of the first set
     220      unsigned long copiedSize = localSet[0].getCopiedSize(space);
     221
     222      // dispose of the first set
     223      localSet.erase(localSet.begin());
     224
     225      // get all remaining sets and in turn if they share the root with
     226      // the first root, add their size to the count and remove them from
     227      // the local list of sets; otherwise skip
     228      while (i < localSet.size())
     229    {
     230      // get a new root object for this set's destination
     231      FilePath *p = localSet[i].destDir.root();
     232
     233      if (*destRoot == *p)
     234        {
     235          copiedSize += localSet[i].getCopiedSize(space);
     236          localSet.erase(localSet.begin() + i);
     237        }
     238      else
     239        {
     240          i ++;
     241        }
     242
     243      // delete the constructed root
     244      delete p;
     245    }
     246
     247      // dispose of destination root
     248      delete destRoot;
     249
     250      // return false if not enough space
     251      if (space.totalFreeSpace() < copiedSize)
     252    {
     253      return false;
    224254    }
    225   } while (localSet.size() != 0);
     255
     256    } while (localSet.size() != 0);
     257
    226258
    227259  // record size and initialise the progressbar with the same
    228   this->dataSize    = 0;
     260  this->dataSize = 0;
    229261  for (unsigned int i = 0; i < this->list.size(); i ++)
    230   { this->dataSize  += this->list[i].getOriginalSize();
    231   }
     262    {
     263      this->dataSize += this->list[i].getOriginalSize();
     264    }
    232265  this->progressBar.init(this->dataSize);
    233266
     
    237270
    238271fileCopier::fileCopier(fileCopyMonitor *monitor, fileCopySetList &_list)
    239 {   this->list  = _list;
    240   this->dataSize    = 0;
    241   this->copied      = 0;
    242   this->monitor     = monitor;
     272{
     273  this->list = _list;
     274  this->dataSize = 0;
     275  this->copied = 0;
     276  this->monitor = monitor;
    243277}
    244278
    245279fileCopier::fileCopier(fileCopyMonitor *monitor)
    246 { this->dataSize    = 0;
    247   this->copied      = 0;
    248   this->monitor     = monitor;
     280{
     281  this->dataSize = 0;
     282  this->copied = 0;
     283  this->monitor = monitor;
    249284}
    250285
    251286void fileCopier::copy()
    252 {   fileCopySetList::iterator here = list.begin();
    253     fileCopySetList::iterator end   = list.end();
     287{
     288  fileCopySetList::iterator here = list.begin();
     289  fileCopySetList::iterator end = list.end();
    254290
    255291  this->progressBar.show();
    256292  while (here != end)
    257   { here->copy(this->monitor, this->progressBar);
    258     here ++;
    259   }
     293    {
     294      here->copy(this->monitor, this->progressBar);
     295      here ++;
     296    }
     297
    260298  this->progressBar.close();
    261299}
  • trunk/gsinstaller/fileCopier.h

    r1475 r1536  
    66
    77class fileCopyMonitor
    8 {   public:
    9         fileCopyMonitor() {};
    10         virtual void copied(string from, string to, bool isDir) = 0;
     8{
     9public:
     10  fileCopyMonitor() {};
     11  virtual void copied(string from, string to, bool isDir) = 0;
    1112};
    1213
    1314class fileCopySet
    14 { private:
    15         FileVector    fileList;
    16     FilePath      sourceDir;
    17         unsigned long   dataSize;
    18   public:
    19     FilePath      destDir;
    20     fileCopySet();
    21     fileCopySet(FileVector files, FilePath &from, FilePath &to);
    22       char *destination(File *file);
    23     unsigned long getOriginalSize();
    24     unsigned long getCopiedSize(DiskSpace &space);
    25     bool copyFile(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar);
    26     void copy(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar);
    27     void copy(fileCopyMonitor *monitor, copyProgressBar &progressBar);
     15{
     16private:
     17  FileVector fileList;
     18  FilePath sourceDir;
     19  unsigned long dataSize;
     20public:
     21  FilePath destDir;
     22  fileCopySet();
     23  fileCopySet(FileVector files, FilePath &from, FilePath &to);
     24  char *destination(File *file);
     25  unsigned long getOriginalSize();
     26  unsigned long getCopiedSize(DiskSpace &space);
     27  bool copyFile(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar);
     28  void copy(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar);
     29  void copy(fileCopyMonitor *monitor, copyProgressBar &progressBar);
    2830};
    2931
     
    3133
    3234class fileCopier
    33 { private:
    34         fileCopySetList list;
    35         unsigned long       dataSize;
    36     unsigned long   copied;
    37       copyProgressBar progressBar;
    38     fileCopyMonitor *monitor;
    39     protected:
    40   public:
    41     fileCopier::fileCopier(fileCopyMonitor *monitor, fileCopySetList &list);
    42     fileCopier::fileCopier(fileCopyMonitor *monitor);
    43     void fileCopier::addSet(fileCopySet &set) { this->list.push_back(set); }
    44     bool checkSpace();
    45     void copy();
     35{
     36private:
     37  fileCopySetList list;
     38  unsigned long dataSize;
     39  unsigned long copied;
     40  copyProgressBar progressBar;
     41  fileCopyMonitor *monitor;
     42protected:
     43public:
     44  fileCopier::fileCopier(fileCopyMonitor *monitor, fileCopySetList &list);
     45  fileCopier::fileCopier(fileCopyMonitor *monitor);
     46  void fileCopier::addSet(fileCopySet &set) { this->list.push_back(set); }
     47  bool checkSpace();
     48  void copy();
    4649};
    4750#define _FILECOPIER_H_
  • trunk/gsinstaller/gsManifest.cpp

    r1498 r1536  
    115115 */
    116116void gsManifest::expandGroups()
    117 {   strArrayMap::iterator here = this->manifests.begin();
    118   strArrayMap::iterator end = this->manifests.end();
     117{
     118  strArrayMap::iterator here = this->manifests.begin();
     119  strArrayMap::iterator end = this->manifests.end();
    119120
    120121  while (here != end)
    121   { this->expandGroup((*here).first);
    122     here ++;
    123   }
     122    {
     123      this->expandGroup((*here).first);
     124      here ++;
     125    }
    124126}
    125127
     
    127129 * expand a particular group
    128130 */
    129 void gsManifest::expandGroup(string &group)
    130 {   stringArray &array = this->manifests[group];
    131 
    132     unsigned int i = 0;
     131void gsManifest::expandGroup(const string &group)
     132{
     133  stringArray &array = this->manifests[group];
     134
     135  unsigned int i = 0;
    133136  while (i < array.size())
    134   { if (this->isGroup(array[i]))
    135     {   this->expandGroupInstance(group, array[i]);
    136     }
     137  {
     138    if (this->isGroup(array[i]))
     139      {
     140    this->expandGroupInstance(group, array[i]);
     141      }
    137142    else
    138     {   i ++;
     143    {   
     144      i ++;
    139145    }
    140146  }
     
    144150 * expand a group instance inside a given group
    145151 */
    146 void gsManifest::expandGroupInstance(string parentgroup, string groupName)
    147 { // remove the group instance from the parent
    148     this->manifests[parentgroup].remove(groupName);
    149 
    150     // create a "clean" name without the { } brackets
    151     string group(groupName, 1, groupName.length() - 2);
     152void gsManifest::expandGroupInstance(const string &parentgroup, string groupName)
     153{
     154  // remove the group instance from the parent
     155  this->manifests[parentgroup].remove(groupName);
     156
     157  // create a "clean" name without the { } brackets
     158  string group(groupName, 1, groupName.length() - 2);
    152159
    153160  // circular reference - we're kind and ignore it!!
    154161  if (parentgroup.compare(group) == 0)
    155   { return;
     162  {
     163    return;
    156164  }
    157165
    158166  // lookup chidl group and add it to the parent
    159     this->manifests[parentgroup].add(this->manifests[group]);
     167  this->manifests[parentgroup].add(this->manifests[group]);
    160168}
    161169
     
    165173 */
    166174bool gsManifest::isGroup(string &name)
    167 { if (name[0] == '{' && name[name.length()-1] == '}')
    168     {   return true;
    169   }
    170     return false;
     175{
     176  if (name[0] == '{' && name[name.length()-1] == '}')
     177    {   
     178      return true;
     179    }
     180  return false;
    171181}
    172182
    173183void gsManifest::expandMacro(string macro, string value)
    174 {   string macroRef = "\$(" + macro + ")";
     184{   
     185  // illegal escape sequence ??
     186  // string macroRef = "\$(" + macro + ")";
     187  string macroRef = "$(" + macro + ")";
    175188
    176189  strArrayMap::iterator here = this->manifests.begin();
     
    178191
    179192  while (here != end)
    180   { stringArray &array = this->manifests[(*here).first];
    181 
    182     unsigned int i = 0;
     193  {
     194    stringArray &array = this->manifests[(*here).first];
     195
     196    unsigned int i = 0;
    183197    while (i < array.size())
    184     { unsigned int pos;
     198      {
     199    unsigned int pos;
    185200        while ((pos = array[i].find(macroRef)) < array[i].length() && pos != -1)
    186             {   array[i].replace(pos, macroRef.length(), value);
     201      {
     202        array[i].replace(pos, macroRef.length(), value);
     203      }
     204    i ++;
    187205      }
    188       i ++;
    189     }
    190206    here ++;
    191207  }
     
    197213
    198214void gsManifest::selectGroup(string groupName, FilePath &destination)
    199 { stringArray &groupArray = this->manifests[groupName];
    200 
    201     groupArray  = this->manifests[groupName];
     215{
     216  stringArray &groupArray = this->manifests[groupName];
     217
     218  // do we really need this twice ??
     219  // groupArray = this->manifests[groupName];
     220
    202221  this->selected[destination].add(groupArray);
    203222}
  • trunk/gsinstaller/gsManifest.h

    r1475 r1536  
    1313
    1414class gsManifest : public installAgent, fileCopyMonitor
    15 {   private:
    16     protected:
    17         strArrayMap                 manifests;
    18     pathStringArrayMap  selected;
     15{
     16private:
     17protected:
     18  strArrayMap manifests;
     19  pathStringArrayMap selected;
    1920
    20     bool getManifestLine(char *line, string &macro);
    21   public:
    22     gsManifest(installManager &manager, FilePath &path); // used for install
    23     gsManifest(installManager &manager); // used for uninstall
    24     bool getManifest(FilePath &path);
    25     void logAction(string actionName, string file);
    26     void logAction(string actionName, string source, string dest);
    27     bool undoAction(string actionName, stringArray &params);
    28     void expandGroupInstance(string parent, string child);
    29     void expandGroup(string &group);
    30     void expandGroups();
    31     bool isGroup(string &name);
    32     void expandMacro(string macroName, string value);
    33     void clearSelection();
    34     bool copy(FilePath *source);
    35     void selectGroup(string groupName, FilePath &destination);
    36     FileVector *selection(FilePath &source, stringArray &array);
    37     FileVector *selection(FilePath &source, FilePath &destination);
    38     bool selectCheckSpace();
    39 
    40     void copied(string from, string to, bool isDir); // from fileCopyMonitor
     21  bool getManifestLine(char *line, string &macro);
     22public:
     23  gsManifest(installManager &manager, FilePath &path); // used for install
     24  gsManifest(installManager &manager); // used for uninstall
     25  bool getManifest(FilePath &path);
     26  void logAction(string actionName, string file);
     27  void logAction(string actionName, string source, string dest);
     28  bool undoAction(string actionName, stringArray &params);
     29  void expandGroupInstance(const string &parentgroup, string groupName);
     30  void expandGroup(const string &group);
     31  void expandGroups();
     32  bool isGroup(string &name);
     33  void expandMacro(string macroName, string value);
     34  void clearSelection();
     35  bool copy(FilePath *source);
     36  void selectGroup(string groupName, FilePath &destination);
     37  FileVector *selection(FilePath &source, stringArray &array);
     38  FileVector *selection(FilePath &source, FilePath &destination);
     39  bool selectCheckSpace();
     40 
     41  void copied(string from, string to, bool isDir); // from fileCopyMonitor
    4142};
    4243#endif;
  • trunk/gsinstaller/gsPlatform.cpp

    r1397 r1536  
    3838
    3939bool gsPlatform::isUserAdministrator()
    40 { if (this->isWindowsNT())
    41     { HANDLE    token;
    42     PSID    adminId;
    43     PACL        aclData;
    44     PSECURITY_DESCRIPTOR            psdAdmin;
    45     SID_IDENTIFIER_AUTHORITY    systemSidAuthority;
    46     GENERIC_MAPPING                     genericMapping;
    47     PRIVILEGE_SET                           privilegeSet;
    48     DWORD       aclSize, status, structureSize;
    49     BOOL        result;
     40{
     41  if (this->isWindowsNT())
     42    {
     43      HANDLE token;
     44      PSID adminId;
     45      PACL aclData;
     46      PSECURITY_DESCRIPTOR psdAdmin;
     47      SID_IDENTIFIER_AUTHORITY systemSidAuthority;
     48      GENERIC_MAPPING genericMapping;
     49      PRIVILEGE_SET privilegeSet;
     50      DWORD aclSize, status, structureSize;
     51      BOOL result;
    5052
    51     // Get an impersonation token
    52     ImpersonateSelf(SecurityImpersonation);
     53      // Get an impersonation token
     54      ImpersonateSelf(SecurityImpersonation);
    5355
    54     if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &token))
    55     {   if (GetLastError() != ERROR_NO_TOKEN)
    56         {   return false;
    57       }
     56      if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &token))
     57    {
     58      if (GetLastError() != ERROR_NO_TOKEN)
     59        {   
     60          return false;
     61        }
    5862
    59       // if we didn't have an access token, take the process token instead
    60       if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
    61       { return false;
    62       }
     63      // if we didn't have an access token, take the process token instead
     64      if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
     65        {   
     66          return false;
     67        }
     68    }
     69
     70      // By now we have a valid process/thread token; now get information on the
     71      // admin group in this domain
     72      if (!AllocateAndInitializeSid(&systemSidAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
     73                    DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
     74                    &adminId))
     75    {   
     76      return false;
     77    }
     78
     79      // allocate space for security descriptor
     80      psdAdmin = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
     81      if (psdAdmin == NULL)
     82    {
     83      return false;
     84    }
     85
     86      // initialise descriptor
     87      if (!InitializeSecurityDescriptor(psdAdmin, SECURITY_DESCRIPTOR_REVISION))
     88    {
     89      return false;
     90    }
     91
     92      // get ACL size and allocate ACL block
     93      aclSize = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(adminId) - sizeof(DWORD);
     94      aclData = (PACL) LocalAlloc(LPTR, aclSize);
     95      if (aclData == NULL)
     96    {
     97      return false;
     98    }
     99
     100      // initalise the acl block
     101      if (!InitializeAcl(aclData, aclSize, ACL_REVISION2))
     102    {   
     103      return false;
     104    }
     105
     106      // try to add the given item to the Access Control Entry (ACE) list (ACL)
     107      if (!AddAccessAllowedAce(aclData, ACL_REVISION2, ACCESS_READ | ACCESS_WRITE, adminId))
     108    {   
     109      return false;
     110    }
     111
     112      // endeavour to add the acl to the discretionary acl (DACL)
     113      if (!SetSecurityDescriptorDacl(psdAdmin, TRUE, aclData, FALSE))
     114    {
     115      return false;
     116    }
     117
     118      // endeavour to set the owner/group identification
     119      SetSecurityDescriptorGroup(psdAdmin, adminId, FALSE);
     120      SetSecurityDescriptorOwner(psdAdmin, adminId, FALSE);
     121
     122      // right, we've now built up a discretionary acl on the current user,
     123      // finally get the generic mapping ready
     124      genericMapping.GenericRead = ACCESS_READ;
     125      genericMapping.GenericWrite = ACCESS_WRITE;
     126      genericMapping.GenericExecute = 0;
     127      genericMapping.GenericAll = ACCESS_READ | ACCESS_WRITE;
     128
     129      // do the actual access check
     130      if (!AccessCheck (psdAdmin, token, ACCESS_READ, &genericMapping,
     131            &privilegeSet, &structureSize, &status, &result))
     132    {
     133      return false;
     134    }
     135
     136      // end impersonisation
     137      RevertToSelf();
     138      return result;
    63139    }
    64 
    65     // By now we have a valid process/thread token; now get information on the
    66     // admin group in this domain
    67     if (!AllocateAndInitializeSid(&systemSidAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
    68                                                                 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
    69                                   &adminId))
    70     {   return false;
    71     }
    72 
    73     // allocate space for security descriptor
    74         psdAdmin    =   LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
    75     if (psdAdmin == NULL)
    76     {   return false;
    77     }
    78 
    79         // initialise descriptor
    80     if (!InitializeSecurityDescriptor(psdAdmin, SECURITY_DESCRIPTOR_REVISION))
    81     {   return false;
    82     }
    83 
    84     // get ACL size and allocate ACL block
    85         aclSize = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(adminId) - sizeof(DWORD);
    86     aclData =   (PACL) LocalAlloc(LPTR, aclSize);
    87     if (aclData == NULL)
    88     {   return false;
    89     }
    90 
    91     // initalise the acl block
    92     if (!InitializeAcl(aclData, aclSize, ACL_REVISION2))
    93     {   return false;
    94     }
    95 
    96     // try to add the given item to the Access Control Entry (ACE) list (ACL)
    97     if (!AddAccessAllowedAce(aclData, ACL_REVISION2, ACCESS_READ | ACCESS_WRITE, adminId))
    98     {   return false;
    99     }
    100 
    101     // endeavour to add the acl to the discretionary acl (DACL)
    102     if (!SetSecurityDescriptorDacl(psdAdmin, TRUE, aclData, FALSE))
    103     {   return false;
    104     }
    105 
    106     // endeavour to set the owner/group identification
    107     SetSecurityDescriptorGroup(psdAdmin, adminId, FALSE);
    108     SetSecurityDescriptorOwner(psdAdmin, adminId, FALSE);
    109 
    110     // right, we've now built up a discretionary acl on the current user,
    111     // finally get the generic mapping ready
    112         genericMapping.GenericRead      = ACCESS_READ;
    113     genericMapping.GenericWrite     = ACCESS_WRITE;
    114     genericMapping.GenericExecute   = 0;
    115     genericMapping.GenericAll           = ACCESS_READ | ACCESS_WRITE;
    116 
    117     // do the actual access check
    118     if (!AccessCheck(   psdAdmin, token, ACCESS_READ, &genericMapping,
    119                                         &privilegeSet, &structureSize, &status, &result))
    120     {   return false;
    121     }
    122 
    123     // end impersonisation
    124     RevertToSelf();
    125     return result;
    126   }
    127     return true;
     140  return true;
    128141}
    129142
    130143bool gsPlatform::reboot()
    131144{
    132     // Check for appropriate privileges if this is NT
    133     if (this->isWindowsNT())
    134   { HANDLE token;
    135     TOKEN_PRIVILEGES tkp;
     145  // Check for appropriate privileges if this is NT
     146  if (this->isWindowsNT())
     147    {
     148      HANDLE token;
     149      TOKEN_PRIVILEGES tkp;
    136150
    137     if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
    138                                                 &token))
    139         {   return false;
    140     }
     151      if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
     152                &token))
     153    {   
     154      return false;
     155    }
     156     
     157      LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
    141158
    142     LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
     159      tkp.PrivilegeCount = 1; // set one privilege
     160      tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    143161
    144     tkp.PrivilegeCount  = 1; // set one privilege
    145     tkp.Privileges[0].Attributes    = SE_PRIVILEGE_ENABLED;
     162      // Get the actual shutdown privilege
     163      AdjustTokenPrivileges(token, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
    146164
    147     // Get the actual shutdown privilege
    148     AdjustTokenPrivileges(token, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
    149 
    150     // as we can't test a return value on the previous call, use GetLastError
    151     if (GetLastError() != ERROR_SUCCESS)
    152     {   return false;
     165      // as we can't test a return value on the previous call, use GetLastError
     166      if (GetLastError() != ERROR_SUCCESS)
     167    {
     168      return false;
     169    }
    153170    }
    154   }
    155171  return ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0);
    156172}
    157173
    158174string gsPlatform::platformString()
    159 {   if (this->isWindowsNT())
    160     {   return gsPlatform_WINDOWSNT;
    161   }
     175{
     176  if (this->isWindowsNT())
     177    {
     178      return gsPlatform_WINDOWSNT;
     179    }
    162180  else if (this->isWindows9x())
    163   { return gsPlatform_WINDOWS9X;
     181  {
     182    return gsPlatform_WINDOWS9X;
    164183  }
    165184  else if (this->isWindows32s())
    166   { return gsPlatform_WINDOWS32S;
     185  {
     186    return gsPlatform_WINDOWS32S;
    167187  }
    168188  else
    169   { return gsPlatform_WINDOWS;
     189  {
     190    return gsPlatform_WINDOWS;
    170191  }
    171192}
  • trunk/gsinstaller/gsPlatform.h

    r1397 r1536  
    1111
    1212class gsPlatform
    13 {   private:
    14         OSVERSIONINFO   platformInfo;
    15     protected:
    16     public:
    17         gsPlatform();
    18     bool isWindows9x();
    19     bool isWindowsNT();
    20     bool isWindows32s();
    21     bool isOldWindows32s();
    22     bool isExplorerShell();
    23     bool isUserAdministrator();
    24     bool reboot();
    25     string platformString();
     13{   
     14private:
     15  OSVERSIONINFO platformInfo;
     16protected:
     17public:
     18  gsPlatform();
     19  bool isWindows9x();
     20  bool isWindowsNT();
     21  bool isWindows32s();
     22  bool isOldWindows32s();
     23  bool isExplorerShell();
     24  bool isUserAdministrator();
     25  bool reboot();
     26  string platformString();
    2627};
    2728#endif
  • trunk/gsinstaller/gsProgman.cpp

    r1498 r1536  
    350350  return reply;
    351351}
    352 
    353 
  • trunk/gsinstaller/gsinstall.cpp

    r1502 r1536  
    2323#include "gsManifest.h"
    2424
    25 char *      app_cmdLine;
     25char *app_cmdLine;
    2626static char app_name[] = "Greenstone Installer";
    27 HINSTANCE   app_instance;
    28 HWND          app_window;
    29 
    30 bool            config_complete = false;
     27HINSTANCE app_instance;
     28HWND app_window;
     29
     30bool config_complete = false;
    3131
    3232typedef vector<dirSelector *> dirSelVector;
    3333
    3434class GSInstall : public installManager
    35 { private:
    36         configureFile   *   configFile;             // the installation configure file
    37 
    38         FilePath *          collectPath;            // where the collection is currently installed
    39     FilePath *          installToPath;      // the first cut at a destination folder
    40     FilePath *          sourcePath;             // the root source folder
    41     FilePath *          gsdlSourcePath;     // the gsdl folder in the source area
    42     FilePath *          destinationPath;    // where the executables will be installed to
    43     FilePath *          dataDestPath;           // where the collection data files will go
    44 
    45     bool                        installVolume;      // whether to install collection data
    46     bool                        installFullVolume;// whether to install all collection data
    47 
    48     dirSelVector        selectedDirs;           // configuration objects
    49 
    50     gsPlatform                  platform;           // platform information
    51     gsRegistry *                gsRegister;     // registry
    52     gsManifest *                manifest;           // manifest of files
    53     gsProgramManager  * progman;            // program manager connection
    54 
    55     void                getSourcePath();
    56     void                getExistingInstall();
    57     public:
    58     bool            installExe;
    59 
    60         GSInstall(bool uninstall);
    61     FilePath *  collectionPath();
    62     FilePath *  installPath();
    63     bool                copyFiles();
    64     bool        updateRegistry();
    65     bool                updateProfiles();
    66     bool                updateProgman();
    67     bool                updateSetupExe();
    68     bool                installNetscape();
    69     void                setDestination();
    70     bool                setUninstall();
    71     void                uninstall();
    72     void                setManifest();
    73     void                addSelectedDir(dirSelector *selector);
     35{
     36private:
     37  configureFile *configFile; // the installation configure file
     38
     39  FilePath *collectPath; // where the collection is currently installed
     40  FilePath *installToPath; // the first cut at a destination folder
     41  FilePath *sourcePath; // the root source folder
     42  FilePath *gsdlSourcePath; // the gsdl folder in the source area
     43  FilePath *destinationPath; // where the executables will be installed to
     44  FilePath *dataDestPath; // where the collection data files will go
     45
     46  bool installVolume; // whether to install collection data
     47  bool installFullVolume; // whether to install all collection data
     48
     49  dirSelVector selectedDirs; // configuration objects
     50
     51  gsPlatform platform; // platform information
     52  gsRegistry *gsRegister; // registry
     53  gsManifest *manifest; // manifest of files
     54  gsProgramManager *progman; // program manager connection
     55
     56  void getSourcePath();
     57  void getExistingInstall();
     58public:
     59  bool installExe;
     60
     61  GSInstall(bool uninstall);
     62  FilePath *collectionPath();
     63  FilePath *installPath();
     64  bool copyFiles();
     65  bool updateRegistry();
     66  bool updateProfiles();
     67  bool updateProgman();
     68  bool updateSetupExe();
     69  bool installNetscape();
     70  void setDestination();
     71  bool setUninstall();
     72  void uninstall();
     73  void setManifest();
     74  void addSelectedDir(dirSelector *selector);
    7475};
    7576
     
    8182void gsInstall_getDesktopExt(int *sx, int *sy)
    8283{
    83     HDC dc = GetDC(GetDesktopWindow());
     84  HDC dc = GetDC(GetDesktopWindow());
    8485  *sx = GetDeviceCaps(dc, HORZRES);
    8586  *sy = GetDeviceCaps(dc, VERTRES);
     
    9495 */
    9596GSInstall::GSInstall(bool uninstall)
    96     : installManager()
    97 { // get the installation configuration file
    98     this->configFile    = new configureFile("install.cfg");
    99 
    100     // set up "default" installation bits
    101   this->installToPath   = new FilePath("C:\\GSDL");
    102     this->collectPath   = NULL;
    103   this->installExe  = true; // we must install the exe files
    104 
    105     // don't attempt this with windows 3.1
     97  : installManager()
     98{
     99  // get the installation configuration file
     100  this->configFile = new configureFile("install.cfg");
     101
     102  // set up "default" installation bits
     103  this->installToPath = new FilePath("C:\\GSDL");
     104  this->collectPath = NULL;
     105  this->installExe = true; // we must install the exe files
     106
     107  // don't attempt this with windows 3.1
    106108  if (!this->platform.isWindows32s())
    107   { // get the registry
    108       this->gsRegister  = new gsRegistry(*this, *this->configFile);
    109   }
     109    {
     110      // get the registry
     111      this->gsRegister  = new gsRegistry(*this, *this->configFile);
     112    }
    110113  else
    111   { // TODO: in windows 3.1 we can't use the register as it isn't fully/properly
    112       //       implemented; we must get the existing path information from elsewhere
    113     this->gsRegister    = new gsRegistry(*this, *this->configFile);
    114   }
     114    {   
     115      // TODO: in windows 3.1 we can't use the register as it isn't fully/properly
     116      //       implemented; we must get the existing path information from elsewhere
     117      this->gsRegister = new gsRegistry(*this, *this->configFile);
     118    }
    115119
    116120  // assume for now we will install the full volume and the database
    117   this->installVolume           = true;
    118   this->installFullVolume   = true;
    119 
    120     // detect any existing installation; unnecessary in uninstall (it's the
     121  this->installVolume = true;
     122  this->installFullVolume = true;
     123
     124  // detect any existing installation; unnecessary in uninstall (it's the
    121125  // "source" directory - see later
    122126  if (uninstall == false)
    123   { this->getExistingInstall();
    124   }
     127    {
     128      this->getExistingInstall();
     129    }
    125130
    126131  // get where we are installing from
     
    129134  // if doing an uninstall we now know where the "uninstall" is
    130135  if (uninstall == true)
    131   { this->collectPath   = this->sourcePath;
    132   }
     136    {   
     137      this->collectPath = this->sourcePath;
     138    }
    133139
    134140  // get the manifest and program manager objects
    135141  if (uninstall)
    136   { this->manifest = new gsManifest(*this);
    137   }
     142    {   
     143      this->manifest = new gsManifest(*this);
     144    }
    138145  else
    139   { this->manifest = new gsManifest(*this, *this->sourcePath);
    140   }
     146    {
     147      this->manifest = new gsManifest(*this, *this->sourcePath);
     148    }
    141149  this->progman  = new gsProgramManager(*this);
    142150
     
    144152  // be required for loading certain modules such as winsock; the number of
    145153  // macros is over-the-top, but is more robust to unforeseen future requirements
    146 /*  if (platform.isWindows32s())
    147   { this->manifest->expandMacro("WINBITS", "16");
    148     this->manifest->expandMacro("WIN16", "16");
    149     this->manifest->expandMacro("WIN32", "32");
    150   }
    151   else
    152   { this->manifest->expandMacro("WINBITS", "32");
    153     this->manifest->expandMacro("WIN16", "");
    154     this->manifest->expandMacro("WIN32", "32");
    155   }
    156 */
     154  /*  if (platform.isWindows32s())
     155      { this->manifest->expandMacro("WINBITS", "16");
     156      this->manifest->expandMacro("WIN16", "16");
     157      this->manifest->expandMacro("WIN32", "32");
     158      }
     159      else
     160      { this->manifest->expandMacro("WINBITS", "32");
     161      this->manifest->expandMacro("WIN16", "");
     162      this->manifest->expandMacro("WIN32", "32");
     163      }
     164  */
    157165  // inform manifest of collection directory name
    158166  string colDir;
    159167  colDir = this->configFile->getString("CollectionDirName");
    160168  if (colDir != "")
    161   { this->manifest->expandMacro("COLDIRNAME", colDir);
    162   }
     169    {
     170      this->manifest->expandMacro("COLDIRNAME", colDir);
     171    }
    163172}
    164173
     
    167176 */
    168177void GSInstall::getExistingInstall()
    169 {   if (!this->platform.isWindows32s())
    170     {   if (gsRegister->collectionInstalled())
    171       { // TODO: check if receptionist etc should be replaced or not
    172 
    173         // TODO: check build version of the volume
    174 
    175         // Get location of the library executable from the registry; this
    176         // is thence used to get the location of gsdl.ini etc.
    177         this->collectPath   = this->gsRegister->collectionPath();
    178       if (this->collectPath != "")
    179       { this->installToPath = this->collectPath;
    180 
    181         // we don't need to install the exe files
    182             this->installExe = false;
    183       }
    184       }
    185   }
     178{
     179  if (!this->platform.isWindows32s())
     180    {
     181      if (gsRegister->collectionInstalled())
     182    {
     183      // TODO: check if receptionist etc should be replaced or not
     184
     185      // TODO: check build version of the volume
     186
     187      // Get location of the library executable from the registry; this
     188      // is thence used to get the location of gsdl.ini etc.
     189      this->collectPath = this->gsRegister->collectionPath();
     190      if (this->collectPath->pathString() != "")
     191        {
     192          this->installToPath = this->collectPath;
     193          // we don't need to install the exe files
     194          this->installExe = false;
     195        }
     196    }
     197    }
    186198}
    187199
     
    749761
    750762bool GSInstall_init_wizard(GSInstall &install)
    751 { PROPSHEETHEADER pshead;
    752     PROPSHEETPAGE   ppage[2];
    753   bool                      reply;
    754 
    755     ZeroMemory(&pshead, sizeof(PROPSHEETHEADER));
    756     pshead.dwSize  = sizeof(PROPSHEETHEADER);
    757     pshead.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_USEHICON | PSH_WIZARD;
    758     pshead.hwndParent  = app_window;
    759     pshead.hInstance   = app_instance;
    760     pshead.hIcon       = NULL;
    761     pshead.pszCaption  = "Greenstone Installer";
    762     pshead.nPages      = 2;
    763     pshead.nStartPage  = 0;
     763{
     764  PROPSHEETHEADER pshead;
     765  PROPSHEETPAGE ppage[2];
     766  bool reply;
     767
     768  ZeroMemory(&pshead, sizeof(PROPSHEETHEADER));
     769  pshead.dwSize = sizeof(PROPSHEETHEADER);
     770  pshead.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_USEHICON | PSH_WIZARD;
     771  pshead.hwndParent = app_window;
     772  pshead.hInstance = app_instance;
     773  pshead.hIcon = NULL;
     774  pshead.pszCaption = "Greenstone Installer";
     775  pshead.nPages = 2;
     776  pshead.nStartPage = 0;
    764777  if (install.installExe == true)
    765   { pshead.ppsp          = ppage;
    766   }
     778    {
     779      pshead.ppsp = ppage;
     780    }
    767781  else // cheat as the executable etc. is already installed
    768   { pshead.ppsp          = &ppage[1];
    769   }
    770     pshead.pfnCallback = GSInstall_wizardProc;
     782    {
     783      pshead.ppsp = &ppage[1];
     784    }
     785  pshead.pfnCallback = GSInstall_wizardProc;
    771786
    772787  GSInstall_init_propertySheet( ppage[0],
    773                                                             "Choose a directory to install your "
     788                "Choose a directory to install your "
    774789                                "GreenStone software to.", NULL,
    775790                                "Select", install, false);
    776791  GSInstall_init_propertySheet(ppage[1],
    777                                                             "Choose a directory to install the collection "
    778                                 "files to.\n\n"
    779                                                             "You can also choose to install all the collection "
    780                                 "files onto your computer hard drive.\n\n"
    781                                 "If you do this, you will not have to load the "
    782                                 "CD-ROM each time you use your Greenstone software "
    783                                 "but more of your hard disk will be used.\n\n"
    784                                 "Some collection files must be installed on your "
    785                                 "computer.\n\n",
    786                                 "Install all collection files",
    787                                 "Select", install, true);
     792                   "Choose a directory to install the collection "
     793                   "files to.\n\n"
     794                   "You can also choose to install all the collection "
     795                   "files onto your computer hard drive.\n\n"
     796                   "If you do this, you will not have to load the "
     797                   "CD-ROM each time you use your Greenstone software "
     798                   "but more of your hard disk will be used.\n\n"
     799                   "Some collection files must be installed on your "
     800                   "computer.\n\n",
     801                   "Install all collection files",
     802                   "Select", install, true);
    788803
    789804  reply = (PropertySheet (&pshead) >= 0);
     
    791806}
    792807
    793 long FAR PASCAL GSInstallWindProc(HWND          Window,
    794                                                                     WORD            Message,
    795                                                                     WPARAM      wParameter,
    796                                                                     LPARAM      lParameter)
    797 { long reply = 0;
     808long FAR PASCAL GSInstallWindProc(HWND Window, WORD Message, WPARAM wParameter, LPARAM lParameter)
     809{
     810  long reply = 0;
    798811
    799812  switch(Message)
    800     { case WM_CREATE:
    801     { ShowWindow(Window, SW_MAXIMIZE);
    802     }
    803     break;
    804 
    805     case WM_COMMAND:
    806         break;
     813    {
     814    case WM_CREATE:
     815      {
     816    ShowWindow(Window, SW_MAXIMIZE);
     817      }
     818      break;
     819
     820    case WM_COMMAND:
     821      break;
    807822
    808823    case WM_USER:
    809     { // uninstall action
    810         if (strstr(app_cmdLine, "-u") != NULL)
    811         { // skip past the -u option itself
    812         char *at = strstr(app_cmdLine, "-u");
    813         at += strlen("-u");
    814 
    815         // extract the log file path from the command line
    816         while (*at == ' ')
    817         { at ++;
    818         }
    819         string logPathString(at);
    820         FilePath logPath(logPathString);
    821 
    822                 GSInstall install(true);
    823         // if we're running in the temporary directory, do the uninstall
    824         if (install.setUninstall())
    825         {   install.uninstall();
    826 
    827             // close the log to write back all changes to the log; if the file
    828           // will be deleted, it must be closed; copying may also fail, so it's
    829           // safer to close it before doing either.
    830             install.closeLog();
    831 
    832           // if the install is empty, terminate all final items (currently the
    833           // log and setup executables,
    834           if (install.isEmpty())
    835           { // delete the log file
    836             DeleteFile(logPath.cString());
    837 
    838             // get it's parent to find where the gssetup executable will be
    839             FilePath *logParent = logPath.parent();
    840                         FilePath uninstallPath(*logParent, "gssetup.exe");
    841 
    842             // delete the gssetup executable
    843             DeleteFile(uninstallPath.cString());
    844 
    845             // dispose of the parent directory information
    846             delete logParent;
    847           }
    848           // if not, then overwrite the original log with the modified one
    849           else
    850           { // do nothing - should be changed already!
    851           }
    852         }
    853       }
     824    {
     825      // uninstall action
     826      if (strstr(app_cmdLine, "-u") != NULL)
     827        {
     828      // skip past the -u option itself
     829      char *at = strstr(app_cmdLine, "-u");
     830      at += strlen("-u");
     831
     832      // extract the log file path from the command line
     833      while (*at == ' ')
     834        {
     835          at ++;
     836        }
     837      string logPathString(at);
     838      FilePath logPath(logPathString);
     839
     840      GSInstall install(true);
     841      // if we're running in the temporary directory, do the uninstall
     842      if (install.setUninstall())
     843        {
     844          install.uninstall();
     845
     846          // close the log to write back all changes to the log; if the file
     847          // will be deleted, it must be closed; copying may also fail, so it's
     848          // safer to close it before doing either.
     849          install.closeLog();
     850
     851          // if the install is empty, terminate all final items (currently the
     852          // log and setup executables,
     853          if (install.isEmpty())
     854        {
     855          // delete the log file
     856          DeleteFile(logPath.cString());
     857
     858          // get it's parent to find where the gssetup executable will be
     859          FilePath *logParent = logPath.parent();
     860          FilePath uninstallPath(*logParent, "gssetup.exe");
     861
     862          // delete the gssetup executable
     863          DeleteFile(uninstallPath.cString());
     864
     865          // dispose of the parent directory information
     866          delete logParent;
     867        }
     868          // if not, then overwrite the original log with the modified one
     869          else
     870        {
     871          // do nothing - should be changed already!
     872        }
     873        }
     874    }
    854875      // install wizard
    855876      else
    856       { GSInstall install(false);
    857         GSInstall_init_wizard(install);
     877    {   
     878      GSInstall install(false);
     879      GSInstall_init_wizard(install);
    858880          if (config_complete == false)
    859         {   MessageBox(0, "Install cancelled", app_name, MB_OK);
    860                 }
    861         else
    862           { // configure the installation
    863             install.setDestination();
    864             install.setManifest();
    865 
    866             // perform installation
    867               install.copyFiles();
    868             install.updateProgman();
    869               install.updateRegistry();
    870             install.updateProfiles();
    871           install.updateSetupExe();
    872 
    873           // the log will need reopening (probably failed initially)
    874                   install.reopenLog();
    875 
    876           // close log
    877           install.closeLog();
    878 
    879             // do further actions
     881        {
     882          MessageBox(0, "Install cancelled", app_name, MB_OK);
     883        }
     884      else
     885        {
     886          // configure the installation
     887          install.setDestination();
     888          install.setManifest();
     889
     890          // perform installation
     891          install.copyFiles();
     892          install.updateProgman();
     893          install.updateRegistry();
     894          install.updateProfiles();
     895          install.updateSetupExe();
     896
     897          // the log will need reopening (probably failed initially)
     898          install.reopenLog();
     899         
     900          // close log
     901          install.closeLog();
     902
     903          // do further actions
    880904          install.installNetscape();
    881           }
     905        }
     906    }
     907      DestroyWindow(Window);
     908    }
     909    break;
     910   
     911    case WM_CLOSE:
     912      /*if (!file_ischanged || IDCANCEL != file_query(Window, file_name))*/
     913      DestroyWindow(Window);
     914      return 0L;
     915     
     916    case WM_DESTROY:
     917      {
     918    PostQuitMessage(0);
    882919      }
    883       DestroyWindow(Window);
    884         }
    885     break;
    886 
    887         case WM_CLOSE:
    888 /*          if (!file_ischanged || IDCANCEL != file_query(Window, file_name))*/
    889             DestroyWindow(Window);
    890         return 0L;
    891 
    892         case WM_DESTROY:
    893         { PostQuitMessage(0);
    894         }
    895         break;
    896 
    897         default:
    898             return(DefWindowProc(Window, Message, wParameter, lParameter));
    899     }
     920      break;
     921
     922    default:
     923      return(DefWindowProc(Window, Message, wParameter, lParameter));
     924    }
    900925  return reply;
    901926}
     
    921946
    922947void WinClassInit(void)
    923 { WNDCLASS  Class;
    924 
    925     Class.lpszClassName = "GSInstall:Main";
    926     Class.hInstance     = app_instance;
    927     Class.lpfnWndProc       = (WNDPROC) GSInstallWindProc;
    928     Class.hCursor               = LoadCursor(NULL, IDC_ARROW);
    929     Class.hIcon                 = NULL; //LoadIcon(app_instance, "GSInstall");
    930     Class.lpszMenuName  = NULL;
    931     Class.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1);
    932     Class.style                 = NULL;
    933     Class.cbClsExtra        = 0;
    934     Class.cbWndExtra        = 0;
    935     RegisterClass(&Class);
    936 /*
    937     Class.lpszClassName = "GSInstall:Splash";
    938     Class.hInstance     = app_instance;
    939     Class.lpfnWndProc       = (WNDPROC) splash_windproc;
    940     Class.hCursor               = LoadCursor(NULL, IDC_ARROW);
    941     Class.hIcon                 = NULL;
    942     Class.lpszMenuName  = NULL;
    943     Class.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
    944     Class.style                 = NULL;
    945     Class.cbClsExtra        = 0;
    946     Class.cbWndExtra        = 0;
    947     RegisterClass(&Class);*/
     948{
     949  WNDCLASS Class;
     950
     951  Class.lpszClassName = "GSInstall:Main";
     952  Class.hInstance = app_instance;
     953  Class.lpfnWndProc = (WNDPROC) GSInstallWindProc;
     954  Class.hCursor = LoadCursor(NULL, IDC_ARROW);
     955  Class.hIcon = NULL; //LoadIcon(app_instance, "GSInstall");
     956  Class.lpszMenuName = NULL;
     957  Class.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1);
     958  //Class.style = NULL;
     959  Class.style = 0;
     960  Class.cbClsExtra = 0;
     961  Class.cbWndExtra = 0;
     962  RegisterClass(&Class);
     963  /*
     964    Class.lpszClassName = "GSInstall:Splash";
     965    Class.hInstance = app_instance;
     966    Class.lpfnWndProc = (WNDPROC) splash_windproc;
     967    Class.hCursor = LoadCursor(NULL, IDC_ARROW);
     968    Class.hIcon = NULL;
     969    Class.lpszMenuName = NULL;
     970    Class.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
     971    Class.style = NULL;
     972    Class.cbClsExtra = 0;
     973    Class.cbWndExtra = 0;
     974    RegisterClass(&Class);*/
    948975}
    949976
    950977int PASCAL WinMain(HINSTANCE Current,
    951                                         HINSTANCE Previous,
    952                                         LPSTR CmdLine,
    953                                         int CmdShow)
    954 { MSG msg;
    955 //  HACCEL accel;
    956 
    957     app_cmdLine = (char *) malloc(lstrlen(CmdLine) + 1);
    958     lstrcpy(app_cmdLine, CmdLine);
    959 
    960     app_instance = Current;
    961     /* -- init application */
    962     if (!Previous)
    963     { WinClassInit();
    964     InitCommonControls();
    965 //    grbStatic_registerClass(Current);
    966     }
    967 
    968     /* -- init instance */
     978           HINSTANCE Previous,
     979           LPSTR CmdLine,
     980           int CmdShow)
     981{
     982  MSG msg;
     983  // HACCEL accel;
     984
     985  app_cmdLine = (char *) malloc(lstrlen(CmdLine) + 1);
     986  lstrcpy(app_cmdLine, CmdLine);
     987
     988  app_instance = Current;
     989  /* -- init application */
     990  if (!Previous)
     991    {
     992      WinClassInit();
     993      InitCommonControls();
     994      //    grbStatic_registerClass(Current);
     995    }
     996 
     997  /* -- init instance */
    969998  GSInstall_init(Current, CmdShow);
    970 
    971 //  config_init("ReTreeval");
    972 
    973 //  accel   = LoadAccelerators(Current, "ReTreevalMenu");
    974 
    975     while (GetMessage(&msg, NULL, 0, 0))
    976     { /*if (!TranslateAccelerator(app_window, accel, &msg))
     999 
     1000  //  config_init("ReTreeval");
     1001 
     1002  //  accel = LoadAccelerators(Current, "ReTreevalMenu");
     1003
     1004  while (GetMessage(&msg, NULL, 0, 0))
     1005    {
     1006      /*if (!TranslateAccelerator(app_window, accel, &msg))
    9771007    { */
    978         TranslateMessage(&msg);
    979             DispatchMessage(&msg);
    980     /*}*/
    981     }
    982     return (int) msg.wParam;
    983 }
     1008      TranslateMessage(&msg);
     1009      DispatchMessage(&msg);
     1010      /*}*/
     1011    }
     1012  return (int) msg.wParam;
     1013}
  • trunk/gsinstaller/registry.cpp

    r1475 r1536  
    33
    44bool registry_createkey(HKEY key, const char *name, PHKEY keyout)
    5 { LONG reply;
    6     DWORD disposition;
    7 
    8     reply = RegCreateKeyEx( key, name, NULL, NULL,
    9                                                 REG_OPTION_NON_VOLATILE,
    10                           KEY_ALL_ACCESS, NULL,
    11                           keyout, &disposition);
    12   if (reply != ERROR_SUCCESS)
    13   { return FALSE;
    14   }
     5{
     6  LONG reply;
     7  DWORD disposition;
     8
     9  reply = RegCreateKeyEx(key, name, 0, NULL,
     10             REG_OPTION_NON_VOLATILE,
     11             KEY_ALL_ACCESS, NULL,
     12             keyout, &disposition);
     13  if (reply != ERROR_SUCCESS)
     14    {
     15      return FALSE;
     16    }
    1517  return TRUE;
    1618}
    1719
    1820bool registry_openkey(HKEY key, const char *name, PHKEY keyout)
    19 { LONG reply;
    20 
    21     reply = RegOpenKeyEx(key, name, NULL, KEY_QUERY_VALUE, keyout);
    22   if (reply != ERROR_SUCCESS)
    23   { return false;
    24   }
     21{
     22  LONG reply;
     23
     24  reply = RegOpenKeyEx(key, name, 0, KEY_QUERY_VALUE, keyout);
     25  if (reply != ERROR_SUCCESS)
     26    {
     27      return false;
     28    }
    2529  return true;
    2630}
    2731
    2832bool registry_deletekey(HKEY key, const char *name)
    29 {   if (RegDeleteKey(key, name) != ERROR_SUCCESS)
    30     {   return false;
    31   }
     33{   
     34  if (RegDeleteKey(key, name) != ERROR_SUCCESS)
     35    {
     36      return false;
     37    }
    3238  return true;
    3339}
    3440
    3541bool registry_closekey(HKEY key)
    36 { LONG reply;
    37     reply = RegCloseKey(key);
    38   if (reply != ERROR_SUCCESS)
    39   { return FALSE;
     42{
     43  LONG reply;
     44  reply = RegCloseKey(key);
     45  if (reply != ERROR_SUCCESS)
     46  {
     47    return FALSE;
    4048  }
    4149  return TRUE;
     
    4351
    4452bool registry_keyExists(HKEY key, const char *name)
    45 { HKEY local;
    46 
    47     if (!registry_openkey(key, name, &local))
    48   { return false;
     53{
     54  HKEY local;
     55 
     56  if (!registry_openkey(key, name, &local))
     57  {
     58    return false;
    4959  }
    5060  registry_closekey(local);
     
    5363
    5464bool registry_ensureKeyExists(HKEY key, const char *name)
    55 { HKEY local;
    56 
    57     if (!registry_openkey(key, name, &local))
    58     {   if (!registry_createkey(key, name, &local))
    59     {   return false;
    60     }
    61   }
    62     registry_closekey(local);
     65{
     66  HKEY local;
     67
     68  if (!registry_openkey(key, name, &local))
     69    {
     70      if (!registry_createkey(key, name, &local))
     71    {
     72      return false;
     73    }
     74    }
     75  registry_closekey(local);
    6376  return true;
    6477}
    6578
    6679bool registry_deleteitem(HKEY key, const char *name)
    67 {   if (RegDeleteValue(key, name) != ERROR_SUCCESS)
    68     {   return false;
    69   }
     80{
     81  if (RegDeleteValue(key, name) != ERROR_SUCCESS)
     82    {
     83      return false;
     84    }
    7085  return true;
    7186}
    7287
    7388bool registry_setstring(HKEY key, const char *name, const char *value)
    74 { LONG reply;
    75 
    76     reply = RegSetValueEx(key, (LPCTSTR) name, NULL, REG_SZ, (CONST BYTE *) value, strlen(value) + 1);
    77   if (reply != ERROR_SUCCESS)
    78   { return false;
     89{
     90  LONG reply;
     91 
     92  reply = RegSetValueEx(key, (LPCTSTR) name, 0, REG_SZ, (CONST BYTE *) value, strlen(value) + 1);
     93  if (reply != ERROR_SUCCESS)
     94  {
     95    return false;
    7996  }
    8097  return true;
     
    8299
    83100bool registry_setlong(HKEY key, char *name, LONG value)
    84 { LONG  reply;
    85     DWORD word;
    86 
     101{
     102  LONG  reply;
     103  DWORD word;
     104 
    87105  word = (DWORD) value;
    88     reply = RegSetValueEx(key, (LPCTSTR) name, NULL, REG_DWORD, (CONST BYTE *) &word, sizeof(DWORD));
    89   if (reply != ERROR_SUCCESS)
    90   { return FALSE;
     106  reply = RegSetValueEx(key, (LPCTSTR) name, 0, REG_DWORD, (CONST BYTE *) &word, sizeof(DWORD));
     107  if (reply != ERROR_SUCCESS)
     108  {
     109    return FALSE;
    91110  }
    92111  return TRUE;
     
    94113
    95114bool registry_setblock(HKEY key, char *name, char *data, int size)
    96 { LONG  reply;
    97 
    98     reply = RegSetValueEx(key, name, NULL, REG_BINARY, (CONST BYTE *) data, size);
    99   if (reply != ERROR_SUCCESS)
    100   { // display_error();
    101     return FALSE;
     115{
     116  LONG  reply;
     117 
     118  reply = RegSetValueEx(key, name, 0, REG_BINARY, (CONST BYTE *) data, size);
     119  if (reply != ERROR_SUCCESS)
     120  {
     121    // display_error();
     122    return FALSE;
    102123  }
    103124  return TRUE;
     
    105126
    106127bool registry_setint(HKEY key, char *name, int value)
    107 { return registry_setlong(key, name, (LONG) value);
     128{
     129  return registry_setlong(key, name, (LONG) value);
    108130}
    109131
    110132bool registry_getstring(HKEY key, char *name, char **string)
    111 { LONG reply;
    112     DWORD type;
     133{
     134  LONG reply;
     135  DWORD type;
    113136  DWORD size;
    114137  BYTE  buffer[128];
     
    116139
    117140  do
    118   {
    119         reply = RegQueryValueEx(key, name, NULL, &type, buffer, &size);
    120     if (reply != ERROR_SUCCESS)
    121       { //display_error();
    122         //sprintf(buffer, "%x {%s}", key, name);
    123         //MessageBox(0, buffer, name, MB_OK);
    124       }
    125     tries ++;
    126   } while (reply != ERROR_SUCCESS && tries < 3);
    127 
    128   if (reply != ERROR_SUCCESS)
    129   { return FALSE;
     141    {
     142      reply = RegQueryValueEx(key, name, NULL, &type, buffer, &size);
     143      if (reply != ERROR_SUCCESS)
     144    {
     145      //display_error();
     146      //sprintf(buffer, "%x {%s}", key, name);
     147      //MessageBox(0, buffer, name, MB_OK);
     148    }
     149      tries ++;
     150    } while (reply != ERROR_SUCCESS && tries < 3);
     151 
     152  if (reply != ERROR_SUCCESS)
     153  {
     154    return FALSE;
    130155  }
    131156
    132157  *string = (char *) malloc(size);
    133158  if (*string == NULL)
    134   { return FALSE;
     159  {
     160    return FALSE;
    135161  }
    136162  strcpy(*string, (char *) buffer);
     
    139165
    140166bool registry_getint(HKEY key, char *name, int *out)
    141 { DWORD type;
    142     DWORD size;
     167{
     168  DWORD type;
     169  DWORD size;
    143170  LONG  reply;
    144171
    145     reply = RegQueryValueEx(key, (LPTSTR) name, NULL, &type, (LPBYTE) out, &size);
    146   if (reply != ERROR_SUCCESS)
    147   { return FALSE;
     172  reply = RegQueryValueEx(key, (LPTSTR) name, NULL, &type, (LPBYTE) out, &size);
     173  if (reply != ERROR_SUCCESS)
     174  {
     175    return FALSE;
    148176  }
    149177  return TRUE;
     
    151179
    152180bool registry_getlong(HKEY key, char *name, LONG *out)
    153 { DWORD type;
    154     DWORD size;
     181{
     182  DWORD type;
     183  DWORD size;
    155184  LONG  reply;
    156185  DWORD got;
     
    158187  size = sizeof(DWORD);
    159188
    160     reply = RegQueryValueEx(key, name, NULL, &type, (LPBYTE) &got, &size);
    161   if (reply != ERROR_SUCCESS)
    162   { return FALSE;
     189  reply = RegQueryValueEx(key, name, NULL, &type, (LPBYTE) &got, &size);
     190  if (reply != ERROR_SUCCESS)
     191  {
     192    return FALSE;
    163193  }
    164194  *out = (LONG) got;
     
    167197
    168198int registry_getblock(HKEY key, char *name, char *data, int size)
    169 { DWORD type;
    170     DWORD lsize;
     199{
     200  DWORD type;
     201  DWORD lsize;
    171202  LONG  reply;
    172 
     203 
    173204  lsize = size;
    174205
    175     reply = RegQueryValueEx(key, name, NULL, &type, (LPBYTE) data, &lsize);
    176   if (reply != ERROR_SUCCESS)
    177   { return -1;
     206  reply = RegQueryValueEx(key, name, NULL, &type, (LPBYTE) data, &lsize);
     207  if (reply != ERROR_SUCCESS)
     208  {
     209    return -1;
    178210  }
    179211  return lsize;
     
    181213
    182214bool registry_fetchlong(char *keystr, LONG *lptr)
    183 { HKEY key;
    184 
    185     if (!registry_openkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
    186     { return FALSE;
    187   }
     215{
     216  HKEY key;
     217 
     218  if (!registry_openkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
     219    {
     220      return FALSE;
     221    }
    188222  if (!registry_getlong(key, keystr, lptr))
    189   { return FALSE;
    190   }
     223    {   
     224      return FALSE;
     225    }
    191226  if (registry_closekey(key) == FALSE)
    192   { return FALSE;
    193     }
     227  {
     228    return FALSE;
     229  }
    194230  return TRUE;
    195231}
    196232
    197233bool registry_fetchblock(char *keystr, char *data, int size)
    198 { HKEY  key;
    199     int     read;
    200 
    201     if (!registry_openkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
    202     { return FALSE;
    203   }
     234{
     235  HKEY key;
     236  int read;
     237
     238  if (!registry_openkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
     239    {
     240      return FALSE;
     241    }
    204242  read = registry_getblock(key, keystr, data, size);
    205243  if (read < 0)
    206   { return FALSE;
    207   }
     244    {   
     245      return FALSE;
     246    }
    208247  if (registry_closekey(key) == FALSE)
    209   { return FALSE;
    210     }
     248  {
     249    return FALSE;
     250  }
    211251  return TRUE;
    212252}
    213253
    214254bool registry_storelong(char *keystr, LONG value)
    215 { HKEY key;
    216 
    217     if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
    218   { return FALSE;
     255{
     256  HKEY key;
     257
     258  if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
     259  {
     260    return FALSE;
    219261  }
    220262  if (!registry_setlong(key, keystr, value))
    221   { return FALSE;
     263  {
     264    return FALSE;
    222265  }
    223266  if (!registry_closekey(key))
    224   { return FALSE;
     267  {
     268    return FALSE;
    225269  }
    226270  return TRUE;
     
    228272
    229273bool registry_storeint(char *keystr, int value)
    230 { HKEY key;
    231 
    232     if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
    233   { return FALSE;
     274{
     275  HKEY key;
     276 
     277  if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
     278  {
     279    return FALSE;
    234280  }
    235281  if (!registry_setint(key, keystr, value))
    236   { return FALSE;
     282  {
     283    return FALSE;
    237284  }
    238285  if (!registry_closekey(key))
    239   { return FALSE;
     286  {
     287    return FALSE;
    240288  }
    241289  return TRUE;
     
    243291
    244292bool registry_storeblock(char *keystr, char *data, int size)
    245 { HKEY key;
    246 
    247     if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
    248   { return FALSE;
     293{
     294  HKEY key;
     295
     296  if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
     297  {
     298    return FALSE;
    249299  }
    250300  if (!registry_setblock(key, keystr, data, size))
    251   { return FALSE;
     301  {
     302    return FALSE;
    252303  }
    253304  if (!registry_closekey(key))
    254   { return FALSE;
     305  {
     306    return FALSE;
    255307  }
    256308  return TRUE;
     
    258310
    259311bool registry_storestring(char *keystr, char *value)
    260 { HKEY key;
    261 
    262     if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
    263   { return FALSE;
     312{
     313  HKEY key;
     314 
     315  if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
     316  {
     317    return FALSE;
    264318  }
    265319  if (!registry_setstring(key, keystr, value))
    266   { return FALSE;
     320  {
     321    return FALSE;
    267322  }
    268323  if (!registry_closekey(key))
    269   { return FALSE;
    270   }
    271   return TRUE;
    272 }
     324  {
     325    return FALSE;
     326  }
     327  return TRUE;
     328}
  • trunk/gsinstaller/stringArray.h

    r1498 r1536  
    88
    99class stringArray
    10 {   private:
    11     protected:
    12   public:
    13         vector<string> array;
    14     stringArray();
    15     stringArray(char *list, char *divider);
    16     void add(char *member);
    17     void add(string member);
    18     void add(stringArray &array);
    19     void insertAt(string member, unsigned int at);
    20     void remove(char *member);
    21     void remove(string member);
    22     void clear();
    23     bool includes(char *member);
    24     bool includes(string member);
    25     static stringArray words(char *line);
    26     unsigned int size(){ return this->array.size(); };
    27     int  indexOf(char *member);
    28     int  indexOf(string member);
    29     int  writeToCString(char *buffer, char *divider, int bufflen);
    30     string toString(string separator);
    31     string &operator[](const unsigned int);
     10{
     11private:
     12protected:
     13public:
     14  vector<string> array;
     15  stringArray();
     16  stringArray(char *list, char *divider);
     17  void add(char *member);
     18  void add(string member);
     19  void add(stringArray &array);
     20  void insertAt(string member, unsigned int at);
     21  void remove(char *member);
     22  void remove(string member);
     23  void clear();
     24  bool includes(char *member);
     25  bool includes(string member);
     26  static stringArray words(char *line);
     27  unsigned int size(){ return this->array.size(); };
     28  int  indexOf(char *member);
     29  int  indexOf(string member);
     30  int  writeToCString(char *buffer, char *divider, int bufflen);
     31  string toString(string separator);
     32  string &operator[](const unsigned int);
    3233};
    3334
  • trunk/gsinstaller/unInstall.h

    r1525 r1536  
    77
    88#include <stdio.h>
     9
     10#if defined (GSDL_USE_IOS_H)
    911#include <fstream.h>
     12#else
     13#include <fstream>
     14#endif
    1015
    1116#include "stringArray.h"
     
    1419
    1520typedef class unInstallCommand
    16 { public:
    17         string          command;
    18         stringArray parameters;
     21{
     22public:
     23  string command;
     24  stringArray parameters;
    1925
    20     unInstallCommand() { };
    21     unInstallCommand(string commandname) { this->command = commandname; };
    22     unInstallCommand(string commandname, stringArray params)
    23     { this->command = commandname;
    24         this->parameters = params;
    25     };
    26     void addParameter(string parameter) { this->parameters.add(parameter); };
    27     string commandName() { return this->command; };
    28     stringArray &parameterList() { return this->parameters; };
     26  unInstallCommand() { };
     27  unInstallCommand(string commandname) { this->command = commandname; };
     28  unInstallCommand(string commandname, stringArray params)
     29  {
     30    this->command = commandname;
     31    this->parameters = params;
     32  };
     33  void addParameter(string parameter) { this->parameters.add(parameter); };
     34  string commandName() { return this->command; };
     35  stringArray &parameterList() { return this->parameters; };
    2936} unInstallCommand;
    3037
     
    3441
    3542class installManager
    36 {   private:
    37         fstream                             logfile;
    38     string                              logfileName;
    39     string                              currentModule;
    40     unInstallCommandMap     modules;
     43{   
     44private:
     45  fstream logfile;
     46  string logfileName;
     47  string currentModule;
     48  unInstallCommandMap modules;
    4149
    42     bool writeString(string str);
    43     bool writeString(char *string);
    44     bool writeSeparator();
    45     string readString();
    46     bool writeCommand(unInstallCommand &command);
    47     string readCommand(stringArray &params);
    48     public:
    49     installManager() { };
    50     bool openLog(string filename, bool write);
    51     bool closeLog();
    52     bool reopenLog();
    53     void setModule(string moduleName);
    54     bool storeCommand(unInstallCommand &command);
    55     string popCommand(stringArray &params);
    56     bool isEmpty();
    57     ~installManager();
     50  bool writeString(string str);
     51  bool writeString(char *string);
     52  bool writeSeparator();
     53  string readString();
     54  bool writeCommand(unInstallCommand &command);
     55  string readCommand(stringArray &params);
     56public:
     57  installManager() { };
     58  bool openLog(string filename, bool write);
     59  bool closeLog();
     60  bool reopenLog();
     61  void setModule(string moduleName);
     62  bool storeCommand(unInstallCommand &command);
     63  string popCommand(stringArray &params);
     64  bool isEmpty();
     65  ~installManager();
    5866};
    5967
    6068class installAgent
    61 {   protected:
    62     installManager *manager;
    63     public:
    64     installAgent(installManager &useManager) { this->manager = &useManager; };
    65     virtual bool undoAction(string actionName, stringArray &params) { return false; };
    66 //    bool undo(string actionName);
     69{   
     70protected:
     71  installManager *manager;
     72public:
     73  installAgent(installManager &useManager) { this->manager = &useManager; };
     74  virtual bool undoAction(string actionName, stringArray &params) { return false; };
     75  //    bool undo(string actionName);
    6776};
    6877
Note: See TracChangeset for help on using the changeset viewer.