Example #1
0
        void AwaitInstall(Game game, string destination)
        {
            var source    = new ELPathInfo(Game);
            var stopWatch = Stopwatch.StartNew();

#if !DEBUG
            await
#endif
            source.CopyTo(destination);

            var installDir = Path.Combine(destination, source.RelativeInstallPath);
            var gamePath   = Path.Combine(destination, source.RelativeRomPath);

            if (PlayniteAPI.ApplicationInfo.IsPortable)
            {
                installDir = installDir.Replace(PlayniteAPI.Paths.ApplicationPath, Playnite.SDK.ExpandableVariables.PlayniteDirectory);
                gamePath   = gamePath.Replace(PlayniteAPI.Paths.ApplicationPath, Playnite.SDK.ExpandableVariables.PlayniteDirectory);
            }

            var gameInfo = new GameInfo()
            {
                InstallDirectory = installDir,
                GameImagePath    = gamePath,
            };
            stopWatch.Stop();
            execContext.Post((a) => Installed?.Invoke(this, new GameInstalledEventArgs(gameInfo, this, stopWatch.Elapsed.TotalSeconds)), null);

            // This is actually ignored in the GameInfo above... Maybe fixed now in latest version. TODO: recheck
            var g = PlayniteAPI.Database.Games[Game.Id];
            g.GameImagePath = gameInfo.GameImagePath;
            PlayniteAPI.Database.Games.Update(g);
            //
        }
Example #2
0
        public void Uninstall()
        {
            var gameImagePathResolved = Game.GameImagePath.Replace(Playnite.SDK.ExpandableVariables.PlayniteDirectory, PlayniteAPI.Paths.ApplicationPath);
            var info = new FileInfo(gameImagePathResolved);

            if (info.Exists)
            {
                var pathInfo = new ELPathInfo(Game);
                if (pathInfo.IsMultiFile)
                {
                    Directory.Delete(Game.InstallDirectory.Replace(Playnite.SDK.ExpandableVariables.PlayniteDirectory, PlayniteAPI.Paths.ApplicationPath), true);
                }
                else
                {
                    File.Delete(gameImagePathResolved);
                }
                execContext.Post((a) => Uninstalled?.Invoke(this, new GameControllerEventArgs(this, 0)), null);
            }
            else
            {
                throw new ArgumentException($"\"{info.FullName}\" does not exist");
            }
        }
