Changeset 1498 for trunk/gsinstaller
- Timestamp:
- 2000-09-05T03:30:48+12:00 (24 years ago)
- Location:
- trunk/gsinstaller
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsinstaller/FilePath.cpp
r1475 r1498 96 96 } 97 97 98 /** 99 * Construct a Filepath from a directory and a sub-directory path 100 */ 101 FilePath::FilePath(string filePath, string subPath) 98 void FilePath::_init(string filePath, string subPath) 102 99 { // copy the directory path 103 100 this->path = filePath; … … 123 120 } 124 121 122 /** 123 * Construct a Filepath from a directory and a sub-directory path 124 */ 125 FilePath::FilePath(string filePath, string subPath) 126 { this->_init(filePath, subPath); 127 } 128 129 FilePath::FilePath(FilePath &path, string subPath) 130 { this->_init(path.pathString(), subPath); 131 } 132 125 133 FilePath::FilePath(string filePath) 126 134 { if (filePath.length() < 3) … … 130 138 else 131 139 { this->path = filePath; 140 141 // trim trailing directory separators 142 if (this->path[this->path.length() - 1] == '\\') 143 { this->path = this->path.substr(0, this->path.length() - 1); 144 } 132 145 } 133 146 -
trunk/gsinstaller/FilePath.h
r1397 r1498 8 8 string path; // full path of this item 9 9 bool is_aRoot; // indicates whether this directory/file is a file root 10 void _init(string path, string subPath); 10 11 public: 11 12 FilePath(); … … 13 14 FilePath(string filePath, string filePath2); 14 15 FilePath(int nPaths, ...); 16 FilePath(FilePath &path, string subPath); 15 17 bool equals(FilePath &path); 16 18 bool equals(const char *path); … … 27 29 string pathString(); 28 30 bool operator==(const FilePath &b) { return this->path == b.path; } 31 bool operator!=(const FilePath &b) { return this->path != b.path; } 29 32 bool operator<(const FilePath &b) { return this->path < b.path; } 30 33 }; -
trunk/gsinstaller/fileCopier.cpp
r1475 r1498 116 116 // this->copied += file->getRawFileSize(); 117 117 118 // note for uninstall the action done 119 if (monitor != NULL) 120 { monitor->copied(file->getFileName(), thisDestDir, true); 121 } 122 118 123 // copy children 119 124 vector<File>::iterator here = file->childBegin(); … … 123 128 here ++; 124 129 } 125 126 if (monitor != NULL)127 { monitor->copied(file->getFileName(), thisDestDir, true);128 }129 130 130 131 // delete constructed destination name -
trunk/gsinstaller/gsManifest.cpp
r1475 r1498 248 248 249 249 void gsManifest::logAction(string actionName, string file) 250 { manager->writeString(actionName); 251 manager->writeSeparator(); 252 manager->writeString(file); 253 manager->writeString("\n"); 250 { unInstallCommand command(actionName); 251 command.addParameter(file); 252 manager->storeCommand(command); 254 253 } 255 254 256 255 void gsManifest::logAction(string actionName, string source, string dest) 257 { manager->writeString(actionName); 258 manager->writeSeparator(); 259 manager->writeString(source); 260 manager->writeSeparator(); 261 manager->writeString(dest); 262 manager->writeString("\n"); 256 { unInstallCommand command(actionName); 257 command.addParameter(source); 258 command.addParameter(dest); 259 manager->storeCommand(command); 263 260 } 264 261 -
trunk/gsinstaller/gsProfile.cpp
r1475 r1498 10 10 void gsProfile::logAction(string action, string sectionName, string item, 11 11 string value) 12 { manager->writeString(action); 13 manager->writeSeparator(); 14 manager->writeString(this->fileName); 15 manager->writeSeparator(); 16 manager->writeString(sectionName); 17 manager->writeSeparator(); 18 manager->writeString(item); 19 manager->writeSeparator(); 20 manager->writeString(value); 21 manager->writeString("\n"); 12 { unInstallCommand command(action); 13 command.addParameter(this->fileName); 14 command.addParameter(sectionName); 15 command.addParameter(item); 16 command.addParameter(value); 17 manager->storeCommand(command); 22 18 } 23 19 -
trunk/gsinstaller/gsProgman.cpp
r1475 r1498 87 87 88 88 void gsProgramManager::logAction(string actionName, string group) 89 { manager->writeString(actionName); 90 manager->writeSeparator(); 91 manager->writeString(group); 92 manager->writeString("\n"); 89 { unInstallCommand command(actionName); 90 command.addParameter(group); 91 manager->storeCommand(command); 93 92 } 94 93 95 94 void gsProgramManager::logAction(string actionName, string group, string item, string parameter) 96 { manager->writeString(actionName); 97 manager->writeSeparator(); 98 manager->writeString(group); 99 manager->writeSeparator(); 100 manager->writeString(item); 101 manager->writeSeparator(); 102 manager->writeString(parameter); 103 manager->writeString("\n"); 95 { unInstallCommand command(actionName); 96 command.addParameter(group); 97 command.addParameter(item); 98 command.addParameter(parameter); 99 manager->storeCommand(command); 104 100 } 105 101 … … 109 105 return true; 110 106 } 111 else if (actionName == "ProgManAddI con")107 else if (actionName == "ProgManAddItem") 112 108 { this->removeIcon(params[0], params[1]); 113 109 return true; … … 211 207 fullPath = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), ".lnk"); 212 208 209 // check if the shortcut already exists then don't create this again 210 if (fullPath->exists()) 211 { delete fullPath; 212 return true; 213 } 214 213 215 // Get a pointer to the IShellLink interface. 214 216 hres = CoCreateInstance(CLSID_ShellLink, NULL, … … 241 243 psl->Release(); 242 244 } 245 delete fullPath; 243 246 } 244 247 else … … 317 320 } 318 321 322 // get path of folder from shell 319 323 SHGetPathFromIDList(pidl, buffer); 320 fullPath = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), "!.lnk"); 321 322 // TODO: delete file 324 325 // delete file 326 fullPath = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), "!.lnk"); 327 if (!DeleteFile(fullPath->cString())) 328 { reply = false; 329 } 330 delete fullPath; 323 331 } 324 332 else -
trunk/gsinstaller/gsRegistry.cpp
r1475 r1498 3 3 gsRegistry::gsRegistry(installManager &manager, configureFile &configFile) 4 4 : installAgent(manager) 5 { unsigned int space; 6 7 // Create string for volume key 5 { // Create string for volume key 8 6 volumeKey = "Software\\" + configFile.getString("CompanyName") + "\\" + 9 7 configFile.getString("CollectionName") + "\\" + … … 18 16 19 17 bool gsRegistry::logAction(string action, HKEY base, string path, string item, string value) 20 { manager->writeString(action); 21 manager->writeSeparator(); 22 manager->writeString(path); 18 { unInstallCommand command(action); 19 command.addParameter(path); 23 20 if (item != "" || value != "") 24 { manager->writeSeparator(); 25 if (item == "") 26 { manager->writeString("{Default}"); 21 { if (item == "") 22 { command.addParameter("{Default}"); 27 23 } 28 24 else 29 { manager->writeString(item);25 { command.addParameter(item); 30 26 } 31 manager->writeSeparator(); 32 manager->writeString(value); 27 command.addParameter(value); 33 28 } 34 manager->writeString("\n");29 return manager->storeCommand(command); 35 30 } 36 31 … … 66 61 67 62 bool gsRegistry::destroyKey(HKEY base, string key) 68 { re gistry_deletekey(base, key.c_str());63 { return registry_deletekey(base, key.c_str()); 69 64 } 70 65 … … 92 87 registry_deleteitem(local, item.c_str()); 93 88 registry_closekey(local); 89 return true; 94 90 } 95 91 -
trunk/gsinstaller/gsinstall.cpp
r1475 r1498 67 67 bool installNetscape(); 68 68 void setDestination(); 69 voidsetUninstall();69 bool setUninstall(); 70 70 void uninstall(); 71 71 void setManifest(); … … 320 320 } 321 321 322 void GSInstall::setUninstall() 323 { 324 // open the log for reading 325 FilePath *logPath = new FilePath(this->collectPath->pathString(), "install.log"); 322 bool GSInstall::setUninstall() 323 { char tempPathStr[MAX_PATH]; 324 325 // if we failed to get the Windows temporary directory, abort 326 if (GetTempPath(MAX_PATH, tempPathStr) == 0) 327 { // TODO: abort! 328 return false; 329 } 330 331 FilePath tempPath(tempPathStr); 332 333 // if we are not running in the Windows temporary directory, copy this exe 334 // and the installation log to the temporary directory and run them there 335 if (*this->sourcePath != tempPath) 336 { // copy this and install.log to temporary directory and restart 337 FilePath exePath(*this->sourcePath, "gssetup.exe"); 338 FilePath logPath(*this->sourcePath, "install.log"); 339 340 FilePath exeDest(tempPath, "gssetup.exe"); 341 FilePath logDest(tempPath, "install.log"); 342 343 CopyFile(exePath.cString(), exeDest.cString(), false); 344 CopyFile(logPath.cString(), logDest.cString(), false); 345 346 // now run the gssetup in the temporary directory 347 launchApp launchUninstall(exeDest); 348 launchUninstall.setCommandLine(" -u " + logPath.pathString()); 349 launchUninstall.run(false, 0, "", "", false); 350 351 return false; 352 } 353 354 // open the log for reading from the directory this exe is now in (which 355 // will in fact be the temporary directory as outlined above) 356 FilePath *logPath = new FilePath(this->sourcePath->pathString(), "install.log"); 326 357 this->openLog(logPath->pathString(), false); 327 358 delete logPath; 359 360 return true; 328 361 } 329 362 … … 338 371 gsProfile gsdlProfile(*this, iniPath->pathString()); 339 372 340 while ((command = this-> readCommand(params)) != "")373 while ((command = this->popCommand(params)) != "") 341 374 { if (!this->manifest->undoAction(command, params)) 342 375 { if (!gsdlProfile.undoAction(command, params)) … … 752 785 case WM_USER: 753 786 { // uninstall action 754 if (strstr(app_cmdLine, "-u") != NULL || true) 755 { char *at = strstr(app_cmdLine, "-u"); 756 at += strlen("-u") + 1; 787 if (strstr(app_cmdLine, "-u") != NULL) 788 { // skip past the -u option itself 789 char *at = strstr(app_cmdLine, "-u"); 790 at += strlen("-u"); 791 792 // extract the log file path from the command line 793 while (*at == ' ') 794 { at ++; 795 } 796 string logPathString(at); 797 FilePath logPath(logPathString); 757 798 758 799 GSInstall install(true); 759 install.setUninstall(); 760 install.uninstall(); 800 // if we're running in the temporary directory, do the uninstall 801 if (install.setUninstall()) 802 { install.uninstall(); 803 804 // close the log to write back all changes to the log; if the file 805 // will be deleted, it must be closed; copying may also fail, so it's 806 // safer to close it before doing either. 807 install.closeLog(); 808 809 // if the install is empty, terminate all final items (currently the 810 // log and setup executables, 811 if (install.isEmpty()) 812 { // delete the log file 813 DeleteFile(logPath.cString()); 814 815 // get it's parent to find where the gssetup executable will be 816 FilePath *logParent = logPath.parent(); 817 FilePath uninstallPath(*logParent, "gssetup.exe"); 818 819 // delete the gssetup executable 820 DeleteFile(uninstallPath.cString()); 821 822 // dispose of the parent directory information 823 delete logParent; 824 } 825 // if not, then overwrite the original log with the modified one 826 else 827 { // do nothing - should be changed already! 828 } 829 } 761 830 } 762 831 // install wizard … … 777 846 install.updateRegistry(); 778 847 install.updateProfiles(); 848 849 // the log will need reopening (probably failed initially) 850 install.reopenLog(); 851 852 // close log 853 install.closeLog(); 779 854 780 855 // do further actions -
trunk/gsinstaller/launchApp.cpp
r1397 r1498 11 11 } 12 12 13 void launchApp::setCommandLine(string commandLine) 14 { this->commandline = commandLine; 15 } 16 13 17 int launchApp::run(bool test, int deftest, string prompt, string header, bool wait) 14 18 { gsPlatform platform; 15 19 FilePath exePath; 20 string runLine; 16 21 17 22 if (test) … … 43 48 process.hProcess = 0; 44 49 50 // build command line if required 51 if (this->commandline != "") 52 { runLine = exePath.pathString() + " " + this->commandline; 53 } 54 45 55 // execute the process 46 if (CreateProcess(exePath.cString(), NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &process) == 0) 56 if (CreateProcess((LPSTR) exePath.cString(), 57 runLine != "" ? (LPSTR) runLine.c_str() : NULL, 58 NULL, NULL, FALSE, 0, NULL, NULL, 59 &startup, &process) == 0) 47 60 { DWORD error = GetLastError(); 48 61 return -2; -
trunk/gsinstaller/launchApp.h
r1397 r1498 12 12 { private: 13 13 _exeMap exeMap; 14 string commandline; 14 15 public: 15 16 launchApp(FilePath &appsrc); 16 17 void platformApp(string platform, FilePath &appsrc); 18 void setCommandLine(string commands); 17 19 int run(bool test, int deftest, string prompt, string title, bool wait); 18 20 }; -
trunk/gsinstaller/stringArray.cpp
r1475 r1498 146 146 } 147 147 148 string stringArray::toString(string separator) 149 { string reply; 150 151 vector<string>::iterator here = this->array.begin(); 152 vector<string>::iterator end = this->array.end(); 153 while (here != end) 154 { if (here != this->array.begin()) 155 { reply += separator; 156 } 157 reply += *here; 158 } 159 return reply; 160 } 161 148 162 stringArray stringArray::words(char *buffer) 149 163 { stringArray reply; … … 176 190 void stringArray::clear() 177 191 { this->array.empty(); 192 this->array.erase(this->array.begin(), this->array.end()); 178 193 } 179 194 -
trunk/gsinstaller/stringArray.h
r1475 r1498 28 28 int indexOf(string member); 29 29 int writeToCString(char *buffer, char *divider, int bufflen); 30 string toString(string separator); 30 31 string &operator[](const unsigned int); 31 32 }; -
trunk/gsinstaller/unInstall.cpp
r1475 r1498 6 6 7 7 bool installManager::openLog(string filename, bool write) 8 { if (this->logfile.rdbuf()->is_open()) 9 { this->logfile.close(); 10 } 11 this->logfile.open(filename.c_str(), (write ? ios::out : ios::in) | ios::app); 8 { string command; 9 stringArray params; 10 11 if (this->logfile.rdbuf()->is_open()) 12 { this->closeLog(); 13 } 14 this->logfileName = filename; 15 this->logfile.open(filename.c_str(), ios::out | ios::in); 16 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 } 27 this->setModule("default"); 28 return true; 29 } 30 31 bool installManager::reopenLog() 32 { if (this->logfile.rdbuf()->is_open()) 33 { this->logfile.close(); 34 } 35 else 36 { this->logfile.close(); 37 } 38 39 this->logfile.open(this->logfileName.c_str(), ios::out | ios::in); 40 return true; 12 41 } 13 42 … … 16 45 } 17 46 47 bool installManager::storeCommand(unInstallCommand &command) 48 { this->modules[this->currentModule].push_back(command); 49 return true; 50 } 51 52 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 if (!this->writeString("\n")) 65 { return false; 66 } 67 return true; 68 } 69 18 70 bool installManager::writeString(char *buffer) 19 71 { string s(buffer); 20 this->writeString(s);72 return this->writeString(s); 21 73 } 22 74 … … 43 95 44 96 string installManager::readString() 45 { string reply ;97 { string reply = ""; 46 98 char c; 47 99 100 if (this->logfile.eof()) 101 { return reply; 102 } 103 48 104 this->logfile >> c; 49 while (c <= ' ' )105 while (c <= ' ' && !this->logfile.eof()) 50 106 { this->logfile.get(); 51 107 } 108 109 if (this->logfile.eof()) 110 { return reply; 111 } 112 52 113 if (c == '\"') 53 114 { do … … 57 118 } 58 119 } 59 while (c != '\"' );120 while (c != '\"' && !this->logfile.eof()); 60 121 } 61 122 else 62 { /*while (c > ' ')123 { while (c > ' ') 63 124 { reply += c; 125 if (this->logfile.eof()) 126 { break; 127 } 64 128 c = this->logfile.get(); 65 }*/ 66 this->logfile.putback(c); 67 this->logfile >> reply; 129 } 130 if (!this->logfile.eof()) 131 { this->logfile.putback(c); 132 } 133 //this->logfile >> reply; 68 134 } 69 135 return reply; … … 71 137 72 138 string installManager::readCommand(stringArray &array) 73 { string reply ;139 { string reply = ""; 74 140 char c; 75 141 76 142 array.clear(); 77 143 144 if (this->logfile.eof()) 145 { return reply; 146 } 147 78 148 reply = this->readString(); 79 while((c = this->logfile.get()) != '\n') 149 if (reply == "") 150 { return reply; 151 } 152 153 while(!this->logfile.eof() && 154 (c = this->logfile.get()) != '\n') 80 155 { this->logfile.putback(c); 81 array.add(this->readString()); 82 } 83 this->logfile.putback(c); 156 array.add(this->readString()); 157 } 158 if (!this->logfile.eof()) 159 { this->logfile.putback(c); 160 } 84 161 85 162 return reply; 163 } 164 165 string installManager::popCommand(stringArray &array) 166 { string command; 167 168 if (this->modules[this->currentModule].size() == 0) 169 { command = ""; 170 } 171 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 } 179 return command; 180 } 181 182 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 190 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(); 202 return true; 203 } 204 205 bool installManager::isEmpty() 206 { unInstallCommandMap::iterator here = this->modules.begin(); 207 unInstallCommandMap::iterator end = this->modules.end(); 208 209 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 } 219 return true; 86 220 } 87 221 88 222 installManager::~installManager() 89 223 { if (this->logfile.rdbuf()->is_open()) 90 { this-> logfile.close();224 { this->closeLog(); 91 225 } 92 226 } -
trunk/gsinstaller/unInstall.h
r1475 r1498 13 13 static string uninstall_ALL = "all"; 14 14 15 typedef struct unInstallCommand 16 { string command; 17 stringArray parameters; 15 typedef class unInstallCommand 16 { public: 17 string command; 18 stringArray parameters; 19 20 unInstallCommand() { }; 21 unInstallCommand(string commandname) { this->command = commandname; }; 22 unInstallCommand(string commandname, stringArray params) 23 { this->command = commandname; 24 this->parameters = params; 25 }; 26 void addParameter(string parameter) { this->parameters.add(parameter); }; 27 string commandName() { return this->command; }; 28 stringArray ¶meterList() { return this->parameters; }; 18 29 } unInstallCommand; 19 30 … … 24 35 class installManager 25 36 { private: 26 fstream logfile; 27 string currentModule; 28 public: 29 installManager() { }; 30 bool openLog(string filename, bool write); 31 void setModule(string moduleName); 37 fstream logfile; 38 string logfileName; 39 string currentModule; 40 unInstallCommandMap modules; 41 32 42 bool writeString(string str); 33 43 bool writeString(char *string); 34 44 bool writeSeparator(); 35 45 string readString(); 46 bool writeCommand(unInstallCommand &command); 36 47 string readCommand(stringArray ¶ms); 48 public: 49 installManager() { }; 50 bool openLog(string filename, bool write); 51 bool closeLog(); 52 bool reopenLog(); 53 void setModule(string moduleName); 54 bool storeCommand(unInstallCommand &command); 55 string popCommand(stringArray ¶ms); 56 bool isEmpty(); 37 57 ~installManager(); 38 58 };
Note:
See TracChangeset
for help on using the changeset viewer.