Changeset 1543
- Timestamp:
- 2000-09-13T15:31:38+12:00 (24 years ago)
- Location:
- trunk/gsinstaller
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsinstaller/gsManifest.cpp
r1539 r1543 205 205 206 206 strArrayMap::iterator here = this->manifests.begin(); 207 strArrayMap::iterator end 207 strArrayMap::iterator end = this->manifests.end(); 208 208 209 209 while (here != end) -
trunk/gsinstaller/gsManifest.h
r1539 r1543 31 31 gsManifest(installManager &manager, FilePath &path); // used for install 32 32 gsManifest(installManager &manager); // used for uninstall 33 virtual ~gsManifest () {} 33 34 bool getManifest(FilePath &path); 34 35 void logAction(string actionName, string file); -
trunk/gsinstaller/gsPlatform.cpp
r1541 r1543 7 7 8 8 gsPlatform::gsPlatform() 9 { this->platformInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 10 GetVersionEx(&this->platformInfo); 9 { 10 this->platformInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 11 GetVersionEx(&this->platformInfo); 11 12 } 12 13 13 14 bool gsPlatform::isWindows9x() 14 { return (this->platformInfo.dwPlatformId & VER_PLATFORM_WIN32_WINDOWS); 15 { 16 return (this->platformInfo.dwPlatformId & VER_PLATFORM_WIN32_WINDOWS); 15 17 } 16 18 17 19 bool gsPlatform::isWindowsNT() 18 { return (this->platformInfo.dwPlatformId & VER_PLATFORM_WIN32_NT); 20 { 21 return (this->platformInfo.dwPlatformId & VER_PLATFORM_WIN32_NT); 19 22 } 20 23 21 24 bool gsPlatform::isWindows32s() 22 { return (this->platformInfo.dwPlatformId & VER_PLATFORM_WIN32s); 25 { 26 return (this->platformInfo.dwPlatformId & VER_PLATFORM_WIN32s); 23 27 } 24 28 25 29 bool 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 } 30 36 return false; 31 37 } 32 38 33 39 bool 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 } 38 46 return false; 39 47 } … … 105 113 return false; 106 114 } 107 108 accessMask = ACCESS_READ | ACCESS_WRITE; 109 110 111 115 116 accessMask = ACCESS_READ | ACCESS_WRITE; 117 112 118 // try to add the given item to the Access Control Entry (ACE) list (ACL) 113 119 if (!AddAccessAllowedAce(aclData, ACL_REVISION2, accessMask, adminId)) … … 115 121 return false; 116 122 } 117 123 118 124 // endeavour to add the acl to the discretionary acl (DACL) 119 125 if (!SetSecurityDescriptorDacl(psdAdmin, TRUE, aclData, FALSE)) … … 138 144 if (!AccessCheck (psdAdmin, token, ACCESS_READ, &genericMapping, 139 145 &privilegeSet, &structureSize, &status, &result)) 140 { return false; 141 } 142 146 { 147 return false; 148 } 149 143 150 // end impersonisation 144 151 RevertToSelf(); 145 152 146 153 LocalFree(psdAdmin); 147 154 LocalFree(aclData); … … 159 166 HANDLE token; 160 167 TOKEN_PRIVILEGES tkp; 161 168 162 169 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, 163 170 &token)) … … 165 172 return false; 166 173 } 167 174 168 175 LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); 169 176 -
trunk/gsinstaller/gsProgman.cpp
r1541 r1543 16 16 * but does nothing whatsoever 17 17 */ 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 string23 HSZ hsz2, // handle to a string 24 HDDEDATA hdata, // handle to a global memory object 25 DWORD dwData1,// transaction-specific data26 DWORD dwData2 // transaction-specific data 27 ) 28 {return NULL;18 HDDEDATA 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; 29 29 } 30 30 … … 33 33 */ 34 34 bool 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]; 46 48 sprintf(buffer, "%d %d", DdeGetLastError(instance), instance); 47 48 return FALSE;49 }49 MessageBox(0, buffer, "GSInstall", MB_OK);*/ 50 return FALSE; 51 } 50 52 51 53 // strike up a conversation with the DDE service 52 54 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 77 81 // free DDE string 78 82 DdeFreeStringHandle(instance, serviceName); … … 81 85 82 86 gsProgramManager::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; 86 91 } 87 92 88 93 void 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); 92 98 } 93 99 94 100 void gsProgramManager::logAction(string actionName, string group, string item, string parameter) 95 { unInstallCommand command(actionName); 101 { 102 unInstallCommand command(actionName); 96 103 command.addParameter(group); 97 104 command.addParameter(item); 98 105 command.addParameter(parameter); 99 106 manager->storeCommand(command); … … 101 108 102 109 bool gsProgramManager::undoAction(string actionName, stringArray ¶ms) 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 } 107 116 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 } 111 121 return false; 112 122 } 113 123 114 124 bool 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; 136 151 return true; 137 152 } 138 153 139 154 bool 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; 149 168 return true; 150 169 } 151 170 152 171 bool gsProgramManager::addProgramGroup(string groupName) 153 { //CreateGroup(groupName); 154 char buffer[256]; 172 { 173 //CreateGroup(groupName); 174 char buffer[256]; 155 175 156 176 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 } 190 219 191 220 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 224 bool 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 203 233 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 233 283 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); 251 289 252 290 // store the link in the "persistent" file 253 254 255 256 291 reply = ppf->Save(wsz, TRUE); 292 293 // release the persistent file handle 294 ppf->Release(); 257 295 } 258 296 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 } 281 322 282 323 if (reply) 283 { this->logAction("ProgManAddItem", groupName, iconName, iconDestination); 284 } 324 { 325 this->logAction("ProgManAddItem", groupName, iconName, iconDestination); 326 } 285 327 return reply; 286 328 } 287 329 288 330 bool gsProgramManager::removeProgramGroup(string groupName) 289 { //CreateGroup(groupName); 290 char buffer[256]; 291 331 { 332 //CreateGroup(groupName); 333 char buffer[256]; 334 292 335 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 381 bool 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]; 333 386 334 387 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 } 383 445 return reply; 384 446 } -
trunk/gsinstaller/gsRegistry.h
r1539 r1543 27 27 public: 28 28 gsRegistry(installManager &manager, configureFile &configFileb); 29 virtual ~gsRegistry () {} 29 30 bool storeKeyString(HKEY base, string path, string item, string value); 30 31 bool collectionInstalled(); -
trunk/gsinstaller/gsinstall.cpp
r1541 r1543 213 213 */ 214 214 void GSInstall::getSourcePath() 215 { static char filename[512]; 216 FilePath *exePath; 215 { 216 static char filename[512]; 217 FilePath *exePath; 217 218 218 219 // get the filepath of this executable 219 220 GetModuleFileName(0, filename, 512); 220 exePath 221 exePath = new FilePath(filename); 221 222 222 223 // get the parent (i.e. the folder containing this executable) for the source 223 224 // folder 224 this->sourcePath 225 this->sourcePath = exePath->parent(); 225 226 226 227 // get the gsdl source path 227 this->gsdlSourcePath 228 this->gsdlSourcePath = new FilePath(this->sourcePath->pathString(), "gsdl"); 228 229 delete exePath; 229 230 } … … 235 236 */ 236 237 bool 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 238 240 if (this->installExe) 239 { this->destinationPath->ensureWriteablePath(); 240 } 241 { 242 this->destinationPath->ensureWriteablePath(); 243 } 241 244 242 245 // ensure that the destination path for the collection itself is available 243 246 if (this->installVolume) 244 { this->dataDestPath->ensureWriteablePath(); 245 } 247 { 248 this->dataDestPath->ensureWriteablePath(); 249 } 246 250 247 251 // do the copy 248 252 this->manifest->copy(this->gsdlSourcePath); 249 253 250 254 return true; … … 256 260 */ 257 261 bool 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 } 262 268 263 269 // ensure all pertinent keys already exist for this volume/collection 264 270 this->gsRegister->ensureKeysExist(); 265 271 266 272 // 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 } 318 327 319 328 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 } 322 332 return true; 323 333 } … … 327 337 */ 328 338 void 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(); 332 343 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 } 335 347 else 336 { this->dataDestPath = this->destinationPath; 337 } 348 { 349 this->dataDestPath = this->destinationPath; 350 } 338 351 339 352 // open the log for writing … … 344 357 345 358 bool GSInstall::setUninstall() 346 { char tempPathStr[MAX_PATH]; 359 { 360 char tempPathStr[MAX_PATH]; 347 361 348 362 // if we failed to get the Windows temporary directory, abort 349 363 if (GetTempPath(MAX_PATH, tempPathStr) == 0) 350 { // TODO: abort! 351 return false; 352 } 364 { 365 // TODO: abort! 366 return false; 367 } 353 368 354 369 FilePath tempPath(tempPathStr); … … 357 372 // and the installation log to the temporary directory and run them there 358 373 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 } 376 392 377 393 // open the log for reading from the directory this exe is now in (which … … 380 396 this->openLog(logPath->pathString(), false); 381 397 delete logPath; 382 398 383 399 return true; 384 400 } 385 401 386 402 void GSInstall::uninstall() 387 { FilePath *iniPath; 388 string command; 403 { 404 FilePath *iniPath; 405 string command; 389 406 stringArray params; 390 407 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 } 407 428 } 408 429 … … 411 432 */ 412 433 void 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 } 416 439 if (this->installFullVolume) 417 { this->manifest->selectGroup("collection", *this->dataDestPath); 418 } 440 { 441 this->manifest->selectGroup("collection", *this->dataDestPath); 442 } 419 443 else 420 { this->manifest->selectGroup("database", *this->dataDestPath); 421 } 444 { 445 this->manifest->selectGroup("database", *this->dataDestPath); 446 } 422 447 } 423 448 … … 427 452 */ 428 453 bool GSInstall::updateProgman() 429 { string groupName; 454 { 455 string groupName; 430 456 431 457 // if we managed to get a connection to the program manager (or explorer 432 458 // shell) then do the requisite updates 433 459 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; 446 475 } 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(), "")) 464 480 { 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(), "")) 469 496 { 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 } 478 510 return true; 479 511 } … … 486 518 */ 487 519 bool GSInstall::updateProfiles() 488 { FilePath *exePath; 489 FilePath *dataPath; 520 { 521 FilePath *exePath; 522 FilePath *dataPath; 490 523 FilePath *iniPath; 491 524 … … 493 526 // folder of this installation sequence; if not, then we pick it up from 494 527 // 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 } 498 532 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"); 502 537 503 538 // TODO: check if this 'if' structure is correct; suspect that it isn't quite … … 507 542 // This all needs investigating 508 543 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 547 587 // clean up 548 588 delete iniPath; 549 589 550 590 return true; 551 591 } … … 556 596 */ 557 597 bool GSInstall::updateSetupExe() 558 { FilePath *destExePath; 598 { 599 FilePath *destExePath; 559 600 FilePath srcExeFile(*this->sourcePath, "gssetup.exe"); 560 601 561 if (this->installExe) 562 { destExePath = this->destinationPath; 563 } 602 if (this->installExe) 603 { 604 destExePath = this->destinationPath; 605 } 564 606 else 565 { destExePath = this->collectPath; 566 } 567 FilePath destExeFile(*destExePath, "gssetup.exe"); 607 { 608 destExePath = this->collectPath; 609 } 610 FilePath destExeFile(*destExePath, "gssetup.exe"); 568 611 569 612 if (!CopyFile(srcExeFile.cString(), destExeFile.cString(), false)) 570 { return false; 571 } 613 { 614 return false; 615 } 572 616 return true; 573 617 } 574 618 575 619 bool 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"); 578 623 579 624 launchApp launchNetscape(netscape32Path); 580 625 launchNetscape.platformApp(gsPlatform_WINDOWS32S, netscape16Path); 581 626 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 } 593 639 return true; 594 640 } 595 641 596 642 FilePath *GSInstall::collectionPath() 597 { return this->collectPath; 643 { 644 return this->collectPath; 598 645 } 599 646 600 647 FilePath *GSInstall::installPath() 601 { return this->installToPath; 648 { 649 return this->installToPath; 602 650 } 603 651 604 652 void GSInstall::addSelectedDir(dirSelector *selector) 605 { this->selectedDirs.push_back(selector); 653 { 654 this->selectedDirs.push_back(selector); 606 655 } 607 656 608 657 typedef struct 609 { dirSelector * dirSelect; 658 { 659 dirSelector * dirSelect; 610 660 } GSInstall_dirPathData; 611 661 612 662 HGLOBAL 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); 616 667 return LoadResource(app_instance, resHdl); 617 668 } … … 622 673 int sx, sy; 623 674 int dx, dy; 624 675 625 676 gsInstall_getDesktopExt(&sx, &sy); 626 677 GetWindowRect(dialog, &rect); … … 632 683 633 684 BOOL 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 635 687 // whole wizard; note doing this in the wizard 636 688 // property sheet initialisation DOES NOT WORK 637 689 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; 641 695 642 696 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 } 647 717 } 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 663 720 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"); 667 725 SetDlgItemText(Dialog, dirpath_PATH, ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA))->selectedPath()); 668 726 break; 669 727 670 728 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 680 740 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 700 765 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 716 783 sprintf(buffer, "Directory %s does not exist - create it?", selector->selectedPath()); 717 784 718 719 785 // if the user cancelled that, then don't permit them to go to the next 786 // page of the wizard 720 787 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 } 727 793 } 728 break; 729 794 delete path; 795 } 796 break; 797 730 798 case PSN_WIZFINISH: 731 { // Finish the activity now 732 config_complete = true; 799 { 800 // Finish the activity now 801 config_complete = true; 733 802 } 734 735 736 break;737 }738 803 break; 804 } 805 break; 806 } 807 return FALSE; 739 808 } 740 809 741 810 void 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()); 747 817 data->dirSelect->setFinal(isFinal); 748 818 749 819 // if there is no extant root selector, make this it 750 820 if (rootSelector == NULL) 751 { rootSelector = data->dirSelect; 752 } 821 { 822 rootSelector = data->dirSelect; 823 } 753 824 754 825 // add this directory selector to the installer … … 756 827 757 828 // set up the rest of the page 758 ppage.dwSize= sizeof(PROPSHEETPAGE);759 ppage.dwFlags= PSP_USETITLE;760 ppage.hInstance 761 ppage.pszTemplate 762 ppage.pszIcon 763 ppage.pszTitle 764 ppage.pfnDlgProc 765 ppage.lParam= (LPARAM) data->dirSelect;766 ppage.pfnCallback 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; 767 838 } 768 839 769 840 int 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 773 846 gsInstall_wizard_centre(dialog); 774 775 776 777 778 779 780 781 782 783 847 break ; 848 849 case PSCB_PRECREATE : 850 // Process PSCB_PRECREATE 851 break ; 852 853 default : 854 // Unknown message 855 break ; 856 } 784 857 return 0; 785 858 } … … 847 920 848 921 case WM_USER: 849 {850 851 852 853 // skip past the -u option itself854 char *at = strstr(app_cmdLine, "-u");855 at += strlen("-u");856 857 // extract the log file path from the command line858 while (*at == ' ')859 {860 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 uninstall867 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 { 869 942 install.uninstall(); 870 943 871 944 // close the log to write back all changes to the log; if the file 872 945 // will be deleted, it must be closed; copying may also fail, so it's 873 946 // safer to close it before doing either. 874 947 install.closeLog(); 875 948 876 949 // if the install is empty, terminate all final items (currently the 877 950 // log and setup executables, … … 880 953 // delete the log file 881 954 DeleteFile(logPath.cString()); 882 955 883 956 // get it's parent to find where the gssetup executable will be 884 957 FilePath *logParent = logPath.parent(); 885 958 FilePath uninstallPath(*logParent, "gssetup.exe"); 886 959 887 960 // delete the gssetup executable 888 961 DeleteFile(uninstallPath.cString()); 889 962 890 963 // dispose of the parent directory information 891 964 delete logParent; … … 896 969 // do nothing - should be changed already! 897 970 } 898 }899 }900 901 902 {903 GSInstall install(false);904 GSInstall_init_wizard(install);905 906 {907 908 }909 else910 {911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 }931 } 932 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 936 1009 case WM_CLOSE: 937 1010 /*if (!file_ischanged || IDCANCEL != file_query(Window, file_name))*/ … … 944 1017 } 945 1018 break; 946 1019 947 1020 default: 948 1021 return(DefWindowProc(Window, Message, wParameter, lParameter)); … … 952 1025 953 1026 void 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 969 1043 PostMessage(app_window, WM_USER, 0, 0L); 970 1044 } -
trunk/gsinstaller/launchApp.cpp
r1541 r1543 4 4 5 5 launchApp::launchApp(FilePath &file) 6 { this->exeMap["default"] = file; 6 { 7 this->exeMap["default"] = file; 7 8 } 8 9 9 10 void launchApp::platformApp(string platform, FilePath &file) 10 { this->exeMap[platform] = file; 11 { 12 this->exeMap[platform] = file; 11 13 } 12 14 13 15 void launchApp::setCommandLine(string commandLine) 14 { this->commandline = commandLine; 16 { 17 this->commandline = commandLine; 15 18 } 16 19 17 20 int 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; 21 25 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 } 28 35 } 29 }30 36 31 37 // get the executable for this platform 32 exePath =this->exeMap[platform.platformString()];38 exePath = this->exeMap[platform.platformString()]; 33 39 34 40 // if we didn't get it, get the default 35 41 if (exePath.isEmpty()) 36 { exePath = this->exeMap["default"]; 37 } 42 { 43 exePath = this->exeMap["default"]; 44 } 38 45 39 46 // couldn't find a path 40 47 if (exePath.isEmpty()) 41 { return -1; 42 } 48 { 49 return -1; 50 } 43 51 44 52 // prepare process information fields 45 53 STARTUPINFO startup; 46 PROCESS_INFORMATION 47 startup.cb= sizeof(STARTUPINFO);48 process.hProcess =0;54 PROCESS_INFORMATION process; 55 startup.cb = sizeof(STARTUPINFO); 56 process.hProcess = 0; 49 57 50 58 // build command line if required 51 59 if (this->commandline != "") 52 { runLine = exePath.pathString() + " " + this->commandline; 53 } 60 { 61 runLine = exePath.pathString() + " " + this->commandline; 62 } 54 63 55 64 MessageBox(0, exePath.cString(), runLine.c_str(), MB_OK); 56 65 57 66 // execute the process 58 67 if (CreateProcess((LPSTR) exePath.cString(), 59 68 (runLine != "" && false) ? (LPSTR) runLine.c_str() : NULL, 60 69 NULL, NULL, FALSE, 0, NULL, NULL, 61 70 &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 } 66 76 67 77 if (wait) 68 { WaitForSingleObject(process.hProcess, INFINITE); 69 } 78 { 79 WaitForSingleObject(process.hProcess, INFINITE); 80 } 70 81 71 82 // success: return a positive number -
trunk/gsinstaller/unInstall.cpp
r1525 r1543 6 6 7 7 bool 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 } 14 16 this->logfileName = filename; 15 17 this->logfile.open(filename.c_str(), ios::out | ios::in); 16 18 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 } 27 33 this->setModule("default"); 28 34 return true; … … 30 36 31 37 bool 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 } 35 43 else 36 { this->logfile.close(); 37 } 44 { 45 this->logfile.close(); 46 } 38 47 39 48 this->logfile.open(this->logfileName.c_str(), ios::out | ios::in); … … 42 51 43 52 void installManager::setModule(string moduleName) 44 { this->currentModule = moduleName; 53 { 54 this->currentModule = moduleName; 45 55 } 46 56 47 57 bool 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; 50 61 } 51 62 52 63 bool 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 } 64 80 if (!this->writeString("\n")) 65 { return false; 66 } 81 { 82 return false; 83 } 67 84 return true; 68 85 } 69 86 70 87 bool installManager::writeString(char *buffer) 71 { string s(buffer); 72 return this->writeString(s); 88 { 89 string s(buffer); 90 return this->writeString(s); 73 91 } 74 92 75 93 bool 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 79 98 quote = str.find_first_of(' ') < str.length(); 80 99 81 if (quote)82 { this->logfile << "\"";83 }84 this->logfile << str;85 100 if (quote) 86 { this->logfile << "\""; 87 } 101 { 102 this->logfile << "\""; 103 } 104 this->logfile << str; 105 if (quote) 106 { 107 this->logfile << "\""; 108 } 88 109 return true; 89 110 } 90 111 91 112 bool installManager::writeSeparator() 92 { this->logfile << " "; 93 return true; 113 { 114 this->logfile << " "; 115 return true; 94 116 } 95 117 96 118 string installManager::readString() 97 { string reply = ""; 98 char c; 119 { 120 string reply = ""; 121 char c; 99 122 100 123 if (this->logfile.eof()) 101 { return reply; 102 } 124 { 125 return reply; 126 } 103 127 104 128 this->logfile >> c; 105 129 while (c <= ' ' && !this->logfile.eof()) 106 { this->logfile.get(); 107 } 130 { 131 this->logfile.get(); 132 } 108 133 109 134 if (this->logfile.eof()) 110 { return reply; 111 } 135 { 136 return reply; 137 } 112 138 113 139 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 } 122 151 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 } 135 168 return reply; 136 169 } 137 170 138 171 string installManager::readCommand(stringArray &array) 139 { string reply = ""; 172 { 173 string reply = ""; 140 174 char c; 141 175 … … 143 177 144 178 if (this->logfile.eof()) 145 { return reply; 146 } 147 148 reply = this->readString(); 179 { 180 return reply; 181 } 182 183 reply = this->readString(); 149 184 if (reply == "") 150 { return reply; 151 } 185 { 186 return reply; 187 } 152 188 153 189 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 } 158 195 if (!this->logfile.eof()) 159 { this->logfile.putback(c); 160 } 196 { 197 this->logfile.putback(c); 198 } 161 199 162 200 return reply; … … 164 202 165 203 string installManager::popCommand(stringArray &array) 166 { string command; 204 { 205 string command; 167 206 168 207 if (this->modules[this->currentModule].size() == 0) 169 { command = ""; 170 } 208 { 209 command = ""; 210 } 171 211 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 } 179 220 return command; 180 221 } 181 222 182 223 bool 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 190 233 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(); 202 247 return true; 203 248 } 204 249 205 250 bool 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(); 208 254 209 255 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 } 219 267 return true; 220 268 } 221 269 222 270 installManager::~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.