public async Task <GamePlayerViewModel.Parameter> GenerateGameLaunchEnvironmentAsync(GameSystemViewModel system, IFileInfo file, IDirectoryInfo rootFolder)
        {
            var dependenciesMet = await system.CheckDependenciesMetAsync();

            if (!dependenciesMet || (system.CheckRootFolderRequired(file) && rootFolder == null))
            {
                return(null);
            }

            var vfsRomPath    = "ROM";
            var vfsSystemPath = "System";
            var vfsSavePath   = "Save";

            var core = system.Core;

            string virtualMainFilePath = null;
            var    provider            = default(IStreamProvider);

            if (core.NativeArchiveSupport || !ArchiveStreamProvider.SupportedExtensions.Contains(Path.GetExtension(file.Name)))
            {
                virtualMainFilePath = $"{vfsRomPath}{Path.DirectorySeparatorChar}{file.Name}";
                provider            = new SingleFileStreamProvider(virtualMainFilePath, file);
                if (rootFolder != null)
                {
                    virtualMainFilePath = file.FullName.Substring(rootFolder.FullName.Length + 1);
                    virtualMainFilePath = $"{vfsRomPath}{Path.DirectorySeparatorChar}{virtualMainFilePath}";
                    provider            = new FolderStreamProvider(vfsRomPath, rootFolder);
                }
            }
            else
            {
                var archiveProvider = new ArchiveStreamProvider(vfsRomPath, file);
                await archiveProvider.InitializeAsync();

                provider = archiveProvider;
                var entries = await provider.ListEntriesAsync();

                virtualMainFilePath = entries.FirstOrDefault(d => system.SupportedExtensions.Contains(Path.GetExtension(d)));
            }

            var systemFolder = await system.GetSystemDirectoryAsync();

            var systemProvider = new FolderStreamProvider(vfsSystemPath, systemFolder);

            core.SystemRootPath = vfsSystemPath;
            var saveFolder = await system.GetSaveDirectoryAsync();

            var saveProvider = new FolderStreamProvider(vfsSavePath, saveFolder);

            core.SaveRootPath = vfsSavePath;

            provider = new CombinedStreamProvider(new HashSet <IStreamProvider>()
            {
                provider, systemProvider, saveProvider
            });

            return(new GamePlayerViewModel.Parameter(core, provider, virtualMainFilePath));
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }