Beispiel #1
0
        internal Dictionary <string, GameInfo> GetInstalledGames()
        {
            var games     = new Dictionary <string, GameInfo>();
            var appList   = EpicLauncher.GetInstalledAppList();
            var manifests = EpicLauncher.GetInstalledManifests();

            foreach (var app in appList)
            {
                if (app.AppName.StartsWith("UE_"))
                {
                    continue;
                }

                var manifest = manifests.FirstOrDefault(a => a.AppName == app.AppName);
                var game     = new GameInfo()
                {
                    Source           = "Epic",
                    GameId           = app.AppName,
                    Name             = manifest?.DisplayName ?? Path.GetFileName(app.InstallLocation),
                    InstallDirectory = manifest?.InstallLocation ?? app.InstallLocation,
                    IsInstalled      = true,
                    PlayAction       = new GameAction()
                    {
                        Type = GameActionType.URL,
                        Path = string.Format(EpicLauncher.GameLaunchUrlMask, app.AppName),
                        IsHandledByPlugin = true
                    }
                };

                games.Add(game.GameId, game);
            }

            return(games);
        }
Beispiel #2
0
        public async void StartInstallWatcher()
        {
            watcherToken = new CancellationTokenSource();

            while (true)
            {
                if (watcherToken.IsCancellationRequested)
                {
                    return;
                }

                var installed = EpicLauncher.GetInstalledAppList();
                var app       = installed?.FirstOrDefault(a => a.AppName == Game.GameId);
                if (app != null)
                {
                    var installInfo = new GameInfo
                    {
                        InstallDirectory = app.InstallLocation,
                        PlayAction       = new GameAction()
                        {
                            Type = GameActionType.URL,
                            Path = string.Format(EpicLauncher.GameLaunchUrlMask, app.AppName),
                            IsHandledByPlugin = true
                        }
                    };

                    OnInstalled(this, new GameInstalledEventArgs(installInfo, this, 0));
                    return;
                }
                ;

                await Task.Delay(5000);
            }
        }
Beispiel #3
0
        internal Dictionary <string, Game> GetInstalledGames()
        {
            var games = new Dictionary <string, Game>();

            foreach (var app in EpicLauncher.GetInstalledAppList())
            {
                if (app.AppName.StartsWith("UE_"))
                {
                    continue;
                }

                var game = new Game()
                {
                    PluginId         = Id,
                    GameId           = app.AppName,
                    Name             = Path.GetFileName(app.InstallLocation),
                    InstallDirectory = app.InstallLocation,
                    IsInstalled      = true,
                    PlayAction       = new GameAction()
                    {
                        Type = GameActionType.URL,
                        Path = string.Format(EpicLauncher.GameLaunchUrlMask, app.AppName),
                        IsHandledByPlugin = true
                    }
                };

                games.Add(game.GameId, game);
            }

            return(games);
        }
Beispiel #4
0
        public override void Play()
        {
            ReleaseResources();
            OnStarting(this, new GameControllerEventArgs(this, 0));
            var startUri         = string.Format(EpicLauncher.GameLaunchUrlMask, game.GameId);
            var startViaLauncher = true;

            Models.InstalledManifiest manifest = null;

            if (!launchelessExceptions.Contains(game.GameId) && settings.StartGamesWithoutLauncher)
            {
                manifest = EpicLauncher.GetInstalledManifests().FirstOrDefault(a => a.AppName == game.GameId);
                if (manifest?.bCanRunOffline == true)
                {
                    startViaLauncher = false;
                }
            }

            if (startViaLauncher)
            {
                ProcessStarter.StartUrl(startUri);
            }
            else
            {
                try
                {
                    var path        = Path.Combine(manifest.InstallLocation, manifest.LaunchExecutable);
                    var defaultArgs = $" -epicapp={game.GameId} -epicenv=Prod -EpicPortal";
                    if (manifest.LaunchCommand.IsNullOrEmpty())
                    {
                        ProcessStarter.StartProcess(path, defaultArgs);
                    }
                    else
                    {
                        ProcessStarter.StartProcess(path, manifest.LaunchCommand + defaultArgs);
                    }
                }
                catch (Exception e)
                {
                    logger.Error(e, "Failed to start Epic game directly.");
                    ProcessStarter.StartUrl(startUri);
                }
            }

            if (Directory.Exists(Game.InstallDirectory))
            {
                stopWatch              = Stopwatch.StartNew();
                procMon                = new ProcessMonitor();
                procMon.TreeStarted   += ProcMon_TreeStarted;
                procMon.TreeDestroyed += Monitor_TreeDestroyed;
                procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
            }
            else
            {
                OnStopped(this, new GameControllerEventArgs(this, 0));
            }
        }
