Skip to content

Commit bfe1b0d

Browse files
Support for core selection based on file type
1 parent d10d772 commit bfe1b0d

File tree

15 files changed

+107
-36
lines changed

15 files changed

+107
-36
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@
4848
branch = master
4949
[submodule "BeetlePCEFast/src"]
5050
path = BeetlePCEFast/src
51-
url = https://github.com/Aftnet/beetle-pce-fast-libretro.git
51+
url = https://github.com/libretro/beetle-pce-fast-libretro.git
5252
branch = master
5353
[submodule "BeetleSaturn/src"]
5454
path = BeetleSaturn/src
5555
url = https://github.com/libretro/beetle-saturn-libretro.git
5656
branch = master
5757
[submodule "BeetlePCFX/src"]
5858
path = BeetlePCFX/src
59-
url = https://github.com/Aftnet/beetle-pcfx-libretro.git
59+
url = https://github.com/libretro/beetle-pcfx-libretro.git
6060
branch = master
6161
[submodule "FBAlpha/src"]
6262
path = FBAlpha/src
63-
url = https://github.com/Aftnet/fbalpha.git
63+
url = https://github.com/libretro/fbalpha.git
6464
branch = master

BeetleSaturn/src

Submodule src updated 70 files

FBAlpha/src

Submodule src updated from 4a71e6c to 529a485

RetriX.Shared/Services/IEmulationService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public enum InjectedInputTypes
2121
};
2222

2323
public delegate void CoresInitializedDelegate(IEmulationService sender);
24+
public delegate void GameStoppedDelegate(IEmulationService sender);
2425
public delegate void GameStartedDelegate(IEmulationService sender);
2526
public delegate void GameRuntimeExceptionOccurredDelegate(IEmulationService sender, Exception exception);
2627

@@ -32,7 +33,7 @@ public interface IEmulationService
3233

3334
string GameID { get; }
3435

35-
Task<GameSystemVM> SuggestSystemForFileAsync(IFileInfo file);
36+
Task<IEnumerable<GameSystemVM>> FilterSystemsForFileAsync(IFileInfo file);
3637
Task<bool> StartGameAsync(GameSystemVM system, IFileInfo file, IDirectoryInfo rootFolder = null);
3738

3839
Task ResetGameAsync();
@@ -48,6 +49,7 @@ public interface IEmulationService
4849

4950
event CoresInitializedDelegate CoresInitialized;
5051
event GameStartedDelegate GameStarted;
52+
event GameStoppedDelegate GameStopped;
5153
event GameRuntimeExceptionOccurredDelegate GameRuntimeExceptionOccurred;
5254
}
5355
}

RetriX.Shared/ViewModels/GameSystemSelectionVM.cs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ public class GameSystemSelectionVM : ViewModelBase
3131
private readonly IPlatformService PlatformService;
3232
private readonly IEmulationService EmulationService;
3333

34-
public IReadOnlyList<GameSystemVM> GameSystems => EmulationService.Systems;
34+
private IFileInfo SelectedGameFile;
35+
36+
private IReadOnlyList<GameSystemVM> gameSystems;
37+
public IReadOnlyList<GameSystemVM> GameSystems
38+
{
39+
get { return gameSystems; }
40+
private set { Set(ref gameSystems, value); }
41+
}
42+
3543
public RelayCommand<GameSystemVM> GameSystemSelectedCommand { get; private set; }
3644

3745
public GameSystemSelectionVM(IFileSystem fileSystem, IUserDialogs dialogsService, ILocalizationService localizationService, IPlatformService platformService, IEmulationService emulationService)
@@ -46,36 +54,56 @@ public GameSystemSelectionVM(IFileSystem fileSystem, IUserDialogs dialogsService
4654

4755
EmulationService.CoresInitialized += OnCoresInitialized;
4856
EmulationService.GameRuntimeExceptionOccurred += OnGameRuntimeExceptionOccurred;
57+
EmulationService.GameStopped += d => { ResetSystemsSelection(); };
58+
59+
ResetSystemsSelection();
4960
}
5061

5162
public async void GameSystemSelected(GameSystemVM system)
5263
{
53-
var extensions = system.SupportedExtensions.Concat(EmulationService.ArchiveExtensions).ToArray();
54-
var file = await FileSystem.PickFileAsync(extensions);
55-
if (file == null)
64+
if (SelectedGameFile == null)
65+
{
66+
var extensions = system.SupportedExtensions.Concat(EmulationService.ArchiveExtensions).ToArray();
67+
SelectedGameFile = await FileSystem.PickFileAsync(extensions);
68+
}
69+
if (SelectedGameFile == null)
5670
{
5771
return;
5872
}
5973

60-
await StartGameAsync(system, file);
74+
await StartGameAsync(system, SelectedGameFile);
6175
}
6276

