-
Notifications
You must be signed in to change notification settings - Fork 821
Expand file tree
/
Copy pathWinGet.cs
More file actions
805 lines (724 loc) · 28.2 KB
/
WinGet.cs
File metadata and controls
805 lines (724 loc) · 28.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
using System.Diagnostics;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text;
using UniGetUI.Core.Data;
using UniGetUI.Core.Logging;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.Tools;
using UniGetUI.Interface.Enums;
using UniGetUI.PackageEngine.Classes.Manager;
using UniGetUI.PackageEngine.Classes.Manager.ManagerHelpers;
using UniGetUI.PackageEngine.Enums;
using UniGetUI.PackageEngine.ManagerClasses.Classes;
using UniGetUI.PackageEngine.ManagerClasses.Manager;
using UniGetUI.PackageEngine.PackageClasses;
using WindowsPackageManager.Interop;
using Architecture = UniGetUI.PackageEngine.Enums.Architecture;
namespace UniGetUI.PackageEngine.Managers.WingetManager
{
public class WinGet : PackageManager
{
internal const string CliToolPreferenceEnvironmentVariable = "UNIGETUI_WINGET_CLI";
internal const string ComApiPolicyEnvironmentVariable = "UNIGETUI_WINGET_COM";
private const string SystemWinGetExecutableName = "winget.exe";
private const string PingetExecutableName = "pinget.exe";
public static string[] FALSE_PACKAGE_NAMES = ["", "e(s)", "have", "the", "Id"];
public static string[] FALSE_PACKAGE_IDS =
[
"",
"e(s)",
"have",
"an",
"'winget",
"pin'",
"have",
"an",
"Version",
];
public static string[] FALSE_PACKAGE_VERSIONS =
[
"",
"have",
"an",
"'winget",
"pin'",
"have",
"an",
"Version",
];
public LocalWinGetSource LocalPcSource { get; }
public LocalWinGetSource AndroidSubsystemSource { get; }
public LocalWinGetSource SteamSource { get; }
public LocalWinGetSource UbisoftConnectSource { get; }
public LocalWinGetSource GOGSource { get; }
public LocalWinGetSource MicrosoftStoreSource { get; }
public static bool NO_PACKAGES_HAVE_BEEN_LOADED { get; private set; }
internal WinGetCliToolKind SelectedCliToolKind { get; private set; } =
WinGetCliToolKind.SystemWinGet;
public WinGet()
{
Capabilities = new ManagerCapabilities
{
CanRunAsAdmin = true,
CanSkipIntegrityChecks = true,
CanRunInteractively = true,
SupportsCustomVersions = true,
CanDownloadInstaller = true,
CanListDependencies = true,
SupportsCustomArchitectures = true,
SupportedCustomArchitectures =
[
Architecture.x86,
Architecture.x64,
Architecture.arm64,
],
SupportsCustomScopes = true,
SupportsCustomLocations = true,
SupportsCustomSources = true,
SupportsCustomPackageIcons = true,
SupportsCustomPackageScreenshots = true,
Sources = new SourceCapabilities
{
KnowsPackageCount = false,
KnowsUpdateDate = true,
MustBeInstalledAsAdmin = true,
},
SupportsProxy = ProxySupport.Partially,
SupportsProxyAuth = false,
};
Properties = new ManagerProperties
{
Id = "winget",
Name = "Winget",
DisplayName = "WinGet",
Description = CoreTools.Translate(
"Microsoft's official package manager. Full of well-known and verified packages<br>Contains: <b>General Software, Microsoft Store apps</b>"
),
IconId = IconType.WinGet,
ColorIconId = "winget_color",
ExecutableFriendlyName = "winget.exe",
InstallVerb = "install",
UninstallVerb = "uninstall",
UpdateVerb = "update",
KnownSources =
[
new ManagerSource(
this,
"winget",
new Uri("https://cdn.winget.microsoft.com/cache")
),
new ManagerSource(
this,
"winget-fonts",
new Uri("https://cdn.winget.microsoft.com/fonts")
),
new ManagerSource(
this,
"msstore",
new Uri("https://storeedgefd.dsx.mp.microsoft.com/v9.0")
),
],
DefaultSource = new ManagerSource(
this,
"winget",
new Uri("https://cdn.winget.microsoft.com/cache")
),
};
SourcesHelper = new WinGetSourceHelper(this);
DetailsHelper = new WinGetPkgDetailsHelper(this);
OperationHelper = new WinGetPkgOperationHelper(this);
LocalPcSource = new LocalWinGetSource(
this,
CoreTools.Translate("Local PC"),
IconType.LocalPc,
LocalWinGetSource.Type_t.LocalPC
);
AndroidSubsystemSource = new(
this,
CoreTools.Translate("Android Subsystem"),
IconType.Android,
LocalWinGetSource.Type_t.Android
);
SteamSource = new(this, "Steam", IconType.Steam, LocalWinGetSource.Type_t.Steam);
UbisoftConnectSource = new(
this,
"Ubisoft Connect",
IconType.UPlay,
LocalWinGetSource.Type_t.Ubisoft
);
GOGSource = new(this, "GOG", IconType.GOG, LocalWinGetSource.Type_t.GOG);
MicrosoftStoreSource = new(
this,
"Microsoft Store",
IconType.MsStore,
LocalWinGetSource.Type_t.MicrosftStore
);
}
public static string GetProxyArgument()
{
if (!Settings.Get(Settings.K.EnableProxy))
return "";
var proxyUri = Settings.GetProxyUrl();
if (proxyUri is null)
return "";
if (Settings.Get(Settings.K.EnableProxyAuth))
{
Logger.Warn(
"Proxy is enabled, but WinGet does not support proxy authentication, so the proxy setting will be ignored"
);
return "";
}
return $"--proxy {proxyUri.ToString().TrimEnd('/')}";
}
/// <summary>
/// Returns the set of installer URL hosts from the WinGet manifest for a specific
/// version of the given package, or null if it can't be resolved. Used for the
/// installer-host-change warning on the Updates page (issue #4617).
/// Returns a set (not a single host) so callers can do set-overlap comparison —
/// see PingetPackageDetailsProvider.TryGetInstallerHostsForVersion for rationale.
/// </summary>
public static IReadOnlySet<string>? TryGetInstallerHostsForVersion(
UniGetUI.PackageEngine.Interfaces.IPackage package,
string version
)
{
return PingetPackageDetailsProvider.TryGetInstallerHostsForVersion(package, version);
}
protected override IReadOnlyList<Package> FindPackages_UnSafe(string query)
{
return WinGetHelper.Instance.FindPackages_UnSafe(query);
}
protected override IReadOnlyList<Package> GetAvailableUpdates_UnSafe()
{
return WinGetHelper
.Instance.GetAvailableUpdates_UnSafe()
.Where(p => p.Id != "Chocolatey.Chocolatey")
.ToArray();
}
protected override IReadOnlyList<Package> GetInstalledPackages_UnSafe()
{
try
{
var packages = WinGetHelper.Instance.GetInstalledPackages_UnSafe();
NO_PACKAGES_HAVE_BEEN_LOADED = false;
return packages;
}
catch (Exception)
{
NO_PACKAGES_HAVE_BEEN_LOADED = true;
throw;
}
}
public ManagerSource GetLocalSource(string id)
{
var IdPieces = id.Split('\\');
if (IdPieces[0] == "MSIX")
{
return MicrosoftStoreSource;
}
string MeaningfulId = IdPieces[^1];
// Fast Local PC Check
if (MeaningfulId[0] == '{')
{
return LocalPcSource;
}
// Check if source is android
if (
MeaningfulId.Count(x => x == '.') >= 2
&& MeaningfulId.All(c =>
(c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '…'
)
)
{
return AndroidSubsystemSource;
}
// Check if source is Steam
if (MeaningfulId == "Steam" || MeaningfulId.StartsWith("Steam App"))
{
return SteamSource;
}
// Check if source is Ubisoft Connect
if (MeaningfulId == "Uplay" || MeaningfulId.StartsWith("Uplay Install"))
{
return UbisoftConnectSource;
}
// Check if source is GOG
if (
MeaningfulId.EndsWith("_is1")
&& MeaningfulId.Replace("_is1", "").All(c => (c >= '0' && c <= '9'))
)
{
return GOGSource;
}
// Otherwise they are Local PC
return LocalPcSource;
}
public override IReadOnlyList<string> FindCandidateExecutableFiles()
{
return FindCandidateExecutableFiles(
executableName => CoreTools.WhichMultiple(executableName),
File.Exists,
GetBundledPingetExecutablePath(),
GetCliToolPreference()
);
}
internal static IReadOnlyList<string> FindCandidateExecutableFiles(
Func<string, IReadOnlyList<string>> findExecutables,
Func<string, bool> fileExists,
string bundledPingetPath,
WinGetCliToolPreference cliToolPreference = WinGetCliToolPreference.Default
)
{
List<string> candidates = [];
if (cliToolPreference is not WinGetCliToolPreference.BundledPinget)
{
candidates.AddRange(findExecutables(SystemWinGetExecutableName));
}
if (cliToolPreference is not WinGetCliToolPreference.SystemWinGet)
{
candidates.AddRange(
FindPingetExecutableFiles(findExecutables, fileExists, bundledPingetPath)
);
}
return candidates.Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
}
private static IEnumerable<string> FindPingetExecutableFiles(
Func<string, IReadOnlyList<string>> findExecutables,
Func<string, bool> fileExists,
string bundledPingetPath
)
{
if (fileExists(bundledPingetPath))
{
yield return bundledPingetPath;
}
foreach (string pingetExecutablePath in findExecutables(PingetExecutableName))
{
yield return pingetExecutablePath;
}
}
internal static string GetBundledPingetExecutablePath()
{
return GetBundledPingetExecutablePath(CoreData.UniGetUIExecutableDirectory, File.Exists);
}
internal static string GetBundledPingetExecutablePath(
string executableDirectory,
Func<string, bool> fileExists
)
{
string installDirectory = CoreData.ResolveInstallationDirectory(
executableDirectory,
fileExists,
static _ => false
);
string rootPingetPath = Path.Join(installDirectory, PingetExecutableName);
if (fileExists(rootPingetPath))
{
return rootPingetPath;
}
string avaloniaPingetPath = Path.Join(
installDirectory,
"Avalonia",
PingetExecutableName
);
return fileExists(avaloniaPingetPath) ? avaloniaPingetPath : rootPingetPath;
}
internal IWinGetManagerHelper CreateCliHelperForSelectedCliTool()
{
return SelectedCliToolKind == WinGetCliToolKind.BundledPinget
? new PingetCliHelper(this, Status.ExecutablePath)
: new WinGetCliHelper(this, Status.ExecutablePath);
}
protected override void _loadManagerExecutableFile(
out bool found,
out string path,
out string callArguments
)
{
var (_found, _path) = GetExecutableFile();
found = _found;
path = _path;
callArguments = "";
if (!found)
{
return;
}
SelectedCliToolKind = GetCliToolKind(path);
if (SelectedCliToolKind == WinGetCliToolKind.BundledPinget)
{
Logger.Warn("Using Pinget CLI tool.");
WinGetHelper.Instance = new PingetCliHelper(this, path);
return;
}
WinGetComApiPolicy comApiPolicy = GetComApiPolicy();
if (!ShouldUseWinGetComApi(SelectedCliToolKind, comApiPolicy))
{
Logger.Warn("WinGet COM API usage is disabled; using WinGetCliHelper().");
WinGetHelper.Instance = new WinGetCliHelper(this, path);
return;
}
try
{
WinGetHelper.Instance = new NativeWinGetHelper(this);
}
catch (Exception ex)
{
if (
ex is WinGetComActivationException activationEx
&& activationEx.IsExpectedFallbackCondition
)
{
Logger.Warn(
$"Native WinGet helper is unavailable on this machine ({activationEx.HResultHex}: {activationEx.Reason})"
);
}
else
{
Logger.Warn(
$"Cannot instantiate Native WinGet Helper due to error: {ex.Message}"
);
Logger.Warn(ex);
}
Logger.Warn("WinGet will resort to using WinGetCliHelper()");
WinGetHelper.Instance = CreateCliHelperForSelectedCliTool();
}
}
internal static WinGetCliToolPreference GetCliToolPreference()
{
return GetCliToolPreference(
static name => Environment.GetEnvironmentVariable(name),
static key => Settings.GetValue(key)
);
}
internal static WinGetCliToolPreference GetCliToolPreference(
Func<string, string?> getEnvironmentVariable,
Func<Settings.K, string> getSettingValue
)
{
string? value = GetPolicyValue(
CliToolPreferenceEnvironmentVariable,
Settings.K.WinGetCliToolPreference,
getEnvironmentVariable,
getSettingValue
);
return ParseCliToolPreference(value) ?? WinGetCliToolPreference.Default;
}
internal static WinGetComApiPolicy GetComApiPolicy()
{
return GetComApiPolicy(
static name => Environment.GetEnvironmentVariable(name),
static key => Settings.GetValue(key)
);
}
internal static WinGetComApiPolicy GetComApiPolicy(
Func<string, string?> getEnvironmentVariable,
Func<Settings.K, string> getSettingValue
)
{
string? value = GetPolicyValue(
ComApiPolicyEnvironmentVariable,
Settings.K.WinGetComApiPolicy,
getEnvironmentVariable,
getSettingValue
);
return ParseComApiPolicy(value) ?? WinGetComApiPolicy.Default;
}
private static string? GetPolicyValue(
string environmentVariableName,
Settings.K settingKey,
Func<string, string?> getEnvironmentVariable,
Func<Settings.K, string> getSettingValue
)
{
string? environmentValue = getEnvironmentVariable(environmentVariableName);
if (!string.IsNullOrWhiteSpace(environmentValue))
{
return environmentValue;
}
string settingValue = getSettingValue(settingKey);
return string.IsNullOrWhiteSpace(settingValue) ? null : settingValue;
}
private static WinGetCliToolPreference? ParseCliToolPreference(string? value)
{
return NormalizeCliToolPreferenceValue(value) switch
{
"default" => WinGetCliToolPreference.Default,
"winget" => WinGetCliToolPreference.SystemWinGet,
"pinget" => WinGetCliToolPreference.BundledPinget,
_ => null,
};
}
private static string NormalizeCliToolPreferenceValue(string? value)
{
return string.IsNullOrWhiteSpace(value) ? "" : value.Trim().ToLowerInvariant();
}
private static WinGetComApiPolicy? ParseComApiPolicy(string? value)
{
return NormalizePolicyValue(value) switch
{
"default" => WinGetComApiPolicy.Default,
"enabled" or "enable" or "on" or "true" or "1" => WinGetComApiPolicy.Enabled,
"disabled" or "disable" or "off" or "false" or "0" => WinGetComApiPolicy.Disabled,
_ => null,
};
}
internal static bool ShouldUseWinGetComApi(
WinGetCliToolKind cliToolKind,
WinGetComApiPolicy comApiPolicy
)
{
return cliToolKind == WinGetCliToolKind.SystemWinGet
&& comApiPolicy != WinGetComApiPolicy.Disabled;
}
private static string NormalizePolicyValue(string? value)
{
return string.IsNullOrWhiteSpace(value)
? ""
: value.Trim().Replace("-", "").Replace("_", "").ToLowerInvariant();
}
internal static WinGetCliToolKind GetCliToolKind(string executablePath)
{
return IsPingetExecutablePath(executablePath)
? WinGetCliToolKind.BundledPinget
: WinGetCliToolKind.SystemWinGet;
}
private static bool IsPingetExecutablePath(string executablePath)
{
if (string.IsNullOrWhiteSpace(executablePath))
{
return false;
}
return Path.GetFileName(executablePath).Equals(
PingetExecutableName,
StringComparison.OrdinalIgnoreCase
)
|| Path.GetFullPath(executablePath)
.Equals(
Path.GetFullPath(GetBundledPingetExecutablePath()),
StringComparison.OrdinalIgnoreCase
);
}
protected override void _loadManagerVersion(out string version)
{
bool usesCliHelper = WinGetHelper.Instance is WinGetCliHelper;
bool usesPingetHelper = WinGetHelper.Instance is PingetCliHelper;
Process process = new()
{
StartInfo = new ProcessStartInfo
{
FileName = Status.ExecutablePath,
Arguments = Status.ExecutableCallArgs + " --version",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8,
StandardErrorEncoding = Encoding.UTF8,
},
};
if (CoreTools.IsAdministrator())
{
string WinGetTemp = Path.Join(Path.GetTempPath(), "UniGetUI", "ElevatedWinGetTemp");
process.StartInfo.Environment["TEMP"] = WinGetTemp;
process.StartInfo.Environment["TMP"] = WinGetTemp;
}
process.Start();
string rawVersion = process.StandardOutput.ReadToEnd().Trim();
version = usesPingetHelper
? $"Pinget CLI Version: {rawVersion}"
: $"System WinGet (CLI) Version: {rawVersion}";
if (usesPingetHelper)
version += "\nUsing Pinget CLI helper (JSON parsing)";
else if (usesCliHelper)
version += "\nUsing WinGet CLI helper (CLI parsing)";
else
{
version += "\nUsing Native WinGet helper (COM Api)";
if (WinGetHelper.Instance is NativeWinGetHelper nativeHelper)
{
version += $"\nActivation mode: {nativeHelper.ActivationMode}";
version += $"\nActivation source: {nativeHelper.ActivationSource}";
}
}
string error = process.StandardError.ReadToEnd();
if (error != "")
Logger.Error("WinGet STDERR not empty: " + error);
}
protected override void _performExtraLoadingSteps()
{
TryRepairTempFolderPermissions();
}
private void ReRegisterCOMServer()
{
WinGetHelper.Instance = new NativeWinGetHelper(this);
NativePackageHandler.Clear();
}
public override void AttemptFastRepair()
{
try
{
TryRepairTempFolderPermissions();
if (WinGetHelper.Instance is NativeWinGetHelper)
{
if (
WinGetHelper.Instance is NativeWinGetHelper nativeHelper
&& nativeHelper.HasActiveLocalPackageQuery
)
{
Logger.Warn(
"WinGet local package enumeration is still running; skipping COM reconnection so the retry can attach to the in-flight task."
);
return;
}
Logger.ImportantInfo("Attempting to reconnect to WinGet COM Server...");
ReRegisterCOMServer();
NO_PACKAGES_HAVE_BEEN_LOADED = false;
}
else
{
Logger.Warn(
"Attempted to reconnect to COM Server but the active backend is not native WinGet."
);
}
}
catch (Exception ex)
{
Logger.Error("An error ocurred while attempting to reconnect to COM Server");
Logger.Error(ex);
}
}
private static void TryRepairTempFolderPermissions()
{
// if (Settings.Get(Settings.K.DisableNewWinGetTroubleshooter)) return;
try
{
string tempPath = Path.GetTempPath();
string winGetTempPath = Path.Combine(tempPath, "WinGet");
if (!Directory.Exists(winGetTempPath))
{
Logger.Warn("WinGet temp folder does not exist, creating it...");
Directory.CreateDirectory(winGetTempPath);
}
var directoryInfo = new DirectoryInfo(winGetTempPath);
var accessControl = directoryInfo.GetAccessControl();
var rules = accessControl.GetAccessRules(true, true, typeof(NTAccount));
bool userHasAccess = false;
string currentUser = WindowsIdentity.GetCurrent().Name;
foreach (FileSystemAccessRule rule in rules)
{
if (
rule.IdentityReference.Value.Equals(
currentUser,
StringComparison.CurrentCultureIgnoreCase
)
)
{
userHasAccess = true;
break;
}
}
if (!userHasAccess)
{
Logger.Warn(
"WinGet temp folder does not have correct permissions set, adding the current user..."
);
var rule = new FileSystemAccessRule(
currentUser,
FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow
);
accessControl.AddAccessRule(rule);
directoryInfo.SetAccessControl(accessControl);
}
}
catch (Exception ex)
{
Logger.Error(
"An error occurred while attempting to properly configure WinGet's temp folder permissions."
);
Logger.Error(ex);
}
}
public override void RefreshPackageIndexes()
{
using Process p = new()
{
StartInfo = new ProcessStartInfo
{
FileName = Status.ExecutablePath,
Arguments =
Status.ExecutableCallArgs
+ " source update"
+ (SelectedCliToolKind == WinGetCliToolKind.SystemWinGet
? " --disable-interactivity "
: " ")
+ GetCliToolProxyArgument(),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8,
},
};
IProcessTaskLogger logger = TaskLogger.CreateNew(LoggableTaskType.RefreshIndexes, p);
if (CoreTools.IsAdministrator())
{
string WinGetTemp = Path.Join(Path.GetTempPath(), "UniGetUI", "ElevatedWinGetTemp");
logger.AddToStdErr(
$"[WARN] Redirecting %TEMP% folder to {WinGetTemp}, since UniGetUI was run as admin"
);
p.StartInfo.Environment["TEMP"] = WinGetTemp;
p.StartInfo.Environment["TMP"] = WinGetTemp;
}
p.Start();
logger.AddToStdOut(p.StandardOutput.ReadToEnd());
logger.AddToStdErr(p.StandardError.ReadToEnd());
logger.Close(p.ExitCode);
p.WaitForExit();
p.Close();
}
private string GetCliToolProxyArgument()
{
return SelectedCliToolKind == WinGetCliToolKind.SystemWinGet
? GetProxyArgument()
: "";
}
}
public class LocalWinGetSource : ManagerSource
{
public enum Type_t
{
LocalPC,
MicrosftStore,
Steam,
GOG,
Android,
Ubisoft,
}
public readonly Type_t Type;
private readonly string name;
private readonly IconType __icon_id;
public override IconType IconId
{
get => __icon_id;
}
public LocalWinGetSource(WinGet manager, string name, IconType iconId, Type_t type)
: base(
manager,
name,
new Uri("https://microsoft.com/local-pc-source"),
isVirtualManager: true
)
{
Type = type;
this.name = name;
__icon_id = iconId;
AsString = Name;
AsString_DisplayName = Name;
}
}
}