Example #3
0
        public override IEnumerable <GameInfo> GetGames()
        {
#if false
            logger.Info($"Looking for games in {path}, using {profile.Name} emulator profile.");
            if (!profile.ImageExtensions.HasNonEmptyItems())
            {
                throw new Exception("Cannot scan for games, emulator doesn't support any file types.");
            }
#endif

            var games = new List <GameInfo>();

            // Hack to exclude anything past disc one for games we're not treating as multi-file / m3u but have multiple discs :|
            var discXpattern = new Regex(@"\(Disc \d", RegexOptions.Compiled);

            settings.Mappings?.Where(m => m.Enabled).ToList().ForEach(mapping =>
            {
                var emulator             = PlayniteAPI.Database.Emulators.First(e => e.Id == mapping.EmulatorId);
                var emuProfile           = emulator.Profiles.First(p => p.Id == mapping.EmulatorProfileId);
                var platform             = PlayniteAPI.Database.Platforms.First(p => p.Id == mapping.PlatformId);
                var imageExtensionsLower = emuProfile.ImageExtensions.Where(ext => !ext.IsNullOrEmpty()).Select(ext => ext.Trim().ToLower());
                var srcPath = mapping.SourcePath;
                var dstPath = mapping.DestinationPathResolved;
                SafeFileEnumerator fileEnumerator;

                if (Directory.Exists(dstPath))
                {
                    #region Import "installed" games
                    fileEnumerator = new SafeFileEnumerator(dstPath, "*.*", SearchOption.TopDirectoryOnly);

                    foreach (var file in fileEnumerator)
                    {
                        if (mapping.GamesUseFolders && file.Attributes.HasFlag(FileAttributes.Directory) && !discXpattern.IsMatch(file.Name))
                        {
                            var rom = new SafeFileEnumerator(file.FullName, "*.*", SearchOption.AllDirectories).FirstOrDefault(f => imageExtensionsLower.Contains(f.Extension.TrimStart('.').ToLower()));
                            if (rom != null)
                            {
                                var newGame = new GameInfo()
                                {
                                    Source           = "EmuLibrary",
                                    Name             = StringExtensions.NormalizeGameName(StringExtensions.GetPathWithoutAllExtensions(Path.GetFileName(file.Name))),
                                    GameImagePath    = PlayniteApi.Paths.IsPortable ? rom.FullName.Replace(PlayniteApi.Paths.ApplicationPath, Playnite.SDK.ExpandableVariables.PlayniteDirectory) : rom.FullName,
                                    InstallDirectory = PlayniteApi.Paths.IsPortable ? file.FullName.Replace(PlayniteApi.Paths.ApplicationPath, Playnite.SDK.ExpandableVariables.PlayniteDirectory) : file.FullName,
                                    IsInstalled      = true,
                                    GameId           = new ELPathInfo(new FileInfo(Path.Combine(new string[] { mapping.SourcePath, file.Name, rom.FullName.Replace(file.FullName, "").TrimStart('\\') })), new DirectoryInfo(Path.Combine(mapping.SourcePath, file.Name))).ToGameId(),
                                    Platform         = platform.Name,
                                    PlayAction       = new GameAction()
                                    {
                                        Type              = GameActionType.Emulator,
                                        EmulatorId        = emulator.Id,
                                        EmulatorProfileId = emuProfile.Id,
                                        IsHandledByPlugin = false, // don't change this. PN will using emulator action
                                    }
                                };

                                games.Add(newGame);
                            }
                        }
                        else if (!mapping.GamesUseFolders)
                        {
                            foreach (var extension in imageExtensionsLower)
                            {
                                if (file.Extension.TrimStart('.') == extension && !discXpattern.IsMatch(file.Name))
                                {
                                    var newGame = new GameInfo()
                                    {
                                        Source           = "EmuLibrary",
                                        Name             = StringExtensions.NormalizeGameName(StringExtensions.GetPathWithoutAllExtensions(Path.GetFileName(file.Name))),
                                        GameImagePath    = PlayniteApi.Paths.IsPortable ? file.FullName.Replace(PlayniteApi.Paths.ApplicationPath, Playnite.SDK.ExpandableVariables.PlayniteDirectory) : file.FullName,
                                        InstallDirectory = PlayniteApi.Paths.IsPortable ? dstPath.Replace(PlayniteApi.Paths.ApplicationPath, Playnite.SDK.ExpandableVariables.PlayniteDirectory) : dstPath,
                                        IsInstalled      = true,
                                        GameId           = new ELPathInfo(new FileInfo(Path.Combine(mapping.SourcePath, file.Name))).ToGameId(),
                                        Platform         = platform.Name,
                                        PlayAction       = new GameAction()
                                        {
                                            Type              = GameActionType.Emulator,
                                            EmulatorId        = emulator.Id,
                                            EmulatorProfileId = emuProfile.Id,
                                            IsHandledByPlugin = false, // don't change this. PN will using emulator action
                                        }
                                    };

                                    games.Add(newGame);
                                }
                            }
                        }
                    }
                }
                #endregion

                #region Import "uninstalled" games
                if (Directory.Exists(srcPath))
                {
                    fileEnumerator = new SafeFileEnumerator(srcPath, "*.*", SearchOption.TopDirectoryOnly);

                    foreach (var file in fileEnumerator)
                    {
                        if (mapping.GamesUseFolders && file.Attributes.HasFlag(FileAttributes.Directory) && !discXpattern.IsMatch(file.Name))
                        {
                            var rom = new SafeFileEnumerator(file.FullName, "*.*", SearchOption.AllDirectories).FirstOrDefault(f => imageExtensionsLower.Contains(f.Extension.TrimStart('.').ToLower()));
                            if (rom != null)
                            {
                                var pathInfo = new ELPathInfo(new FileInfo(rom.FullName), new DirectoryInfo(file.FullName));
                                var equivalentInstalledPath = Path.Combine(dstPath, pathInfo.RelativeRomPath);
                                if (File.Exists(equivalentInstalledPath))
                                {
                                    continue;
                                }

                                var newGame = new GameInfo()
                                {
                                    Source      = "EmuLibrary",
                                    Name        = StringExtensions.NormalizeGameName(StringExtensions.GetPathWithoutAllExtensions(Path.GetFileName(file.Name))),
                                    IsInstalled = false,
                                    GameId      = pathInfo.ToGameId(),
                                    Platform    = platform.Name,
                                    PlayAction  = new GameAction()
                                    {
                                        Type              = GameActionType.Emulator,
                                        EmulatorId        = emulator.Id,
                                        EmulatorProfileId = emuProfile.Id,
                                        IsHandledByPlugin = false, // don't change this. PN will using emulator action
                                    }
                                };

                                games.Add(newGame);
                            }
                        }
                        else if (!mapping.GamesUseFolders)
                        {
                            foreach (var extension in imageExtensionsLower)
                            {
                                if (file.Extension.TrimStart('.') == extension && !discXpattern.IsMatch(file.Name))
                                {
                                    var equivalentInstalledPath = Path.Combine(dstPath, file.Name);
                                    if (File.Exists(equivalentInstalledPath))
                                    {
                                        continue;
                                    }

                                    var newGame = new GameInfo()
                                    {
                                        Source      = "EmuLibrary",
                                        Name        = StringExtensions.NormalizeGameName(StringExtensions.GetPathWithoutAllExtensions(Path.GetFileName(file.Name))),
                                        IsInstalled = false,
                                        GameId      = new ELPathInfo(new FileInfo(file.FullName)).ToGameId(),
                                        Platform    = platform.Name,
                                        PlayAction  = new GameAction()
                                        {
                                            Type              = GameActionType.Emulator,
                                            EmulatorId        = emulator.Id,
                                            EmulatorProfileId = emuProfile.Id,
                                            IsHandledByPlugin = false, // don't change this. PN will using emulator action
                                        }
                                    };

                                    games.Add(newGame);
                                }
                            }
                        }
                    }
                }
            });
            #endregion

            return(games);
        }