Changeset 229 for trunk/src/helpers/xprf2.c
- Timestamp:
- Nov 24, 2002, 9:45:05 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/xprf2.c
r167 r229 77 77 78 78 APIRET xprfCopyKey(HINI hiniSource, // in: source profile (can be HINI_USER or HINI_SYSTEM) 79 P SZ pszSourceApp,// in: source application80 P SZ pszKey,// in: source/target key79 PCSZ pszSourceApp, // in: source application 80 PCSZ pszKey, // in: source/target key 81 81 PXINI hiniTarget, // in: target profile opened with xprfOpenProfile 82 P SZ pszTargetApp)// in: target app82 PCSZ pszTargetApp) // in: target app 83 83 { 84 84 ULONG ulSizeOfData = 0; 85 85 APIRET arc = NO_ERROR; 86 86 87 if (PrfQueryProfileSize(hiniSource, pszSourceApp, pszKey, &ulSizeOfData)) 87 if (PrfQueryProfileSize(hiniSource, 88 (PSZ)pszSourceApp, 89 (PSZ)pszKey, 90 &ulSizeOfData)) 88 91 { 89 92 PSZ pData = 0; … … 107 110 fflush(stdout); 108 111 if (PrfQueryProfileData(hiniSource, 109 pszSourceApp,110 pszKey,112 (PSZ)pszSourceApp, 113 (PSZ)pszKey, 111 114 pData, 112 115 &ulSizeOfData)) 113 116 { 114 if (!xprfWriteProfileData(hiniTarget, 115 pszTargetApp, 116 pszKey, 117 pData, 118 ulSizeOfData)) 117 arc = xprfWriteProfileData(hiniTarget, 118 pszTargetApp, 119 pszKey, 120 pData, 121 ulSizeOfData); 122 } 123 else 124 arc = PRFERR_READ; 125 126 free(pData); 127 } 128 else 129 arc = ERROR_NOT_ENOUGH_MEMORY; 130 } 131 else 132 arc = PRFERR_DATASIZE; 133 134 return arc; 135 } 136 137 /* 138 *@@ xprfCopyKey2: 139 * copies a single key from an xprf* PXINI to a Prf* HINI. 140 * hiniSource must therefore have been opened using 141 * xprfOpenProfile. 142 * 143 * This returns 0 (NO_ERROR) if copying succeeded. Otherwise either 144 * an OS/2 error code (ERROR_*) or one of the profile error 145 * codes defined in prfh.h is returned. 146 * 147 *@@added V1.0.0 (2002-09-17) [umoeller] 148 */ 149 150 APIRET xprfCopyKey2(PXINI hiniSource, // in: source profile (can be HINI_USER or HINI_SYSTEM) 151 PCSZ pszSourceApp, // in: source application 152 PCSZ pszKey, // in: source/target key 153 HINI hiniTarget, // in: target profile opened with xprfOpenProfile 154 PCSZ pszTargetApp) // in: target app 155 { 156 ULONG ulSizeOfData = 0; 157 APIRET arc = NO_ERROR; 158 159 if (xprfQueryProfileSize(hiniSource, pszSourceApp, pszKey, &ulSizeOfData)) 160 { 161 PSZ pData = 0; 162 163 // copy data 164 if (ulSizeOfData == 0) 165 { 166 // data size == 0: this shouldn't really happen, 167 // but if it does, we'll just create a NULL string. 168 // Users have reported that some INI files seem to 169 // contain those "empty" keys. I don't see how these 170 // can exist, but they seem to... 171 pData = (PSZ)malloc(1); 172 *pData = 0; 173 } 174 else 175 pData = (PSZ)malloc(ulSizeOfData); 176 177 if (pData) 178 { 179 fflush(stdout); 180 if (xprfQueryProfileData(hiniSource, 181 pszSourceApp, 182 pszKey, 183 pData, 184 &ulSizeOfData)) 185 { 186 if (!PrfWriteProfileData(hiniTarget, 187 (PSZ)pszTargetApp, 188 (PSZ)pszKey, 189 pData, 190 ulSizeOfData)) 119 191 arc = PRFERR_WRITE; 120 192 } … … 135 207 /* 136 208 *@@ xprfCopyApp: 137 * copies a single application from a nPrf* HINI to an xprf* PXINI.209 * copies a single application from a Prf* HINI to an xprf* PXINI. 138 210 * hiniTarget must therefore have been opened using 139 211 * xprfOpenProfile. … … 146 218 */ 147 219 148 APIRET xprfCopyApp(HINI hiniSource, // in: source profile (can be HINI_USER or HINI_SYSTEM)149 P SZ pszSourceApp,// in: source application150 PXINI hiniTarget, // in: target profile opened with xprfOpenProfile151 P SZ pszTargetApp,// in: name of pszSourceApp in hiniTarget152 PSZ pszErrorKey) // out: failing key in case of error; ptr can be NULL220 APIRET xprfCopyApp(HINI hiniSource, // in: source profile (can be HINI_USER or HINI_SYSTEM) 221 PCSZ pszSourceApp, // in: source application 222 PXINI hiniTarget, // in: target profile opened with xprfOpenProfile 223 PCSZ pszTargetApp, // in: name of pszSourceApp in hiniTarget 224 PSZ pszErrorKey) // out: failing key in case of error; ptr can be NULL 153 225 { 154 226 APIRET arc = NO_ERROR; … … 167 239 { 168 240 // copy this key 169 arc = xprfCopyKey(hiniSource, 170 pszSourceApp, 171 pKey2, 172 hiniTarget, 173 pszTargetApp); 174 if (arc) 241 if (arc = xprfCopyKey(hiniSource, 242 pszSourceApp, 243 pKey2, 244 hiniTarget, 245 pszTargetApp)) 175 246 { 176 247 // error: copy failing key to buffer … … 179 250 break; 180 251 } 252 253 pKey2 += strlen(pKey2)+1; 254 } // end while (*pKey2 != 0) 255 256 free (pszKeysList); 257 } 258 else 259 arc = PRFERR_KEYSLIST; 260 261 return arc; 262 } 263 264 /* 265 *@@ xprfCopyApp2: 266 * copies a single application from an xprf* PXINI to a Prf* HINI. 267 * hiniTarget must therefore have been opened using 268 * xprfOpenProfile. 269 * 270 * This calls xprfCopyKey2 for each key in the application. 271 * 272 * This returns 0 (NO_ERROR) if copying succeeded. Otherwise either 273 * an OS/2 error code (ERROR_*) or one of the profile error 274 * codes defined in prfh.h is returned. 275 * 276 *@@added V1.0.0 (2002-09-17) [umoeller] 277 */ 278 279 APIRET xprfCopyApp2(PXINI hiniSource, // in: source profile (can be HINI_USER or HINI_SYSTEM) 280 PCSZ pszSourceApp, // in: source application 281 HINI hiniTarget, // in: target profile opened with xprfOpenProfile 282 PCSZ pszTargetApp, // in: name of pszSourceApp in hiniTarget 283 PSZ pszErrorKey) // out: failing key in case of error; ptr can be NULL 284 { 285 APIRET arc = NO_ERROR; 286 PSZ pszKeysList = NULL; 287 288 if (pszErrorKey) 289 *pszErrorKey = 0; 290 291 if (!(arc = xprfQueryKeysForApp(hiniSource, 292 pszSourceApp, 293 &pszKeysList))) 294 { 295 PSZ pKey2 = pszKeysList; 296 297 while (*pKey2 != 0) 298 { 299 // copy this key 300 if (arc = xprfCopyKey2(hiniSource, 301 pszSourceApp, 302 pKey2, 303 hiniTarget, 304 pszTargetApp)) 305 { 306 // error: copy failing key to buffer 307 if (pszErrorKey) 308 strcpy(pszErrorKey, pKey2); 309 break; 310 } 311 181 312 pKey2 += strlen(pKey2)+1; 182 313 } // end while (*pKey2 != 0) … … 208 339 209 340 APIRET xprfCopyProfile(HINI hOld, // in: source profile (can be HINI_USER or HINI_SYSTEM) 210 P SZ pszNew,// in: new filename (can be fully qualified)341 PCSZ pszNew, // in: new filename (can be fully qualified) 211 342 PFN_PRF_PROGRESS pfnProgressCallback, 212 343 ULONG ulUser, // in: passed to pfnProgressCallback 213 344 ULONG ulCount, // in: index of INI being copied (0 <= ulCount <= ulMax) 214 ULONG ulMax) // in: maximum index (for progress); 0 means 1 INI, 1 means 2 INIs, ... 345 ULONG ulMax, // in: maximum index (for progress); 0 means 1 INI, 1 means 2 INIs, ... 346 PSZ pszFailingApp) // out: failing app on error 215 347 { 216 348 APIRET arc = NO_ERROR; … … 218 350 ULONG ulSizeOfAppsList; 219 351 352 if (pszFailingApp) 353 *pszFailingApp = 0; 354 220 355 if (!pszNew) 221 356 arc = ERROR_INVALID_PARAMETER; 222 357 else 223 358 { 224 DosDelete( pszNew);359 DosDelete((PSZ)pszNew); 225 360 226 361 // open new profile 227 arc = xprfOpenProfile(pszNew, 228 &pxiniNew); 229 230 // get size of applications list 231 if (arc == NO_ERROR) 232 { 362 if (!(arc = xprfOpenProfile(pszNew, 363 &pxiniNew))) 364 { 365 // get size of applications list 233 366 if (!PrfQueryProfileSize(hOld, NULL, NULL, &ulSizeOfAppsList)) 234 367 arc = PRFERR_APPSLIST; … … 256 389 { 257 390 CHAR szErrorKey[1000]; 391 258 392 // copy application (this will call prfhCopyKey in turn) 259 arc = xprfCopyApp(hOld, 260 pApp2, 261 pxiniNew, 262 pApp2, 263 szErrorKey); 264 265 if (pfnProgressCallback) 393 if (arc = xprfCopyApp(hOld, 394 pApp2, 395 pxiniNew, 396 pApp2, 397 szErrorKey)) 398 { 399 if (pszFailingApp) 400 strhncpy0(pszFailingApp, pApp2, CCHMAXPATH); 401 } 402 else if (pfnProgressCallback) 266 403 { 267 404 ULONG ulNow2, ulMax2; … … 325 462 APIRET xprfSaveINIs(HAB hab, // in: anchor block 326 463 PFN_PRF_PROGRESS pfnProgressCallback, 327 ULONG ulUser) 464 ULONG ulUser, 465 PSZ pszFailingINI, 466 PSZ pszFailingApp, 467 PSZ pszFailingKey) 328 468 { 329 469 PRFPROFILE Profiles; … … 400 540 401 541 if (arc == NO_ERROR) 542 { 543 if (pszFailingINI) 544 strcpy(pszFailingINI, 545 szSysNew); 546 402 547 arc = xprfCopyProfile(HINI_SYSTEM, 403 548 szSysNew, // new filename 404 549 pfnProgressCallback, 405 ulUser, 0, 1); 550 ulUser, 551 0, 552 1, 553 pszFailingApp); 554 } 555 406 556 /* 407 557 * create OS2SYS.XFL: … … 410 560 411 561 if (arc == NO_ERROR) 562 { 563 if (pszFailingINI) 564 strcpy(pszFailingINI, 565 szUserNew); 566 412 567 arc = xprfCopyProfile(HINI_USER, 413 568 szUserNew, // new filename 414 569 pfnProgressCallback, 415 ulUser, 1, 1); 570 ulUser, 571 1, 572 1, 573 pszFailingApp); 574 } 416 575 } 417 576 … … 453 612 { 454 613 // finally, replace system profiles 455 arc = DosMove(szSysNew, Profiles.pszSysName); 456 if (arc == NO_ERROR) 457 arc = DosMove(szUserNew, Profiles.pszUserName); 614 if (!(arc = DosMove(szSysNew, Profiles.pszSysName))) 615 { 616 if (arc = DosMove(szUserNew, Profiles.pszUserName)) 617 { 618 if (pszFailingINI) 619 strcpy(pszFailingINI, 620 szUserNew); 621 } 622 } 623 else 624 { 625 if (pszFailingINI) 626 strcpy(pszFailingINI, 627 szSysNew); 628 } 458 629 } 459 630 … … 468 639 // testing 469 640 470 /* BOOL _Optlink fnCallback(ULONG ulUser, ULONG ulNow, ULONG ulMax) 641 #ifdef __BUILD_XPRF2_MAIN__ 642 643 BOOL _Optlink fnCallback(ULONG ulUser, ULONG ulNow, ULONG ulMax) 471 644 { 472 645 printf("\r done %03d%%", ulNow * 100 / ulMax); … … 476 649 int main(int argc, char* argv[]) 477 650 { 478 if (argc != 3)479 printf("Syntax: xprf2 <source.ini> <target.ini>\n"); 480 else481 { 482 HAB hab = WinInitialize(0);483 484 // HINI hiniSource = PrfOpenProfile(hab, argv[1]);485 // if (hiniSource) 486 {487 APIRET arc = xprfCopyProfile(hiniSource,488 argv[2],489 fnCallback,490 0, 0, 0);491 xprfSaveProfiles(hab, NULL, 0);492 // if (arc) 493 494 495 // printf("xprfCopyProfile returned %d.\n", arc);496 }497 // else498 // printf("Cannot open %s\n", argv[1]); 499 500 WinTerminate(hab); 501 }502 503 return (0); 504 } */ 505 651 APIRET arc = 2; 652 653 HAB hab = WinInitialize(0); 654 655 CHAR szFailingINI[CCHMAXPATH] = "", 656 szFailingApp[CCHMAXPATH] = "", 657 szFailingKey[CCHMAXPATH] = ""; 658 659 arc = xprfSaveINIs(hab, 660 NULL, 661 0, 662 szFailingINI, 663 szFailingApp, 664 szFailingKey); 665 666 printf("xprfCopyProfile returned %d ('%s', '%s', '%s'.\n", 667 arc, 668 szFailingINI, 669 szFailingApp, 670 szFailingKey); 671 672 WinTerminate(hab); 673 674 return arc; 675 } 676 677 #endif 678
Note:
See TracChangeset
for help on using the changeset viewer.