6377
public async Task StartGameFromFileAsync(IFileInfo file)
6478
{
65-
var system = await EmulationService.SuggestSystemForFileAsync(file);
66-
if (system == null)
79+
//Find compatible systems for file extension
80+
var compatibleSystems = await EmulationService.FilterSystemsForFileAsync(file);
81+
82+
//If none, do nothing
83+
if (!compatibleSystems.Any())
6784
{
6885
return;
6986
}
7087

71-
await StartGameAsync(system, file);
88+
//If just one, start game with it
89+
if (compatibleSystems.Count() == 1)
90+
{
91+
await StartGameAsync(compatibleSystems.First(), file);
92+
return;
93+
}
94+
95+
//If multiple ones, filter system selection accordingly and have user select a system
96+
await EmulationService.StopGameAsync();
97+
GameSystems = compatibleSystems.ToArray();
98+
SelectedGameFile = file;
7299
}
73100

74101
private async Task StartGameAsync(GameSystemVM system, IFileInfo file)
75102
{
76103
var dependenciesMet = await system.CheckDependenciesMetAsync();
77104
if (!dependenciesMet)
78105
{
106+
ResetSystemsSelection();
79107
await DisplayNotification(SystemUnmetDependenciesAlertTitleKey, SystemUnmetDependenciesAlertMessageKey);
80108
return;
81109
}
@@ -88,11 +116,13 @@ private async Task StartGameAsync(GameSystemVM system, IFileInfo file)
88116
folder = await FileSystem.PickDirectoryAsync();
89117
if (folder == null)
90118
{
119+
ResetSystemsSelection();
91120
return;
92121
}
93122

94123
if (!Path.GetDirectoryName(file.FullName).StartsWith(folder.FullName))
95124
{
125+
ResetSystemsSelection();
96126
await DisplayNotification(SelectFolderInvalidAlertTitleKey, SelectFolderInvalidAlertMessageKey);
97127
return;
98128
}
@@ -101,20 +131,29 @@ private async Task StartGameAsync(GameSystemVM system, IFileInfo file)
101131
var startSuccess = await EmulationService.StartGameAsync(system, file, folder);
102132
if (!startSuccess)
103133
{
134+
ResetSystemsSelection();
104135
await DisplayNotification(GameLoadingFailAlertTitleKey, GameLoadingFailAlertMessageKey);
105136
}
106137
}
107138

108139
private void OnCoresInitialized(IEmulationService sender)
109140
{
110-
RaisePropertyChanged(nameof(GameSystems));
141+
GameSystems = EmulationService.Systems;
111142
}
112143

113144
private void OnGameRuntimeExceptionOccurred(IEmulationService sender, Exception e)
114145
{
146+
ResetSystemsSelection();
115147
DisplayNotification(GameRunningFailAlertTitleKey, GameRunningFailAlertMessageKey);
116148
}
117149

