-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from KrystianLesniak/develop
Release: 1.7.0
- Loading branch information
Showing
19 changed files
with
235 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...GamesLauncher.Platforms/SyncEngines/Common/ControlPanelUninstall/ControlPanelUninstall.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using GamesLauncher.Platforms.SyncEngines.Common.ControlPanelUninstall.Models; | ||
using Microsoft.Win32; | ||
using System.Collections.Concurrent; | ||
|
||
namespace GamesLauncher.Platforms.SyncEngines.Common.ControlPanelUninstall | ||
{ | ||
internal static class ControlPanelUninstall | ||
{ | ||
internal static async Task<IEnumerable<UninstallProgram>> GetPrograms() | ||
{ | ||
var programs = new ConcurrentBag<UninstallProgram>(); | ||
|
||
var registryHives = new RegistryHive[] { RegistryHive.LocalMachine, RegistryHive.CurrentUser }; | ||
var registryViews = new RegistryView[] { RegistryView.Registry32, RegistryView.Registry64 }; | ||
|
||
await Parallel.ForEachAsync(registryHives, async (hive, ct) => | ||
{ | ||
await Parallel.ForEachAsync(registryViews, async (view, ct) => | ||
{ | ||
SearchPrograms(hive, view, programs); | ||
await Task.CompletedTask; | ||
}); | ||
}); | ||
|
||
return programs; | ||
|
||
|
||
static void SearchPrograms(RegistryHive hive, RegistryView view, ConcurrentBag<UninstallProgram> programs) | ||
{ | ||
const string uninstallRootKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"; | ||
|
||
using var baseKey = RegistryKey.OpenBaseKey(hive, view); | ||
|
||
using var uninstallSubKey = baseKey.OpenSubKey(uninstallRootKey); | ||
if (uninstallSubKey == null) | ||
return; | ||
|
||
foreach (var programUninstallSubKeyName in uninstallSubKey.GetSubKeyNames()) | ||
{ | ||
try | ||
{ | ||
using var prog = baseKey.OpenSubKey(uninstallRootKey + programUninstallSubKeyName); | ||
if (prog == null) | ||
continue; | ||
|
||
programs.Add(new UninstallProgram() | ||
{ | ||
DisplayIcon = prog.GetValue("DisplayIcon")?.ToString(), | ||
DisplayName = prog.GetValue("DisplayName")?.ToString() ?? string.Empty, | ||
UninstallCommand = prog.GetValue("UninstallString")?.ToString(), | ||
SubKeyName = programUninstallSubKeyName | ||
}); | ||
} | ||
catch (System.Security.SecurityException) | ||
{ | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...mesLauncher.Platforms/SyncEngines/Common/ControlPanelUninstall/Models/UninstallProgram.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace GamesLauncher.Platforms.SyncEngines.Common.ControlPanelUninstall.Models | ||
{ | ||
internal class UninstallProgram | ||
{ | ||
public string DisplayName { get; internal set; } = string.Empty; | ||
public string SubKeyName { get; internal set; } = string.Empty; | ||
public string? DisplayIcon { get; internal set; } | ||
public string? UninstallCommand { get; internal set; } | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...cher.Platforms/SyncEngines/ISyncEngine.cs → ...cEngines/Common/Interfaces/ISyncEngine.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/GamesLauncher.Platforms/SyncEngines/Ubisoft/UbisoftSyncEngine.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using Flow.Launcher.Plugin; | ||
using GamesLauncher.Platforms.SyncEngines.Common.ControlPanelUninstall; | ||
using GamesLauncher.Platforms.SyncEngines.Common.ControlPanelUninstall.Models; | ||
using GamesLauncher.Platforms.SyncEngines.Common.Interfaces; | ||
|
||
namespace GamesLauncher.Platforms.SyncEngines.Ubisoft | ||
{ | ||
internal class UbisoftSyncEngine : ISyncEngine | ||
{ | ||
public string PlatformName => "Ubisoft Connect"; | ||
public IEnumerable<Game> SynchronizedGames { get; private set; } = Array.Empty<Game>(); | ||
|
||
|
||
private readonly string UbisoftConnectUninstallRegistryKeyStart = "Uplay Install "; | ||
|
||
private readonly IPublicAPI publicApi; | ||
|
||
public UbisoftSyncEngine(IPublicAPI publicApi) | ||
{ | ||
this.publicApi = publicApi; | ||
} | ||
|
||
public async Task SynchronizeGames() | ||
{ | ||
var ubiUninstallPrograms = (await ControlPanelUninstall.GetPrograms()) | ||
.Where(x => x.SubKeyName.StartsWith(UbisoftConnectUninstallRegistryKeyStart)); | ||
|
||
if (!ubiUninstallPrograms.Any()) | ||
return; | ||
|
||
var syncedGames = new List<Game>(); | ||
|
||
foreach (var ubiUninstallProgram in ubiUninstallPrograms) | ||
{ | ||
syncedGames.Add(new Game( | ||
title: ubiUninstallProgram.DisplayName, | ||
platform: PlatformName, | ||
runTask: GetGameRunTask(ubiUninstallProgram), | ||
iconPath: ubiUninstallProgram.DisplayIcon ?? Path.Combine("Icons", "ubisoft.ico"), | ||
uninstallAction: GetUninstallAction(ubiUninstallProgram) | ||
)); | ||
} | ||
|
||
SynchronizedGames = syncedGames; | ||
} | ||
|
||
private Func<Task> GetGameRunTask(UninstallProgram ubiUninstallProgram) | ||
{ | ||
var gameId = ubiUninstallProgram.SubKeyName.Replace(UbisoftConnectUninstallRegistryKeyStart, string.Empty).Trim(); | ||
var uriString = $"uplay://launch/{gameId}/0"; | ||
|
||
return async () => | ||
{ | ||
publicApi.OpenAppUri(new Uri(uriString)); | ||
await Task.CompletedTask; | ||
}; | ||
} | ||
|
||
private UninstallAction? GetUninstallAction(UninstallProgram ubiUninstallProgram) | ||
{ | ||
var uninstallCommand = ubiUninstallProgram.UninstallCommand; | ||
var subKeyName = ubiUninstallProgram.SubKeyName; | ||
|
||
if (uninstallCommand == null) return null; | ||
|
||
return new UninstallAction(async () => | ||
{ | ||
publicApi.ShellRun(uninstallCommand); | ||
for (int i = 0; i < 12; i++) | ||
{ | ||
var programs = await ControlPanelUninstall.GetPrograms(); | ||
if (programs.Any(x => x.SubKeyName.Equals(subKeyName)) == false) | ||
break; | ||
await Task.Delay(TimeSpan.FromSeconds(5)); | ||
} | ||
await SynchronizeGames(); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.