Changeset 1546 for trunk/gsinstaller
- Timestamp:
- 2000-09-14T03:19:34+12:00 (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsinstaller/unInstall.cpp
r1543 r1546 6 6 7 7 bool installManager::openLog(string filename, bool write) 8 { 9 string command; 10 stringArray params; 11 12 if (this->logfile.rdbuf()->is_open()) 13 { 14 this->closeLog(); 15 } 16 this->logfileName = filename; 17 this->logfile.open(filename.c_str(), ios::out | ios::in); 18 if (write == false) 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 } 8 { string command; 9 stringArray params; 10 11 // close the log if already open 12 if (this->logfile.rdbuf()->is_open()) 13 { this->closeLog(); 31 14 } 32 } 15 16 // note the new file details and do an open 17 this->logfileName = filename; 18 this->logfile.open(filename.c_str(), ios::out | ios::in); 19 20 // if the file didn't open, then this is almost certainly being compiled 21 // with Microsoft Visual C++ which has a library which fails to open the 22 // file if it doesn't already exist. Do a createfile and hope for success. 23 // TODO: add proper error handling here 24 if (!this->logfile.rdbuf()->is_open() && write == true) 25 { HANDLE fHandle; 26 27 fHandle = CreateFile(filename.c_str(), GENERIC_READ | GENERIC_WRITE, 28 FILE_SHARE_WRITE, NULL, CREATE_NEW, 29 FILE_ATTRIBUTE_NORMAL, NULL); 30 if (fHandle) 31 { CloseHandle(fHandle); 32 } 33 this->logfile.open(filename.c_str(), ios::out | ios::in); 34 } 35 36 // if we aren't seeking write access, then get the commands into this 37 // object 38 if (write == false) 39 { while ((command = this->readCommand(params)) != "") 40 { if (command[0] == '[' && command[command.length()-1] == ']') 41 { this->setModule(command.substr(1, command.length() - 2)); 42 } 43 else 44 { unInstallCommand action(command, params); 45 this->storeCommand(action); 46 } 47 } 48 } 49 50 // set to the default module 33 51 this->setModule("default"); 34 52 return true; … … 36 54 37 55 bool installManager::reopenLog() 38 { 39 if (this->logfile.rdbuf()->is_open()) 40 { 41 this->logfile.close(); 42 } 56 { if (this->logfile.rdbuf()->is_open()) 57 { this->logfile.close(); 58 } 43 59 else 44 { 45 this->logfile.close(); 46 } 60 { this->logfile.close(); 61 } 47 62 48 63 this->logfile.open(this->logfileName.c_str(), ios::out | ios::in); … … 51 66 52 67 void installManager::setModule(string moduleName) 53 { 54 this->currentModule = moduleName; 68 { this->currentModule = moduleName; 55 69 } 56 70 57 71 bool installManager::storeCommand(unInstallCommand &command) 58 { 59 this->modules[this->currentModule].push_back(command); 60 return true; 72 { this->modules[this->currentModule].push_back(command); 73 return true; 61 74 } 62 75 63 76 bool installManager::writeCommand(unInstallCommand &command) 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 } 77 { if (!this->writeString(command.command)) 78 { return false; 79 } 80 for (unsigned int p = 0; p < command.parameters.size(); p ++) 81 { if (!this->writeSeparator()) 82 { return false; 83 } 84 if (!this->writeString(command.parameters[p])) 85 { return false; 86 } 87 } 80 88 if (!this->writeString("\n")) 81 { 82 return false; 83 } 89 { return false; 90 } 84 91 return true; 85 92 } 86 93 87 94 bool installManager::writeString(char *buffer) 88 { 89 string s(buffer); 90 return this->writeString(s); 95 { string s(buffer); 96 return this->writeString(s); 91 97 } 92 98 93 99 bool installManager::writeString(string str) 94 { 95 bool quote; 96 97 // TODO: check for space characters in str and quote if necessary 100 { bool quote; 101 102 // TODO: check for space characters in str and quote if necessary 98 103 quote = str.find_first_of(' ') < str.length(); 99 104 105 if (quote) 106 { this->logfile << "\""; 107 } 108 this->logfile << str; 100 109 if (quote) 101 { 102 this->logfile << "\""; 103 } 104 this->logfile << str; 105 if (quote) 106 { 107 this->logfile << "\""; 108 } 110 { this->logfile << "\""; 111 } 109 112 return true; 110 113 } 111 114 112 115 bool installManager::writeSeparator() 113 { 114 this->logfile << " "; 115 return true; 116 { this->logfile << " "; 117 return true; 116 118 } 117 119 118 120 string installManager::readString() 119 { 120 string reply = ""; 121 char c; 121 { string reply = ""; 122 char c; 122 123 123 124 if (this->logfile.eof()) 124 { 125 return reply; 126 } 125 { return reply; 126 } 127 127 128 128 this->logfile >> c; 129 129 while (c <= ' ' && !this->logfile.eof()) 130 { 131 this->logfile.get(); 132 } 130 { this->logfile.get(); 131 } 133 132 134 133 if (this->logfile.eof()) 135 { 136 return reply; 137 } 134 { return reply; 135 } 138 136 139 137 if (c == '\"') 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 } 138 { do 139 { c = this->logfile.get(); 140 if (c != '\"') 141 { reply += c; 142 } 143 } 144 while (c != '\"' && !this->logfile.eof()); 145 } 151 146 else 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 } 147 { while (c > ' ') 148 { reply += c; 149 if (this->logfile.eof()) 150 { break; 151 } 152 c = this->logfile.get(); 153 } 154 if (!this->logfile.eof()) 155 { this->logfile.putback(c); 156 } 157 //this->logfile >> reply; 158 } 168 159 return reply; 169 160 } 170 161 171 162 string installManager::readCommand(stringArray &array) 172 { 173 string reply = ""; 163 { string reply = ""; 174 164 char c; 175 165 … … 177 167 178 168 if (this->logfile.eof()) 179 { 180 return reply; 181 } 182 183 reply = this->readString(); 169 { return reply; 170 } 171 172 reply = this->readString(); 184 173 if (reply == "") 185 { 186 return reply; 187 } 174 { return reply; 175 } 188 176 189 177 while(!this->logfile.eof() && 190 (c = this->logfile.get()) != '\n') 191 { 192 this->logfile.putback(c); 193 array.add(this->readString()); 194 } 178 (c = this->logfile.get()) != '\n') 179 { this->logfile.putback(c); 180 array.add(this->readString()); 181 } 195 182 if (!this->logfile.eof()) 196 { 197 this->logfile.putback(c); 198 } 183 { this->logfile.putback(c); 184 } 199 185 200 186 return reply; … … 202 188 203 189 string installManager::popCommand(stringArray &array) 204 { 205 string command; 190 { string command; 206 191 207 192 if (this->modules[this->currentModule].size() == 0) 208 { 209 command = ""; 210 } 193 { command = ""; 194 } 211 195 else 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 } 196 { unsigned int last; 197 198 last = this->modules[this->currentModule].size() - 1; 199 command = this->modules[this->currentModule][last].commandName(); 200 array = this->modules[this->currentModule][last].parameterList(); 201 this->modules[this->currentModule].erase(this->modules[this->currentModule].begin() + last); 202 } 220 203 return command; 221 204 } 222 205 223 206 bool installManager::closeLog() 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 207 { if (this->logfile.rdbuf()->is_open() == false) 208 { return false; 209 } 210 211 unInstallCommandMap::iterator here = this->modules.begin(); 212 unInstallCommandMap::iterator end = this->modules.end(); 213 233 214 while (here != end) 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(); 215 { this->writeString("[" + (*here).first + "]\n"); 216 217 unInstallCommandList::iterator ahere = (*here).second.begin(); 218 unInstallCommandList::iterator aend = (*here).second.end(); 219 while (ahere != aend) 220 { this->writeCommand(*ahere); 221 ahere ++; 222 } 223 here ++; 224 } 225 this->logfile.close(); 247 226 return true; 248 227 } 249 228 250 229 bool installManager::isEmpty() 251 { 252 unInstallCommandMap::iterator here = this->modules.begin(); 253 unInstallCommandMap::iterator end = this->modules.end(); 230 { unInstallCommandMap::iterator here = this->modules.begin(); 231 unInstallCommandMap::iterator end = this->modules.end(); 254 232 255 233 while (here != end) 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 } 234 { this->writeString("[" + (*here).first + "]\n"); 235 236 unInstallCommandList::iterator ahere = (*here).second.begin(); 237 unInstallCommandList::iterator aend = (*here).second.end(); 238 if (ahere != aend) 239 { return false; 240 } 241 here ++; 242 } 267 243 return true; 268 244 } 269 245 270 246 installManager::~installManager() 271 { 272 if (this->logfile.rdbuf()->is_open()) 273 {274 this->closeLog(); 275 } 276 } 247 { if (this->logfile.rdbuf()->is_open()) 248 { this->closeLog(); 249 } 250 } 251 252
Note:
See TracChangeset
for help on using the changeset viewer.