public async Task StopGameAsync() { await CoreRunner?.UnloadGameAsync(); StreamProvider?.Dispose(); StreamProvider = null; RootFrame.GoBack(); }
public async Task <bool> StartGameAsync(GameSystemVM system, IFile file, IFolder rootFolder = null) { if (CoreRunner == null) { RootFrame.Navigate(typeof(GamePlayerPage)); } else { await CoreRunner.UnloadGameAsync(); } StreamProvider?.Dispose(); StreamProvider = null; string virtualMainFilePath = null; if (!ArchiveExtensions.Contains(Path.GetExtension(file.Name))) { IStreamProvider streamProvider; GetStreamProviderAndVirtualPath(system, file, rootFolder, out streamProvider, out virtualMainFilePath); StreamProvider = streamProvider; } else { var archiveProvider = new ArchiveStreamProvider(VFS.RomPath, file); await archiveProvider.InitializeAsync(); StreamProvider = archiveProvider; var entries = await StreamProvider.ListEntriesAsync(); virtualMainFilePath = entries.FirstOrDefault(d => system.SupportedExtensions.Contains(Path.GetExtension(d))); } //Navigation should cause the player page to load, which in turn should initialize the core runner while (CoreRunner == null) { await Task.Delay(100); } if (virtualMainFilePath == null) { return(false); } system.Core.OpenFileStream = OnCoreOpenFileStream; system.Core.CloseFileStream = OnCoreCloseFileStream; var loadSuccessful = false; try { loadSuccessful = await CoreRunner.LoadGameAsync(system.Core, virtualMainFilePath); } catch { await StopGameAsync(); return(false); } if (loadSuccessful) { GameStarted(this); } else { await StopGameAsync(); return(false); } return(loadSuccessful); }
public async Task <bool> StartGameAsync(GameSystemVM system, IFileInfo file, IDirectoryInfo rootFolder = null) { var core = system.Core; if (CoreRunner == null) { RootFrame.Navigate(GamePlayerPageType); } else { await CoreRunner.UnloadGameAsync(); } StreamProvider?.Dispose(); StreamProvider = null; string virtualMainFilePath = null; if (core.NativeArchiveSupport || !ArchiveExtensions.Contains(Path.GetExtension(file.Name))) { virtualMainFilePath = $"{VFSRomPath}{Path.DirectorySeparatorChar}{file.Name}"; StreamProvider = new SingleFileStreamProvider(virtualMainFilePath, file); if (rootFolder != null) { virtualMainFilePath = file.FullName.Substring(rootFolder.FullName.Length + 1); virtualMainFilePath = $"{VFSRomPath}{Path.DirectorySeparatorChar}{virtualMainFilePath}"; StreamProvider = new FolderStreamProvider(VFSRomPath, rootFolder); } } else { var archiveProvider = new ArchiveStreamProvider(VFSRomPath, file); await archiveProvider.InitializeAsync(); StreamProvider = archiveProvider; var entries = await StreamProvider.ListEntriesAsync(); virtualMainFilePath = entries.FirstOrDefault(d => system.SupportedExtensions.Contains(Path.GetExtension(d))); } var systemFolder = await system.GetSystemDirectoryAsync(); var systemProvider = new FolderStreamProvider(VFSSystemPath, systemFolder); var saveFolder = await system.GetSaveDirectoryAsync(); var saveProvider = new FolderStreamProvider(VFSSavePath, saveFolder); StreamProvider = new CombinedStreamProvider(new HashSet <IStreamProvider>() { StreamProvider, systemProvider, saveProvider }); //Navigation should cause the player page to load, which in turn should initialize the core runner while (CoreRunner == null) { await Task.Delay(100); } if (virtualMainFilePath == null) { return(false); } var loadSuccessful = false; try { loadSuccessful = await CoreRunner.LoadGameAsync(core, virtualMainFilePath); } catch { await StopGameAsync(); return(false); } if (loadSuccessful) { GameStarted?.Invoke(this); } else { await StopGameAsync(); return(false); } return(loadSuccessful); }