Changeset 1536 for trunk/gsinstaller
- Timestamp:
- 2000-09-11T17:29:32+12:00 (24 years ago)
- Location:
- trunk/gsinstaller
- Files:
-
- 3 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsinstaller/FilePath.cpp
r1498 r1536 6 6 #include <stdarg.h> 7 7 #include <stdio.h> 8 #include <dir.h> 8 //#include <dir.h> 9 #include <direct.h> 9 10 10 11 static char divider = '\\'; … … 12 13 13 14 bool __pathIsAValidRoot(string path) 14 { DWORD driveMask; 15 int driveNum; 15 { 16 DWORD driveMask; 17 int driveNum; 16 18 17 19 if (path.length() > 3) 18 { return false; 19 } 20 21 if (path[1] != ':' || !isalpha(path[0])) 22 { return false; 23 } 20 { 21 return false; 22 } 23 24 if (path[1] != ':' || !isalpha(path[0])) 25 { 26 return false; 27 } 28 24 29 if (isupper(path[0])) 25 { driveNum = path[0] - 'A'; 26 } 27 else 28 { driveNum = path[0] - 'a'; 29 } 30 { 31 driveNum = path[0] - 'A'; 32 } 33 34 else 35 { 36 driveNum = path[0] - 'a'; 37 } 38 30 39 if (driveNum > 25) 31 { return false; 32 } 40 { 41 return false; 42 } 43 33 44 driveMask = GetLogicalDrives(); 45 34 46 if ((driveMask & (1 << driveNum)) != (1 << driveNum)) 35 { return false; 36 } 47 { 48 return false; 49 } 50 37 51 return true; 38 52 } 39 53 40 FilePath::FilePath() 41 { 42 } 54 FilePath::FilePath() {} 43 55 44 56 FilePath::FilePath(int npaths, ...) 45 { va_list list; 46 string* pathArray; 47 48 pathArray = new string[npaths]; 57 { 58 va_list list; 59 string* pathArray; 60 61 pathArray = new string[npaths]; 49 62 50 63 // initialise use of variable parameters … … 52 65 53 66 if (pathArray) 54 { for (int i = 0; i < npaths; i ++) 55 { // get next parameter (guaranteed to be a char * by caller!!!) 56 pathArray[i] = va_arg(list, char *); 57 58 // discount leading slashes 59 if (pathArray[i][0] == divider) 60 { pathArray[i] = pathArray[i].substr(1); 61 } 62 63 // get rid of terminating slashes if present 64 if (pathArray[i][pathArray[i].length() - 1] == divider) 65 { pathArray[i] = pathArray[i].substr(0, pathArray[i].length() - 1); 66 } 67 } 68 } 67 { 68 for (int i = 0; i < npaths; i ++) 69 { 70 // get next parameter (guaranteed to be a char * by caller!!!) 71 pathArray[i] = va_arg(list, char *); 72 73 // discount leading slashes 74 if (pathArray[i][0] == divider) 75 { 76 pathArray[i] = pathArray[i].substr(1); 77 } 78 79 // get rid of terminating slashes if present 80 if (pathArray[i][pathArray[i].length() - 1] == divider) 81 { 82 pathArray[i] = pathArray[i].substr(0, pathArray[i].length() - 1); 83 } 84 } 85 } 69 86 70 87 // end of variable arguments 71 88 va_end(list); 72 89 73 90 // construct path in the usual manner 74 91 if (npaths > 0) 75 { this->path = pathArray[0]; 76 } 92 { 93 this->path = pathArray[0]; 94 } 95 77 96 for (int i = 1; i < npaths; i ++) 78 { // don't add slashes if suppressed 79 if (pathArray[i][0] != '!') 80 { this->path.append("\\"); 81 this->path.append(pathArray[i]); 82 } 83 // if slashes suppressed, skip the magic character 84 else 85 { this->path.append(pathArray[i].substr(1)); 86 } 87 } 97 { 98 // don't add slashes if suppressed 99 if (pathArray[i][0] != '!') 100 { 101 this->path.append("\\"); 102 this->path.append(pathArray[i]); 103 } 104 105 // if slashes suppressed, skip the magic character 106 else 107 { 108 this->path.append(pathArray[i].substr(1)); 109 } 110 } 88 111 89 112 // destroy temporary array 90 113 if (pathArray) 91 { delete[] pathArray; 92 } 114 { 115 delete[] pathArray; 116 } 93 117 94 118 // set if this is a valid root (unlikely in this circumstance) … … 97 121 98 122 void FilePath::_init(string filePath, string subPath) 99 { // copy the directory path 123 { 124 // copy the directory path 100 125 this->path = filePath; 101 126 … … 103 128 // filePath is empty, we're not actually going to add any divider at 104 129 // all 130 105 131 if (filePath.length() > 0 && 106 132 this->path[filePath.length()-1] != divider) 107 { this->path.append(dividerStr); 133 { 134 this->path.append(dividerStr); 108 135 } 109 136 110 137 // copy in the subdirectory path, eliminating any leading divider 111 138 if (subPath[0] != divider) 112 { this->path.append(subPath); 113 } 114 else 115 { this->path.append(subPath.substr(1)); 116 } 117 118 // set if this is a valid root (unlikely when joining two paths) 139 { 140 this->path.append(subPath); 141 } 142 else 143 { 144 this->path.append(subPath.substr(1)); 145 } 146 147 // set if this is a valid root (unlikely when joining two paths) 119 148 this->is_aRoot = __pathIsAValidRoot(this->path); 120 149 } … … 123 152 * Construct a Filepath from a directory and a sub-directory path 124 153 */ 154 125 155 FilePath::FilePath(string filePath, string subPath) 126 { this->_init(filePath, subPath); 156 { 157 this->_init(filePath, subPath); 127 158 } 128 159 129 160 FilePath::FilePath(FilePath &path, string subPath) 130 { this->_init(path.pathString(), subPath); 161 { 162 this->_init(path.pathString(), subPath); 131 163 } 132 164 133 165 FilePath::FilePath(string filePath) 134 { if (filePath.length() < 3) 135 { this->path = filePath; 136 this->path.append("\\"); 137 } 138 else 139 { this->path = filePath; 140 141 // trim trailing directory separators 142 if (this->path[this->path.length() - 1] == '\\') 143 { this->path = this->path.substr(0, this->path.length() - 1); 144 } 145 } 166 { 167 if (filePath.length() < 3) 168 { 169 this->path = filePath; 170 this->path.append("\\"); 171 } 172 else 173 { 174 this->path = filePath; 175 176 // trim trailing directory separators 177 if (this->path[this->path.length() - 1] == '\\') 178 { 179 this->path = this->path.substr(0, this->path.length() - 1); 180 } 181 } 146 182 147 183 // check for a valid root … … 150 186 151 187 bool FilePath::isEmpty() 152 { return this->path.length() == 0; 188 { 189 return this->path.length() == 0; 153 190 } 154 191 155 192 bool FilePath::isRoot() 156 { return this->is_aRoot; 193 { 194 return this->is_aRoot; 157 195 } 158 196 159 197 bool FilePath::equals(FilePath &other) 160 { if (this->path.compare(other.path) == 0) 161 { return true; 162 } 198 { 199 if (this->path.compare(other.path) == 0) 200 { 201 return true; 202 } 203 163 204 return false; 164 205 } 165 206 166 207 bool FilePath::equals(const char *other) 167 { if (strcmp(this->path.c_str(), other) == 0) 168 { return true; 169 } 208 { 209 if (strcmp(this->path.c_str(), other) == 0) 210 { 211 return true; 212 } 213 170 214 return false; 171 215 } … … 175 219 */ 176 220 FilePath *FilePath::rootDrive() 177 { FilePath *reply = this->root(); 178 179 if (reply->path.length() >= 2 && 180 reply->path[1] == ':' && 221 { 222 FilePath *reply = this->root(); 223 224 if (reply->path.length() >= 2 && 225 reply->path[1] == ':' && 181 226 isalpha(reply->path[0])) // if this is a drive letter destination 182 { reply->path = reply->path.substr(0, 2); 183 } 184 else 185 { reply->path = ""; 227 { 228 reply->path = reply->path.substr(0, 2); 229 } 230 else 231 { 232 reply->path = ""; 186 233 } 187 234 return reply; … … 192 239 */ 193 240 FilePath *FilePath::root() 194 { // TODO: cope with network destinations 195 FilePath *reply = new FilePath(this->path); 241 { 242 // TODO: cope with network destinations 243 FilePath *reply = new FilePath(this->path); 196 244 197 245 unsigned int truncate = reply->path.find(divider); 198 246 if (truncate != -1) // if it's got a divider then skip past it; 199 // we will assume that it's a drive letter first 200 { truncate ++; 201 reply->path = reply->path.substr(0, truncate); 202 } 247 // we will assume that it's a drive letter first 248 { 249 truncate ++; 250 reply->path = reply->path.substr(0, truncate); 251 } 252 203 253 // if we've got a drive, then we'll use it plus the divider 204 254 else if (reply->path[1] == ':' && reply->path.length() == 2 && 205 isalpha(reply->path[0])) 206 { reply->path = reply->path + dividerStr; 207 } 208 else 209 { reply->path = ""; 210 } 255 isalpha(reply->path[0])) 256 { 257 reply->path = reply->path + dividerStr; 258 } 259 else 260 { 261 reply->path = ""; 262 } 211 263 return reply; 212 264 } … … 216 268 */ 217 269 bool FilePath::exists() 218 { File f(this->path);219 220 270 { 271 File f(this->path); 272 return f.exists(); 221 273 } 222 274 … … 225 277 */ 226 278 FilePath *FilePath::parent() 227 { // TODO: cope with network roots 228 FilePath *reply = new FilePath(this->path); 229 230 // get the last divider 231 unsigned int truncate = reply->path.find_last_of(divider); 279 { 280 // TODO: cope with network roots 281 FilePath *reply = new FilePath(this->path); 282 283 // get the last divider 284 unsigned int truncate = reply->path.find_last_of(divider); 232 285 233 286 // if it exists, then we can do a normal get parent 234 287 if (truncate != -1) 235 { // if it's the leftmost one as well then we'll skip it to 236 // give a parent of <drive>:\ as this patches some problems 237 // with windows calls! Note that a parent call to the returned 238 // object in this case will return itself 239 if (truncate == reply->path.find(divider)) 240 { truncate ++; 241 } 242 reply->path = reply->path.substr(0, truncate); 243 } 288 { 289 // if it's the leftmost one as well then we'll skip it to 290 // give a parent of <drive>:\ as this patches some problems 291 // with windows calls! Note that a parent call to the returned 292 // object in this case will return itself 293 if (truncate == reply->path.find(divider)) 294 { 295 truncate ++; 296 } 297 reply->path = reply->path.substr(0, truncate); 298 } 299 244 300 // if we've got a drive letter only, then append the divider to 245 301 // patch problematic windows calls; again subsequent parent 246 302 // calls to our returned object would in effect return itself 247 303 else if (reply->path[1] == ':' && reply->path.length() == 2 && 248 isalpha(reply->path[0])) 249 { reply->path = reply->path + dividerStr; 250 } 304 isalpha(reply->path[0])) 305 { 306 reply->path = reply->path + dividerStr; 307 } 308 251 309 // a non-rooted object; return blank 252 310 else 253 { reply->path = ""; 254 } 255 reply->is_aRoot = __pathIsAValidRoot(reply->path); 311 { 312 reply->path = ""; 313 } 314 315 reply->is_aRoot = __pathIsAValidRoot(reply->path); 256 316 return reply; 257 317 } 258 318 259 319 FilePath *FilePath::append(FilePath &subPath) 260 { return new FilePath(this->path, subPath.path); 320 { 321 return new FilePath(this->path, subPath.path); 261 322 } 262 323 263 324 FilePath *FilePath::append(char *subPath) 264 { return new FilePath(this->path, subPath); 325 { 326 return new FilePath(this->path, subPath); 265 327 } 266 328 267 329 const char *FilePath::cString() 268 { return this->path.c_str(); 330 { 331 return this->path.c_str(); 269 332 } 270 333 271 334 string FilePath::pathString() 272 { return this->path; 335 { 336 return this->path; 273 337 } 274 338 275 339 bool FilePath::ensureWriteablePath() 276 { //TODO: don't assume that all roots are writeable! 277 if (this->isRoot()) 278 { return true; 279 } 280 281 // does this path exist? 282 File thisFile(this->path); 340 { 341 //TODO: don't assume that all roots are writeable! 342 if (this->isRoot()) 343 { 344 return true; 345 } 346 347 // does this path exist? 348 File thisFile(this->path); 283 349 bool reply = false; 284 350 285 351 // if not, ensure writeable parent 286 352 if (thisFile.exists() == false) 287 { FilePath *parent; 288 289 // create parent reference 290 parent = this->parent(); 291 if (parent->equals(thisFile.getFileName())) 292 { delete parent; 293 return true; 294 } 295 296 // if parent is writeable then try to make the directory 297 if (parent->ensureWriteablePath()) 298 { // make this directory; if it succeeded we reply positively 299 if (mkdir(this->path.c_str()) == 0) 300 { reply = true; 301 } 302 } 303 // destroy parent reference 304 delete parent; 305 } 353 { 354 FilePath *parent; 355 356 // create parent reference 357 parent = this->parent(); 358 359 if (parent->equals(thisFile.getFileName())) 360 { 361 delete parent; 362 return true; 363 } 364 365 // if parent is writeable then try to make the directory 366 if (parent->ensureWriteablePath()) 367 { 368 // make this directory; if it succeeded we reply positively 369 if (_mkdir(this->path.c_str()) == 0) 370 { 371 reply = true; 372 } 373 } 374 375 // destroy parent reference 376 delete parent; 377 } 378 306 379 else if (thisFile.isDirectory() == true) 307 { // is this writeable by user?; if so we're okay 308 if (thisFile.isWriteable()) 309 { reply = true; 310 } 311 } 312 380 { 381 // is this writeable by user?; if so we're okay 382 if (thisFile.isWriteable()) 383 { 384 reply = true; 385 } 386 } 313 387 return reply; 314 388 } -
trunk/gsinstaller/FilePath.h
r1498 r1536 5 5 6 6 class FilePath 7 { private: 8 string path; // full path of this item 9 bool is_aRoot; // indicates whether this directory/file is a file root 10 void _init(string path, string subPath); 11 public: 12 FilePath(); 13 FilePath(string filePath); 14 FilePath(string filePath, string filePath2); 15 FilePath(int nPaths, ...); 16 FilePath(FilePath &path, string subPath); 17 bool equals(FilePath &path); 18 bool equals(const char *path); 19 bool isRoot(); 20 bool isEmpty(); 21 FilePath *append(FilePath &path); 22 FilePath *append(char *path); 23 FilePath *parent(); 24 FilePath *root(); 25 FilePath *rootDrive(); 26 bool ensureWriteablePath(); 27 bool exists(); 28 const char *cString(); 29 string pathString(); 30 bool operator==(const FilePath &b) { return this->path == b.path; } 31 bool operator!=(const FilePath &b) { return this->path != b.path; } 32 bool operator<(const FilePath &b) { return this->path < b.path; } 7 { 8 private: 9 string path; // full path of this item 10 bool is_aRoot; // indicates whether this directory/file is a file root 11 void _init(string path, string subPath); 12 public: 13 FilePath(); 14 FilePath(string filePath); 15 FilePath(string filePath, string filePath2); 16 FilePath(int nPaths, ...); 17 FilePath(FilePath &path, string subPath); 18 bool equals(FilePath &path); 19 bool equals(const char *path); 20 bool isRoot(); 21 bool isEmpty(); 22 FilePath *append(FilePath &path); 23 FilePath *append(char *path); 24 FilePath *parent(); 25 FilePath *root(); 26 FilePath *rootDrive(); 27 bool ensureWriteablePath(); 28 bool exists(); 29 const char *cString(); 30 string pathString(); 31 bool operator==(const FilePath &b) const { return this->path == b.path; } 32 bool operator!=(const FilePath &b) const { return this->path != b.path; } 33 bool operator<(const FilePath &b) const { return this->path < b.path; } 33 34 }; 34 35 #endif -
trunk/gsinstaller/copyProgress.cpp
r1475 r1536 7 7 8 8 extern HINSTANCE app_instance; 9 extern gsInstall_getDesktopExt(int *x, int *y);9 extern void gsInstall_getDesktopExt(int *x, int *y); 10 10 11 LRESULT CALLBACK copyProgressBar_windowProc( HWND window, UINT message, 12 WPARAM wParam, LPARAM lParam) 13 { switch (message) 14 { case WM_CREATE: 15 { CREATESTRUCT *createStruct = (CREATESTRUCT *) lParam; 11 LRESULT CALLBACK copyProgressBar_windowProc(HWND window, UINT message, 12 WPARAM wParam, LPARAM lParam) 13 { 14 switch (message) 15 { 16 case WM_CREATE: 17 { 18 CREATESTRUCT *createStruct = (CREATESTRUCT *) lParam; 16 19 long *createParams; 17 20 copyProgressBar *progressBar; 18 21 19 createParams = (long *) createStruct->lpCreateParams; 22 createParams = (long *) createStruct->lpCreateParams; 23 24 SetWindowLong(window, GWL_USERDATA, createParams[0]); 25 progressBar = (copyProgressBar *) GetWindowLong(window, GWL_USERDATA); 26 if (progressBar == NULL) 27 { 28 MessageBox(0, "A", "A", MB_OK); 29 } 20 30 21 SetWindowLong(window, GWL_USERDATA, createParams[0]); 22 progressBar = (copyProgressBar *) GetWindowLong(window, GWL_USERDATA); 23 if (progressBar == NULL) 24 { MessageBox(0, "A", "A", MB_OK); 31 CreateWindowEx( 0, "STATIC", (char *) createParams[1], WS_CHILD | WS_VISIBLE, 32 10, 5, 180, 20, window, (HMENU) 0, 33 app_instance, NULL); 25 34 } 35 break; 26 36 27 CreateWindowEx( 0, "STATIC", (char *) createParams[1], WS_CHILD | WS_VISIBLE,28 10, 5, 180, 20, window, (HMENU) 0, 29 app_instance, NULL);37 default: 38 return(DefWindowProc(window, message, wParam, lParam)); 39 } 30 40 31 } 32 break; 33 34 default: 35 return(DefWindowProc(window, message, wParam, lParam)); 36 } 37 38 return 0; 41 return 0; 39 42 } 40 43 -
trunk/gsinstaller/dirSelector.cpp
r1397 r1536 92 92 93 93 void dirSelector::requestPath(HWND parent, LPSTR message) 94 { OPENFILENAME openStr; 95 char fileName[256] = "dir.dir\0"; 96 DWORD error; 97 BROWSEINFO bInfo; 98 int image; 94 { 95 OPENFILENAME openStr; 96 char fileName[256] = "dir.dir\0"; 97 DWORD error; 98 BROWSEINFO bInfo; 99 int image; 99 100 100 101 bInfo.hwndOwner = parent; 101 bInfo.pidlRoot 102 bInfo.pszDisplayName 103 bInfo.lpszTitle 104 bInfo.ulFlags 105 bInfo.lpfn 106 bInfo.lParam 107 bInfo.iImage 102 bInfo.pidlRoot = NULL; 103 bInfo.pszDisplayName = fileName; 104 bInfo.lpszTitle = message; 105 bInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; 106 bInfo.lpfn = initSelect; 107 bInfo.lParam = (LONG) this; 108 bInfo.iImage = image = 0; 108 109 LPITEMIDLIST itemList = SHBrowseForFolder(&bInfo); 109 110 if (itemList != NULL) 110 { SHGetPathFromIDList(itemList, fileName); 111 this->setPath(fileName); 112 } 111 { 112 SHGetPathFromIDList(itemList, fileName); 113 this->setPath(fileName); 114 } 113 115 return; 114 116 115 openStr.lStructSize = sizeof(OPENFILENAME); 116 openStr.hwndOwner = parent; 117 openStr.hInstance = 0;// app_instance; //this->dlgBlock; 118 openStr.lpstrFilter = NULL; 119 openStr.lpstrCustomFilter = NULL; 120 openStr.nMaxCustFilter = NULL; 121 openStr.nFilterIndex = 0; 122 openStr.lpstrFile = fileName; 123 openStr.nMaxFile = 255; 124 openStr.lpstrFileTitle = NULL; 125 openStr.lpstrInitialDir = NULL; 126 openStr.lpstrTitle = message; 127 openStr.Flags = OFN_ENABLEHOOK | OFN_NOTESTFILECREATE | OFN_NOVALIDATE | OFN_EXPLORER; // || OFN_ENABLETEMPLATE | OFN_EXPLORER; 128 openStr.nFileOffset = 0; 129 openStr.nFileExtension = 4; 130 openStr.lpstrDefExt = NULL; 131 openStr.lCustData = NULL; 132 openStr.lpfnHook = hookProc; 133 openStr.lpTemplateName = 0; // "MySaveAsDlg"; 117 openStr.lStructSize = sizeof(OPENFILENAME); 118 openStr.hwndOwner = parent; 119 openStr.hInstance = 0; // app_instance; //this->dlgBlock; 120 openStr.lpstrFilter = NULL; 121 openStr.lpstrCustomFilter = NULL; 122 // openStr.nMaxCustFilter = NULL; 123 openStr.nMaxCustFilter = 0; 124 openStr.nFilterIndex = 0; 125 openStr.lpstrFile = fileName; 126 openStr.nMaxFile = 255; 127 openStr.lpstrFileTitle = NULL; 128 openStr.lpstrInitialDir = NULL; 129 openStr.lpstrTitle = message; 130 openStr.Flags = OFN_ENABLEHOOK | OFN_NOTESTFILECREATE | OFN_NOVALIDATE | OFN_EXPLORER; // || OFN_ENABLETEMPLATE | OFN_EXPLORER; 131 openStr.nFileOffset = 0; 132 openStr.nFileExtension = 4; 133 openStr.lpstrDefExt = NULL; 134 // openStr.lCustData = NULL; 135 openStr.lCustData = 0; 136 openStr.lpfnHook = hookProc; 137 openStr.lpTemplateName = 0; // "MySaveAsDlg"; 134 138 if (GetSaveFileName(&openStr) == 0) 135 { error = CommDlgExtendedError(); 136 } 139 { 140 error = CommDlgExtendedError(); 141 } 137 142 else 138 { if (this->path != NULL) 139 { free(this->path); 143 { 144 if (this->path != NULL) 145 { 146 free(this->path); 147 } 148 this->path = (char *) malloc (strlen(openStr.lpstrFile) + 1); 149 strcpy(this->path, openStr.lpstrFile); 140 150 } 141 this->path = (char *) malloc (strlen(openStr.lpstrFile) + 1);142 strcpy(this->path, openStr.lpstrFile);143 }144 151 } 145 152 146 153 char *dirSelector::selectedPath() 147 { return this->path; 154 { 155 return this->path; 148 156 } -
trunk/gsinstaller/dirent.cpp
r1524 r1536 1 1 #include <string.h> 2 2 #include <windows.h> 3 #include <malloc.h> 3 4 4 5 #include "dirent.h" 5 6 6 7 void _getFileName(DIRSTR *dirlist, WIN32_FIND_DATA *winFileData) 7 { // get leaf if directory name is given 8 char *leafname = strrchr(winFileData->cFileName, '\\'); 8 { 9 // get leaf if directory name is given 10 char *leafname = strrchr(winFileData->cFileName, '\\'); 9 11 10 if (leafname) 11 { leafname ++; 12 if (leafname) 13 { 14 leafname ++; 12 15 } 13 16 else 14 { leafname = winFileData->cFileName; 17 { 18 leafname = winFileData->cFileName; 15 19 } 16 20 strcpy(dirlist->fileData.d_name, leafname); 17 21 } 18 22 19 23 DIRSTR *opendir(const char *name) 20 { char buffer[MAX_PATH]; 24 { 25 char buffer[MAX_PATH]; 21 26 WIN32_FIND_DATA winFileData; 22 23 DIRSTR *newlist = (DIRSTR *) malloc(sizeof(DIRSTR)); 27 DIRSTR *newlist = (DIRSTR *) malloc(sizeof(DIRSTR)); 24 28 25 29 strcpy(buffer, name); 26 30 if (buffer[strlen(buffer)-1] != '\\') 27 { strcat(buffer, "\\*"); 28 } 31 { 32 strcat(buffer, "\\*"); 33 } 29 34 else 30 { strcat(buffer, "*"); 31 } 35 { 36 strcat(buffer, "*"); 37 } 32 38 33 39 newlist->searchHandle = FindFirstFile(buffer, &winFileData); 34 40 if (newlist->searchHandle == INVALID_HANDLE_VALUE) 35 { DWORD error = GetLastError(); 36 if (error == ERROR_NO_MORE_FILES) 37 { newlist->first = 2; 41 { 42 DWORD error = GetLastError(); 43 if (error == ERROR_NO_MORE_FILES) 44 { 45 newlist->first = 2; 46 } 47 else 48 { 49 free(newlist); 50 newlist = NULL; 51 } 38 52 } 39 else 40 { free(newlist); 41 newlist = NULL; 53 else 54 { 55 _getFileName(newlist, &winFileData); 56 newlist->first = 1; 42 57 } 43 }44 else45 { _getFileName(newlist, &winFileData);46 newlist->first = 1;47 }48 58 return newlist; 49 59 } 50 60 51 61 dirent *readdir(DIRSTR *dirlist) 52 { if (dirlist->first == 2) 53 { // empty directory 54 return NULL; 55 } 56 else if (dirlist->first != 1) 57 { WIN32_FIND_DATA winFileData; 58 59 if (FindNextFile(dirlist->searchHandle, &winFileData) == 0) 60 { DWORD error = GetLastError(); 61 62 return NULL; 62 { 63 if (dirlist->first == 2) 64 { 65 // empty directory 66 return NULL; 63 67 } 64 else 65 { _getFileName(dirlist, &winFileData); 68 else if (dirlist->first != 1) 69 { 70 WIN32_FIND_DATA winFileData; 71 72 if (FindNextFile(dirlist->searchHandle, &winFileData) == 0) 73 { 74 DWORD error = GetLastError(); 75 return NULL; 76 } 77 else 78 { 79 _getFileName(dirlist, &winFileData); 80 } 66 81 } 67 }68 82 else 69 { dirlist->first = 0; 70 } 83 { 84 dirlist->first = 0; 85 } 71 86 72 87 return &dirlist->fileData; … … 74 89 75 90 void closedir(DIRSTR *dirlist) 76 { free(dirlist); 91 { 92 free(dirlist); 77 93 } 78 79 80 -
trunk/gsinstaller/file.h
r1397 r1536 7 7 8 8 class File 9 { private: 10 string name; 11 unsigned long size; 12 vector<File> children; 13 bool is_dir; 14 bool does_exist; 15 bool is_writable; 9 { 10 private: 11 string name; 12 unsigned long size; 13 vector<File> children; 14 bool is_dir; 15 bool does_exist; 16 bool is_writable; 16 17 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 18 void _getDetails(); 19 void getChildren(); 20 protected: 21 public: 22 File(); 23 File(string filename, unsigned long filesize); 24 File(string filename); 25 void copy(char *destination); 26 bool isDirectory(); 27 bool isWriteable(); 28 bool exists(); 29 unsigned long getRawFileSize(); 30 unsigned long getFileSize(); 31 const char *getFileName(); 32 unsigned long getDiskSpace(DiskSpace &diskSpace); 33 vector<File>::iterator childBegin(); 34 vector<File>::iterator childEnd(); 34 35 }; 35 36 -
trunk/gsinstaller/fileCopier.cpp
r1498 r1536 3 3 #include <stdlib.h> 4 4 #include <stdio.h> 5 #include <dir.h> 5 //#include <dir.h> 6 #include <direct.h> 6 7 7 8 fileCopySet::fileCopySet() 8 { this->sourceDir = NULL; 9 this->destDir = NULL; 9 { 10 // do we need this - they're FilePath's, not pointers 11 // this->sourceDir = NULL; 12 // this->destDir = NULL; 10 13 } 11 14 12 15 fileCopySet::fileCopySet(FileVector files, FilePath &from, FilePath &to) 13 { this->fileList = files; 14 this->sourceDir = from; 15 this->destDir = to; 16 this->dataSize = 0; 17 18 FileVector::iterator here = files.begin(); 19 FileVector::iterator end = files.end(); 20 21 while (here != end) 22 { this->dataSize += here->getFileSize(); 23 here ++; 24 } 16 { 17 this->fileList = files; 18 this->sourceDir = from; 19 this->destDir = to; 20 this->dataSize = 0; 21 22 FileVector::iterator here = files.begin(); 23 FileVector::iterator end = files.end(); 24 25 while (here != end) 26 { 27 this->dataSize += here->getFileSize(); 28 here ++; 29 } 25 30 } 26 31 … … 30 35 */ 31 36 char *fileCopySet::destination(File *file) 32 { const char *oldname = file->getFileName(); 33 char *newname = (char *) malloc(strlen(oldname) - strlen(this->sourceDir.cString()) + strlen(this->destDir.cString()) + 1); 37 { 38 const char *oldname = file->getFileName(); 39 char *newname = (char *) malloc(strlen(oldname) - strlen(this->sourceDir.cString()) + strlen(this->destDir.cString()) + 1); 34 40 35 41 if (newname != NULL) 36 { strcpy(newname, this->destDir.cString()); 37 strcat(newname, &oldname[strlen(this->sourceDir.cString())]); 38 } 42 { 43 strcpy(newname, this->destDir.cString()); 44 strcat(newname, &oldname[strlen(this->sourceDir.cString())]); 45 } 39 46 40 47 return newname; … … 45 52 */ 46 53 bool fileCopySet::copyFile(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar) 47 { unsigned long copied = 0; 48 unsigned long bytes_read, bytes_written; 49 unsigned char buffer[65536]; 54 { 55 unsigned long copied = 0; 56 unsigned long bytes_read, bytes_written; 57 unsigned char buffer[65536]; 50 58 FILE *read_handle, *write_handle; 51 59 char *destination; 52 60 53 61 // get destination as a char[] block; will free it later 54 destination 62 destination = this->destination(file); 55 63 56 64 // get read and write file handles 57 read_handle 65 read_handle = fopen(file->getFileName(), "rb"); 58 66 if (read_handle == NULL) 59 { return false; 60 } 61 write_handle = fopen(destination, "wb"); 67 { 68 return false; 69 } 70 write_handle = fopen(destination, "wb"); 62 71 if (write_handle == NULL) 63 { fclose(read_handle); 64 return false; 65 } 72 { 73 fclose(read_handle); 74 return false; 75 } 66 76 67 77 while (copied < file->getFileSize()) 68 { // TODO: lock 69 70 // read so many bytes 71 if (file->getFileSize() - copied < 65536) 72 { bytes_read = file->getFileSize() - copied; 73 } 74 else 75 { bytes_read = 65536; 76 } 77 bytes_read = fread((void *) buffer, 1, bytes_read, read_handle); 78 79 // write so many bytes 80 bytes_written = fwrite((void *) buffer, 1, bytes_read, write_handle); 81 82 // TODO: unlock 83 84 // note new bytes copied 85 copied += bytes_written; 86 this->dataSize += bytes_written; 87 } 78 { 79 // TODO: lock 80 // read so many bytes 81 if (file->getFileSize() - copied < 65536) 82 { 83 bytes_read = file->getFileSize() - copied; 84 } 85 else 86 { 87 bytes_read = 65536; 88 } 89 bytes_read = fread((void *) buffer, 1, bytes_read, read_handle); 90 91 // write so many bytes 92 bytes_written = fwrite((void *) buffer, 1, bytes_read, write_handle); 93 94 // TODO: unlock 95 96 // note new bytes copied 97 copied += bytes_written; 98 this->dataSize += bytes_written; 99 } 88 100 fclose(read_handle); 89 101 fclose(write_handle); … … 91 103 // free destination filename text 92 104 if (monitor != NULL) 93 { monitor->copied(file->getFileName(), destination, false); 94 } 105 { 106 monitor->copied(file->getFileName(), destination, false); 107 } 95 108 delete destination; 96 109 return true; … … 102 115 */ 103 116 void fileCopySet::copy(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar) 104 { // just skip this file if it doesn't exist 105 if (file->exists() == false) 106 { return; 107 } 117 { 118 // just skip this file if it doesn't exist 119 if (file->exists() == false) 120 { 121 return; 122 } 108 123 109 124 // if a directory, scan it. 110 if (file->isDirectory()) 111 { // create directory 112 char *thisDestDir = this->destination(file); 113 mkdir(thisDestDir); 114 115 // note amount of data copied 116 // this->copied += file->getRawFileSize(); 117 118 // note for uninstall the action done 119 if (monitor != NULL) 120 { monitor->copied(file->getFileName(), thisDestDir, true); 125 if (file->isDirectory()) 126 { 127 // create directory 128 char *thisDestDir = this->destination(file); 129 _mkdir(thisDestDir); 130 131 // note amount of data copied 132 // this->copied += file->getRawFileSize(); 133 134 // note for uninstall the action done 135 if (monitor != NULL) 136 { 137 monitor->copied(file->getFileName(), thisDestDir, true); 121 138 } 122 139 123 // copy children 124 vector<File>::iterator here = file->childBegin(); 125 vector<File>::iterator end = file->childEnd(); 126 while (here != end) 127 { this->copy(here, monitor, progressBar); 128 here ++; 129 } 130 131 // delete constructed destination name 132 delete thisDestDir; 133 } 140 // copy children 141 vector<File>::iterator here = file->childBegin(); 142 vector<File>::iterator end = file->childEnd(); 143 while (here != end) 144 { 145 this->copy(here, monitor, progressBar); 146 here ++; 147 } 148 149 // delete constructed destination name 150 delete thisDestDir; 151 } 152 134 153 // not a directory; just copy the file 135 154 else 136 { // copy file itself 137 this->copyFile(file, monitor, progressBar); 138 } 155 { 156 // copy file itself 157 this->copyFile(file, monitor, progressBar); 158 } 159 139 160 progressBar.done(file->getRawFileSize()); 140 161 } 141 162 142 163 void fileCopySet::copy(fileCopyMonitor *monitor, copyProgressBar &progressBar) 143 { FileVector::iterator here = fileList.begin(); 144 FileVector::iterator end = fileList.end(); 145 146 while (here != end) 147 { this->copy(here, monitor, progressBar); 148 here ++; 149 } 164 { 165 FileVector::iterator here = fileList.begin(); 166 FileVector::iterator end = fileList.end(); 167 while (here != end) 168 { 169 this->copy(here, monitor, progressBar); 170 here ++; 171 } 150 172 } 151 173 152 174 unsigned long fileCopySet::getCopiedSize(DiskSpace &space) 153 { // initialise counters for size 154 unsigned long copiedSize = 0; 175 { 176 // initialise counters for size 177 unsigned long copiedSize = 0; 155 178 156 179 // iterate through our list of files to obtain total space requirement 157 180 FileVector::iterator here = fileList.begin(); 158 FileVector::iterator end = fileList.end(); 159 160 while (here != end) 161 { copiedSize += here->getDiskSpace(space); 162 here ++; 163 } 164 181 FileVector::iterator end = fileList.end(); 182 while (here != end) 183 { 184 copiedSize += here->getDiskSpace(space); 185 here ++; 186 } 165 187 return copiedSize; 166 188 } 167 189 168 190 unsigned long fileCopySet::getOriginalSize() 169 { // initialise counters for size 170 return this->dataSize; 191 { 192 // initialise counters for size 193 return this->dataSize; 171 194 } 172 195 … … 176 199 */ 177 200 bool fileCopier::checkSpace() 178 { fileCopySetList localSet = this->list; 179 180 do 181 { unsigned int i = 0; 182 183 // get destination root and use it to obtain space check information 184 FilePath *destRoot = localSet[0].destDir.root(); 185 DiskSpace space(destRoot->cString()); 186 187 // check that diskspace checking is functional 188 if (space.initialisedOk() == false) 189 { delete destRoot; 190 return false; 201 { 202 fileCopySetList localSet = this->list; 203 204 do 205 { 206 unsigned int i = 0; 207 208 // get destination root and use it to obtain space check information 209 FilePath *destRoot = localSet[0].destDir.root(); 210 DiskSpace space(destRoot->cString()); 211 212 // check that diskspace checking is functional 213 if (space.initialisedOk() == false) 214 { 215 delete destRoot; 216 return false; 191 217 } 192 218 193 // get size of the first set 194 unsigned long copiedSize = localSet[0].getCopiedSize(space); 195 196 // dispose of the first set 197 localSet.erase(localSet.begin()); 198 199 // get all remaining sets and in turn if they share the root with 200 // the first root, add their size to the count and remove them from 201 // the local list of sets; otherwise skip 202 while (i < localSet.size()) 203 { // get a new root object for this set's destination 204 FilePath *p = localSet[i].destDir.root(); 205 206 if (*destRoot == *p) 207 { copiedSize += localSet[i].getCopiedSize(space); 208 localSet.erase(localSet.begin() + i); 209 } 210 else 211 { i ++; 212 } 213 214 // delete the constructed root 215 delete p; 216 } 217 218 // dispose of destination root 219 delete destRoot; 220 221 // return false if not enough space 222 if (space.totalFreeSpace() < copiedSize) 223 { return false; 219 // get size of the first set 220 unsigned long copiedSize = localSet[0].getCopiedSize(space); 221 222 // dispose of the first set 223 localSet.erase(localSet.begin()); 224 225 // get all remaining sets and in turn if they share the root with 226 // the first root, add their size to the count and remove them from 227 // the local list of sets; otherwise skip 228 while (i < localSet.size()) 229 { 230 // get a new root object for this set's destination 231 FilePath *p = localSet[i].destDir.root(); 232 233 if (*destRoot == *p) 234 { 235 copiedSize += localSet[i].getCopiedSize(space); 236 localSet.erase(localSet.begin() + i); 237 } 238 else 239 { 240 i ++; 241 } 242 243 // delete the constructed root 244 delete p; 245 } 246 247 // dispose of destination root 248 delete destRoot; 249 250 // return false if not enough space 251 if (space.totalFreeSpace() < copiedSize) 252 { 253 return false; 224 254 } 225 } while (localSet.size() != 0); 255 256 } while (localSet.size() != 0); 257 226 258 227 259 // record size and initialise the progressbar with the same 228 this->dataSize 260 this->dataSize = 0; 229 261 for (unsigned int i = 0; i < this->list.size(); i ++) 230 { this->dataSize += this->list[i].getOriginalSize(); 231 } 262 { 263 this->dataSize += this->list[i].getOriginalSize(); 264 } 232 265 this->progressBar.init(this->dataSize); 233 266 … … 237 270 238 271 fileCopier::fileCopier(fileCopyMonitor *monitor, fileCopySetList &_list) 239 { this->list = _list; 240 this->dataSize = 0; 241 this->copied = 0; 242 this->monitor = monitor; 272 { 273 this->list = _list; 274 this->dataSize = 0; 275 this->copied = 0; 276 this->monitor = monitor; 243 277 } 244 278 245 279 fileCopier::fileCopier(fileCopyMonitor *monitor) 246 { this->dataSize = 0; 247 this->copied = 0; 248 this->monitor = monitor; 280 { 281 this->dataSize = 0; 282 this->copied = 0; 283 this->monitor = monitor; 249 284 } 250 285 251 286 void fileCopier::copy() 252 { fileCopySetList::iterator here = list.begin(); 253 fileCopySetList::iterator end = list.end(); 287 { 288 fileCopySetList::iterator here = list.begin(); 289 fileCopySetList::iterator end = list.end(); 254 290 255 291 this->progressBar.show(); 256 292 while (here != end) 257 { here->copy(this->monitor, this->progressBar); 258 here ++; 259 } 293 { 294 here->copy(this->monitor, this->progressBar); 295 here ++; 296 } 297 260 298 this->progressBar.close(); 261 299 } -
trunk/gsinstaller/fileCopier.h
r1475 r1536 6 6 7 7 class fileCopyMonitor 8 { public: 9 fileCopyMonitor() {}; 10 virtual void copied(string from, string to, bool isDir) = 0; 8 { 9 public: 10 fileCopyMonitor() {}; 11 virtual void copied(string from, string to, bool isDir) = 0; 11 12 }; 12 13 13 14 class fileCopySet 14 { private: 15 FileVector fileList; 16 FilePath sourceDir; 17 unsigned long dataSize; 18 public: 19 FilePath destDir; 20 fileCopySet(); 21 fileCopySet(FileVector files, FilePath &from, FilePath &to); 22 char *destination(File *file); 23 unsigned long getOriginalSize(); 24 unsigned long getCopiedSize(DiskSpace &space); 25 bool copyFile(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar); 26 void copy(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar); 27 void copy(fileCopyMonitor *monitor, copyProgressBar &progressBar); 15 { 16 private: 17 FileVector fileList; 18 FilePath sourceDir; 19 unsigned long dataSize; 20 public: 21 FilePath destDir; 22 fileCopySet(); 23 fileCopySet(FileVector files, FilePath &from, FilePath &to); 24 char *destination(File *file); 25 unsigned long getOriginalSize(); 26 unsigned long getCopiedSize(DiskSpace &space); 27 bool copyFile(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar); 28 void copy(File *file, fileCopyMonitor *monitor, copyProgressBar &progressBar); 29 void copy(fileCopyMonitor *monitor, copyProgressBar &progressBar); 28 30 }; 29 31 … … 31 33 32 34 class fileCopier 33 { private: 34 fileCopySetList list; 35 unsigned long dataSize; 36 unsigned long copied; 37 copyProgressBar progressBar; 38 fileCopyMonitor *monitor; 39 protected: 40 public: 41 fileCopier::fileCopier(fileCopyMonitor *monitor, fileCopySetList &list); 42 fileCopier::fileCopier(fileCopyMonitor *monitor); 43 void fileCopier::addSet(fileCopySet &set) { this->list.push_back(set); } 44 bool checkSpace(); 45 void copy(); 35 { 36 private: 37 fileCopySetList list; 38 unsigned long dataSize; 39 unsigned long copied; 40 copyProgressBar progressBar; 41 fileCopyMonitor *monitor; 42 protected: 43 public: 44 fileCopier::fileCopier(fileCopyMonitor *monitor, fileCopySetList &list); 45 fileCopier::fileCopier(fileCopyMonitor *monitor); 46 void fileCopier::addSet(fileCopySet &set) { this->list.push_back(set); } 47 bool checkSpace(); 48 void copy(); 46 49 }; 47 50 #define _FILECOPIER_H_ -
trunk/gsinstaller/gsManifest.cpp
r1498 r1536 115 115 */ 116 116 void gsManifest::expandGroups() 117 { strArrayMap::iterator here = this->manifests.begin(); 118 strArrayMap::iterator end = this->manifests.end(); 117 { 118 strArrayMap::iterator here = this->manifests.begin(); 119 strArrayMap::iterator end = this->manifests.end(); 119 120 120 121 while (here != end) 121 { this->expandGroup((*here).first); 122 here ++; 123 } 122 { 123 this->expandGroup((*here).first); 124 here ++; 125 } 124 126 } 125 127 … … 127 129 * expand a particular group 128 130 */ 129 void gsManifest::expandGroup(string &group) 130 { stringArray &array = this->manifests[group]; 131 132 unsigned int i = 0; 131 void gsManifest::expandGroup(const string &group) 132 { 133 stringArray &array = this->manifests[group]; 134 135 unsigned int i = 0; 133 136 while (i < array.size()) 134 { if (this->isGroup(array[i])) 135 { this->expandGroupInstance(group, array[i]); 136 } 137 { 138 if (this->isGroup(array[i])) 139 { 140 this->expandGroupInstance(group, array[i]); 141 } 137 142 else 138 { i ++; 143 { 144 i ++; 139 145 } 140 146 } … … 144 150 * expand a group instance inside a given group 145 151 */ 146 void gsManifest::expandGroupInstance(string parentgroup, string groupName) 147 { // remove the group instance from the parent 148 this->manifests[parentgroup].remove(groupName); 149 150 // create a "clean" name without the { } brackets 151 string group(groupName, 1, groupName.length() - 2); 152 void gsManifest::expandGroupInstance(const string &parentgroup, string groupName) 153 { 154 // remove the group instance from the parent 155 this->manifests[parentgroup].remove(groupName); 156 157 // create a "clean" name without the { } brackets 158 string group(groupName, 1, groupName.length() - 2); 152 159 153 160 // circular reference - we're kind and ignore it!! 154 161 if (parentgroup.compare(group) == 0) 155 { return; 162 { 163 return; 156 164 } 157 165 158 166 // lookup chidl group and add it to the parent 159 167 this->manifests[parentgroup].add(this->manifests[group]); 160 168 } 161 169 … … 165 173 */ 166 174 bool gsManifest::isGroup(string &name) 167 { if (name[0] == '{' && name[name.length()-1] == '}') 168 { return true; 169 } 170 return false; 175 { 176 if (name[0] == '{' && name[name.length()-1] == '}') 177 { 178 return true; 179 } 180 return false; 171 181 } 172 182 173 183 void gsManifest::expandMacro(string macro, string value) 174 { string macroRef = "\$(" + macro + ")"; 184 { 185 // illegal escape sequence ?? 186 // string macroRef = "\$(" + macro + ")"; 187 string macroRef = "$(" + macro + ")"; 175 188 176 189 strArrayMap::iterator here = this->manifests.begin(); … … 178 191 179 192 while (here != end) 180 { stringArray &array = this->manifests[(*here).first]; 181 182 unsigned int i = 0; 193 { 194 stringArray &array = this->manifests[(*here).first]; 195 196 unsigned int i = 0; 183 197 while (i < array.size()) 184 { unsigned int pos; 198 { 199 unsigned int pos; 185 200 while ((pos = array[i].find(macroRef)) < array[i].length() && pos != -1) 186 { array[i].replace(pos, macroRef.length(), value); 201 { 202 array[i].replace(pos, macroRef.length(), value); 203 } 204 i ++; 187 205 } 188 i ++;189 }190 206 here ++; 191 207 } … … 197 213 198 214 void gsManifest::selectGroup(string groupName, FilePath &destination) 199 { stringArray &groupArray = this->manifests[groupName]; 200 201 groupArray = this->manifests[groupName]; 215 { 216 stringArray &groupArray = this->manifests[groupName]; 217 218 // do we really need this twice ?? 219 // groupArray = this->manifests[groupName]; 220 202 221 this->selected[destination].add(groupArray); 203 222 } -
trunk/gsinstaller/gsManifest.h
r1475 r1536 13 13 14 14 class gsManifest : public installAgent, fileCopyMonitor 15 { private: 16 protected: 17 strArrayMap manifests; 18 pathStringArrayMap selected; 15 { 16 private: 17 protected: 18 strArrayMap manifests; 19 pathStringArrayMap selected; 19 20 20 21 22 23 24 25 26 27 28 void expandGroupInstance(string parent, string child);29 void expandGroup(string &group);30 31 32 33 34 35 36 37 38 39 40 21 bool getManifestLine(char *line, string ¯o); 22 public: 23 gsManifest(installManager &manager, FilePath &path); // used for install 24 gsManifest(installManager &manager); // used for uninstall 25 bool getManifest(FilePath &path); 26 void logAction(string actionName, string file); 27 void logAction(string actionName, string source, string dest); 28 bool undoAction(string actionName, stringArray ¶ms); 29 void expandGroupInstance(const string &parentgroup, string groupName); 30 void expandGroup(const string &group); 31 void expandGroups(); 32 bool isGroup(string &name); 33 void expandMacro(string macroName, string value); 34 void clearSelection(); 35 bool copy(FilePath *source); 36 void selectGroup(string groupName, FilePath &destination); 37 FileVector *selection(FilePath &source, stringArray &array); 38 FileVector *selection(FilePath &source, FilePath &destination); 39 bool selectCheckSpace(); 40 41 void copied(string from, string to, bool isDir); // from fileCopyMonitor 41 42 }; 42 43 #endif; -
trunk/gsinstaller/gsPlatform.cpp
r1397 r1536 38 38 39 39 bool gsPlatform::isUserAdministrator() 40 { if (this->isWindowsNT()) 41 { HANDLE token; 42 PSID adminId; 43 PACL aclData; 44 PSECURITY_DESCRIPTOR psdAdmin; 45 SID_IDENTIFIER_AUTHORITY systemSidAuthority; 46 GENERIC_MAPPING genericMapping; 47 PRIVILEGE_SET privilegeSet; 48 DWORD aclSize, status, structureSize; 49 BOOL result; 40 { 41 if (this->isWindowsNT()) 42 { 43 HANDLE token; 44 PSID adminId; 45 PACL aclData; 46 PSECURITY_DESCRIPTOR psdAdmin; 47 SID_IDENTIFIER_AUTHORITY systemSidAuthority; 48 GENERIC_MAPPING genericMapping; 49 PRIVILEGE_SET privilegeSet; 50 DWORD aclSize, status, structureSize; 51 BOOL result; 50 52 51 52 53 // Get an impersonation token 54 ImpersonateSelf(SecurityImpersonation); 53 55 54 if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &token)) 55 { if (GetLastError() != ERROR_NO_TOKEN) 56 { return false; 57 } 56 if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &token)) 57 { 58 if (GetLastError() != ERROR_NO_TOKEN) 59 { 60 return false; 61 } 58 62 59 // if we didn't have an access token, take the process token instead 60 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) 61 { return false; 62 } 63 // if we didn't have an access token, take the process token instead 64 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) 65 { 66 return false; 67 } 68 } 69 70 // By now we have a valid process/thread token; now get information on the 71 // admin group in this domain 72 if (!AllocateAndInitializeSid(&systemSidAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, 73 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, 74 &adminId)) 75 { 76 return false; 77 } 78 79 // allocate space for security descriptor 80 psdAdmin = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); 81 if (psdAdmin == NULL) 82 { 83 return false; 84 } 85 86 // initialise descriptor 87 if (!InitializeSecurityDescriptor(psdAdmin, SECURITY_DESCRIPTOR_REVISION)) 88 { 89 return false; 90 } 91 92 // get ACL size and allocate ACL block 93 aclSize = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(adminId) - sizeof(DWORD); 94 aclData = (PACL) LocalAlloc(LPTR, aclSize); 95 if (aclData == NULL) 96 { 97 return false; 98 } 99 100 // initalise the acl block 101 if (!InitializeAcl(aclData, aclSize, ACL_REVISION2)) 102 { 103 return false; 104 } 105 106 // try to add the given item to the Access Control Entry (ACE) list (ACL) 107 if (!AddAccessAllowedAce(aclData, ACL_REVISION2, ACCESS_READ | ACCESS_WRITE, adminId)) 108 { 109 return false; 110 } 111 112 // endeavour to add the acl to the discretionary acl (DACL) 113 if (!SetSecurityDescriptorDacl(psdAdmin, TRUE, aclData, FALSE)) 114 { 115 return false; 116 } 117 118 // endeavour to set the owner/group identification 119 SetSecurityDescriptorGroup(psdAdmin, adminId, FALSE); 120 SetSecurityDescriptorOwner(psdAdmin, adminId, FALSE); 121 122 // right, we've now built up a discretionary acl on the current user, 123 // finally get the generic mapping ready 124 genericMapping.GenericRead = ACCESS_READ; 125 genericMapping.GenericWrite = ACCESS_WRITE; 126 genericMapping.GenericExecute = 0; 127 genericMapping.GenericAll = ACCESS_READ | ACCESS_WRITE; 128 129 // do the actual access check 130 if (!AccessCheck (psdAdmin, token, ACCESS_READ, &genericMapping, 131 &privilegeSet, &structureSize, &status, &result)) 132 { 133 return false; 134 } 135 136 // end impersonisation 137 RevertToSelf(); 138 return result; 63 139 } 64 65 // By now we have a valid process/thread token; now get information on the 66 // admin group in this domain 67 if (!AllocateAndInitializeSid(&systemSidAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, 68 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, 69 &adminId)) 70 { return false; 71 } 72 73 // allocate space for security descriptor 74 psdAdmin = LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); 75 if (psdAdmin == NULL) 76 { return false; 77 } 78 79 // initialise descriptor 80 if (!InitializeSecurityDescriptor(psdAdmin, SECURITY_DESCRIPTOR_REVISION)) 81 { return false; 82 } 83 84 // get ACL size and allocate ACL block 85 aclSize = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(adminId) - sizeof(DWORD); 86 aclData = (PACL) LocalAlloc(LPTR, aclSize); 87 if (aclData == NULL) 88 { return false; 89 } 90 91 // initalise the acl block 92 if (!InitializeAcl(aclData, aclSize, ACL_REVISION2)) 93 { return false; 94 } 95 96 // try to add the given item to the Access Control Entry (ACE) list (ACL) 97 if (!AddAccessAllowedAce(aclData, ACL_REVISION2, ACCESS_READ | ACCESS_WRITE, adminId)) 98 { return false; 99 } 100 101 // endeavour to add the acl to the discretionary acl (DACL) 102 if (!SetSecurityDescriptorDacl(psdAdmin, TRUE, aclData, FALSE)) 103 { return false; 104 } 105 106 // endeavour to set the owner/group identification 107 SetSecurityDescriptorGroup(psdAdmin, adminId, FALSE); 108 SetSecurityDescriptorOwner(psdAdmin, adminId, FALSE); 109 110 // right, we've now built up a discretionary acl on the current user, 111 // finally get the generic mapping ready 112 genericMapping.GenericRead = ACCESS_READ; 113 genericMapping.GenericWrite = ACCESS_WRITE; 114 genericMapping.GenericExecute = 0; 115 genericMapping.GenericAll = ACCESS_READ | ACCESS_WRITE; 116 117 // do the actual access check 118 if (!AccessCheck( psdAdmin, token, ACCESS_READ, &genericMapping, 119 &privilegeSet, &structureSize, &status, &result)) 120 { return false; 121 } 122 123 // end impersonisation 124 RevertToSelf(); 125 return result; 126 } 127 return true; 140 return true; 128 141 } 129 142 130 143 bool gsPlatform::reboot() 131 144 { 132 // Check for appropriate privileges if this is NT 133 if (this->isWindowsNT()) 134 { HANDLE token; 135 TOKEN_PRIVILEGES tkp; 145 // Check for appropriate privileges if this is NT 146 if (this->isWindowsNT()) 147 { 148 HANDLE token; 149 TOKEN_PRIVILEGES tkp; 136 150 137 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, 138 &token)) 139 { return false; 140 } 151 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, 152 &token)) 153 { 154 return false; 155 } 156 157 LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); 141 158 142 LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); 159 tkp.PrivilegeCount = 1; // set one privilege 160 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 143 161 144 tkp.PrivilegeCount = 1; // set oneprivilege145 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;162 // Get the actual shutdown privilege 163 AdjustTokenPrivileges(token, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0); 146 164 147 // Get the actual shutdown privilege 148 AdjustTokenPrivileges(token, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0); 149 150 // as we can't test a return value on the previous call, use GetLastError 151 if (GetLastError() != ERROR_SUCCESS) 152 { return false; 165 // as we can't test a return value on the previous call, use GetLastError 166 if (GetLastError() != ERROR_SUCCESS) 167 { 168 return false; 169 } 153 170 } 154 }155 171 return ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0); 156 172 } 157 173 158 174 string gsPlatform::platformString() 159 { if (this->isWindowsNT()) 160 { return gsPlatform_WINDOWSNT; 161 } 175 { 176 if (this->isWindowsNT()) 177 { 178 return gsPlatform_WINDOWSNT; 179 } 162 180 else if (this->isWindows9x()) 163 { return gsPlatform_WINDOWS9X; 181 { 182 return gsPlatform_WINDOWS9X; 164 183 } 165 184 else if (this->isWindows32s()) 166 { return gsPlatform_WINDOWS32S; 185 { 186 return gsPlatform_WINDOWS32S; 167 187 } 168 188 else 169 { return gsPlatform_WINDOWS; 189 { 190 return gsPlatform_WINDOWS; 170 191 } 171 192 } -
trunk/gsinstaller/gsPlatform.h
r1397 r1536 11 11 12 12 class gsPlatform 13 { private: 14 OSVERSIONINFO platformInfo; 15 protected: 16 public: 17 gsPlatform(); 18 bool isWindows9x(); 19 bool isWindowsNT(); 20 bool isWindows32s(); 21 bool isOldWindows32s(); 22 bool isExplorerShell(); 23 bool isUserAdministrator(); 24 bool reboot(); 25 string platformString(); 13 { 14 private: 15 OSVERSIONINFO platformInfo; 16 protected: 17 public: 18 gsPlatform(); 19 bool isWindows9x(); 20 bool isWindowsNT(); 21 bool isWindows32s(); 22 bool isOldWindows32s(); 23 bool isExplorerShell(); 24 bool isUserAdministrator(); 25 bool reboot(); 26 string platformString(); 26 27 }; 27 28 #endif -
trunk/gsinstaller/gsProgman.cpp
r1498 r1536 350 350 return reply; 351 351 } 352 353 -
trunk/gsinstaller/gsinstall.cpp
r1502 r1536 23 23 #include "gsManifest.h" 24 24 25 char * 25 char *app_cmdLine; 26 26 static char app_name[] = "Greenstone Installer"; 27 HINSTANCE 28 HWND 29 30 bool 27 HINSTANCE app_instance; 28 HWND app_window; 29 30 bool config_complete = false; 31 31 32 32 typedef vector<dirSelector *> dirSelVector; 33 33 34 34 class GSInstall : public installManager 35 { private: 36 configureFile * configFile; // the installation configure file 37 38 FilePath * collectPath; // where the collection is currently installed 39 FilePath * installToPath; // the first cut at a destination folder 40 FilePath * sourcePath; // the root source folder 41 FilePath * gsdlSourcePath; // the gsdl folder in the source area 42 FilePath * destinationPath; // where the executables will be installed to 43 FilePath * dataDestPath; // where the collection data files will go 44 45 bool installVolume; // whether to install collection data 46 bool installFullVolume;// whether to install all collection data 47 48 dirSelVector selectedDirs; // configuration objects 49 50 gsPlatform platform; // platform information 51 gsRegistry * gsRegister; // registry 52 gsManifest * manifest; // manifest of files 53 gsProgramManager * progman; // program manager connection 54 55 void getSourcePath(); 56 void getExistingInstall(); 57 public: 58 bool installExe; 59 60 GSInstall(bool uninstall); 61 FilePath * collectionPath(); 62 FilePath * installPath(); 63 bool copyFiles(); 64 bool updateRegistry(); 65 bool updateProfiles(); 66 bool updateProgman(); 67 bool updateSetupExe(); 68 bool installNetscape(); 69 void setDestination(); 70 bool setUninstall(); 71 void uninstall(); 72 void setManifest(); 73 void addSelectedDir(dirSelector *selector); 35 { 36 private: 37 configureFile *configFile; // the installation configure file 38 39 FilePath *collectPath; // where the collection is currently installed 40 FilePath *installToPath; // the first cut at a destination folder 41 FilePath *sourcePath; // the root source folder 42 FilePath *gsdlSourcePath; // the gsdl folder in the source area 43 FilePath *destinationPath; // where the executables will be installed to 44 FilePath *dataDestPath; // where the collection data files will go 45 46 bool installVolume; // whether to install collection data 47 bool installFullVolume; // whether to install all collection data 48 49 dirSelVector selectedDirs; // configuration objects 50 51 gsPlatform platform; // platform information 52 gsRegistry *gsRegister; // registry 53 gsManifest *manifest; // manifest of files 54 gsProgramManager *progman; // program manager connection 55 56 void getSourcePath(); 57 void getExistingInstall(); 58 public: 59 bool installExe; 60 61 GSInstall(bool uninstall); 62 FilePath *collectionPath(); 63 FilePath *installPath(); 64 bool copyFiles(); 65 bool updateRegistry(); 66 bool updateProfiles(); 67 bool updateProgman(); 68 bool updateSetupExe(); 69 bool installNetscape(); 70 void setDestination(); 71 bool setUninstall(); 72 void uninstall(); 73 void setManifest(); 74 void addSelectedDir(dirSelector *selector); 74 75 }; 75 76 … … 81 82 void gsInstall_getDesktopExt(int *sx, int *sy) 82 83 { 83 84 HDC dc = GetDC(GetDesktopWindow()); 84 85 *sx = GetDeviceCaps(dc, HORZRES); 85 86 *sy = GetDeviceCaps(dc, VERTRES); … … 94 95 */ 95 96 GSInstall::GSInstall(bool uninstall) 96 : installManager() 97 { // get the installation configuration file 98 this->configFile = new configureFile("install.cfg"); 99 100 // set up "default" installation bits 101 this->installToPath = new FilePath("C:\\GSDL"); 102 this->collectPath = NULL; 103 this->installExe = true; // we must install the exe files 104 105 // don't attempt this with windows 3.1 97 : installManager() 98 { 99 // get the installation configuration file 100 this->configFile = new configureFile("install.cfg"); 101 102 // set up "default" installation bits 103 this->installToPath = new FilePath("C:\\GSDL"); 104 this->collectPath = NULL; 105 this->installExe = true; // we must install the exe files 106 107 // don't attempt this with windows 3.1 106 108 if (!this->platform.isWindows32s()) 107 { // get the registry 108 this->gsRegister = new gsRegistry(*this, *this->configFile); 109 } 109 { 110 // get the registry 111 this->gsRegister = new gsRegistry(*this, *this->configFile); 112 } 110 113 else 111 { // TODO: in windows 3.1 we can't use the register as it isn't fully/properly 112 // implemented; we must get the existing path information from elsewhere 113 this->gsRegister = new gsRegistry(*this, *this->configFile); 114 } 114 { 115 // TODO: in windows 3.1 we can't use the register as it isn't fully/properly 116 // implemented; we must get the existing path information from elsewhere 117 this->gsRegister = new gsRegistry(*this, *this->configFile); 118 } 115 119 116 120 // assume for now we will install the full volume and the database 117 this->installVolume 118 this->installFullVolume 119 120 121 this->installVolume = true; 122 this->installFullVolume = true; 123 124 // detect any existing installation; unnecessary in uninstall (it's the 121 125 // "source" directory - see later 122 126 if (uninstall == false) 123 { this->getExistingInstall(); 124 } 127 { 128 this->getExistingInstall(); 129 } 125 130 126 131 // get where we are installing from … … 129 134 // if doing an uninstall we now know where the "uninstall" is 130 135 if (uninstall == true) 131 { this->collectPath = this->sourcePath; 132 } 136 { 137 this->collectPath = this->sourcePath; 138 } 133 139 134 140 // get the manifest and program manager objects 135 141 if (uninstall) 136 { this->manifest = new gsManifest(*this); 137 } 142 { 143 this->manifest = new gsManifest(*this); 144 } 138 145 else 139 { this->manifest = new gsManifest(*this, *this->sourcePath); 140 } 146 { 147 this->manifest = new gsManifest(*this, *this->sourcePath); 148 } 141 149 this->progman = new gsProgramManager(*this); 142 150 … … 144 152 // be required for loading certain modules such as winsock; the number of 145 153 // macros is over-the-top, but is more robust to unforeseen future requirements 146 /* if (platform.isWindows32s())147 { this->manifest->expandMacro("WINBITS", "16");148 149 150 }151 else152 { this->manifest->expandMacro("WINBITS", "32");153 154 155 }156 */154 /* if (platform.isWindows32s()) 155 { this->manifest->expandMacro("WINBITS", "16"); 156 this->manifest->expandMacro("WIN16", "16"); 157 this->manifest->expandMacro("WIN32", "32"); 158 } 159 else 160 { this->manifest->expandMacro("WINBITS", "32"); 161 this->manifest->expandMacro("WIN16", ""); 162 this->manifest->expandMacro("WIN32", "32"); 163 } 164 */ 157 165 // inform manifest of collection directory name 158 166 string colDir; 159 167 colDir = this->configFile->getString("CollectionDirName"); 160 168 if (colDir != "") 161 { this->manifest->expandMacro("COLDIRNAME", colDir); 162 } 169 { 170 this->manifest->expandMacro("COLDIRNAME", colDir); 171 } 163 172 } 164 173 … … 167 176 */ 168 177 void GSInstall::getExistingInstall() 169 { if (!this->platform.isWindows32s()) 170 { if (gsRegister->collectionInstalled()) 171 { // TODO: check if receptionist etc should be replaced or not 172 173 // TODO: check build version of the volume 174 175 // Get location of the library executable from the registry; this 176 // is thence used to get the location of gsdl.ini etc. 177 this->collectPath = this->gsRegister->collectionPath(); 178 if (this->collectPath != "") 179 { this->installToPath = this->collectPath; 180 181 // we don't need to install the exe files 182 this->installExe = false; 183 } 184 } 185 } 178 { 179 if (!this->platform.isWindows32s()) 180 { 181 if (gsRegister->collectionInstalled()) 182 { 183 // TODO: check if receptionist etc should be replaced or not 184 185 // TODO: check build version of the volume 186 187 // Get location of the library executable from the registry; this 188 // is thence used to get the location of gsdl.ini etc. 189 this->collectPath = this->gsRegister->collectionPath(); 190 if (this->collectPath->pathString() != "") 191 { 192 this->installToPath = this->collectPath; 193 // we don't need to install the exe files 194 this->installExe = false; 195 } 196 } 197 } 186 198 } 187 199 … … 749 761 750 762 bool GSInstall_init_wizard(GSInstall &install) 751 { PROPSHEETHEADER pshead; 752 PROPSHEETPAGE ppage[2]; 753 bool reply; 754 755 ZeroMemory(&pshead, sizeof(PROPSHEETHEADER)); 756 pshead.dwSize = sizeof(PROPSHEETHEADER); 757 pshead.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_USEHICON | PSH_WIZARD; 758 pshead.hwndParent = app_window; 759 pshead.hInstance = app_instance; 760 pshead.hIcon = NULL; 761 pshead.pszCaption = "Greenstone Installer"; 762 pshead.nPages = 2; 763 pshead.nStartPage = 0; 763 { 764 PROPSHEETHEADER pshead; 765 PROPSHEETPAGE ppage[2]; 766 bool reply; 767 768 ZeroMemory(&pshead, sizeof(PROPSHEETHEADER)); 769 pshead.dwSize = sizeof(PROPSHEETHEADER); 770 pshead.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_USEHICON | PSH_WIZARD; 771 pshead.hwndParent = app_window; 772 pshead.hInstance = app_instance; 773 pshead.hIcon = NULL; 774 pshead.pszCaption = "Greenstone Installer"; 775 pshead.nPages = 2; 776 pshead.nStartPage = 0; 764 777 if (install.installExe == true) 765 { pshead.ppsp = ppage; 766 } 778 { 779 pshead.ppsp = ppage; 780 } 767 781 else // cheat as the executable etc. is already installed 768 { pshead.ppsp = &ppage[1]; 769 } 770 pshead.pfnCallback = GSInstall_wizardProc; 782 { 783 pshead.ppsp = &ppage[1]; 784 } 785 pshead.pfnCallback = GSInstall_wizardProc; 771 786 772 787 GSInstall_init_propertySheet( ppage[0], 773 788 "Choose a directory to install your " 774 789 "GreenStone software to.", NULL, 775 790 "Select", install, false); 776 791 GSInstall_init_propertySheet(ppage[1], 777 778 779 780 781 782 783 784 785 786 787 792 "Choose a directory to install the collection " 793 "files to.\n\n" 794 "You can also choose to install all the collection " 795 "files onto your computer hard drive.\n\n" 796 "If you do this, you will not have to load the " 797 "CD-ROM each time you use your Greenstone software " 798 "but more of your hard disk will be used.\n\n" 799 "Some collection files must be installed on your " 800 "computer.\n\n", 801 "Install all collection files", 802 "Select", install, true); 788 803 789 804 reply = (PropertySheet (&pshead) >= 0); … … 791 806 } 792 807 793 long FAR PASCAL GSInstallWindProc(HWND Window, 794 WORD Message, 795 WPARAM wParameter, 796 LPARAM lParameter) 797 { long reply = 0; 808 long FAR PASCAL GSInstallWindProc(HWND Window, WORD Message, WPARAM wParameter, LPARAM lParameter) 809 { 810 long reply = 0; 798 811 799 812 switch(Message) 800 { case WM_CREATE: 801 { ShowWindow(Window, SW_MAXIMIZE); 802 } 803 break; 804 805 case WM_COMMAND: 806 break; 813 { 814 case WM_CREATE: 815 { 816 ShowWindow(Window, SW_MAXIMIZE); 817 } 818 break; 819 820 case WM_COMMAND: 821 break; 807 822 808 823 case WM_USER: 809 { // uninstall action 810 if (strstr(app_cmdLine, "-u") != NULL) 811 { // skip past the -u option itself 812 char *at = strstr(app_cmdLine, "-u"); 813 at += strlen("-u"); 814 815 // extract the log file path from the command line 816 while (*at == ' ') 817 { at ++; 818 } 819 string logPathString(at); 820 FilePath logPath(logPathString); 821 822 GSInstall install(true); 823 // if we're running in the temporary directory, do the uninstall 824 if (install.setUninstall()) 825 { install.uninstall(); 826 827 // close the log to write back all changes to the log; if the file 828 // will be deleted, it must be closed; copying may also fail, so it's 829 // safer to close it before doing either. 830 install.closeLog(); 831 832 // if the install is empty, terminate all final items (currently the 833 // log and setup executables, 834 if (install.isEmpty()) 835 { // delete the log file 836 DeleteFile(logPath.cString()); 837 838 // get it's parent to find where the gssetup executable will be 839 FilePath *logParent = logPath.parent(); 840 FilePath uninstallPath(*logParent, "gssetup.exe"); 841 842 // delete the gssetup executable 843 DeleteFile(uninstallPath.cString()); 844 845 // dispose of the parent directory information 846 delete logParent; 847 } 848 // if not, then overwrite the original log with the modified one 849 else 850 { // do nothing - should be changed already! 851 } 852 } 853 } 824 { 825 // uninstall action 826 if (strstr(app_cmdLine, "-u") != NULL) 827 { 828 // skip past the -u option itself 829 char *at = strstr(app_cmdLine, "-u"); 830 at += strlen("-u"); 831 832 // extract the log file path from the command line 833 while (*at == ' ') 834 { 835 at ++; 836 } 837 string logPathString(at); 838 FilePath logPath(logPathString); 839 840 GSInstall install(true); 841 // if we're running in the temporary directory, do the uninstall 842 if (install.setUninstall()) 843 { 844 install.uninstall(); 845 846 // close the log to write back all changes to the log; if the file 847 // will be deleted, it must be closed; copying may also fail, so it's 848 // safer to close it before doing either. 849 install.closeLog(); 850 851 // if the install is empty, terminate all final items (currently the 852 // log and setup executables, 853 if (install.isEmpty()) 854 { 855 // delete the log file 856 DeleteFile(logPath.cString()); 857 858 // get it's parent to find where the gssetup executable will be 859 FilePath *logParent = logPath.parent(); 860 FilePath uninstallPath(*logParent, "gssetup.exe"); 861 862 // delete the gssetup executable 863 DeleteFile(uninstallPath.cString()); 864 865 // dispose of the parent directory information 866 delete logParent; 867 } 868 // if not, then overwrite the original log with the modified one 869 else 870 { 871 // do nothing - should be changed already! 872 } 873 } 874 } 854 875 // install wizard 855 876 else 856 { GSInstall install(false); 857 GSInstall_init_wizard(install); 877 { 878 GSInstall install(false); 879 GSInstall_init_wizard(install); 858 880 if (config_complete == false) 859 { MessageBox(0, "Install cancelled", app_name, MB_OK); 860 } 861 else 862 { // configure the installation 863 install.setDestination(); 864 install.setManifest(); 865 866 // perform installation 867 install.copyFiles(); 868 install.updateProgman(); 869 install.updateRegistry(); 870 install.updateProfiles(); 871 install.updateSetupExe(); 872 873 // the log will need reopening (probably failed initially) 874 install.reopenLog(); 875 876 // close log 877 install.closeLog(); 878 879 // do further actions 881 { 882 MessageBox(0, "Install cancelled", app_name, MB_OK); 883 } 884 else 885 { 886 // configure the installation 887 install.setDestination(); 888 install.setManifest(); 889 890 // perform installation 891 install.copyFiles(); 892 install.updateProgman(); 893 install.updateRegistry(); 894 install.updateProfiles(); 895 install.updateSetupExe(); 896 897 // the log will need reopening (probably failed initially) 898 install.reopenLog(); 899 900 // close log 901 install.closeLog(); 902 903 // do further actions 880 904 install.installNetscape(); 881 } 905 } 906 } 907 DestroyWindow(Window); 908 } 909 break; 910 911 case WM_CLOSE: 912 /*if (!file_ischanged || IDCANCEL != file_query(Window, file_name))*/ 913 DestroyWindow(Window); 914 return 0L; 915 916 case WM_DESTROY: 917 { 918 PostQuitMessage(0); 882 919 } 883 DestroyWindow(Window); 884 } 885 break; 886 887 case WM_CLOSE: 888 /* if (!file_ischanged || IDCANCEL != file_query(Window, file_name))*/ 889 DestroyWindow(Window); 890 return 0L; 891 892 case WM_DESTROY: 893 { PostQuitMessage(0); 894 } 895 break; 896 897 default: 898 return(DefWindowProc(Window, Message, wParameter, lParameter)); 899 } 920 break; 921 922 default: 923 return(DefWindowProc(Window, Message, wParameter, lParameter)); 924 } 900 925 return reply; 901 926 } … … 921 946 922 947 void WinClassInit(void) 923 { WNDCLASS Class; 924 925 Class.lpszClassName = "GSInstall:Main"; 926 Class.hInstance = app_instance; 927 Class.lpfnWndProc = (WNDPROC) GSInstallWindProc; 928 Class.hCursor = LoadCursor(NULL, IDC_ARROW); 929 Class.hIcon = NULL; //LoadIcon(app_instance, "GSInstall"); 930 Class.lpszMenuName = NULL; 931 Class.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1); 932 Class.style = NULL; 933 Class.cbClsExtra = 0; 934 Class.cbWndExtra = 0; 935 RegisterClass(&Class); 936 /* 937 Class.lpszClassName = "GSInstall:Splash"; 938 Class.hInstance = app_instance; 939 Class.lpfnWndProc = (WNDPROC) splash_windproc; 940 Class.hCursor = LoadCursor(NULL, IDC_ARROW); 941 Class.hIcon = NULL; 942 Class.lpszMenuName = NULL; 943 Class.hbrBackground = (HBRUSH) (COLOR_WINDOW+1); 944 Class.style = NULL; 945 Class.cbClsExtra = 0; 946 Class.cbWndExtra = 0; 947 RegisterClass(&Class);*/ 948 { 949 WNDCLASS Class; 950 951 Class.lpszClassName = "GSInstall:Main"; 952 Class.hInstance = app_instance; 953 Class.lpfnWndProc = (WNDPROC) GSInstallWindProc; 954 Class.hCursor = LoadCursor(NULL, IDC_ARROW); 955 Class.hIcon = NULL; //LoadIcon(app_instance, "GSInstall"); 956 Class.lpszMenuName = NULL; 957 Class.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1); 958 //Class.style = NULL; 959 Class.style = 0; 960 Class.cbClsExtra = 0; 961 Class.cbWndExtra = 0; 962 RegisterClass(&Class); 963 /* 964 Class.lpszClassName = "GSInstall:Splash"; 965 Class.hInstance = app_instance; 966 Class.lpfnWndProc = (WNDPROC) splash_windproc; 967 Class.hCursor = LoadCursor(NULL, IDC_ARROW); 968 Class.hIcon = NULL; 969 Class.lpszMenuName = NULL; 970 Class.hbrBackground = (HBRUSH) (COLOR_WINDOW+1); 971 Class.style = NULL; 972 Class.cbClsExtra = 0; 973 Class.cbWndExtra = 0; 974 RegisterClass(&Class);*/ 948 975 } 949 976 950 977 int PASCAL WinMain(HINSTANCE Current, 951 HINSTANCE Previous, 952 LPSTR CmdLine, 953 int CmdShow) 954 { MSG msg; 955 // HACCEL accel; 956 957 app_cmdLine = (char *) malloc(lstrlen(CmdLine) + 1); 958 lstrcpy(app_cmdLine, CmdLine); 959 960 app_instance = Current; 961 /* -- init application */ 962 if (!Previous) 963 { WinClassInit(); 964 InitCommonControls(); 965 // grbStatic_registerClass(Current); 966 } 967 968 /* -- init instance */ 978 HINSTANCE Previous, 979 LPSTR CmdLine, 980 int CmdShow) 981 { 982 MSG msg; 983 // HACCEL accel; 984 985 app_cmdLine = (char *) malloc(lstrlen(CmdLine) + 1); 986 lstrcpy(app_cmdLine, CmdLine); 987 988 app_instance = Current; 989 /* -- init application */ 990 if (!Previous) 991 { 992 WinClassInit(); 993 InitCommonControls(); 994 // grbStatic_registerClass(Current); 995 } 996 997 /* -- init instance */ 969 998 GSInstall_init(Current, CmdShow); 970 971 // config_init("ReTreeval"); 972 973 // accel = LoadAccelerators(Current, "ReTreevalMenu"); 974 975 while (GetMessage(&msg, NULL, 0, 0)) 976 { /*if (!TranslateAccelerator(app_window, accel, &msg)) 999 1000 // config_init("ReTreeval"); 1001 1002 // accel = LoadAccelerators(Current, "ReTreevalMenu"); 1003 1004 while (GetMessage(&msg, NULL, 0, 0)) 1005 { 1006 /*if (!TranslateAccelerator(app_window, accel, &msg)) 977 1007 { */ 978 979 980 /*}*/981 982 983 } 1008 TranslateMessage(&msg); 1009 DispatchMessage(&msg); 1010 /*}*/ 1011 } 1012 return (int) msg.wParam; 1013 } -
trunk/gsinstaller/registry.cpp
r1475 r1536 3 3 4 4 bool registry_createkey(HKEY key, const char *name, PHKEY keyout) 5 { LONG reply; 6 DWORD disposition; 7 8 reply = RegCreateKeyEx( key, name, NULL, NULL, 9 REG_OPTION_NON_VOLATILE, 10 KEY_ALL_ACCESS, NULL, 11 keyout, &disposition); 12 if (reply != ERROR_SUCCESS) 13 { return FALSE; 14 } 5 { 6 LONG reply; 7 DWORD disposition; 8 9 reply = RegCreateKeyEx(key, name, 0, NULL, 10 REG_OPTION_NON_VOLATILE, 11 KEY_ALL_ACCESS, NULL, 12 keyout, &disposition); 13 if (reply != ERROR_SUCCESS) 14 { 15 return FALSE; 16 } 15 17 return TRUE; 16 18 } 17 19 18 20 bool registry_openkey(HKEY key, const char *name, PHKEY keyout) 19 { LONG reply; 20 21 reply = RegOpenKeyEx(key, name, NULL, KEY_QUERY_VALUE, keyout); 22 if (reply != ERROR_SUCCESS) 23 { return false; 24 } 21 { 22 LONG reply; 23 24 reply = RegOpenKeyEx(key, name, 0, KEY_QUERY_VALUE, keyout); 25 if (reply != ERROR_SUCCESS) 26 { 27 return false; 28 } 25 29 return true; 26 30 } 27 31 28 32 bool registry_deletekey(HKEY key, const char *name) 29 { if (RegDeleteKey(key, name) != ERROR_SUCCESS) 30 { return false; 31 } 33 { 34 if (RegDeleteKey(key, name) != ERROR_SUCCESS) 35 { 36 return false; 37 } 32 38 return true; 33 39 } 34 40 35 41 bool registry_closekey(HKEY key) 36 { LONG reply; 37 reply = RegCloseKey(key); 38 if (reply != ERROR_SUCCESS) 39 { return FALSE; 42 { 43 LONG reply; 44 reply = RegCloseKey(key); 45 if (reply != ERROR_SUCCESS) 46 { 47 return FALSE; 40 48 } 41 49 return TRUE; … … 43 51 44 52 bool registry_keyExists(HKEY key, const char *name) 45 { HKEY local; 46 47 if (!registry_openkey(key, name, &local)) 48 { return false; 53 { 54 HKEY local; 55 56 if (!registry_openkey(key, name, &local)) 57 { 58 return false; 49 59 } 50 60 registry_closekey(local); … … 53 63 54 64 bool registry_ensureKeyExists(HKEY key, const char *name) 55 { HKEY local; 56 57 if (!registry_openkey(key, name, &local)) 58 { if (!registry_createkey(key, name, &local)) 59 { return false; 60 } 61 } 62 registry_closekey(local); 65 { 66 HKEY local; 67 68 if (!registry_openkey(key, name, &local)) 69 { 70 if (!registry_createkey(key, name, &local)) 71 { 72 return false; 73 } 74 } 75 registry_closekey(local); 63 76 return true; 64 77 } 65 78 66 79 bool registry_deleteitem(HKEY key, const char *name) 67 { if (RegDeleteValue(key, name) != ERROR_SUCCESS) 68 { return false; 69 } 80 { 81 if (RegDeleteValue(key, name) != ERROR_SUCCESS) 82 { 83 return false; 84 } 70 85 return true; 71 86 } 72 87 73 88 bool registry_setstring(HKEY key, const char *name, const char *value) 74 { LONG reply; 75 76 reply = RegSetValueEx(key, (LPCTSTR) name, NULL, REG_SZ, (CONST BYTE *) value, strlen(value) + 1); 77 if (reply != ERROR_SUCCESS) 78 { return false; 89 { 90 LONG reply; 91 92 reply = RegSetValueEx(key, (LPCTSTR) name, 0, REG_SZ, (CONST BYTE *) value, strlen(value) + 1); 93 if (reply != ERROR_SUCCESS) 94 { 95 return false; 79 96 } 80 97 return true; … … 82 99 83 100 bool registry_setlong(HKEY key, char *name, LONG value) 84 { LONG reply; 85 DWORD word; 86 101 { 102 LONG reply; 103 DWORD word; 104 87 105 word = (DWORD) value; 88 reply = RegSetValueEx(key, (LPCTSTR) name, NULL, REG_DWORD, (CONST BYTE *) &word, sizeof(DWORD)); 89 if (reply != ERROR_SUCCESS) 90 { return FALSE; 106 reply = RegSetValueEx(key, (LPCTSTR) name, 0, REG_DWORD, (CONST BYTE *) &word, sizeof(DWORD)); 107 if (reply != ERROR_SUCCESS) 108 { 109 return FALSE; 91 110 } 92 111 return TRUE; … … 94 113 95 114 bool registry_setblock(HKEY key, char *name, char *data, int size) 96 { LONG reply; 97 98 reply = RegSetValueEx(key, name, NULL, REG_BINARY, (CONST BYTE *) data, size); 99 if (reply != ERROR_SUCCESS) 100 { // display_error(); 101 return FALSE; 115 { 116 LONG reply; 117 118 reply = RegSetValueEx(key, name, 0, REG_BINARY, (CONST BYTE *) data, size); 119 if (reply != ERROR_SUCCESS) 120 { 121 // display_error(); 122 return FALSE; 102 123 } 103 124 return TRUE; … … 105 126 106 127 bool registry_setint(HKEY key, char *name, int value) 107 { return registry_setlong(key, name, (LONG) value); 128 { 129 return registry_setlong(key, name, (LONG) value); 108 130 } 109 131 110 132 bool registry_getstring(HKEY key, char *name, char **string) 111 { LONG reply; 112 DWORD type; 133 { 134 LONG reply; 135 DWORD type; 113 136 DWORD size; 114 137 BYTE buffer[128]; … … 116 139 117 140 do 118 { 119 reply = RegQueryValueEx(key, name, NULL, &type, buffer, &size); 120 if (reply != ERROR_SUCCESS) 121 { //display_error(); 122 //sprintf(buffer, "%x {%s}", key, name); 123 //MessageBox(0, buffer, name, MB_OK); 124 } 125 tries ++; 126 } while (reply != ERROR_SUCCESS && tries < 3); 127 128 if (reply != ERROR_SUCCESS) 129 { return FALSE; 141 { 142 reply = RegQueryValueEx(key, name, NULL, &type, buffer, &size); 143 if (reply != ERROR_SUCCESS) 144 { 145 //display_error(); 146 //sprintf(buffer, "%x {%s}", key, name); 147 //MessageBox(0, buffer, name, MB_OK); 148 } 149 tries ++; 150 } while (reply != ERROR_SUCCESS && tries < 3); 151 152 if (reply != ERROR_SUCCESS) 153 { 154 return FALSE; 130 155 } 131 156 132 157 *string = (char *) malloc(size); 133 158 if (*string == NULL) 134 { return FALSE; 159 { 160 return FALSE; 135 161 } 136 162 strcpy(*string, (char *) buffer); … … 139 165 140 166 bool registry_getint(HKEY key, char *name, int *out) 141 { DWORD type; 142 DWORD size; 167 { 168 DWORD type; 169 DWORD size; 143 170 LONG reply; 144 171 145 reply = RegQueryValueEx(key, (LPTSTR) name, NULL, &type, (LPBYTE) out, &size); 146 if (reply != ERROR_SUCCESS) 147 { return FALSE; 172 reply = RegQueryValueEx(key, (LPTSTR) name, NULL, &type, (LPBYTE) out, &size); 173 if (reply != ERROR_SUCCESS) 174 { 175 return FALSE; 148 176 } 149 177 return TRUE; … … 151 179 152 180 bool registry_getlong(HKEY key, char *name, LONG *out) 153 { DWORD type; 154 DWORD size; 181 { 182 DWORD type; 183 DWORD size; 155 184 LONG reply; 156 185 DWORD got; … … 158 187 size = sizeof(DWORD); 159 188 160 reply = RegQueryValueEx(key, name, NULL, &type, (LPBYTE) &got, &size); 161 if (reply != ERROR_SUCCESS) 162 { return FALSE; 189 reply = RegQueryValueEx(key, name, NULL, &type, (LPBYTE) &got, &size); 190 if (reply != ERROR_SUCCESS) 191 { 192 return FALSE; 163 193 } 164 194 *out = (LONG) got; … … 167 197 168 198 int registry_getblock(HKEY key, char *name, char *data, int size) 169 { DWORD type; 170 DWORD lsize; 199 { 200 DWORD type; 201 DWORD lsize; 171 202 LONG reply; 172 203 173 204 lsize = size; 174 205 175 reply = RegQueryValueEx(key, name, NULL, &type, (LPBYTE) data, &lsize); 176 if (reply != ERROR_SUCCESS) 177 { return -1; 206 reply = RegQueryValueEx(key, name, NULL, &type, (LPBYTE) data, &lsize); 207 if (reply != ERROR_SUCCESS) 208 { 209 return -1; 178 210 } 179 211 return lsize; … … 181 213 182 214 bool registry_fetchlong(char *keystr, LONG *lptr) 183 { HKEY key; 184 185 if (!registry_openkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key)) 186 { return FALSE; 187 } 215 { 216 HKEY key; 217 218 if (!registry_openkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key)) 219 { 220 return FALSE; 221 } 188 222 if (!registry_getlong(key, keystr, lptr)) 189 { return FALSE; 190 } 223 { 224 return FALSE; 225 } 191 226 if (registry_closekey(key) == FALSE) 192 { return FALSE; 193 } 227 { 228 return FALSE; 229 } 194 230 return TRUE; 195 231 } 196 232 197 233 bool registry_fetchblock(char *keystr, char *data, int size) 198 { HKEY key; 199 int read; 200 201 if (!registry_openkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key)) 202 { return FALSE; 203 } 234 { 235 HKEY key; 236 int read; 237 238 if (!registry_openkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key)) 239 { 240 return FALSE; 241 } 204 242 read = registry_getblock(key, keystr, data, size); 205 243 if (read < 0) 206 { return FALSE; 207 } 244 { 245 return FALSE; 246 } 208 247 if (registry_closekey(key) == FALSE) 209 { return FALSE; 210 } 248 { 249 return FALSE; 250 } 211 251 return TRUE; 212 252 } 213 253 214 254 bool registry_storelong(char *keystr, LONG value) 215 { HKEY key; 216 217 if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key)) 218 { return FALSE; 255 { 256 HKEY key; 257 258 if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key)) 259 { 260 return FALSE; 219 261 } 220 262 if (!registry_setlong(key, keystr, value)) 221 { return FALSE; 263 { 264 return FALSE; 222 265 } 223 266 if (!registry_closekey(key)) 224 { return FALSE; 267 { 268 return FALSE; 225 269 } 226 270 return TRUE; … … 228 272 229 273 bool registry_storeint(char *keystr, int value) 230 { HKEY key; 231 232 if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key)) 233 { return FALSE; 274 { 275 HKEY key; 276 277 if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key)) 278 { 279 return FALSE; 234 280 } 235 281 if (!registry_setint(key, keystr, value)) 236 { return FALSE; 282 { 283 return FALSE; 237 284 } 238 285 if (!registry_closekey(key)) 239 { return FALSE; 286 { 287 return FALSE; 240 288 } 241 289 return TRUE; … … 243 291 244 292 bool registry_storeblock(char *keystr, char *data, int size) 245 { HKEY key; 246 247 if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key)) 248 { return FALSE; 293 { 294 HKEY key; 295 296 if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key)) 297 { 298 return FALSE; 249 299 } 250 300 if (!registry_setblock(key, keystr, data, size)) 251 { return FALSE; 301 { 302 return FALSE; 252 303 } 253 304 if (!registry_closekey(key)) 254 { return FALSE; 305 { 306 return FALSE; 255 307 } 256 308 return TRUE; … … 258 310 259 311 bool registry_storestring(char *keystr, char *value) 260 { HKEY key; 261 262 if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key)) 263 { return FALSE; 312 { 313 HKEY key; 314 315 if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key)) 316 { 317 return FALSE; 264 318 } 265 319 if (!registry_setstring(key, keystr, value)) 266 { return FALSE; 320 { 321 return FALSE; 267 322 } 268 323 if (!registry_closekey(key)) 269 { return FALSE; 270 } 271 return TRUE; 272 } 324 { 325 return FALSE; 326 } 327 return TRUE; 328 } -
trunk/gsinstaller/stringArray.h
r1498 r1536 8 8 9 9 class stringArray 10 { private: 11 protected: 12 public: 13 vector<string> array; 14 stringArray(); 15 stringArray(char *list, char *divider); 16 void add(char *member); 17 void add(string member); 18 void add(stringArray &array); 19 void insertAt(string member, unsigned int at); 20 void remove(char *member); 21 void remove(string member); 22 void clear(); 23 bool includes(char *member); 24 bool includes(string member); 25 static stringArray words(char *line); 26 unsigned int size(){ return this->array.size(); }; 27 int indexOf(char *member); 28 int indexOf(string member); 29 int writeToCString(char *buffer, char *divider, int bufflen); 30 string toString(string separator); 31 string &operator[](const unsigned int); 10 { 11 private: 12 protected: 13 public: 14 vector<string> array; 15 stringArray(); 16 stringArray(char *list, char *divider); 17 void add(char *member); 18 void add(string member); 19 void add(stringArray &array); 20 void insertAt(string member, unsigned int at); 21 void remove(char *member); 22 void remove(string member); 23 void clear(); 24 bool includes(char *member); 25 bool includes(string member); 26 static stringArray words(char *line); 27 unsigned int size(){ return this->array.size(); }; 28 int indexOf(char *member); 29 int indexOf(string member); 30 int writeToCString(char *buffer, char *divider, int bufflen); 31 string toString(string separator); 32 string &operator[](const unsigned int); 32 33 }; 33 34 -
trunk/gsinstaller/unInstall.h
r1525 r1536 7 7 8 8 #include <stdio.h> 9 10 #if defined (GSDL_USE_IOS_H) 9 11 #include <fstream.h> 12 #else 13 #include <fstream> 14 #endif 10 15 11 16 #include "stringArray.h" … … 14 19 15 20 typedef class unInstallCommand 16 { public: 17 string command; 18 stringArray parameters; 21 { 22 public: 23 string command; 24 stringArray parameters; 19 25 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; }; 26 unInstallCommand() { }; 27 unInstallCommand(string commandname) { this->command = commandname; }; 28 unInstallCommand(string commandname, stringArray params) 29 { 30 this->command = commandname; 31 this->parameters = params; 32 }; 33 void addParameter(string parameter) { this->parameters.add(parameter); }; 34 string commandName() { return this->command; }; 35 stringArray ¶meterList() { return this->parameters; }; 29 36 } unInstallCommand; 30 37 … … 34 41 35 42 class installManager 36 { private: 37 fstream logfile; 38 string logfileName; 39 string currentModule; 40 unInstallCommandMap modules; 43 { 44 private: 45 fstream logfile; 46 string logfileName; 47 string currentModule; 48 unInstallCommandMap modules; 41 49 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 50 bool writeString(string str); 51 bool writeString(char *string); 52 bool writeSeparator(); 53 string readString(); 54 bool writeCommand(unInstallCommand &command); 55 string readCommand(stringArray ¶ms); 56 public: 57 installManager() { }; 58 bool openLog(string filename, bool write); 59 bool closeLog(); 60 bool reopenLog(); 61 void setModule(string moduleName); 62 bool storeCommand(unInstallCommand &command); 63 string popCommand(stringArray ¶ms); 64 bool isEmpty(); 65 ~installManager(); 58 66 }; 59 67 60 68 class installAgent 61 { protected: 62 installManager *manager; 63 public: 64 installAgent(installManager &useManager) { this->manager = &useManager; }; 65 virtual bool undoAction(string actionName, stringArray ¶ms) { return false; }; 66 // bool undo(string actionName); 69 { 70 protected: 71 installManager *manager; 72 public: 73 installAgent(installManager &useManager) { this->manager = &useManager; }; 74 virtual bool undoAction(string actionName, stringArray ¶ms) { return false; }; 75 // bool undo(string actionName); 67 76 }; 68 77
Note:
See TracChangeset
for help on using the changeset viewer.