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));
        }
Esempio n. 2
0
        public async Task <Tuple <GameLaunchEnvironment, GameLaunchEnvironment.GenerateResult> > GenerateGameLaunchEnvironmentAsync(GameSystemViewModel system, IFileInfo file, IDirectoryInfo rootFolder)
        {
            var dependenciesMet = await system.CheckDependenciesMetAsync();

            if (!dependenciesMet)
            {
                return(Tuple.Create(default(GameLaunchEnvironment), GameLaunchEnvironment.GenerateResult.DependenciesUnmet));
            }

            if (system.CheckRootFolderRequired(file) && rootFolder == null)
            {
                return(Tuple.Create(default(GameLaunchEnvironment), GameLaunchEnvironment.GenerateResult.RootFolderRequired));
            }

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

            var core = system.Core;

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

            if (ArchiveStreamProvider.SupportedExtensions.Contains(Path.GetExtension(file.Name)) && core.NativeArchiveSupport == false)
            {
                var archiveProvider = new ArchiveStreamProvider(vfsRomPath, file);
                provider = archiveProvider;
                var entries = await provider.ListEntriesAsync();

                virtualMainFilePath = entries.FirstOrDefault(d => system.SupportedExtensions.Contains(Path.GetExtension(d)));
                if (string.IsNullOrEmpty(virtualMainFilePath))
                {
                    return(Tuple.Create(default(GameLaunchEnvironment), GameLaunchEnvironment.GenerateResult.NoMainFileFound));
                }
            }
            else
            {
                virtualMainFilePath = Path.Combine(vfsRomPath, file.Name);
                provider            = new SingleFileStreamProvider(virtualMainFilePath, file);
                if (rootFolder != null)
                {
                    virtualMainFilePath = file.FullName.Substring(rootFolder.FullName.Length + 1);
                    virtualMainFilePath = Path.Combine(vfsRomPath, virtualMainFilePath);
                    provider            = new FolderStreamProvider(vfsRomPath, rootFolder);
                }
            }

            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(Tuple.Create(new GameLaunchEnvironment(core, provider, virtualMainFilePath), GameLaunchEnvironment.GenerateResult.Success));
        }