Skip to content

Commit 65b413d

Browse files
committed
CollectionInterface: overrideMap = get the non-writable-directory UAC working correctly
1 parent 0faf2d2 commit 65b413d

2 files changed

Lines changed: 35 additions & 16 deletions

File tree

src/Classes/OverrideMapUpdaterClass.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class OverrideMapUpdater {
3030

3131
// save the underlying overrideMap.xml
3232
tinyxml2::XMLError OverrideMapUpdater::saveFile(void) { return pOverrideMapXML->SaveFile(sOverMapPath().c_str()); }
33+
tinyxml2::XMLError OverrideMapUpdater::saveFile(std::string sNewPath) { return pOverrideMapXML->SaveFile(sNewPath.c_str()); }
34+
tinyxml2::XMLError OverrideMapUpdater::saveFile(std::wstring wsNewPath) { return pOverrideMapXML->SaveFile(pcjHelper::wstring_to_utf8(wsNewPath).c_str()); }
3335

3436
// TODO: !!!error handling on all XML processing!!!
3537

src/Dialogs/CollectionInterfaceDialog.cpp

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,16 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
377377
pobjOvMapUpdater = new OverrideMapUpdater;
378378
}
379379

380+
// For FL downloads, need to add the association here if overrideMap-updating is enabled
381+
if (doUpdateOverrideMap && (wsCategory == L"FunctionList"))
382+
pobjOvMapUpdater->add_udl_assoc(ws_id_name + L".xml", wsFilename);
383+
384+
// do the main download if writable, or add it to the queue if not
380385
int count = 0;
381386
if (isWritable) {
382387
// download directly to the final destination
383388
didDownload |= pobjCI->downloadFileToDisk(wsURL, wsPath);
384389
count++;
385-
386-
// For FL downloads, need to add the association here if overrideMap-updating is enabled
387-
if (doUpdateOverrideMap && (wsCategory == L"FunctionList"))
388-
pobjOvMapUpdater->add_udl_assoc(ws_id_name + L".xml", wsFilename);
389390
}
390391
else {
391392
// check if it needs to be overwritten before elevating permissions
@@ -418,14 +419,6 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
418419
pobjCI->downloadFileToDisk(xURL, xPath);
419420
count++;
420421
didDownload = true;
421-
422-
// For xtra[FL], need to add the association here if overrideMap-updating is enabled
423-
if (doUpdateOverrideMap && (category == L"FL"))
424-
{
425-
std::wstring xDisp = alsoDownload[category][L"DISPLAY"];
426-
pobjOvMapUpdater->add_udl_assoc(ws_id_name + L".xml", xDisp);
427-
}
428-
429422
}
430423
else {
431424
if (pobjCI->ask_overwrite_if_exists(xPath)) {
@@ -437,6 +430,14 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
437430
total--;
438431
}
439432
}
433+
434+
// For xtra[FL], need to add the association here if overrideMap-updating is enabled
435+
if (doUpdateOverrideMap && (category == L"FL"))
436+
{
437+
std::wstring xDisp = alsoDownload[category][L"DISPLAY"];
438+
pobjOvMapUpdater->add_udl_assoc(ws_id_name + L".xml", xDisp);
439+
}
440+
440441
}
441442
// update progress bar
442443
if (total < 1) total = 1;
@@ -462,11 +463,14 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
462463

463464
if (mapUacDelayed.size()) {
464465
int total = static_cast<int>(mapUacDelayed.size()) + 1; // want one extra "slot" for the MOVE command
466+
if (doUpdateOverrideMap) total++; // want an extra entry for the overrideMap.xml
465467
int count = 0;
466468
std::wstring wsAsk = L"Cannot write the following files:";
467469
for (const auto& pair : mapUacDelayed) {
468470
wsAsk += std::wstring(L"\n") + pair.second;
469471
}
472+
if (doUpdateOverrideMap)
473+
wsAsk += std::wstring(L"\n") + pobjOvMapUpdater->wsOverMapPath();
470474
wsAsk += L"\n\nI will download temporary files, and then try to copy them to the right location with elevated UAC permission. (The OS may prompt you for UAC.)";
471475
int ans = ::MessageBox(hwndDlg, wsAsk.c_str(), L"Need Directory Permission", MB_OKCANCEL);
472476
if (ans == IDOK) {
@@ -488,16 +492,29 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
488492
Edit_SetText(GetDlgItem(hwndDlg, IDC_CI_PROGRESSLBL), wcDLPCT);
489493
}
490494

495+
// need to add the override map to the list of UAC commands
496+
if (doUpdateOverrideMap) {
497+
std::wstring tmpOvM = pobjCI->getWritableTempDir() + L"\\~$TMPFILE.UPDATED.overrideMap.xml";
498+
pobjOvMapUpdater->saveFile(tmpOvM);
499+
500+
args += L"MOVE /Y \"" + tmpOvM + L"\" \"" + pobjOvMapUpdater->wsOverMapPath() + L"\" & ";
501+
502+
++count;
503+
504+
::SendDlgItemMessage(hwndDlg, IDC_CI_PROGRESSBAR, PBM_SETPOS, 100 * count / total, 0);
505+
swprintf_s(wcDLPCT, L"Downloading %d%%", 100 * count / total);
506+
Edit_SetText(GetDlgItem(hwndDlg, IDC_CI_PROGRESSLBL), wcDLPCT);
507+
508+
// don't want to try to write a second time, below, so set false
509+
doUpdateOverrideMap = false;
510+
}
511+
491512
//::MessageBox(hwndDlg, (std::wstring(L"cmd.exe ") + args).c_str(), L"TODO: UAC Command", MB_OK);
492513
ShellExecute(hwndDlg, L"runas", L"cmd.exe", args.c_str(), NULL, SW_SHOWMINIMIZED);
493514

494515
::SendDlgItemMessage(hwndDlg, IDC_CI_PROGRESSBAR, PBM_SETPOS, 100, 0);
495516
swprintf_s(wcDLPCT, L"Downloading %d%% [DONE]", 100);
496517
Edit_SetText(GetDlgItem(hwndDlg, IDC_CI_PROGRESSLBL), wcDLPCT);
497-
498-
if (doUpdateOverrideMap)
499-
pobjOvMapUpdater->add_udl_assoc(mapUacDelayed);
500-
501518
}
502519
}
503520

0 commit comments

Comments
 (0)