-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContext.cpp
More file actions
835 lines (681 loc) · 22.2 KB
/
Context.cpp
File metadata and controls
835 lines (681 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
#include "stdafx.h"
#include "Context.h"
#if __has_include("Context.g.cpp")
#include "Context.g.cpp"
#endif
#include "App.xaml.h"
#include "Prerequisite.h"
#include "Update.h"
#include "util/HandleStream.h"
#include "util/Utils.h"
using namespace winrt;
using namespace Microsoft::UI::Xaml;
using namespace Microsoft::UI::Xaml::Media::Imaging;
using namespace string_view_literals;
namespace
{
constexpr auto kConfigFileName = L"SuiteInstaller.ini";
constexpr auto kUpdatesInfoFileName = L"UpdatesInfo.ini";
constexpr auto kAppNameProp = L"ProductName";
constexpr auto kAppIcon = L"AppIcon";
constexpr auto kPropertiesSection = L"Properties";
constexpr auto kProductCodeKey = L"ProductCode";
} // namespace
namespace winrt::SuiteInstaller::implementation
{
Context::Context()
{
filesystem::path configFilePath = GetModulePath().replace_filename(kConfigFileName);
LoadPrerequisites(configFilePath);
mAppName = L"SuiteInstaller";
mProductCode = GetIniValue(configFilePath.c_str(), kPropertiesSection, kProductCodeKey);
mReleaseNotesFilePath = GetIniValue(configFilePath.c_str(), kPropertiesSection, L"ReleaseNotes");
mExternalUiPath = GetIniValue(configFilePath.c_str(), kPropertiesSection, L"ExternalUiPath");
mUpdaterPath = GetIniValue(configFilePath.c_str(), kPropertiesSection, L"UpdaterPath");
mFeedBackLink = GetIniValue(configFilePath.c_str(), kPropertiesSection, L"FeedbackLink");
mHelpLink = GetIniValue(configFilePath.c_str(), kPropertiesSection, L"HelpLink");
mAppName = GetIniValue(configFilePath.c_str(), kPropertiesSection, kAppNameProp);
mRunAsAdmin = GetIniValue(configFilePath.c_str(), kPropertiesSection, L"RunAsAdmin") == L"2";
mAllUsers = GetIniValue(configFilePath.c_str(), kPropertiesSection, L"AllUsers") == L"1";
LoadInstalledState();
LoadReleaseNotes();
LoadUpdates();
}
void Context::LoadPrerequisites(const filesystem::path & aConfigFilePath)
{
mPrerequisites = winrt::multi_threaded_observable_vector<SuiteInstaller::Prerequisite>();
auto prereqList = GetIniFileSectionNames(aConfigFilePath.c_str());
for (auto prereq : prereqList)
{
wcout << prereq;
// skip Properties section
if (prereq == kPropertiesSection)
continue;
auto keysList = GetKeysInSection(prereq, aConfigFilePath.c_str());
auto images =
single_threaded_observable_vector<Microsoft::UI::Xaml::Media::Imaging::BitmapImage>();
Microsoft::UI::Xaml::Media::Imaging::BitmapImage icon;
auto prereqData =
make<Prerequisite>(prereq.c_str(), L"", L"", L"", L"", L"", false, icon, images);
auto prereqModel = prereqData.as<Prerequisite>();
prereqModel->Installed(false); // assume not installed, will be updated later
for (auto key : keysList)
{
if (key == L"Display")
{
auto title = GetIniValue(aConfigFilePath.c_str(), prereq, key);
prereqModel->Title(title.c_str());
}
else if (key == L"Description")
{
auto value = GetIniValue(aConfigFilePath.c_str(), prereq, key);
prereqModel->Description(value.c_str());
}
else if (key == L"Publisher")
{
auto value = GetIniValue(aConfigFilePath.c_str(), prereq, key);
prereqModel->Publisher(value.c_str());
}
else if (key == L"Category")
{
auto value = GetIniValue(aConfigFilePath.c_str(), prereq, key);
prereqModel->Category(value.c_str());
}
else if (key == L"AdditionalTerms")
{
auto value = GetIniValue(aConfigFilePath.c_str(), prereq, key);
prereqModel->AdditionalTerms(value.c_str());
}
else if (key == L"Icon")
{
filesystem::path imgPath = GetIniValue(aConfigFilePath.c_str(), prereq, key);
if (imgPath.is_relative())
imgPath = GetModulePath().remove_filename() / imgPath;
icon.UriSource(winrt::Windows::Foundation::Uri(imgPath.c_str()));
}
else if (key == L"Images")
{
auto value = GetIniValue(aConfigFilePath.c_str(), prereq, key);
if (!value.empty())
{
const wregex ws_re(L";");
for (auto it = wsregex_token_iterator(value.begin(), value.end(), ws_re, -1);
it != wsregex_token_iterator(); ++it)
{
filesystem::path imgPath(it->str());
if (imgPath.is_relative())
imgPath = GetModulePath().remove_filename() / imgPath;
images.Append(Microsoft::UI::Xaml::Media::Imaging::BitmapImage(
Windows::Foundation::Uri(imgPath.c_str())));
}
}
}
}
mPrerequisites.Append(prereqData);
}
}
hstring Context::AppName() const
{
return mAppName;
}
void Context::AppName(hstring const & aAppName)
{
mAppName = aAppName;
OnPropertyChanged(kAppNameProp);
}
winrt::Microsoft::UI::Xaml::Media::Imaging::BitmapImage Context::AppIcon()
{
return mAppIcon;
}
void Context::AppIcon(winrt::Microsoft::UI::Xaml::Media::Imaging::BitmapImage aAppIcon)
{
mAppIcon = aAppIcon;
OnPropertyChanged(kAppIcon);
}
Windows::Foundation::Collections::IObservableVector<winrt::SuiteInstaller::Prerequisite>
Context::Prerequisites()
{
return mPrerequisites;
}
Windows::Foundation::Collections::IObservableVector<winrt::SuiteInstaller::Prerequisite>
Context::InstalledPrerequisites()
{
return mInstalledPrerequisites;
}
Windows::Foundation::Collections::IObservableVector<winrt::SuiteInstaller::Update>
Context::UpdateDescriptions()
{
return mUpdateDescriptions;
}
Windows::Foundation::Collections::IObservableVector<winrt::SuiteInstaller::Update>
Context::UpdateFeatures()
{
return mUpdateFeatures;
}
Windows::Foundation::Collections::IObservableVector<winrt::SuiteInstaller::Update>
Context::UpdateEnhancements()
{
return mUpdateEnhancements;
}
Windows::Foundation::Collections::IObservableVector<winrt::SuiteInstaller::Update>
Context::UpdateBugfixes()
{
return mUpdateBugfixes;
}
Windows::Foundation::Collections::IObservableVector<winrt::SuiteInstaller::Update>
Context::AllUpdates()
{
return mAllUpdates;
}
int32_t Context::PrerequisitesSize()
{
return mPrerequisites.Size();
}
winrt::event_token Context::PropertyChanged(
Microsoft::UI::Xaml::Data::PropertyChangedEventHandler const & aHandler)
{
return mPropertyChanged.add(aHandler);
}
void Context::PropertyChanged(winrt::event_token const & aToken)
{
mPropertyChanged.remove(aToken);
}
void Context::OnPropertyChanged(hstring aPropertyName)
{
mPropertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ aPropertyName });
}
void Context::MarkPrereqInstalled(const winrt::SuiteInstaller::Prerequisite & aPrereq)
{
aPrereq.Installed(true);
InstalledPrerequisites().Append(aPrereq);
uint32_t idx = 0;
if (Prerequisites().IndexOf(aPrereq, idx))
Prerequisites().RemoveAt(idx);
}
winrt::Windows::Foundation::IAsyncOperation<bool> Context::LoadInstalledState()
{
if (mInstallStateLoaded)
co_return true;
winrt::apartment_context callingThread;
co_await winrt::resume_background();
wstring resultFile = filesystem::temp_directory_path() / (mProductCode + kConfigFileName);
LaunchProcessAndWait(mExternalUiPath + LR"( /i )" + mProductCode +
LR"( AI_UNINSTALLER_CTP="" LIST_PREREQ=ALL PREREQ_LIST=NONE RESULT_FILE=)" +
resultFile);
auto prereqList = GetIniFileSectionNames(resultFile);
co_await callingThread;
for (auto prereqId : prereqList)
{
auto installState = GetIniValue(resultFile, prereqId, L"InstallState");
auto found = GetIniValue(resultFile, prereqId, L"Found");
auto openPath = GetIniValue(resultFile, prereqId, L"OpenPath");
if (installState == L"Installed")
{
for (auto prereqData : Prerequisites())
{
if (prereqData.Id() == prereqId)
{
MarkPrereqInstalled(prereqData);
prereqData.OpenPath(openPath);
break;
}
}
}
}
// erase the generated file after loading its info
filesystem::remove(resultFile);
mInstallStateLoaded = true;
OnPropertyChanged(L"InstallStateLoaded");
co_return true;
}
winrt::Windows::Foundation::IAsyncOperation<bool> Context::ReadUpdatesIni(wstring_view aFilePath)
{
auto sectionsList = GetIniFileSectionNames(aFilePath);
ranges::sort(sectionsList);
sectionsList.erase(ranges::remove(sectionsList, L"General").begin(), sectionsList.end());
if (sectionsList.empty())
co_return false;
const auto prefixAndCollection =
array{ pair{ L"Description", &mUpdateDescriptions }, pair{ L"Feature", &mUpdateFeatures },
pair{ L"Enhancement", &mUpdateEnhancements }, pair{ L"BugFix", &mUpdateBugfixes } };
for (auto & [prefix, collection] : prefixAndCollection)
{
if (*collection)
collection->Clear();
else
*collection = winrt::single_threaded_observable_vector<SuiteInstaller::Update>();
}
if (mAllUpdates)
mAllUpdates.Clear();
else
mAllUpdates = winrt::single_threaded_observable_vector<SuiteInstaller::Update>();
auto latestUpdate = *(sectionsList | views::reverse).begin();
auto keys = GetKeysInSection(latestUpdate, aFilePath);
auto filterStartingWith = [&keys](const wchar_t * const aPrefix)
{
return keys | views::filter(
[=](auto key)
{
return key.starts_with(aPrefix);
});
};
for (auto & [prefix, collection] : prefixAndCollection)
{
for (auto key : filterStartingWith(prefix))
{
auto text = GetIniValue(aFilePath, latestUpdate, key);
auto updateData = make<Update>();
auto updateModel = updateData.as<Update>();
wstring title;
wstring description;
// extract the title (part before the :)
if (size_t pos = text.find(':'); pos != text.npos)
{
title = text.substr(0, pos - 1);
description = text.substr(pos + 1);
// capitalize first letter
description[0] = towupper(description[0]);
}
else
{
description = text;
}
updateModel->Title(title.c_str());
updateModel->Description(description.c_str());
collection->Append(updateData);
mAllUpdates.Append(updateData);
}
}
co_return true;
}
winrt::Windows::Foundation::IAsyncOperation<bool> Context::LoadUpdates()
{
if (mUpdatesLoaded)
co_return true;
if (mUpdaterPath.empty())
co_return false;
mUpdatesLoaded = true;
OnPropertyChanged(L"UpdatesLoaded");
// Prepend product code to the updates info temp filename to avoid collisions between products.
auto resultFile = filesystem::temp_directory_path() / (mProductCode + kUpdatesInfoFileName);
winrt::apartment_context callingThread;
co_await winrt::resume_background();
LaunchProcessAndWait(
std::format(L"{} /justcheck -dumpdetected {}", mUpdaterPath, resultFile.c_str()));
if (co_await ReadUpdatesIni(resultFile.c_str()))
{
mNewUpdate = true;
OnPropertyChanged(L"NewUpdate");
}
// erase the generated file after loading its info
filesystem::remove(resultFile);
co_return true;
}
winrt::Windows::Foundation::IAsyncOperation<bool> Context::LoadReleaseNotes()
{
if (mReleaseNotesLoaded)
co_return true;
mReleaseNotesLoaded = true;
const auto & resultFile = mReleaseNotesFilePath;
co_await ReadUpdatesIni(resultFile.c_str());
co_return true;
}
void ReadProgressMessaged(HANDLE aPipe,
winrt::Microsoft::UI::Dispatching::DispatcherQueue aDispatcher,
bool * aContinueReading)
{
// Wait for the installer stub (client) to connect.
if (!ConnectNamedPipe(aPipe, nullptr) && GetLastError() != ERROR_PIPE_CONNECTED)
{
wcerr << L"ConnectNamedPipe failed (" << GetLastError() << L")\n";
return;
}
// Wrap the pipe handle into our stream helper.
HandleStream stream(aPipe);
auto installmodel = App::AppService().InstallingPrereqs();
uint32_t downloadingPrereqIdx = 0;
uint32_t installingPrereqIdx = downloadingPrereqIdx;
installingPrereqIdx;
uint32_t prereqCount = installmodel.Prerequisites().Size();
uint32_t doneCount = 0;
auto prereq = installmodel.Prerequisites().GetAt(downloadingPrereqIdx);
auto prereqInstall = installmodel.Prerequisites().GetAt(installingPrereqIdx);
aDispatcher.TryEnqueue(
[prereq, installmodel]()
{
prereq.DownloadInProgress(true);
installmodel.InvInstallInProgress(false);
});
auto Respond = [&](UINT aRes = IDCANCEL)
{
Serialization::Serialize(static_cast<UINT>(aRes), stream);
stream.flush();
};
// Process incoming messages.
UINT msgId = 0;
bool displayActionData = true;
while (*aContinueReading && Serialization::Deserialize(msgId, stream))
{
// Use the remainder to determine the message type.
bool isDownload = msgId / 10'000 == 1;
switch (msgId % 10000)
{
case 3004: // Action data message.
{
wstring msg;
if (!Serialization::Deserialize(msg, stream))
{
*aContinueReading = false;
break;
}
if (!installmodel.HaveInstall())
break;
if (!displayActionData)
break;
if (isDownload)
{
if (msg.ends_with(L"completed"))
{
++downloadingPrereqIdx;
aDispatcher.TryEnqueue(
[prereq]()
{
prereq.DownloadInProgress(false);
prereq.CurrentAction(L"Downloaded");
});
if (prereqCount <= downloadingPrereqIdx)
break;
auto range = prereq.TotalRange();
prereq = installmodel.Prerequisites().GetAt(downloadingPrereqIdx - doneCount);
aDispatcher.TryEnqueue(
[prereq, msg, range]()
{
prereq.DownloadInProgress(true);
prereq.ProgressValue(0);
prereq.TotalRange(range);
});
}
else
{
aDispatcher.TryEnqueue(
[prereq, msg]()
{
prereq.CurrentAction(msg);
});
}
}
else
{
// advance installing
bool completed = msg.ends_with(L"completed");
if (completed)
{
++installingPrereqIdx;
aDispatcher.TryEnqueue(
[prereqInstall, installmodel, &doneCount]()
{
prereqInstall.Installed(true);
doneCount++;
installmodel.RemovePrerequisite(prereqInstall);
});
if (prereqCount <= installingPrereqIdx)
{
displayActionData = false;
break;
}
prereqInstall = installmodel.Prerequisites().GetAt(installingPrereqIdx - doneCount);
}
else
{
aDispatcher.TryEnqueue(
[prereqInstall, msg]()
{
prereqInstall.CurrentAction(msg);
prereqInstall.DownloadInProgress(false);
prereqInstall.InstallInProgress(true);
});
}
}
break;
}
case 5008: // Reset progress range.
{
UINT value;
if (!Serialization::Deserialize(value, stream))
{
*aContinueReading = false;
break;
}
if (!installmodel.HaveInstall())
return Respond();
if (!isDownload)
break;
aDispatcher.TryEnqueue(
[prereq, installmodel, value, prereqCount]()
{
prereq.ProgressValue(0);
prereq.TotalRange(value / prereqCount);
});
break;
}
case 5010: // Progress update.
{
UINT value;
if (!Serialization::Deserialize(value, stream))
{
*aContinueReading = false;
break;
}
if (!installmodel.HaveInstall())
break;
if (isDownload)
{
aDispatcher.TryEnqueue(
[prereq, value]()
{
auto currentProgress = prereq.ProgressValue();
auto totalRange = prereq.TotalRange();
if (totalRange == 0)
return;
currentProgress += value;
if (currentProgress > totalRange)
currentProgress = totalRange;
prereq.ProgressValue(currentProgress);
});
}
else
{
// advance installing progress ticks only once per app, so the installing current installing
// app can be advanced from action data.
value;
}
break;
}
default:
{
Respond();
*aContinueReading = false;
break;
}
}
if (*aContinueReading)
{
Respond(IDOK);
}
}
}
winrt::Windows::Foundation::IAsyncOperation<bool> Context::InstallPackages(
winrt::Microsoft::UI::Dispatching::DispatcherQueue aDispatcher)
{
winrt::apartment_context callingThread;
auto installmodel = App::AppService().InstallingPrereqs();
wstring prereqs;
for (auto prereq : installmodel.Prerequisites())
{
if (!prereqs.empty())
prereqs += '|';
prereqs += prereq.Id();
prereq.DownloadInProgress(false);
prereq.InstallInProgress(false);
// [TODO] this could be a shared property for all prerequisites
prereq.ShowRemoveBtn(false);
}
co_await winrt::resume_background();
// Set up the process startup info.
PROCESS_INFORMATION pi{};
STARTUPINFO si{};
si.cb = sizeof(si);
wstring resultFile = filesystem::temp_directory_path() / (mProductCode + kConfigFileName);
// Build pipe name and command-line.
wstring pipeName = LR"(\\.\pipe\PackagesProgress)" + mProductCode;
wstring command = std::format(
LR"(/i {} /qn AI_PARALLEL_DOWNLOAD=1 AI_UNINSTALLER_CTP="" )"
LR"(PREREQ_LIST="{}" LIST_PREREQ="{}" RESULT_FILE="{}" REINSTALLMODE=ecmus PREREQ_PROGRESS_PIPE_NAME={} {})",
mProductCode, prereqs, prereqs, resultFile, pipeName,
(mRunAsAdmin || !mAllUsers)
? L"REINSTALL=Config"
: L""); // reinstall Config feature only if the silent installation has necesary priviledges
// Create the installer process. Use ShellExecute to elevate privileges if needed.
SHELLEXECUTEINFO sei = {
.cbSize = sizeof(SHELLEXECUTEINFO),
.fMask = SEE_MASK_NOCLOSEPROCESS,
.lpVerb = mRunAsAdmin ? L"runas" : nullptr, // Use "runas" to elevate privileges if needed.
.lpFile = mExternalUiPath.c_str(),
.lpParameters = command.c_str(),
.nShow = SW_SHOWNORMAL,
};
auto readdCloseBtn = [installmodel]
{
for (auto prereq : installmodel.Prerequisites())
{
prereq.ShowRemoveBtn(true);
}
};
if (!ShellExecuteEx(&sei))
{
DWORD err = GetLastError();
OutputDebugString(std::format(L"ShellExecuteEx failed with error {}\n", err).c_str());
aDispatcher.TryEnqueue(readdCloseBtn);
co_return false;
}
auto closeProcHandles = make_scope_guard(CloseHandle(sei.hProcess));
// Create a named pipe for progress messages.
HANDLE pipe = CreateNamedPipe(pipeName.c_str(), PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES, 1024, 1024, 5000, nullptr);
if (pipe == INVALID_HANDLE_VALUE)
{
OutputDebugString(std::format(L"CreateNamedPipe failed ({})\n", GetLastError()).c_str());
aDispatcher.TryEnqueue(readdCloseBtn);
co_return false;
}
auto closePipe = make_scope_guard(CloseHandle(pipe));
bool continueReading = true;
// Read progress messages from the installer stub.
thread th(ReadProgressMessaged, pipe, aDispatcher, &continueReading);
WaitForSingleObject(sei.hProcess, INFINITE);
DWORD exitCode;
if (GetExitCodeProcess(sei.hProcess, &exitCode))
{
printf("Process exited with code %lu\n", exitCode);
}
else
{
printf("Failed to get exit code: %lu\n", GetLastError());
}
continueReading = false;
th.join();
auto prereqList = GetIniFileSectionNames(resultFile);
for (auto prereqId : prereqList)
{
auto installState = GetIniValue(resultFile, prereqId, L"InstallState");
auto openPath = GetIniValue(resultFile, prereqId, L"OpenPath");
if (installState == L"Installed")
{
aDispatcher.TryEnqueue(
[openPath, prereqId, this]()
{
for (auto prereqData : App::AppService().RuntimeContext().Prerequisites())
{
if (prereqData.Id() == prereqId)
{
MarkPrereqInstalled(prereqData);
prereqData.OpenPath(openPath);
break;
}
}
});
}
}
// erase the generated file after loading its info
filesystem::remove(resultFile);
aDispatcher.TryEnqueue(
[installmodel, this, aDispatcher]()
{
if (installmodel.Prerequisites().Size() > 0)
{
InstallPackages(aDispatcher);
}
else
{
installmodel.InvInstallInProgress(true);
}
});
co_return true;
}
Windows::Foundation::Collections::IObservableVector<winrt::SuiteInstaller::Prerequisite>
Context::GetSearchList(hstring aQuery)
{
wstring query = aQuery.c_str();
transform(query.begin(), query.end(), query.begin(), ::towlower);
auto filterPrerequisites = [&](auto const & prerequisites, auto & result)
{
for (auto const & prereq : prerequisites)
{
wstring title = prereq.Title().c_str();
transform(title.begin(), title.end(), title.begin(), ::towlower);
if (title.find(query) != wstring::npos)
{
result.Append(prereq);
}
}
};
auto searchedPrereqs = winrt::single_threaded_observable_vector<SuiteInstaller::Prerequisite>();
filterPrerequisites(mPrerequisites, searchedPrereqs);
filterPrerequisites(mInstalledPrerequisites, searchedPrereqs);
return searchedPrereqs;
}
bool Context::UpdatesLoaded()
{
return mUpdatesLoaded;
}
bool Context::InstallStateLoaded()
{
return mInstallStateLoaded;
}
bool Context::NewUpdate()
{
return mNewUpdate;
}
hstring Context::FeedbackLink() const
{
return mFeedBackLink;
}
hstring Context::HelpLink() const
{
return mHelpLink;
}
void Context::LaunchUpdater()
{
if (mUpdaterPath.empty())
return;
auto hInst = (INT_PTR)::ShellExecute(0, 0, mUpdaterPath.c_str(), 0, 0, SW_SHOWNORMAL);
if (hInst <= 32)
{
OutputDebugString(
std::format(L"Failed to launch updater. ShellExecute Return Code: {}, Last Error: {}\n",
hInst, GetLastError())
.c_str());
}
}
} // namespace winrt::SuiteInstaller::implementation