Changeset 1543 for trunk/gsinstaller


Ignore:
Timestamp:
2000-09-13T15:31:38+12:00 (24 years ago)
Author:
sjboddie
Message:

* empty log message *

Location:
trunk/gsinstaller
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsinstaller/gsManifest.cpp

    r1539 r1543  
    205205
    206206  strArrayMap::iterator here = this->manifests.begin();
    207   strArrayMap::iterator end = this->manifests.end();
     207  strArrayMap::iterator end = this->manifests.end();
    208208
    209209  while (here != end)
  • trunk/gsinstaller/gsManifest.h

    r1539 r1543  
    3131  gsManifest(installManager &manager, FilePath &path); // used for install
    3232  gsManifest(installManager &manager); // used for uninstall
     33  virtual ~gsManifest () {}
    3334  bool getManifest(FilePath &path);
    3435  void logAction(string actionName, string file);
  • trunk/gsinstaller/gsPlatform.cpp

    r1541 r1543  
    77
    88gsPlatform::gsPlatform()
    9 { this->platformInfo.dwOSVersionInfoSize    = sizeof(OSVERSIONINFO);
    10     GetVersionEx(&this->platformInfo);
     9{
     10  this->platformInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
     11  GetVersionEx(&this->platformInfo);
    1112}
    1213
    1314bool gsPlatform::isWindows9x()
    14 {   return (this->platformInfo.dwPlatformId & VER_PLATFORM_WIN32_WINDOWS);
     15{
     16  return (this->platformInfo.dwPlatformId & VER_PLATFORM_WIN32_WINDOWS);
    1517}
    1618
    1719bool gsPlatform::isWindowsNT()
    18 {   return (this->platformInfo.dwPlatformId & VER_PLATFORM_WIN32_NT);
     20{
     21  return (this->platformInfo.dwPlatformId & VER_PLATFORM_WIN32_NT);
    1922}
    2023
    2124bool gsPlatform::isWindows32s()
    22 {   return (this->platformInfo.dwPlatformId & VER_PLATFORM_WIN32s);
     25{
     26  return (this->platformInfo.dwPlatformId & VER_PLATFORM_WIN32s);
    2327}
    2428
    2529bool gsPlatform::isOldWindows32s()
    26 {   if (this->platformInfo.dwMajorVersion == 0 ||
    27             this->platformInfo.dwMinorVersion < 30)
    28     {   return true;
    29   }
     30{   
     31  if (this->platformInfo.dwMajorVersion == 0 ||
     32      this->platformInfo.dwMinorVersion < 30)
     33    {
     34      return true;
     35    }
    3036  return false;
    3137}
    3238
    3339bool gsPlatform::isExplorerShell()
    34 {   if (this->isWindows9x() ||
    35             (this->isWindowsNT() && this->platformInfo.dwMajorVersion >= 4))
    36     {   return true;
    37   }
     40{
     41  if (this->isWindows9x() ||
     42      (this->isWindowsNT() && this->platformInfo.dwMajorVersion >= 4))
     43    {
     44      return true;
     45    }
    3846  return false;
    3947}
     
    105113      return false;
    106114    }
    107 
    108     accessMask = ACCESS_READ | ACCESS_WRITE;
    109 
    110 
    111 
     115     
     116      accessMask = ACCESS_READ | ACCESS_WRITE;
     117     
    112118      // try to add the given item to the Access Control Entry (ACE) list (ACL)
    113119      if (!AddAccessAllowedAce(aclData, ACL_REVISION2, accessMask, adminId))
     
    115121      return false;
    116122    }
    117 
     123     
    118124      // endeavour to add the acl to the discretionary acl (DACL)
    119125      if (!SetSecurityDescriptorDacl(psdAdmin, TRUE, aclData, FALSE))
     
    138144      if (!AccessCheck (psdAdmin, token, ACCESS_READ, &genericMapping,
    139145            &privilegeSet, &structureSize, &status, &result))
    140     {   return false;
    141     }
    142 
     146    {
     147      return false;
     148    }
     149     
    143150      // end impersonisation
    144151      RevertToSelf();
    145 
     152     
    146153      LocalFree(psdAdmin);
    147154      LocalFree(aclData);
     
    159166      HANDLE token;
    160167      TOKEN_PRIVILEGES tkp;
    161 
     168     
    162169      if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
    163170                &token))
     
    165172      return false;
    166173    }
    167 
     174     
    168175      LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
    169176
  • trunk/gsinstaller/gsProgman.cpp

    r1541 r1543  
    1616 * but does nothing whatsoever
    1717 */
    18 HDDEDATA CALLBACK DdeCallBack(
    19     UINT uType, // transaction type
    20     UINT uFmt,  // clipboard data format
    21     HCONV hconv,    // handle to the conversation
    22     HSZ hsz1,   // handle to a string
    23     HSZ hsz2,   // handle to a string
    24     HDDEDATA hdata, // handle to a global memory object
    25     DWORD dwData1,  // transaction-specific data
    26     DWORD dwData2   // transaction-specific data
    27    )
    28 {   return NULL;
     18HDDEDATA CALLBACK DdeCallBack(UINT uType,       // transaction type
     19                  UINT uFmt,        // clipboard data format
     20                  HCONV hconv,      // handle to the conversation
     21                  HSZ hsz1,         // handle to a string
     22                  HSZ hsz2,         // handle to a string
     23                  HDDEDATA hdata,   // handle to a global memory object
     24                  DWORD dwData1,    // transaction-specific data
     25                  DWORD dwData2     // transaction-specific data
     26                  )
     27{
     28  return NULL;
    2929}
    3030
     
    3333 */
    3434bool DDEShellCommand(DWORD instance, char *command)
    35 {   HSZ             serviceName;
    36     HCONV           conversation;
    37   int               commandLength;
    38   HDDEDATA  ddeData;
    39   DWORD         result;
    40   bool          reply   = false;
    41 
    42     // create DDE string from service request
    43     serviceName = DdeCreateStringHandle(instance, "PROGMAN", CP_WINANSI);
    44   if (serviceName   == NULL)
    45   { /*char buffer[20];
     35{   
     36  HSZ serviceName;
     37  HCONV conversation;
     38  int commandLength;
     39  HDDEDATA ddeData;
     40  DWORD result;
     41  bool reply = false;
     42
     43  // create DDE string from service request
     44  serviceName = DdeCreateStringHandle(instance, "PROGMAN", CP_WINANSI);
     45  if (serviceName == NULL)
     46    {   
     47      /*char buffer[20];
    4648    sprintf(buffer, "%d %d", DdeGetLastError(instance), instance);
    47     MessageBox(0, buffer, "GSInstall", MB_OK);*/
    48     return FALSE;
    49   }
     49    MessageBox(0, buffer, "GSInstall", MB_OK);*/
     50      return FALSE;
     51    }
    5052
    5153  // strike up a conversation with the DDE service
    5254  if ((conversation = DdeConnect(instance, serviceName, serviceName, NULL)) != NULL)
    53   { commandLength   = lstrlen(command);
    54 
    55         // send the message via DDE
    56 //    MessageBox(0, command, "Executing", MB_OK);
    57     ddeData = DdeClientTransaction((LPBYTE) command, commandLength + 1,
    58                                                                     conversation, NULL, CF_TEXT, XTYP_EXECUTE,
    59                                     1000, &result);
    60         // if our reply isn't NULL, it succeeded
    61     reply = (ddeData != NULL);
    62     if (reply == false)
    63     { /*
    64         char buffer[20];
    65 
    66         sprintf(buffer, "%d", DdeGetLastError(instance));
    67       MessageBox(0, buffer, "DDE Error", MB_OK);*/
    68     }
    69 
    70     // disconnect the conversation
    71     DdeDisconnect(conversation);
    72   }
    73   else
    74   { MessageBox(0, "DDE Connect failed", "GSInstall", MB_OK);
    75   }
    76 
     55    {
     56      commandLength = lstrlen(command);
     57
     58      // send the message via DDE
     59      //    MessageBox(0, command, "Executing", MB_OK);
     60      ddeData = DdeClientTransaction((LPBYTE) command, commandLength + 1,
     61                     conversation, NULL, CF_TEXT, XTYP_EXECUTE,
     62                     1000, &result);
     63      // if our reply isn't NULL, it succeeded
     64      reply = (ddeData != NULL);
     65      if (reply == false)
     66    { /*
     67        char buffer[20];
     68       
     69        sprintf(buffer, "%d", DdeGetLastError(instance));
     70        MessageBox(0, buffer, "DDE Error", MB_OK);*/
     71    }
     72     
     73      // disconnect the conversation
     74      DdeDisconnect(conversation);
     75    }
     76  else
     77    {
     78      MessageBox(0, "DDE Connect failed", "GSInstall", MB_OK);
     79    }
     80 
    7781  // free DDE string
    7882  DdeFreeStringHandle(instance, serviceName);
     
    8185
    8286gsProgramManager::gsProgramManager(installManager &manager)
    83     : installAgent(manager)
    84 {   this->platform  = new gsPlatform();
    85     this->connected = false;
     87  : installAgent(manager)
     88{   
     89  this->platform = new gsPlatform();
     90  this->connected = false;
    8691}
    8792
    8893void gsProgramManager::logAction(string actionName, string group)
    89 { unInstallCommand command(actionName);
    90     command.addParameter(group);
    91     manager->storeCommand(command);
     94{
     95  unInstallCommand command(actionName);
     96  command.addParameter(group);
     97  manager->storeCommand(command);
    9298}
    9399
    94100void gsProgramManager::logAction(string actionName, string group, string item, string parameter)
    95 { unInstallCommand command(actionName);
     101{
     102  unInstallCommand command(actionName);
    96103  command.addParameter(group);
    97     command.addParameter(item);
     104  command.addParameter(item);
    98105  command.addParameter(parameter);
    99106  manager->storeCommand(command);
     
    101108
    102109bool gsProgramManager::undoAction(string actionName, stringArray &params)
    103 { if (actionName == "ProgManCreateGroup")
    104     {   this->removeProgramGroup(params[0]);
    105     return true;
    106   }
     110{
     111  if (actionName == "ProgManCreateGroup")
     112    {
     113      this->removeProgramGroup(params[0]);
     114      return true;
     115    }
    107116  else if (actionName == "ProgManAddItem")
    108   { this->removeIcon(params[0], params[1]);
    109     return true;
    110   }
     117    {
     118      this->removeIcon(params[0], params[1]);
     119      return true;
     120    }
    111121  return false;
    112122}
    113123
    114124bool gsProgramManager::connect()
    115 { HRESULT response;
    116 
    117     if (this->platform->isExplorerShell())
    118   { // Initialise the shell connection
    119     response = CoInitialize(NULL);
    120     if (response < 0)
    121     {   return false;
    122     }
    123   }
    124   else
    125   { FARPROC procPtr;
    126 
    127     procPtr = MakeProcInstance((FARPROC) DdeCallBack, app_instance);
    128 
    129     instance    = 0L;
    130     if (DdeInitialize(&instance, (PFNCALLBACK) procPtr, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
    131     { MessageBox(0, "DDE failed to initialise", "GSInstall", MB_OK);
    132         return false;
    133     }
    134   }
    135   this->connected   = true;
     125{
     126  HRESULT response;
     127 
     128  if (this->platform->isExplorerShell())
     129    {
     130      // Initialise the shell connection
     131      response = CoInitialize(NULL);
     132      if (response < 0)
     133    {
     134      return false;
     135    }
     136    }
     137  else
     138    {
     139      FARPROC procPtr;
     140     
     141      procPtr = MakeProcInstance((FARPROC) DdeCallBack, app_instance);
     142     
     143      instance = 0L;
     144      if (DdeInitialize(&instance, (PFNCALLBACK) procPtr, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
     145    {
     146      MessageBox(0, "DDE failed to initialise", "GSInstall", MB_OK);
     147      return false;
     148    }
     149    }
     150  this->connected = true;
    136151  return true;
    137152}
    138153
    139154bool gsProgramManager::disconnect()
    140 { if (this->connected)
    141     {   if (this->platform->isExplorerShell())
    142         {   CoUninitialize();
    143       }
    144     else
    145       { DdeUninitialize(instance);
    146     }
    147   }
    148   this->connected   = false;
     155{
     156  if (this->connected)
     157    {
     158      if (this->platform->isExplorerShell())
     159    {
     160      CoUninitialize();
     161    }
     162      else
     163    {
     164      DdeUninitialize(instance);
     165    }
     166    }
     167  this->connected = false;
    149168  return true;
    150169}
    151170
    152171bool gsProgramManager::addProgramGroup(string groupName)
    153 {   //CreateGroup(groupName);
    154     char buffer[256];
     172{
     173  //CreateGroup(groupName);
     174  char buffer[256];
    155175
    156176  if (this->platform->isExplorerShell())
    157   { // add using shell controls
    158     LPITEMIDLIST pidl;
    159 
    160     if (this->platform->isUserAdministrator())
    161     { if (SHGetSpecialFolderLocation(0, CSIDL_COMMON_PROGRAMS, &pidl) != NOERROR)
    162         {   return false;
    163       }
    164     }
    165     else
    166     { if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
    167         {   return false;
    168       }
    169     }
    170     SHGetPathFromIDList(pidl, buffer);
    171 
    172     // Create the folder as required
    173     FilePath *path  = new FilePath(buffer, groupName);
    174     if (!CreateDirectory((char *) path->cString(), NULL))
    175     {   // it probably existed already - if so skip it!
    176         DWORD reason = GetLastError();
    177       if (reason != ERROR_ALREADY_EXISTS)
    178       { return false;
    179       }
    180     }
    181   }
    182   else
    183   { // add using program manager DDE
    184     sprintf(buffer, "[CreateGroup (%s)]", groupName.c_str());
    185     if (!DDEShellCommand(this->instance, buffer))
    186     {   // flag error by returning false
    187       return false;
    188     }
    189   }
     177    {
     178      // add using shell controls
     179      LPITEMIDLIST pidl;
     180     
     181      if (this->platform->isUserAdministrator())
     182    {
     183      if (SHGetSpecialFolderLocation(0, CSIDL_COMMON_PROGRAMS, &pidl) != NOERROR)
     184        {   
     185          return false;
     186        }
     187    }
     188      else
     189    {
     190      if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
     191        {
     192          return false;
     193        }
     194    }
     195      SHGetPathFromIDList(pidl, buffer);
     196
     197      // Create the folder as required
     198      FilePath *path = new FilePath(buffer, groupName);
     199      if (!CreateDirectory((char *) path->cString(), NULL))
     200    {
     201      // it probably existed already - if so skip it!
     202      DWORD reason = GetLastError();
     203      if (reason != ERROR_ALREADY_EXISTS)
     204        {
     205          return false;
     206        }
     207    }
     208    }
     209  else
     210    {
     211      // add using program manager DDE
     212      sprintf(buffer, "[CreateGroup (%s)]", groupName.c_str());
     213      if (!DDEShellCommand(this->instance, buffer))
     214    {
     215      // flag error by returning false
     216      return false;
     217    }
     218    }
    190219
    191220  this->logAction("ProgManCreateGroup", groupName);
    192     return true;
    193 }
    194 
    195 bool gsProgramManager::addIcon( string groupName,               // group of the icon
    196                                                                 string iconName,                // name of the icon
    197                                 string iconDestination, // destination file of the icon
    198                                                             string description)         // the textual description
    199                                                                                 // of the icon (not usually displayed)
    200 {   bool                    reply = false;
    201     char                    buffer[MAX_PATH];
    202 
     221  return true;
     222}
     223
     224bool gsProgramManager::addIcon(string groupName, // group of the icon
     225                   string iconName, // name of the icon
     226                   string iconDestination, // destination file of the icon
     227                   string description) // the textual description
     228  // of the icon (not usually displayed)
     229{   
     230  bool reply = false;
     231  char buffer[MAX_PATH];
     232 
    203233  if (this->platform->isExplorerShell())
    204   { // create item using the shell
    205     LPITEMIDLIST    pidl;
    206     HRESULT hres;
    207     IShellLink* psl;
    208     FilePath *  fullPath;
    209 
    210     if (this->platform->isUserAdministrator())
    211     { if (SHGetSpecialFolderLocation(0, CSIDL_COMMON_PROGRAMS, &pidl) != NOERROR)
    212         { return false;
    213       }
    214     }
    215     else
    216     { if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
    217         { return false;
    218       }
    219       }
    220 
    221         SHGetPathFromIDList(pidl, buffer);
    222         fullPath    = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), "!.lnk");
    223 
    224     // check if the shortcut already exists then don't create this again
    225     if (fullPath->exists())
    226     { delete fullPath;
    227         return true;
    228     }
    229 
    230         // Get a pointer to the IShellLink interface.
    231     hres = CoCreateInstance(CLSID_ShellLink, NULL,
    232                                                  CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) &psl);
     234    {
     235      // create item using the shell
     236      LPITEMIDLIST pidl;
     237      HRESULT hres;
     238      IShellLink* psl;
     239      FilePath *fullPath;
     240
     241      if (this->platform->isUserAdministrator())
     242    {
     243      if (SHGetSpecialFolderLocation(0, CSIDL_COMMON_PROGRAMS, &pidl) != NOERROR)
     244        {
     245          return false;
     246        }
     247    }
     248      else
     249    {
     250      if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
     251        {
     252          return false;
     253        }
     254    }
     255
     256      SHGetPathFromIDList(pidl, buffer);
     257      fullPath = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), "!.lnk");
     258     
     259      // check if the shortcut already exists then don't create this again
     260      if (fullPath->exists())
     261    {
     262      delete fullPath;
     263      return true;
     264    }
     265     
     266      // Get a pointer to the IShellLink interface.
     267      hres = CoCreateInstance(CLSID_ShellLink, NULL,
     268                  CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) &psl);
     269      if (SUCCEEDED(hres))
     270    {
     271      IPersistFile* ppf;
     272
     273      // Set the path to the shortcut target, and add the
     274      // description.
     275      psl->SetPath(iconDestination.c_str());
     276
     277      psl->SetDescription(description.c_str());
     278     
     279      // Query IShellLink for the IPersistFile interface for saving the
     280      // shortcut in persistent storage.
     281      hres = psl->QueryInterface(IID_IPersistFile, (void **) &ppf);
     282     
    233283      if (SUCCEEDED(hres))
    234     { IPersistFile* ppf;
    235 
    236         // Set the path to the shortcut target, and add the
    237         // description.
    238       psl->SetPath(iconDestination.c_str());
    239 
    240         psl->SetDescription(description.c_str());
    241 
    242         // Query IShellLink for the IPersistFile interface for saving the
    243       // shortcut in persistent storage.
    244         hres = psl->QueryInterface(IID_IPersistFile, (void **) &ppf);
    245 
    246         if (SUCCEEDED(hres))
    247       { WCHAR wsz[MAX_PATH];
    248 
    249           // Ensure that the string is ANSI.
    250         MultiByteToWideChar(CP_ACP, 0, fullPath->cString(), -1, wsz, MAX_PATH);
     284        {
     285          WCHAR wsz[MAX_PATH];
     286         
     287          // Ensure that the string is ANSI.
     288          MultiByteToWideChar(CP_ACP, 0, fullPath->cString(), -1, wsz, MAX_PATH);
    251289
    252290          // store the link in the "persistent" file
    253         reply = ppf->Save(wsz, TRUE);
    254 
    255           // release the persistent file handle
    256         ppf->Release();
     291          reply = ppf->Save(wsz, TRUE);
     292         
     293          // release the persistent file handle
     294          ppf->Release();
    257295        }
    258296      psl->Release();
    259       }
    260     delete fullPath;
    261   }
    262   else
    263   { // Back to the dark ages with win 3.1!
    264 
    265     // ensure that the requisite group is active; the add icon command will
    266     // use the active group.
    267     sprintf(buffer, "[ShowGroup(%s,5)]", groupName.c_str());
    268     if (!DDEShellCommand(this->instance, buffer))
    269     { // TODO: articulate/determine possible errors; expand error handling
    270             return false;
    271     }
    272 
    273     // and now add the item itself to the active (given) group
    274     sprintf(buffer, "[AddItem(%s,%s)]", iconDestination.c_str(), iconName.c_str());
    275     if (!DDEShellCommand(this->instance, buffer))
    276     {   // TODO: again work out what the problems could be
    277         return false;
    278     }
    279     reply = true;
    280   }
     297    }
     298      delete fullPath;
     299    }
     300  else
     301    {   
     302      // Back to the dark ages with win 3.1!
     303     
     304      // ensure that the requisite group is active; the add icon command will
     305      // use the active group.
     306      sprintf(buffer, "[ShowGroup(%s,5)]", groupName.c_str());
     307      if (!DDEShellCommand(this->instance, buffer))
     308    {
     309      // TODO: articulate/determine possible errors; expand error handling
     310      return false;
     311    }
     312     
     313      // and now add the item itself to the active (given) group
     314      sprintf(buffer, "[AddItem(%s,%s)]", iconDestination.c_str(), iconName.c_str());
     315      if (!DDEShellCommand(this->instance, buffer))
     316    {
     317      // TODO: again work out what the problems could be
     318      return false;
     319    }
     320      reply = true;
     321    }
    281322
    282323  if (reply)
    283   { this->logAction("ProgManAddItem", groupName, iconName, iconDestination);
    284   }
     324    {   
     325      this->logAction("ProgManAddItem", groupName, iconName, iconDestination);
     326    }
    285327  return reply;
    286328}
    287329
    288330bool gsProgramManager::removeProgramGroup(string groupName)
    289 {   //CreateGroup(groupName);
    290     char buffer[256];
    291 
     331{
     332  //CreateGroup(groupName);
     333  char buffer[256];
     334 
    292335  if (this->platform->isExplorerShell())
    293   { // add using shell controls
    294     LPITEMIDLIST pidl;
    295 
    296     if (this->platform->isUserAdministrator())
    297     { if (SHGetSpecialFolderLocation(0, CSIDL_COMMON_PROGRAMS, &pidl) != NOERROR)
    298         {   return false;
    299       }
    300     }
    301     else
    302     { if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
    303         {   return false;
    304       }
    305     }
    306     SHGetPathFromIDList(pidl, buffer);
    307 
    308     // Create the folder as required
    309     FilePath *path  = new FilePath(buffer, groupName);
    310     if (!RemoveDirectory((char *) path->cString()))
    311     {   // TODO: find cause of failure to remove
    312         DWORD reason = GetLastError();
    313       if (reason != 0)
    314       { return false;
    315       }
    316     }
    317   }
    318   else
    319   { // add using program manager DDE
    320     sprintf(buffer, "[DeleteGroup (%s)]", groupName.c_str());
    321     if (!DDEShellCommand(this->instance, buffer))
    322     {   // flag error by returning false
    323       return false;
    324     }
    325   }
    326     return true;
    327 }
    328 
    329 bool gsProgramManager::removeIcon(string groupName,             // group of the icon
    330                                                                     string iconName)                    // name of the icon
    331 {   bool                    reply = false;
    332     char                    buffer[MAX_PATH];
     336    {
     337      // add using shell controls
     338      LPITEMIDLIST pidl;
     339     
     340      if (this->platform->isUserAdministrator())
     341    {
     342      if (SHGetSpecialFolderLocation(0, CSIDL_COMMON_PROGRAMS, &pidl) != NOERROR)
     343        {   
     344          return false;
     345        }
     346    }
     347      else
     348    {
     349      if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
     350        {
     351          return false;
     352        }
     353    }
     354      SHGetPathFromIDList(pidl, buffer);
     355     
     356      // Create the folder as required
     357      FilePath *path = new FilePath(buffer, groupName);
     358      if (!RemoveDirectory((char *) path->cString()))
     359    {
     360      // TODO: find cause of failure to remove
     361      DWORD reason = GetLastError();
     362      if (reason != 0)
     363        {
     364          return false;
     365        }
     366    }
     367    }
     368  else
     369    {
     370      // add using program manager DDE
     371      sprintf(buffer, "[DeleteGroup (%s)]", groupName.c_str());
     372      if (!DDEShellCommand(this->instance, buffer))
     373    {
     374      // flag error by returning false
     375      return false;
     376    }
     377    }
     378  return true;
     379}
     380
     381bool gsProgramManager::removeIcon(string groupName, // group of the icon
     382                  string iconName) // name of the icon
     383{
     384  bool reply = false;
     385  char buffer[MAX_PATH];
    333386
    334387  if (this->platform->isExplorerShell())
    335   { // create item using the shell
    336     LPITEMIDLIST    pidl;
    337     HRESULT hres;
    338     IShellLink* psl;
    339     FilePath *  fullPath;
    340 
    341     // if the user is adminstrator, take the folder from the common programs folder
    342     // (in the "All Users" profile)
    343     if (this->platform->isUserAdministrator())
    344     {   if (SHGetSpecialFolderLocation(0, CSIDL_COMMON_PROGRAMS, &pidl) != NOERROR)
    345         {   return false;
    346             }
    347     }
    348     // otherwise get it from the user's own programs folder in their profile
    349     else
    350     { if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
    351         { return false;
    352       }
    353     }
    354 
    355     // get path of folder from shell
    356         SHGetPathFromIDList(pidl, buffer);
    357 
    358     // delete file
    359     fullPath    = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), "!.lnk");
    360         if (!DeleteFile(fullPath->cString()))
    361     { reply = false;
    362     }
    363     delete fullPath;
    364   }
    365   else
    366   { // Back to the dark ages with win 3.1!
    367 
    368     // ensure that the requisite group is active; the add icon command will
    369     // use the active group.
    370     sprintf(buffer, "[ShowGroup(%s,5)]", groupName.c_str());
    371     if (!DDEShellCommand(this->instance, buffer))
    372     { // TODO: articulate/determine possible errors; expand error handling
    373             return false;
    374     }
    375 
    376     // and now add the item itself to the active (given) group
    377     sprintf(buffer, "[DeleteItem(%s)]", iconName.c_str());
    378     if (!DDEShellCommand(this->instance, buffer))
    379     {   // TODO: again work out what the problems could be
    380         return false;
    381     }
    382   }
     388    {
     389      // create item using the shell
     390      LPITEMIDLIST pidl;
     391      //      HRESULT hres;
     392      //      IShellLink * psl;
     393      FilePath * fullPath;
     394
     395      // if the user is adminstrator, take the folder from the common programs folder
     396      // (in the "All Users" profile)
     397      if (this->platform->isUserAdministrator())
     398    {
     399      if (SHGetSpecialFolderLocation(0, CSIDL_COMMON_PROGRAMS, &pidl) != NOERROR)
     400        {
     401          return false;
     402        }
     403    }
     404      // otherwise get it from the user's own programs folder in their profile
     405      else
     406    {
     407      if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
     408        {
     409          return false;
     410        }
     411    }
     412
     413      // get path of folder from shell
     414      SHGetPathFromIDList(pidl, buffer);
     415     
     416      // delete file
     417      fullPath = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), "!.lnk");
     418      if (!DeleteFile(fullPath->cString()))
     419    {
     420      reply = false;
     421    }
     422      delete fullPath;
     423    }
     424  else
     425    {
     426      // Back to the dark ages with win 3.1!
     427
     428      // ensure that the requisite group is active; the add icon command will
     429      // use the active group.
     430      sprintf(buffer, "[ShowGroup(%s,5)]", groupName.c_str());
     431      if (!DDEShellCommand(this->instance, buffer))
     432    {
     433      // TODO: articulate/determine possible errors; expand error handling
     434      return false;
     435    }
     436
     437      // and now add the item itself to the active (given) group
     438      sprintf(buffer, "[DeleteItem(%s)]", iconName.c_str());
     439      if (!DDEShellCommand(this->instance, buffer))
     440    {
     441      // TODO: again work out what the problems could be
     442      return false;
     443    }
     444    }
    383445  return reply;
    384446}
  • trunk/gsinstaller/gsRegistry.h

    r1539 r1543  
    2727public:
    2828  gsRegistry(installManager &manager, configureFile &configFileb);
     29  virtual ~gsRegistry () {}
    2930  bool storeKeyString(HKEY base, string path, string item, string value);
    3031  bool collectionInstalled();
  • trunk/gsinstaller/gsinstall.cpp

    r1541 r1543  
    213213 */
    214214void GSInstall::getSourcePath()
    215 { static char filename[512];
    216     FilePath     *exePath;
     215{
     216  static char filename[512];
     217  FilePath *exePath;
    217218
    218219  // get the filepath of this executable
    219220  GetModuleFileName(0, filename, 512);
    220   exePath   = new FilePath(filename);
     221  exePath = new FilePath(filename);
    221222
    222223  // get the parent (i.e. the folder containing this executable) for the source
    223224  // folder
    224   this->sourcePath  = exePath->parent();
     225  this->sourcePath = exePath->parent();
    225226
    226227  // get the gsdl source path
    227   this->gsdlSourcePath  = new FilePath(this->sourcePath->pathString(), "gsdl");
     228  this->gsdlSourcePath = new FilePath(this->sourcePath->pathString(), "gsdl");
    228229  delete exePath;
    229230}
     
    235236 */
    236237bool GSInstall::copyFiles()
    237 {   // ensure that we have got the required destination and that we can write there
     238{
     239  // ensure that we have got the required destination and that we can write there
    238240  if (this->installExe)
    239   { this->destinationPath->ensureWriteablePath();
    240   }
     241    {
     242      this->destinationPath->ensureWriteablePath();
     243    }
    241244
    242245  // ensure that the destination path for the collection itself is available
    243246  if (this->installVolume)
    244   { this->dataDestPath->ensureWriteablePath();
    245   }
     247    {
     248      this->dataDestPath->ensureWriteablePath();
     249    }
    246250
    247251  // do the copy
    248     this->manifest->copy(this->gsdlSourcePath);
     252  this->manifest->copy(this->gsdlSourcePath);
    249253
    250254  return true;
     
    256260 */
    257261bool GSInstall::updateRegistry()
    258 { // don't do registry stuff under windows 32s
    259     if (this->platform.isWindows32s() && FALSE)
    260     {   return true;
    261   }
     262{
     263  // don't do registry stuff under windows 32s
     264  if (this->platform.isWindows32s() && FALSE)
     265    {
     266      return true;
     267    }
    262268
    263269  // ensure all pertinent keys already exist for this volume/collection
    264     this->gsRegister->ensureKeysExist();
     270  this->gsRegister->ensureKeysExist();
    265271
    266272  // now move on to add key items
    267     if (this->installExe)
    268   { FilePath *serverPath    = new FilePath(this->destinationPath->pathString(), "server.exe");
    269     FilePath *setupPath     = new FilePath(this->destinationPath->pathString(), "gssetup.exe");
    270       FilePath *logPath = new FilePath(this->destinationPath->pathString(), "install.log");
    271     string exeKeyPath, uninstallCmd, uninstallKeyPath;
    272     gsPlatform platform;
    273 
    274     // store the normal collection key information
    275     this->gsRegister->storeKeyString(   HKEY_LOCAL_MACHINE,
    276                                                                         this->gsRegister->collectKeyId(),
    277                                       "library",
    278                                       serverPath->pathString());
    279 
    280     // This test is in fact for 9x or NT 4+; we're worried about the registry
    281     // format, not about the shell as such
    282     if (platform.isExplorerShell())
    283     { // get special app path key for windows 9x
    284         exeKeyPath  =   this->gsRegister->exeKeyId("library.exe");
    285 
    286       // ensure that the exe key exists
    287         this->gsRegister->ensureKeyExists(HKEY_LOCAL_MACHINE, exeKeyPath);
    288 
    289         // store default key for this application
    290         this->gsRegister->storeKeyString(   HKEY_LOCAL_MACHINE,
    291                                                                         exeKeyPath,
    292                                           "",
    293                                         serverPath->pathString());
    294 
    295       // store path for this application
    296         this->gsRegister->storeKeyString(   HKEY_LOCAL_MACHINE,
    297                                                                         exeKeyPath,
    298                                           "path",
    299                                         this->destinationPath->pathString());
    300 
    301       // create uninstall command line
    302       uninstallCmd = setupPath->pathString() + " -u " + logPath->pathString();
    303       uninstallKeyPath = this->gsRegister->uninstallKeyId(this->configFile->getString("CollectionName"));
    304 
    305       // ensure uninstall key exists
    306       this->gsRegister->ensureKeyExists(HKEY_LOCAL_MACHINE, uninstallKeyPath);
    307 
    308       this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE, uninstallKeyPath,
    309                                                                         "DisplayName",
    310                                         this->configFile->getString("CollectionName"));
    311       this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE, uninstallKeyPath,
    312                                                                         "UninstallString", uninstallCmd);
    313     }
    314     delete setupPath;
    315     delete serverPath;
    316       delete logPath;
    317   }
     273  if (this->installExe)
     274    {
     275      //      FilePath *serverPath = new FilePath(this->destinationPath->pathString(), "server.exe");
     276      FilePath *serverPath = new FilePath(this->destinationPath->pathString(), "library.exe");
     277      FilePath *setupPath = new FilePath(this->destinationPath->pathString(), "gssetup.exe");
     278      FilePath *logPath = new FilePath(this->destinationPath->pathString(), "install.log");
     279      string exeKeyPath, uninstallCmd, uninstallKeyPath;
     280      gsPlatform platform;
     281
     282      // store the normal collection key information
     283      this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE,
     284                       this->gsRegister->collectKeyId(),
     285                       "library",
     286                       serverPath->pathString());
     287
     288      // This test is in fact for 9x or NT 4+; we're worried about the registry
     289      // format, not about the shell as such
     290      if (platform.isExplorerShell())
     291    {
     292      // get special app path key for windows 9x
     293      exeKeyPath = this->gsRegister->exeKeyId("library.exe");
     294
     295      // ensure that the exe key exists
     296      this->gsRegister->ensureKeyExists(HKEY_LOCAL_MACHINE, exeKeyPath);
     297
     298      // store default key for this application
     299      this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE,
     300                       exeKeyPath,
     301                       "",
     302                       serverPath->pathString());
     303
     304      // store path for this application
     305      this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE,
     306                       exeKeyPath,
     307                       "path",
     308                       this->destinationPath->pathString());
     309
     310      // create uninstall command line
     311      uninstallCmd = setupPath->pathString() + " -u " + logPath->pathString();
     312      uninstallKeyPath = this->gsRegister->uninstallKeyId(this->configFile->getString("CollectionName"));
     313
     314      // ensure uninstall key exists
     315      this->gsRegister->ensureKeyExists(HKEY_LOCAL_MACHINE, uninstallKeyPath);
     316     
     317      this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE, uninstallKeyPath,
     318                       "DisplayName",
     319                       this->configFile->getString("CollectionName"));
     320      this->gsRegister->storeKeyString(HKEY_LOCAL_MACHINE, uninstallKeyPath,
     321                       "UninstallString", uninstallCmd);
     322    }
     323      delete setupPath;
     324      delete serverPath;
     325      delete logPath;
     326    }
    318327
    319328  if (this->installVolume || this->installFullVolume)
    320   { // no actual key items are held in the volume key; for future use
    321   }
     329    {   
     330      // no actual key items are held in the volume key; for future use
     331    }
    322332  return true;
    323333}
     
    327337 */
    328338void GSInstall::setDestination()
    329 { // get configuration from the install wizard pages
    330     this->destinationPath       = new FilePath(this->selectedDirs[0]->selectedPath());
    331     this->installFullVolume = this->selectedDirs[1]->getOption();
     339{
     340  // get configuration from the install wizard pages
     341  this->destinationPath = new FilePath(this->selectedDirs[0]->selectedPath());
     342  this->installFullVolume = this->selectedDirs[1]->getOption();
    332343  if (this->installFullVolume || true)  // NB: always take path from 2nd dialog
    333   { this->dataDestPath  = new FilePath(this->selectedDirs[1]->selectedPath());
    334   }
     344    {
     345      this->dataDestPath = new FilePath(this->selectedDirs[1]->selectedPath());
     346    }
    335347  else
    336   { this->dataDestPath  = this->destinationPath;
    337   }
     348    {
     349      this->dataDestPath = this->destinationPath;
     350    }
    338351
    339352  // open the log for writing
     
    344357
    345358bool GSInstall::setUninstall()
    346 { char tempPathStr[MAX_PATH];
     359{
     360  char tempPathStr[MAX_PATH];
    347361
    348362  // if we failed to get the Windows temporary directory, abort
    349363  if (GetTempPath(MAX_PATH, tempPathStr) == 0)
    350   { // TODO: abort!
    351     return false;
    352   }
     364    {
     365      // TODO: abort!
     366      return false;
     367    }
    353368
    354369  FilePath tempPath(tempPathStr);
     
    357372  // and the installation log to the temporary directory and run them there
    358373  if (*this->sourcePath != tempPath)
    359   { // copy this and install.log to temporary directory and restart
    360     FilePath exePath(*this->sourcePath, "gssetup.exe");
    361     FilePath logPath(*this->sourcePath, "install.log");
    362 
    363     FilePath exeDest(tempPath, "gssetup.exe");
    364     FilePath logDest(tempPath, "install.log");
    365 
    366     CopyFile(exePath.cString(), exeDest.cString(), false);
    367     CopyFile(logPath.cString(), logDest.cString(), false);
    368 
    369     // now run the gssetup in the temporary directory
    370     launchApp launchUninstall(exeDest);
    371     launchUninstall.setCommandLine(" -u " + logPath.pathString());
    372     launchUninstall.run(false, 0, "", "", false);
    373 
    374     return false;
    375   }
     374    {
     375      // copy this and install.log to temporary directory and restart
     376      FilePath exePath(*this->sourcePath, "gssetup.exe");
     377      FilePath logPath(*this->sourcePath, "install.log");
     378
     379      FilePath exeDest(tempPath, "gssetup.exe");
     380      FilePath logDest(tempPath, "install.log");
     381     
     382      CopyFile(exePath.cString(), exeDest.cString(), false);
     383      CopyFile(logPath.cString(), logDest.cString(), false);
     384
     385      // now run the gssetup in the temporary directory
     386      launchApp launchUninstall(exeDest);
     387      launchUninstall.setCommandLine(" -u " + logPath.pathString());
     388      launchUninstall.run(false, 0, "", "", false);
     389
     390      return false;
     391    }
    376392
    377393  // open the log for reading from the directory this exe is now in (which
     
    380396  this->openLog(logPath->pathString(), false);
    381397  delete logPath;
    382 
     398 
    383399  return true;
    384400}
    385401
    386402void GSInstall::uninstall()
    387 { FilePath *iniPath;
    388     string      command;
     403{
     404  FilePath *iniPath;
     405  string command;
    389406  stringArray params;
    390407
    391     this->manifest = new gsManifest(*this); // get a manifest manager
    392 
    393   iniPath   = new FilePath(this->collectPath->pathString(), "gsdl.ini");
    394     gsProfile gsdlProfile(*this, iniPath->pathString());
    395 
    396     while ((command = this->popCommand(params)) != "")
    397   { if (!this->manifest->undoAction(command, params))
    398     { if (!gsdlProfile.undoAction(command, params))
    399         { if (!this->gsRegister->undoAction(command, params))
    400         { if (!this->progman->undoAction(command, params))
    401             {
    402           }
    403         }
    404       }
    405     }
    406   }
     408  this->manifest = new gsManifest(*this); // get a manifest manager
     409
     410  iniPath = new FilePath(this->collectPath->pathString(), "gsdl.ini");
     411  gsProfile gsdlProfile(*this, iniPath->pathString());
     412
     413  while ((command = this->popCommand(params)) != "")
     414    {
     415      if (!this->manifest->undoAction(command, params))
     416    {
     417      if (!gsdlProfile.undoAction(command, params))
     418        {
     419          if (!this->gsRegister->undoAction(command, params))
     420        {
     421          if (!this->progman->undoAction(command, params))
     422            {
     423            }
     424        }
     425        }
     426    }
     427    }
    407428}
    408429
     
    411432 */
    412433void GSInstall::setManifest()
    413 {   if (this->installExe)
    414     {   this->manifest->selectGroup("library", *this->destinationPath);
    415   }
     434{
     435  if (this->installExe)
     436    {
     437      this->manifest->selectGroup("library", *this->destinationPath);
     438    }
    416439  if (this->installFullVolume)
    417   { this->manifest->selectGroup("collection", *this->dataDestPath);
    418   }
     440    {   
     441      this->manifest->selectGroup("collection", *this->dataDestPath);
     442    }
    419443  else
    420   { this->manifest->selectGroup("database", *this->dataDestPath);
    421   }
     444    {   
     445      this->manifest->selectGroup("database", *this->dataDestPath);
     446    }
    422447}
    423448
     
    427452 */
    428453bool GSInstall::updateProgman()
    429 { string groupName;
     454{
     455  string groupName;
    430456
    431457  // if we managed to get a connection to the program manager (or explorer
    432458  // shell) then do the requisite updates
    433459  if (this->progman->connect())
    434   { // get group name from folders
    435     groupName = this->configFile->getString("ProgramGroupName");
    436       if (groupName == "")
    437     {   // TODO: error handling
    438         this->progman->disconnect();
    439         return false;
    440       }
    441 
    442       // add the group
    443         if (!this->progman->addProgramGroup(groupName))
    444       { this->progman->disconnect();
    445         return false;
     460    {
     461      // get group name from folders
     462      groupName = this->configFile->getString("ProgramGroupName");
     463      if (groupName == "")
     464    {
     465      // TODO: error handling
     466      this->progman->disconnect();
     467      return false;
     468    }
     469     
     470      // add the group
     471      if (!this->progman->addProgramGroup(groupName))
     472    {
     473      this->progman->disconnect();
     474      return false;
    446475    }
    447 
    448     // add a "server" icon
    449     FilePath libraryPath(this->destinationPath->pathString(), "library.exe");
    450       if (!this->progman->addIcon(groupName, "Library (without nextwork support)", libraryPath.pathString(), ""))
    451     { // assume that it may be there already
    452       }
    453 
    454     // check for server existence
    455     FilePath serverPath(this->destinationPath->pathString(), "server.exe");
    456     if (serverPath.exists())
    457     { if (!this->progman->addIcon(groupName, "Server", serverPath.pathString(), ""))
    458         {   // assume that it may be there already
    459       }
    460       }
    461 
    462     FilePath readMePath(this->destinationPath->pathString(), "readme.txt");
    463       if (!this->progman->addIcon(groupName, "ReadMe", readMePath.pathString(), ""))
     476     
     477      // add a "server" icon
     478      FilePath libraryPath(this->destinationPath->pathString(), "library.exe");
     479      if (!this->progman->addIcon(groupName, "Library", libraryPath.pathString(), ""))
    464480    {
    465       }
    466 
    467     FilePath supportPath(this->destinationPath->pathString(), "support.html");
    468       if (!this->progman->addIcon(groupName, "Technical Support", supportPath.pathString(), ""))
     481      // assume that it may be there already
     482    }
     483
     484      // check for server existence
     485      //      FilePath serverPath(this->destinationPath->pathString(), "server.exe");
     486      //      if (serverPath.exists())
     487      //    {
     488      //      if (!this->progman->addIcon(groupName, "Server", serverPath.pathString(), ""))
     489      //        {
     490          // assume that it may be there already
     491      //        }
     492      //    }
     493     
     494      FilePath readMePath(this->destinationPath->pathString(), "readme.txt");
     495      if (!this->progman->addIcon(groupName, "ReadMe", readMePath.pathString(), ""))
    469496    {
    470       }
    471 
    472     // TODO: uninstall icon
    473     // FilePath uninstallPath(this->destinationPath->pathString(), "gssetup.exe");
    474 
    475     // disconnect from program manager
    476     this->progman->disconnect();
    477   }
     497    }
     498
     499      FilePath supportPath(this->destinationPath->pathString(), "support.html");
     500      if (!this->progman->addIcon(groupName, "Technical Support", supportPath.pathString(), ""))
     501    {
     502    }
     503
     504      // TODO: uninstall icon
     505      // FilePath uninstallPath(this->destinationPath->pathString(), "gssetup.exe");
     506     
     507      // disconnect from program manager
     508      this->progman->disconnect();
     509    }
    478510  return true;
    479511}
     
    486518 */
    487519bool GSInstall::updateProfiles()
    488 { FilePath *exePath;
    489     FilePath *dataPath;
     520{
     521  FilePath *exePath;
     522  FilePath *dataPath;
    490523  FilePath *iniPath;
    491524
     
    493526  // folder of this installation sequence;  if not, then we pick it up from
    494527  // the existing location of that folder
    495     if (this->installExe)
    496     {   exePath = this->destinationPath;
    497   }
     528  if (this->installExe)
     529    {
     530      exePath = this->destinationPath;
     531    }
    498532  else
    499     {   exePath = this->collectPath;
    500   }
    501   iniPath   = new FilePath(exePath->pathString(), "gsdl.ini");
     533    {
     534      exePath = this->collectPath;
     535    }
     536  iniPath = new FilePath(exePath->pathString(), "gsdl.ini");
    502537
    503538  // TODO: check if this 'if' structure is correct; suspect that it isn't quite
     
    507542  //       This all needs investigating
    508543  if (this->installVolume)
    509   { // Manufacture the appropriate section name now; an equivalent string
    510     // is also constructed
    511     string volumeSectionString = this->configFile->getString("CollectionName") +
    512                                                              "#" + this->configFile->getString("CollectionVolume");
    513 
    514     // if we're installing the full data for the collection, then take the
    515     // data path to be at the selected destination directory for the collection
    516     // files; otherwise take the data path to be on the CD/distribution media
    517     if (this->installFullVolume)
    518     {   dataPath    =   this->dataDestPath;
    519     }
    520     else
    521     {   dataPath    = this->gsdlSourcePath;
    522     }
    523 
    524     // create a profile object to write to the gsdl.ini file
    525     gsProfile gsdlProfile(*this, iniPath->pathString());
    526 
    527     // if installing the executable, add the database and greenstone home
    528     // directories
    529     if (this->installExe)
    530     {   // set the correct exe entries in gsdl.ini (in the gsdl section)
    531             gsdlProfile.writeString("gsdl", "gsdlhome", dataPath->pathString());
    532       gsdlProfile.writeString("gsdl", "gdbmhome", this->dataDestPath->pathString());
    533     }
    534 
    535     // set the correct collection volume entries in gsdl.ini
    536     if (this->installVolume)
    537     { // note the collection in the general gsdl section; and add the undo item too
    538         gsdlProfile.ensureListMember("gsdl", gsdl_COLLIST, volumeSectionString);
    539 
    540       // note the volume data in its own section
    541         gsdlProfile.writeString(volumeSectionString, "gsdlhome", dataPath->pathString());
    542         gsdlProfile.writeString(volumeSectionString, "gdbmhome", this->dataDestPath->pathString());
    543         gsdlProfile.writeString(volumeSectionString, "staticpath", dataPath->pathString());
    544     }
    545   }
    546 
     544    {
     545      // Manufacture the appropriate section name now; an equivalent string
     546      // is also constructed
     547      string volumeSectionString = this->configFile->getString("CollectionName") +
     548    "#" + this->configFile->getString("CollectionVolume");
     549
     550      // if we're installing the full data for the collection, then take the
     551      // data path to be at the selected destination directory for the collection
     552      // files; otherwise take the data path to be on the CD/distribution media
     553      if (this->installFullVolume)
     554    {
     555      dataPath = this->dataDestPath;
     556    }
     557      else
     558    {
     559      dataPath = this->gsdlSourcePath;
     560    }
     561
     562      // create a profile object to write to the gsdl.ini file
     563      gsProfile gsdlProfile(*this, iniPath->pathString());
     564
     565      // if installing the executable, add the database and greenstone home
     566      // directories
     567      if (this->installExe)
     568    {
     569      // set the correct exe entries in gsdl.ini (in the gsdl section)
     570      gsdlProfile.writeString("gsdl", "gsdlhome", dataPath->pathString());
     571      gsdlProfile.writeString("gsdl", "gdbmhome", this->dataDestPath->pathString());
     572    }
     573
     574      // set the correct collection volume entries in gsdl.ini
     575      if (this->installVolume)
     576    {
     577      // note the collection in the general gsdl section; and add the undo item too
     578      gsdlProfile.ensureListMember("gsdl", gsdl_COLLIST, volumeSectionString);
     579
     580      // note the volume data in its own section
     581      gsdlProfile.writeString(volumeSectionString, "gsdlhome", dataPath->pathString());
     582      gsdlProfile.writeString(volumeSectionString, "gdbmhome", this->dataDestPath->pathString());
     583      gsdlProfile.writeString(volumeSectionString, "staticpath", dataPath->pathString());
     584    }
     585    }
     586 
    547587  // clean up
    548588  delete iniPath;
    549 
     589 
    550590  return true;
    551591}
     
    556596 */
    557597bool GSInstall::updateSetupExe()
    558 { FilePath *destExePath;
     598{
     599  FilePath *destExePath;
    559600  FilePath srcExeFile(*this->sourcePath, "gssetup.exe");
    560601
    561     if (this->installExe)
    562     {   destExePath = this->destinationPath;
    563   }
     602  if (this->installExe)
     603    {
     604      destExePath = this->destinationPath;
     605    }
    564606  else
    565     {   destExePath = this->collectPath;
    566   }
    567     FilePath destExeFile(*destExePath, "gssetup.exe");
     607    {
     608      destExePath = this->collectPath;
     609    }
     610  FilePath destExeFile(*destExePath, "gssetup.exe");
    568611
    569612  if (!CopyFile(srcExeFile.cString(), destExeFile.cString(), false))
    570   { return false;
    571   }
     613    {
     614      return false;
     615    }
    572616  return true;
    573617}
    574618
    575619bool GSInstall::installNetscape()
    576 {   FilePath    netscape32Path(this->sourcePath->pathString(), "netscape\\n32e405.exe");
    577   FilePath  netscape16Path(this->sourcePath->pathString(), "netscape\\n16e405.exe");
     620{
     621  FilePath netscape32Path(this->sourcePath->pathString(), "netscape\\n32e405.exe");
     622  FilePath netscape16Path(this->sourcePath->pathString(), "netscape\\n16e405.exe");
    578623
    579624  launchApp launchNetscape(netscape32Path);
    580625  launchNetscape.platformApp(gsPlatform_WINDOWS32S, netscape16Path);
    581626  if (launchNetscape.run(true, 1,
    582                                                 "This library is displayed using a web browser.  If you don't "
    583                               "currently have a web browser installed on your machine you may "
    584                               "install the Netscape 4.05 browser now.\n\n"
    585                               "Note that if your current browser was provided by your internet "
    586                               "service provider, you should install Netscape in a different "
    587                               "directory.\n\n"
    588                               "Would you like to install the Netscape 4.05 browser now?",
    589                               "Greenstone Installer", false) < 0)
    590   { MessageBox(0, "Error", app_name, MB_OK);
    591     return false;
    592   }
     627             "This library is displayed using a web browser.  If you don't "
     628             "currently have a web browser installed on your machine you may "
     629             "install the Netscape 4.05 browser now.\n\n"
     630             "Note that if your current browser was provided by your internet "
     631             "service provider, you should install Netscape in a different "
     632             "directory.\n\n"
     633             "Would you like to install the Netscape 4.05 browser now?",
     634             "Greenstone Installer", false) < 0)
     635    {
     636      MessageBox(0, "Error", app_name, MB_OK);
     637      return false;
     638    }
    593639  return true;
    594640}
    595641
    596642FilePath *GSInstall::collectionPath()
    597 {   return this->collectPath;
     643{
     644  return this->collectPath;
    598645}
    599646
    600647FilePath *GSInstall::installPath()
    601 {   return this->installToPath;
     648{
     649  return this->installToPath;
    602650}
    603651
    604652void GSInstall::addSelectedDir(dirSelector *selector)
    605 {   this->selectedDirs.push_back(selector);
     653{
     654  this->selectedDirs.push_back(selector);
    606655}
    607656
    608657typedef struct
    609 { dirSelector * dirSelect;
     658{
     659  dirSelector * dirSelect;
    610660} GSInstall_dirPathData;
    611661
    612662HGLOBAL loadDirBrowser()
    613 { HRSRC resHdl;
    614 
    615     resHdl = FindResource(app_instance, "MySaveAsDlg", RT_DIALOG);
     663{
     664  HRSRC resHdl;
     665
     666  resHdl = FindResource(app_instance, "MySaveAsDlg", RT_DIALOG);
    616667  return LoadResource(app_instance, resHdl);
    617668}
     
    622673  int sx, sy;
    623674  int dx, dy;
    624 
     675 
    625676  gsInstall_getDesktopExt(&sx, &sy);
    626677  GetWindowRect(dialog, &rect);
     
    632683
    633684BOOL FAR PASCAL GSInstall_dlgproc(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam)
    634 { static bool first = true;     // static variable to hack the position of the
     685{
     686  static bool first = true;   // static variable to hack the position of the
    635687                              // whole wizard; note doing this in the wizard
    636688                              // property sheet initialisation DOES NOT WORK
    637689
    638     switch (Message)
    639     {   case WM_INITDIALOG:
    640     {   dirSelector *selector = (dirSelector *) ((PROPSHEETPAGE *) lParam)->lParam;
     690  switch (Message)
     691    {
     692    case WM_INITDIALOG:
     693      {
     694    dirSelector *selector = (dirSelector *) ((PROPSHEETPAGE *) lParam)->lParam;
    641695
    642696        SetDlgItemText(Dialog, dirpath_PROMPT, selector->prompt);
    643       if (selector->optPrompt != NULL)
    644       { SetDlgItemText(Dialog, dirpath_OPTION, selector->optPrompt);
    645           EnableWindow(GetDlgItem(Dialog, dirpath_BROWSE), true); // was false
    646         EnableWindow(GetDlgItem(Dialog, dirpath_PATH), true);       // was false
     697    if (selector->optPrompt != NULL)
     698      {
     699        SetDlgItemText(Dialog, dirpath_OPTION, selector->optPrompt);
     700        EnableWindow(GetDlgItem(Dialog, dirpath_BROWSE), true); // was false
     701        EnableWindow(GetDlgItem(Dialog, dirpath_PATH), true); // was false
     702      }
     703    else
     704      {
     705        ShowWindow(GetDlgItem(Dialog, dirpath_OPTION), SW_HIDE);
     706      }
     707    SetWindowLong(Dialog, GWL_USERDATA, ((PROPSHEETPAGE *) lParam)->lParam);
     708    SetDlgItemText(Dialog, dirpath_PATH, selector->selectedPath());
     709   
     710    // if this is the first time this function is called, then centre the
     711    // wizard into the centre of our screen.
     712    if (first)
     713      {
     714        gsInstall_wizard_centre(GetParent(Dialog));
     715        first = false;
     716      }
    647717      }
    648       else
    649       { ShowWindow(GetDlgItem(Dialog, dirpath_OPTION), SW_HIDE);
    650       }
    651       SetWindowLong(Dialog, GWL_USERDATA, ((PROPSHEETPAGE *) lParam)->lParam);
    652       SetDlgItemText(Dialog, dirpath_PATH, selector->selectedPath());
    653 
    654       // if this is the first time this function is called, then centre the
    655       // wizard into the centre of our screen.
    656       if (first)
    657       { gsInstall_wizard_centre(GetParent(Dialog));
    658         first = false;
    659       }
    660     }
    661     return TRUE;
    662 
     718      return TRUE;
     719     
    663720    case WM_COMMAND:
    664         switch (LOWORD(wParam))
    665       { case dirpath_BROWSE:
    666             ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->requestPath(Dialog, "Select Directory");
     721      switch (LOWORD(wParam))
     722    {
     723    case dirpath_BROWSE:
     724      ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->requestPath(Dialog, "Select Directory");
    667725          SetDlgItemText(Dialog, dirpath_PATH, ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->selectedPath());
    668         break;
     726      break;
    669727
    670728        case dirpath_OPTION:
    671             ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->setOption(IsDlgButtonChecked(Dialog, dirpath_OPTION));
    672             if (HIWORD(wParam) == BN_CLICKED && false) // don't do the enable/disable these days
    673           { EnableWindow(GetDlgItem(Dialog, dirpath_BROWSE), IsDlgButtonChecked(Dialog, dirpath_OPTION));
    674             EnableWindow(GetDlgItem(Dialog, dirpath_PATH), IsDlgButtonChecked(Dialog, dirpath_OPTION));
    675           }
    676         break;
    677       }
    678     break;
    679 
     729      ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->setOption(IsDlgButtonChecked(Dialog, dirpath_OPTION));
     730      if (HIWORD(wParam) == BN_CLICKED && false)
     731        // don't do the enable/disable these days
     732        {
     733          EnableWindow(GetDlgItem(Dialog, dirpath_BROWSE), IsDlgButtonChecked(Dialog, dirpath_OPTION));
     734          EnableWindow(GetDlgItem(Dialog, dirpath_PATH), IsDlgButtonChecked(Dialog, dirpath_OPTION));
     735        }
     736      break;
     737    }
     738      break;
     739     
    680740    case WM_NOTIFY:
    681         switch (((LPNMHDR) lParam)->code)
    682       { case PSN_SETACTIVE:
    683         {   dirSelector *selector = ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA));
    684 
    685             // bodge to set the dialogue path to the correct value
    686             if (selector != rootSelector)
    687           { selector->setPath(rootSelector->selectedPath());
    688             SetDlgItemText(Dialog, dirpath_PATH, selector->selectedPath());
    689           }
    690 
    691             if (selector->isFinal())
    692             { PropSheet_SetWizButtons(GetParent(Dialog), PSWIZB_BACK | PSWIZB_FINISH);
    693             }
    694           else
    695             { PropSheet_SetWizButtons(GetParent(Dialog), PSWIZB_BACK | PSWIZB_NEXT);
    696           }
    697         }
    698         break;
    699 
     741      switch (((LPNMHDR) lParam)->code)
     742    {
     743    case PSN_SETACTIVE:
     744      {
     745        dirSelector *selector = ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA));
     746       
     747        // bodge to set the dialogue path to the correct value
     748        if (selector != rootSelector)
     749          {
     750        selector->setPath(rootSelector->selectedPath());
     751        SetDlgItemText(Dialog, dirpath_PATH, selector->selectedPath());
     752          }
     753       
     754        if (selector->isFinal())
     755          {
     756        PropSheet_SetWizButtons(GetParent(Dialog), PSWIZB_BACK | PSWIZB_FINISH);
     757          }
     758        else
     759          {
     760        PropSheet_SetWizButtons(GetParent(Dialog), PSWIZB_BACK | PSWIZB_NEXT);
     761          }
     762      }
     763      break;
     764     
    700765        case PSN_KILLACTIVE:
    701         break;
    702 
    703                 case PSN_WIZNEXT:
    704           { // note the path from the dialog
    705             dirSelector *selector = ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA));
    706             selector->setPathFromEdit(GetDlgItem(Dialog, dirpath_PATH));
    707 
    708             // create a new FilePath object to check on the proposed destination
    709                     FilePath *path = new FilePath(selector->selectedPath());
    710 
    711           // if the proposed destination doesn't exist, ask the user whether to
    712           // create it now.  TODO: actually create it if asked!
    713           if (path->exists() == false)
    714           { char buffer[128];
    715 
     766      break;
     767     
     768    case PSN_WIZNEXT:
     769      {
     770        // note the path from the dialog
     771        dirSelector *selector = ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA));
     772        selector->setPathFromEdit(GetDlgItem(Dialog, dirpath_PATH));
     773
     774        // create a new FilePath object to check on the proposed destination
     775        FilePath *path = new FilePath(selector->selectedPath());
     776
     777        // if the proposed destination doesn't exist, ask the user whether to
     778        // create it now.  TODO: actually create it if asked!
     779        if (path->exists() == false)
     780          {
     781        char buffer[128];
     782       
    716783            sprintf(buffer, "Directory %s does not exist - create it?", selector->selectedPath());
    717784
    718             // if the user cancelled that, then don't permit them to go to the next
    719             // page of the wizard
     785        // if the user cancelled that, then don't permit them to go to the next
     786        // page of the wizard
    720787            if (MessageBox(0, buffer, app_name, MB_YESNO | MB_TOPMOST) == IDNO)
    721             {   delete path;
    722                 SetWindowLong(Dialog, DWL_MSGRESULT, TRUE);
    723               return TRUE;
    724             }
    725           }
    726           delete path;
     788          {
     789            delete path;
     790            SetWindowLong(Dialog, DWL_MSGRESULT, TRUE);
     791            return TRUE;
     792          }
    727793          }
    728         break;
    729 
     794        delete path;
     795      }
     796      break;
     797     
    730798        case PSN_WIZFINISH:
    731           { // Finish the activity now
    732             config_complete = true;
     799      {
     800        // Finish the activity now
     801        config_complete = true;
    733802          }
    734         break;
    735       }
    736     break;
    737   }
    738     return FALSE;
     803      break;
     804    }
     805      break;
     806    }
     807  return FALSE;
    739808}
    740809
    741810void GSInstall_init_propertySheet(PROPSHEETPAGE &ppage, char *prompt, char *optPrompt,
    742                                                                     char *title, GSInstall &installer, bool isFinal)
    743 { GSInstall_dirPathData *data = new GSInstall_dirPathData;
    744 
    745     // create the directory Selector
    746     data->dirSelect     = new dirSelector(prompt, optPrompt, title, installer.installPath());
     811                  char *title, GSInstall &installer, bool isFinal)
     812{
     813  GSInstall_dirPathData *data = new GSInstall_dirPathData;
     814
     815  // create the directory Selector
     816  data->dirSelect = new dirSelector(prompt, optPrompt, title, installer.installPath());
    747817  data->dirSelect->setFinal(isFinal);
    748818
    749819  // if there is no extant root selector, make this it
    750820  if (rootSelector == NULL)
    751   { rootSelector = data->dirSelect;
    752   }
     821    {
     822      rootSelector = data->dirSelect;
     823    }
    753824
    754825  // add this directory selector to the installer
     
    756827
    757828  // set up the rest of the page
    758     ppage.dwSize        = sizeof(PROPSHEETPAGE);
    759     ppage.dwFlags       = PSP_USETITLE;
    760   ppage.hInstance   = app_instance;
    761   ppage.pszTemplate = "getDirPath";
    762   ppage.pszIcon         = 0;
    763   ppage.pszTitle        = app_name;
    764   ppage.pfnDlgProc  = (DLGPROC) GSInstall_dlgproc;
    765     ppage.lParam      = (LPARAM) data->dirSelect;
    766   ppage.pfnCallback = NULL;
     829  ppage.dwSize = sizeof(PROPSHEETPAGE);
     830  ppage.dwFlags = PSP_USETITLE;
     831  ppage.hInstance = app_instance;
     832  ppage.pszTemplate = "getDirPath";
     833  ppage.pszIcon = 0;
     834  ppage.pszTitle = app_name;
     835  ppage.pfnDlgProc = (DLGPROC) GSInstall_dlgproc;
     836  ppage.lParam = (LPARAM) data->dirSelect;
     837  ppage.pfnCallback = NULL;
    767838}
    768839
    769840int CALLBACK GSInstall_wizardProc(HWND dialog, UINT Message, LPARAM lParameter)
    770 { switch (Message)
    771     { case PSCB_INITIALIZED :
    772             // Process PSCB_INITIALIZED
     841{
     842  switch (Message)
     843    {
     844    case PSCB_INITIALIZED :
     845      // Process PSCB_INITIALIZED
    773846      gsInstall_wizard_centre(dialog);
    774         break ;
    775 
    776         case PSCB_PRECREATE :
    777             // Process PSCB_PRECREATE
    778         break ;
    779 
    780         default :
    781             // Unknown message
    782         break ;
    783     }
     847      break ;
     848
     849    case PSCB_PRECREATE :
     850      // Process PSCB_PRECREATE
     851      break ;
     852
     853    default :
     854      // Unknown message
     855      break ;
     856    }
    784857  return 0;
    785858}
     
    847920
    848921    case WM_USER:
    849     {
    850       // uninstall action
    851       if (strstr(app_cmdLine, "-u") != NULL)
    852         {
    853       // skip past the -u option itself
    854       char *at = strstr(app_cmdLine, "-u");
    855       at += strlen("-u");
    856 
    857       // extract the log file path from the command line
    858       while (*at == ' ')
    859         {
    860           at ++;
    861         }
    862       string logPathString(at);
    863       FilePath logPath(logPathString);
    864 
    865       GSInstall install(true);
    866       // if we're running in the temporary directory, do the uninstall
    867       if (install.setUninstall())
    868         {
     922      {
     923    // uninstall action
     924    if (strstr(app_cmdLine, "-u") != NULL)
     925      {
     926        // skip past the -u option itself
     927        char *at = strstr(app_cmdLine, "-u");
     928        at += strlen("-u");
     929       
     930        // extract the log file path from the command line
     931        while (*at == ' ')
     932          {
     933        at ++;
     934          }
     935        string logPathString(at);
     936        FilePath logPath(logPathString);
     937       
     938        GSInstall install(true);
     939        // if we're running in the temporary directory, do the uninstall
     940        if (install.setUninstall())
     941          {
    869942          install.uninstall();
    870 
     943         
    871944          // close the log to write back all changes to the log; if the file
    872945          // will be deleted, it must be closed; copying may also fail, so it's
    873946          // safer to close it before doing either.
    874947          install.closeLog();
    875 
     948         
    876949          // if the install is empty, terminate all final items (currently the
    877950          // log and setup executables,
     
    880953          // delete the log file
    881954          DeleteFile(logPath.cString());
    882 
     955         
    883956          // get it's parent to find where the gssetup executable will be
    884957          FilePath *logParent = logPath.parent();
    885958          FilePath uninstallPath(*logParent, "gssetup.exe");
    886 
     959         
    887960          // delete the gssetup executable
    888961          DeleteFile(uninstallPath.cString());
    889 
     962         
    890963          // dispose of the parent directory information
    891964          delete logParent;
     
    896969          // do nothing - should be changed already!
    897970        }
    898         }
    899     }
    900       // install wizard
    901       else
    902     {   
    903       GSInstall install(false);
    904       GSInstall_init_wizard(install);
    905           if (config_complete == false)
    906         {
    907           MessageBox(0, "Install cancelled", app_name, MB_OK);
    908         }
    909       else
    910         {
    911           // configure the installation
    912           install.setDestination();
    913           install.setManifest();
    914 
    915           // perform installation
    916           install.copyFiles();
    917           install.updateProgman();
    918           install.updateRegistry();
    919           install.updateProfiles();
    920           install.updateSetupExe();
    921 
    922           // the log will need reopening (probably failed initially)
    923           install.reopenLog();
    924          
    925           // close log
    926           install.closeLog();
    927 
    928           // do further actions
    929           install.installNetscape();
    930         }
    931     }
    932       DestroyWindow(Window);
    933     }
    934     break;
    935    
     971          }
     972      }
     973    // install wizard
     974    else
     975      {
     976        GSInstall install(false);
     977        GSInstall_init_wizard(install);
     978        if (config_complete == false)
     979          {
     980        MessageBox(0, "Install cancelled", app_name, MB_OK);
     981          }
     982        else
     983          {
     984        // configure the installation
     985        install.setDestination();
     986        install.setManifest();
     987       
     988        // perform installation
     989        install.copyFiles();
     990        install.updateProgman();
     991        install.updateRegistry();
     992        install.updateProfiles();
     993        install.updateSetupExe();
     994       
     995        // the log will need reopening (probably failed initially)
     996        install.reopenLog();
     997       
     998        // close log
     999        install.closeLog();
     1000       
     1001        // do further actions
     1002        install.installNetscape();
     1003          }
     1004    }
     1005    DestroyWindow(Window);
     1006      }
     1007      break;
     1008     
    9361009    case WM_CLOSE:
    9371010      /*if (!file_ischanged || IDCANCEL != file_query(Window, file_name))*/
     
    9441017      }
    9451018      break;
    946 
     1019     
    9471020    default:
    9481021      return(DefWindowProc(Window, Message, wParameter, lParameter));
     
    9521025
    9531026void GSInstall_init(HINSTANCE instance, int Show)
    954 { int sx, sy;
    955 
    956     gsInstall_getDesktopExt(&sx, &sy);
    957 
    958     app_window = CreateWindow("GSInstall:Main", "GreenStone Installer",
    959                                                             WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | CS_DBLCLKS,
    960                                                             0, 0,
    961                                                             sx, sy,
    962                                                             NULL,
    963                                                             NULL,
    964                                                             app_instance,
    965                                                             NULL);
    966 
    967     ShowWindow(app_window, Show);
    968 
     1027{
     1028  int sx, sy;
     1029
     1030  gsInstall_getDesktopExt(&sx, &sy);
     1031 
     1032  app_window = CreateWindow("GSInstall:Main", "GreenStone Installer",
     1033                WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | CS_DBLCLKS,
     1034                0, 0,
     1035                sx, sy,
     1036                NULL,
     1037                NULL,
     1038                app_instance,
     1039                NULL);
     1040 
     1041  ShowWindow(app_window, Show);
     1042 
    9691043  PostMessage(app_window, WM_USER, 0, 0L);
    9701044}
  • trunk/gsinstaller/launchApp.cpp

    r1541 r1543  
    44
    55launchApp::launchApp(FilePath &file)
    6 {   this->exeMap["default"] = file;
     6{
     7  this->exeMap["default"] = file;
    78}
    89
    910void launchApp::platformApp(string platform, FilePath &file)
    10 {   this->exeMap[platform] = file;
     11{
     12  this->exeMap[platform] = file;
    1113}
    1214
    1315void launchApp::setCommandLine(string commandLine)
    14 {   this->commandline = commandLine;
     16{
     17  this->commandline = commandLine;
    1518}
    1619
    1720int launchApp::run(bool test, int deftest, string prompt, string header, bool wait)
    18 { gsPlatform    platform;
    19     FilePath        exePath;
    20   string            runLine;
     21{
     22  gsPlatform platform;
     23  FilePath exePath;
     24  string runLine;
    2125
    22     if (test)
    23   { // if user didn't want it then cancel
    24     if (MessageBox(0, prompt.c_str(), header.c_str(),
    25                                  MB_YESNO | MB_ICONQUESTION | MB_SYSTEMMODAL |
    26                      (deftest == 0 ? MB_DEFBUTTON1 : MB_DEFBUTTON2)) == IDNO)
    27     {   return 0;
     26  if (test)
     27    {
     28      // if user didn't want it then cancel
     29      if (MessageBox(0, prompt.c_str(), header.c_str(),
     30             MB_YESNO | MB_ICONQUESTION | MB_SYSTEMMODAL |
     31             (deftest == 0 ? MB_DEFBUTTON1 : MB_DEFBUTTON2)) == IDNO)
     32    {
     33      return 0;
     34    }
    2835    }
    29   }
    3036
    3137  // get the executable for this platform
    32   exePath   =   this->exeMap[platform.platformString()];
     38  exePath = this->exeMap[platform.platformString()];
    3339
    3440  // if we didn't get it, get the default
    3541  if (exePath.isEmpty())
    36   { exePath = this->exeMap["default"];
    37   }
     42    {
     43      exePath = this->exeMap["default"];
     44    }
    3845
    3946  // couldn't find a path
    4047  if (exePath.isEmpty())
    41   { return -1;
    42   }
     48    {
     49      return -1;
     50    }
    4351
    4452  // prepare process information fields
    4553  STARTUPINFO startup;
    46   PROCESS_INFORMATION   process;
    47     startup.cb              = sizeof(STARTUPINFO);
    48   process.hProcess  =   0;
     54  PROCESS_INFORMATION process;
     55  startup.cb = sizeof(STARTUPINFO);
     56  process.hProcess = 0;
    4957
    5058  // build command line if required
    5159  if (this->commandline != "")
    52   { runLine = exePath.pathString() + " " + this->commandline;
    53   }
     60    {
     61      runLine = exePath.pathString() + " " + this->commandline;
     62    }
    5463
    5564  MessageBox(0, exePath.cString(), runLine.c_str(), MB_OK);
    5665
    57     // execute the process
     66  // execute the process
    5867  if (CreateProcess((LPSTR) exePath.cString(),
    59                                     (runLine != "" && false) ? (LPSTR) runLine.c_str() : NULL,
     68            (runLine != "" && false) ? (LPSTR) runLine.c_str() : NULL,
    6069                    NULL, NULL, FALSE, 0, NULL, NULL,
    6170                    &startup, &process) == 0)
    62   { DWORD   error   = GetLastError();
    63     MessageBox(0, "Failed", "Failed", MB_OK);
    64     return -2;
    65   }
     71    {
     72      DWORD error = GetLastError();
     73      MessageBox(0, "Failed", "Failed", MB_OK);
     74      return -2;
     75    }
    6676
    6777  if (wait)
    68   { WaitForSingleObject(process.hProcess, INFINITE);
    69   }
     78    {
     79      WaitForSingleObject(process.hProcess, INFINITE);
     80    }
    7081
    7182  // success: return a positive number
  • trunk/gsinstaller/unInstall.cpp

    r1525 r1543  
    66
    77bool installManager::openLog(string filename, bool write)
    8 { string command;
    9     stringArray params;
    10 
    11     if (this->logfile.rdbuf()->is_open())
    12     {   this->closeLog();
    13   }
     8{
     9  string command;
     10  stringArray params;
     11
     12  if (this->logfile.rdbuf()->is_open())
     13    {
     14      this->closeLog();
     15    }
    1416  this->logfileName = filename;
    1517  this->logfile.open(filename.c_str(), ios::out | ios::in);
    1618  if (write == false)
    17   { while ((command = this->readCommand(params)) != "")
    18     { if (command[0] == '[' && command[command.length()-1] == ']')
    19         { this->setModule(command.substr(1, command.length() - 2));
    20         }
    21         else
    22         { unInstallCommand action(command, params);
    23             this->storeCommand(action);
    24         }
    25     }
    26   }
     19    {
     20      while ((command = this->readCommand(params)) != "")
     21    {
     22      if (command[0] == '[' && command[command.length()-1] == ']')
     23        {
     24          this->setModule(command.substr(1, command.length() - 2));
     25        }
     26      else
     27        {
     28          unInstallCommand action(command, params);
     29          this->storeCommand(action);
     30        }
     31    }
     32    }
    2733  this->setModule("default");
    2834  return true;
     
    3036
    3137bool installManager::reopenLog()
    32 { if (this->logfile.rdbuf()->is_open())
    33   { this->logfile.close();
    34   }
     38{
     39  if (this->logfile.rdbuf()->is_open())
     40    {
     41      this->logfile.close();
     42    }
    3543  else
    36   { this->logfile.close();
    37     }
     44    {
     45      this->logfile.close();
     46    }
    3847 
    3948  this->logfile.open(this->logfileName.c_str(), ios::out | ios::in);
     
    4251
    4352void installManager::setModule(string moduleName)
    44 {   this->currentModule = moduleName;
     53{
     54  this->currentModule = moduleName;
    4555}
    4656
    4757bool installManager::storeCommand(unInstallCommand &command)
    48 { this->modules[this->currentModule].push_back(command);
    49     return true;
     58{
     59  this->modules[this->currentModule].push_back(command);
     60  return true;
    5061}
    5162
    5263bool installManager::writeCommand(unInstallCommand &command)
    53 { if (!this->writeString(command.command))
    54     { return false;
    55   }
    56     for (unsigned int p = 0; p < command.parameters.size(); p ++)
    57   { if (!this->writeSeparator())
    58     { return false;
    59     }
    60     if (!this->writeString(command.parameters[p]))
    61     { return false;
    62     }
    63   }
     64{
     65  if (!this->writeString(command.command))
     66    {
     67      return false;
     68    }
     69  for (unsigned int p = 0; p < command.parameters.size(); p ++)
     70    {
     71      if (!this->writeSeparator())
     72    {
     73      return false;
     74    }
     75      if (!this->writeString(command.parameters[p]))
     76    {
     77      return false;
     78    }
     79    }
    6480  if (!this->writeString("\n"))
    65   { return false;
    66   }
     81    {
     82      return false;
     83    }
    6784  return true;
    6885}
    6986
    7087bool installManager::writeString(char *buffer)
    71 { string s(buffer);
    72     return this->writeString(s);
     88{
     89  string s(buffer);
     90  return this->writeString(s);
    7391}
    7492
    7593bool installManager::writeString(string str)
    76 { bool quote;
    77 
    78     // TODO: check for space characters in str and quote if necessary
     94{
     95  bool quote;
     96 
     97  // TODO: check for space characters in str and quote if necessary
    7998  quote = str.find_first_of(' ') < str.length();
    8099
    81     if (quote)
    82   { this->logfile << "\"";
    83   }
    84     this->logfile << str;
    85100  if (quote)
    86   { this->logfile << "\"";
    87   }
     101    {
     102      this->logfile << "\"";
     103    }
     104  this->logfile << str;
     105  if (quote)
     106    {
     107      this->logfile << "\"";
     108    }
    88109  return true;
    89110}
    90111
    91112bool installManager::writeSeparator()
    92 {   this->logfile << " ";
    93     return true;
     113{
     114  this->logfile << " ";
     115  return true;
    94116}
    95117
    96118string installManager::readString()
    97 {   string reply = "";
    98     char c;
     119{
     120  string reply = "";
     121  char c;
    99122
    100123  if (this->logfile.eof())
    101     {   return reply;
    102   }
     124    {
     125      return reply;
     126    }
    103127
    104128  this->logfile >> c;
    105129  while (c <= ' ' && !this->logfile.eof())
    106   { this->logfile.get();
    107   }
     130    {   
     131      this->logfile.get();
     132    }
    108133
    109134  if (this->logfile.eof())
    110   { return reply;
    111   }
     135    {
     136      return reply;
     137    }
    112138
    113139  if (c == '\"')
    114   { do
    115     {   c = this->logfile.get();
    116         if (c != '\"')
    117       { reply += c;
    118       }
    119     }
    120     while (c != '\"' && !this->logfile.eof());
    121   }
     140    {
     141      do
     142    {
     143      c = this->logfile.get();
     144      if (c != '\"')
     145        {
     146          reply += c;
     147        }
     148    }
     149      while (c != '\"' && !this->logfile.eof());
     150    }
    122151  else
    123   { while (c > ' ')
    124     { reply += c;
    125         if (this->logfile.eof())
    126       { break;
    127       }
    128         c = this->logfile.get();
    129     }
    130     if (!this->logfile.eof())
    131     {   this->logfile.putback(c);
    132     }
    133     //this->logfile >> reply;
    134   }
     152    {
     153      while (c > ' ')
     154    {
     155      reply += c;
     156      if (this->logfile.eof())
     157        {
     158          break;
     159        }
     160      c = this->logfile.get();
     161    }
     162      if (!this->logfile.eof())
     163    {
     164      this->logfile.putback(c);
     165    }
     166      //this->logfile >> reply;
     167    }
    135168  return reply;
    136169}
    137170
    138171string installManager::readCommand(stringArray &array)
    139 {   string reply = "";
     172{
     173  string reply = "";
    140174  char c;
    141175
     
    143177
    144178  if (this->logfile.eof())
    145   { return reply;
    146   }
    147 
    148     reply = this->readString();
     179    {
     180      return reply;
     181    }
     182
     183  reply = this->readString();
    149184  if (reply == "")
    150   { return reply;
    151   }
     185    {
     186      return reply;
     187    }
    152188
    153189  while(!this->logfile.eof() &&
    154             (c = this->logfile.get()) != '\n')
    155   { this->logfile.putback(c);
    156     array.add(this->readString());
    157   }
     190    (c = this->logfile.get()) != '\n')
     191    {
     192      this->logfile.putback(c);
     193      array.add(this->readString());
     194    }
    158195  if (!this->logfile.eof())
    159   { this->logfile.putback(c);
    160   }
     196    {
     197      this->logfile.putback(c);
     198    }
    161199
    162200  return reply;
     
    164202
    165203string installManager::popCommand(stringArray &array)
    166 { string command;
     204{
     205  string command;
    167206
    168207  if (this->modules[this->currentModule].size() == 0)
    169   { command = "";
    170   }
     208    {
     209      command = "";
     210    }
    171211  else
    172   { unsigned int last;
    173 
    174       last = this->modules[this->currentModule].size() - 1;
    175     command = this->modules[this->currentModule][last].commandName();
    176     array       = this->modules[this->currentModule][last].parameterList();
    177     this->modules[this->currentModule].erase(this->modules[this->currentModule].begin() + last);
    178   }
     212    {
     213      unsigned int last;
     214
     215      last = this->modules[this->currentModule].size() - 1;
     216      command = this->modules[this->currentModule][last].commandName();
     217      array = this->modules[this->currentModule][last].parameterList();
     218      this->modules[this->currentModule].erase(this->modules[this->currentModule].begin() + last);
     219    }
    179220  return command;
    180221}
    181222
    182223bool installManager::closeLog()
    183 { if (this->logfile.rdbuf()->is_open() == false)
    184   { return false;
    185   }
    186 
    187     unInstallCommandMap::iterator here = this->modules.begin();
    188     unInstallCommandMap::iterator end  = this->modules.end();
    189 
     224{
     225  if (this->logfile.rdbuf()->is_open() == false)
     226    {
     227      return false;
     228    }
     229
     230  unInstallCommandMap::iterator here = this->modules.begin();
     231  unInstallCommandMap::iterator end = this->modules.end();
     232 
    190233  while (here != end)
    191   { this->writeString("[" + (*here).first + "]\n");
    192 
    193     unInstallCommandList::iterator  ahere = (*here).second.begin();
    194     unInstallCommandList::iterator  aend  = (*here).second.end();
    195     while (ahere != aend)
    196         { this->writeCommand(*ahere);
    197         ahere ++;
    198     }
    199     here ++;
    200   }
    201     this->logfile.close();
     234    {
     235      this->writeString("[" + (*here).first + "]\n");
     236
     237      unInstallCommandList::iterator ahere = (*here).second.begin();
     238      unInstallCommandList::iterator aend  = (*here).second.end();
     239      while (ahere != aend)
     240    {
     241      this->writeCommand(*ahere);
     242      ahere ++;
     243    }
     244      here ++;
     245    }
     246  this->logfile.close();
    202247  return true;
    203248}
    204249
    205250bool installManager::isEmpty()
    206 { unInstallCommandMap::iterator here = this->modules.begin();
    207     unInstallCommandMap::iterator end  = this->modules.end();
     251{
     252  unInstallCommandMap::iterator here = this->modules.begin();
     253  unInstallCommandMap::iterator end = this->modules.end();
    208254
    209255  while (here != end)
    210   { this->writeString("[" + (*here).first + "]\n");
    211 
    212     unInstallCommandList::iterator  ahere = (*here).second.begin();
    213     unInstallCommandList::iterator  aend  = (*here).second.end();
    214     if (ahere != aend)
    215     {   return false;
    216     }
    217     here ++;
    218   }
     256    {
     257      this->writeString("[" + (*here).first + "]\n");
     258
     259      unInstallCommandList::iterator    ahere = (*here).second.begin();
     260      unInstallCommandList::iterator  aend  = (*here).second.end();
     261      if (ahere != aend)
     262    {
     263      return false;
     264    }
     265      here ++;
     266    }
    219267  return true;
    220268}
    221269
    222270installManager::~installManager()
    223 {   if (this->logfile.rdbuf()->is_open())
    224     {   this->closeLog();
    225   }
    226 }
    227 
    228 
     271{
     272  if (this->logfile.rdbuf()->is_open())
     273    {
     274      this->closeLog();
     275    }
     276}
Note: See TracChangeset for help on using the changeset viewer.