Beispiel #5
0
        public override void Uninstall()
        {
            if (!EpicLauncher.IsInstalled)
            {
                throw new Exception("Epic Launcher is not installed.");
            }

            EpicLauncher.StartClient();
            StartUninstallWatcher();
        }
        internal Dictionary <string, GameInfo> GetInstalledGames()
        {
            var games     = new Dictionary <string, GameInfo>();
            var appList   = EpicLauncher.GetInstalledAppList();
            var manifests = EpicLauncher.GetInstalledManifests();

            foreach (var app in appList)
            {
                if (app.AppName.StartsWith("UE_"))
                {
                    continue;
                }

                var manifest = manifests.FirstOrDefault(a => a.AppName == app.AppName);

                // DLC
                if (manifest.AppName != manifest.MainGameAppName)
                {
                    continue;
                }

                // UE plugins
                if (manifest.AppCategories?.Any(a => a == "plugins" || a == "plugins/engine") == true)
                {
                    continue;
                }

                var game = new GameInfo()
                {
                    Source           = "Epic",
                    GameId           = app.AppName,
                    Name             = manifest?.DisplayName ?? Path.GetFileName(app.InstallLocation),
                    InstallDirectory = manifest?.InstallLocation ?? app.InstallLocation,
                    IsInstalled      = true,
                    PlayAction       = new GameAction()
                    {
                        Type = GameActionType.URL,
                        Path = string.Format(EpicLauncher.GameLaunchUrlMask, app.AppName),
                        IsHandledByPlugin = true
                    },
                    Platform = "PC"
                };

                game.Name = game.Name.RemoveTrademarks();
                games.Add(game.GameId, game);
            }

            return(games);
        }
Beispiel #7
0
        public async void StartUninstallWatcher()
        {
            watcherToken = new CancellationTokenSource();

            while (true)
            {
                if (watcherToken.IsCancellationRequested)
                {
                    return;
                }

                var installed = EpicLauncher.GetInstalledAppList();
                var app       = installed?.FirstOrDefault(a => a.AppName == Game.GameId);
                if (app == null)
                {
                    OnUninstalled(this, new GameControllerEventArgs(this, 0));
                    return;
                }

                await Task.Delay(2000);
            }
        }
Beispiel #8
0
        public override GameMetadata GetMetadata(Game game)
        {
            var gameInfo = new GameInfo()
            {
                Links = new List <Link>()
            };
            var metadata = new GameMetadata()
            {
                GameInfo = gameInfo
            };

            using (var client = new WebStoreClient())
            {
                var catalogs = client.QuerySearch(game.Name).GetAwaiter().GetResult();
                if (catalogs.HasItems())
                {
                    var catalog = catalogs.FirstOrDefault(a => a.title.Equals(game.Name, StringComparison.InvariantCultureIgnoreCase));
                    if (catalog == null)
                    {
                        catalog = catalogs[0];
                    }

                    var product = client.GetProductInfo(catalog.productSlug).GetAwaiter().GetResult();
                    if (product.pages.HasItems())
                    {
                        var page = product.pages.FirstOrDefault(a => a.type is string type && type == "productHome");
                        if (page == null)
                        {
                            page = product.pages[0];
                        }

                        gameInfo.Developers = page.data.about.developerAttribution?.
                                              Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).
                                              Select(a => a.Trim()).ToList();
                        gameInfo.Publishers = page.data.about.publisherAttribution?.
                                              Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).
                                              Select(a => a.Trim()).ToList();
                        metadata.BackgroundImage = new MetadataFile(page.data.hero.backgroundImageUrl);
                        gameInfo.Links.Add(new Link(
                                               library.PlayniteApi.Resources.GetString("LOCCommonLinksStorePage"),
                                               "https://www.epicgames.com/store/en-US/product/" + catalog.productSlug));

                        if (page.data.socialLinks.HasItems())
                        {
                            var links = page.data.socialLinks.
                                        Where(a => a.Key.StartsWith("link") && !a.Value.IsNullOrEmpty()).
                                        Select(a => new Link(a.Key.Replace("link", ""), a.Value)).ToList();
                            if (links.HasItems())
                            {
                                gameInfo.Links.AddRange(links);
                            }
                        }

                        if (!page.data.about.description.IsNullOrEmpty())
                        {
                            gameInfo.Description = Markup.MarkdownToHtml(page.data.about.description);
                        }
                    }
                }
            }

            gameInfo.Links.Add(new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name));

            // There's not icon available on Epic servers so we will load one from EXE
            if (game.IsInstalled && string.IsNullOrEmpty(game.Icon))
            {
                var manifest = EpicLauncher.GetInstalledManifests().FirstOrDefault(a => a.AppName == game.GameId);
                if (manifest != null)
                {
                    var exePath = Path.Combine(manifest.InstallLocation, manifest.LaunchExecutable);
                    if (File.Exists(exePath))
                    {
                        using (var ms = new MemoryStream())
                        {
                            if (IconExtractor.ExtractMainIconFromFile(exePath, ms))
                            {
                                var iconName = Guid.NewGuid() + ".ico";
                                metadata.Icon = new MetadataFile(iconName, ms.ToArray());
                            }
                        }
                    }
                }
            }

            return(metadata);
        }
Beispiel #9
0
 public override void Open()
 {
     EpicLauncher.StartClient();
 }