Skip to content

Commit da74e81

Browse files
authored
Merge pull request #291 from altpyrion/linux-autodetect
feat: auto-detect of native dolphin
2 parents 104f46c + edf6217 commit da74e81

3 files changed

Lines changed: 44 additions & 7 deletions

File tree

WheelWizard/Features/DolphinInstaller/LinuxDolphinInstaller.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace WheelWizard.DolphinInstaller;
33
public interface ILinuxDolphinInstaller
44
{
55
bool IsDolphinInstalledInFlatpak();
6+
bool IsDolphinInstalledNative();
67
bool IsFlatpakInstalled();
78
Task<OperationResult> InstallFlatpak(IProgress<int>? progress = null);
89
Task<OperationResult> InstallFlatpakDolphin(IProgress<int>? progress = null);
@@ -17,6 +18,11 @@ public bool IsDolphinInstalledInFlatpak()
1718
return processResult.IsSuccess && processResult.Value == 0;
1819
}
1920

21+
public bool IsDolphinInstalledNative()
22+
{
23+
return commandEnvironment.IsCommandAvailable("dolphin-emu");
24+
}
25+
2026
public bool IsFlatpakInstalled()
2127
{
2228
return commandEnvironment.IsCommandAvailable("flatpak");

WheelWizard/Services/PathManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Runtime.InteropServices;
2+
using Serilog;
23
using WheelWizard.Helpers;
34
using WheelWizard.Settings;
45
#if WINDOWS
@@ -849,7 +850,9 @@ private static string TryFindPortableUserFolderPath()
849850
return null;
850851
}
851852

852-
public static string? TryFindUserFolderPath()
853+
public static string? TryFindUserFolderPath() => TryFindUserFolderPath(DolphinFilePath);
854+
855+
public static string? TryFindUserFolderPath(string dolphinFilePath)
853856
{
854857
var portableUserFolderPath = TryFindPortableUserFolderPath();
855858
if (!string.IsNullOrWhiteSpace(portableUserFolderPath))
@@ -880,7 +883,7 @@ private static string TryFindPortableUserFolderPath()
880883
}
881884
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
882885
{
883-
if (IsFlatpakDolphinFilePath())
886+
if (IsFlatpakDolphinFilePath(dolphinFilePath))
884887
{
885888
return TryFindLinuxFlatpakUserFolderPath();
886889
}

WheelWizard/Views/Pages/Settings/WhWzSettings.axaml.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,28 @@ private async void DolphinExeBrowse_OnClick(object sender, RoutedEventArgs e)
148148

149149
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
150150
{
151-
if (IsFlatpakDolphinInstalled() && DolphinExeInput.Text == "")
151+
// Made this more extensible for future support for e.g. snap
152+
var dolphinPaths = new (Func<bool> IsInstalled, string Path)[]
152153
{
153-
DolphinExeInput.Text = "flatpak run org.DolphinEmu.dolphin-emu";
154-
return;
154+
(IsFlatpakDolphinInstalled, "flatpak run org.DolphinEmu.dolphin-emu"),
155+
(IsNativeDolphinInstalled, "dolphin-emu"),
156+
};
157+
158+
foreach (var (isInstalled, path) in dolphinPaths)
159+
{
160+
if (isInstalled())
161+
{
162+
var result = await new YesNoWindow()
163+
.SetMainText(t("question.dolphin_found.title"))
164+
.SetExtraText($"{t("question.dolphin_found.extra")}\n{path}")
165+
.AwaitAnswer();
166+
167+
if (result)
168+
{
169+
DolphinExeInput.Text = path;
170+
return;
171+
}
172+
}
155173
}
156174

157175
if (!EnvHelper.IsFlatpakSandboxed() && !IsFlatpakDolphinInstalled())
@@ -249,6 +267,11 @@ private bool IsFlatpakDolphinInstalled()
249267
return LinuxDolphinInstallerService.IsDolphinInstalledInFlatpak();
250268
}
251269

270+
private bool IsNativeDolphinInstalled()
271+
{
272+
return LinuxDolphinInstallerService.IsDolphinInstalledNative();
273+
}
274+
252275
private async void GameLocationBrowse_OnClick(object sender, RoutedEventArgs e)
253276
{
254277
var fileType = new FilePickerFileType("Game files") { Patterns = ["*.iso", "*.wbfs", "*.rvz"] };
@@ -262,8 +285,13 @@ private async void GameLocationBrowse_OnClick(object sender, RoutedEventArgs e)
262285

263286
private async void DolphinUserPathBrowse_OnClick(object sender, RoutedEventArgs e)
264287
{
265-
// Attempt to find Dolphin's default path if no valid folder is set
266-
var folderPath = PathManager.TryFindUserFolderPath();
288+
// Detect Data folder based on the Dolphin path currently in the input field
289+
// (which may have been edited but not yet saved)
290+
var currentDolphinPath = DolphinExeInput.Text;
291+
var folderPath = string.IsNullOrWhiteSpace(currentDolphinPath)
292+
? PathManager.TryFindUserFolderPath()
293+
: PathManager.TryFindUserFolderPath(currentDolphinPath);
294+
267295
if (!string.IsNullOrEmpty(folderPath))
268296
{
269297
// Ask the user if they want to use the automatically found folder

0 commit comments

Comments
 (0)