150+
private void ResetSystemsSelection()
151+
{
152+
//Reset systems selection
153+
GameSystems = EmulationService.Systems;
154+
SelectedGameFile = null;
155+
}
156+
118157
private Task DisplayNotification(string titleKey, string messageKey)
119158
{
120159
var title = LocalizationService.GetLocalizedString(titleKey);

RetriX.UWP/Package.appxmanifest

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
3-
<Identity Name="15612Aftnet.RetriX" Publisher="CN=Alberto Fustinoni, O=AlbertoFustinoni, L=Kawasaki, S=Kanagawa, C=JP" Version="1.9.2.0" />
3+
<Identity Name="15612Aftnet.RetriX" Publisher="CN=Alberto Fustinoni, O=AlbertoFustinoni, L=Kawasaki, S=Kanagawa, C=JP" Version="1.9.3.0" />
44
<mp:PhoneIdentity PhoneProductId="efc54b08-6566-4c74-810c-e9437145cdf4" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
55
<Properties>
66
<DisplayName>ms-resource:AppName\Text</DisplayName>
@@ -169,6 +169,16 @@
169169
</uap:SupportedFileTypes>
170170
</uap:FileTypeAssociation>
171171
</uap:Extension>
172+
<uap:Extension Category="windows.fileTypeAssociation">
173+
<uap:FileTypeAssociation Name="cuefiles">
174+
<uap:DisplayName>ms-resource:CueFileDescription\Text</uap:DisplayName>
175+
<uap:Logo>Assets\FileIcon.png</uap:Logo>
176+
<uap:InfoTip>ms-resource:CueFileDescription\Text</uap:InfoTip>
177+
<uap:SupportedFileTypes>
178+
<uap:FileType>.cue</uap:FileType>
179+
</uap:SupportedFileTypes>
180+
</uap:FileTypeAssociation>
181+
</uap:Extension>
172182
</Extensions>
173183
</Application>
174184
</Applications>

RetriX.UWP/Services/EmulationService.cs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace RetriX.UWP.Services
2020
{
2121
public class EmulationService : IEmulationService
2222
{
23+
private static readonly Type GamePlayerPageType = typeof(GamePlayerPage);
24+
2325
private const char CoreExtensionDelimiter = '|';
2426
private static readonly IReadOnlyDictionary<InjectedInputTypes, InputTypes> InjectedInputMapping = new Dictionary<InjectedInputTypes, InputTypes>
2527
{
@@ -59,6 +61,7 @@ public class EmulationService : IEmulationService
5961

6062
public event CoresInitializedDelegate CoresInitialized;
6163
public event GameStartedDelegate GameStarted;
64+
public event GameStoppedDelegate GameStopped;
6265
public event GameRuntimeExceptionOccurredDelegate GameRuntimeExceptionOccurred;
6366

6467
public EmulationService(IFileSystem fileSystem, IUserDialogs dialogsService, ILocalizationService localizationService, IPlatformService platformService, ICryptographyService cryptographyService, IInputManager inputManager)
@@ -104,19 +107,19 @@ public EmulationService(IFileSystem fileSystem, IUserDialogs dialogsService, ILo
104107
}).ContinueWith(d =>
105108
{
106109
InitializationComplete = true;
107-
PlatformService.RunOnUIThreadAsync(() => CoresInitialized(this));
110+
PlatformService.RunOnUIThreadAsync(() => CoresInitialized?.Invoke(this));
108111
});
109112
}
110113

111-
public async Task<Shared.ViewModels.GameSystemVM> SuggestSystemForFileAsync(IFileInfo file)
114+
public async Task<IEnumerable<GameSystemVM>> FilterSystemsForFileAsync(IFileInfo file)
112115
{
113116
while (!InitializationComplete)
114117
{
115118
await Task.Delay(100);
116119
}
117120

118121
var extension = Path.GetExtension(file.Name);
119-
return Systems.FirstOrDefault(d => d.SupportedExtensions.Contains(extension));
122+
return Systems.Where(d => d.SupportedExtensions.Contains(extension));
120123
}
121124

122125
public async Task<bool> StartGameAsync(Shared.ViewModels.GameSystemVM system, IFileInfo file, IDirectoryInfo rootFolder = null)
@@ -125,7 +128,7 @@ public async Task<bool> StartGameAsync(Shared.ViewModels.GameSystemVM system, IF
125128

126129
if (CoreRunner == null)
127130
{
128-
RootFrame.Navigate(typeof(GamePlayerPage));
131+
RootFrame.Navigate(GamePlayerPageType);
129132
}
130133
else
131134
{
@@ -176,7 +179,7 @@ public async Task<bool> StartGameAsync(Shared.ViewModels.GameSystemVM system, IF
176179

177180
if (loadSuccessful)
178181
{
179-
GameStarted(this);
182+
GameStarted?.Invoke(this);
180183
}
181184
else
182185
{
@@ -194,10 +197,13 @@ public Task ResetGameAsync()
194197

195198
public async Task StopGameAsync()
196199
{
197-
await CoreRunner?.UnloadGameAsync();
198-
StreamProvider?.Dispose();
199-
StreamProvider = null;
200-
RootFrame.GoBack();
200+
if (CoreRunner != null)
201+
{
202+
await CoreRunner.UnloadGameAsync();
203+
}
204+
205+
CleanupAndGoBack();
206+
GameStopped?.Invoke(this);
201207
}
202208

203209
public Task PauseGameAsync()
@@ -253,10 +259,8 @@ private void OnCoreExceptionOccurred(ICore core, Exception e)
253259
{
254260
var task = PlatformService.RunOnUIThreadAsync(() =>
255261
{
256-
StreamProvider?.Dispose();
257-
StreamProvider = null;
258-
RootFrame.GoBack();
259-
GameRuntimeExceptionOccurred(this, e);
262+
CleanupAndGoBack();
263+
GameRuntimeExceptionOccurred?.Invoke(this, e);
260264
});
261265
}
262266

@@ -293,5 +297,18 @@ private void GetStreamProviderAndVirtualPath(ViewModels.GameSystemVM system, IFi
293297
var combinedProvider = new CombinedStreamProvider(new HashSet<IStreamProvider> { romProvider, systemProvider, saveProvider });
294298
provider = combinedProvider;
295299
}
300+
301+
private void CleanupAndGoBack()
302+
{
303+
StreamProvider?.Dispose();
304+
StreamProvider = null;
305+
306+
if (RootFrame.CurrentSourcePageType == GamePlayerPageType)
307+
{
308+
RootFrame.GoBack();
309+
}
310+
311+
PlatformService.ChangeMousePointerVisibility(MousePointerVisibility.Visible);
312+
}
296313
}
297314
}

RetriX.UWP/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,7 @@ Restart RetriX and try again.</value>
356356
<data name="CHDRomDescription.Text" xml:space="preserve">
357357
<value>CHD compressed Rom</value>
358358
</data>
359+
<data name="CueFileDescription.Text" xml:space="preserve">
360+
<value>Cue sheet</value>
361+
</data>
359362
</root>

0 commit comments

Comments
 (0)