Ejemplo n.º 1
0
        public void CreateShortcut(Game game)
        {
            try
            {
                var    path = Environment.ExpandEnvironmentVariables(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Paths.GetSafeFilename(game.Name) + ".url"));
                string icon = string.Empty;

                if (!game.Icon.IsNullOrEmpty())
                {
                    icon = Database.GetFullFilePath(game.Icon);
                }
                else
                {
                    icon = game.GetDefaultIcon(AppSettings, Database, Extensions.GetLibraryPlugin(game.PluginId));
                    if (!File.Exists(icon))
                    {
                        icon = string.Empty;
                    }
                }

                if (File.Exists(icon))
                {
                    if (Path.GetExtension(icon) != ".ico")
                    {
                        var targetIconPath = Path.Combine(PlaynitePaths.TempPath, Guid.NewGuid() + ".ico");
                        BitmapExtensions.ConvertToIcon(icon, targetIconPath);
                        var md5          = FileSystem.GetMD5(targetIconPath);
                        var existingFile = Path.Combine(PlaynitePaths.TempPath, md5 + ".ico");
                        if (File.Exists(existingFile))
                        {
                            icon = existingFile;
                            File.Delete(targetIconPath);
                        }
                        else
                        {
                            File.Move(targetIconPath, existingFile);
                            icon = existingFile;
                        }
                    }
                }
                else
                {
                    icon = PlaynitePaths.DesktopExecutablePath;
                }

                var args = new CmdLineOptions()
                {
                    Start = game.Id.ToString()
                }.ToString();
                Programs.CreateUrlShortcut($"playnite://playnite/start/{game.Id}", icon, path);
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(exc, "Failed to create shortcut: ");
                Dialogs.ShowMessage(
                    string.Format(resources.GetString("LOCGameShortcutError"), exc.Message),
                    resources.GetString("LOCGameError"),
                    MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
        public void CreateShortcut(Game game)
        {
            try
            {
                var    path = Environment.ExpandEnvironmentVariables(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Paths.GetSafeFilename(game.Name) + ".lnk"));
                string icon = string.Empty;

                if (!string.IsNullOrEmpty(game.Icon) && Path.GetExtension(game.Icon) == ".ico")
                {
                    icon = Database.GetFullFilePath(game.Icon);
                }
                else if (game.PlayAction?.Type == GameActionType.File)
                {
                    icon = game.GetRawExecutablePath();
                }

                var args = new CmdLineOptions()
                {
                    Start = game.Id.ToString()
                }.ToString();
                Programs.CreateShortcut(PlaynitePaths.DesktopExecutablePath, args, icon, path);
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(exc, "Failed to create shortcut: ");
                Dialogs.ShowMessage(
                    string.Format(resources.GetString("LOCGameShortcutError"), exc.Message),
                    resources.GetString("LOCGameError"),
                    MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 3
0
        public static void SetBootupStateRegistration(bool runOnBootup)
        {
            var startupPath  = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            var shortcutPath = Path.Combine(startupPath, "Playnite.lnk");

            if (runOnBootup)
            {
                var args = new CmdLineOptions()
                {
                    HideSplashScreen = true
                }.ToString();

                if (File.Exists(shortcutPath))
                {
                    var existLnk = Programs.GetLnkShortcutData(shortcutPath);
                    if (existLnk.Path == PlaynitePaths.DesktopExecutablePath &&
                        existLnk.Arguments == args)
                    {
                        return;
                    }
                }

                FileSystem.DeleteFile(shortcutPath);
                Programs.CreateShortcut(PlaynitePaths.DesktopExecutablePath, args, "", shortcutPath);
            }
            else
            {
                FileSystem.DeleteFile(shortcutPath);
            }
        }
Ejemplo n.º 4
0
        public void UpdateJumpList()
        {
            try
            {
                var jumpList = new JumpList();
                jumpList.ShowFrequentCategory = false;
                jumpList.ShowRecentCategory   = false;

                if (AppSettings.QuickLaunchItems > 0)
                {
                    foreach (var lastGame in QuickLaunchItems)
                    {
                        var args = new CmdLineOptions()
                        {
                            Start = lastGame.Id.ToString()
                        }.ToString();
                        JumpTask task = new JumpTask
                        {
                            Title           = lastGame.Name,
                            Arguments       = args,
                            Description     = string.Empty,
                            CustomCategory  = "Recent",
                            ApplicationPath = PlaynitePaths.DesktopExecutablePath
                        };

                        if (lastGame.Icon?.EndsWith(".ico", StringComparison.OrdinalIgnoreCase) == true)
                        {
                            task.IconResourcePath = Database.GetFullFilePath(lastGame.Icon);
                        }
                        else if (lastGame.PlayAction?.Type == GameActionType.File)
                        {
                            task.IconResourcePath = lastGame.GetRawExecutablePath();
                        }

                        jumpList.JumpItems.Add(task);
                    }

                    JumpList.SetJumpList(System.Windows.Application.Current, jumpList);
                }
                else
                {
                    JumpList.SetJumpList(System.Windows.Application.Current, new JumpList());
                }

                jumpList.Apply();
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(exc, "Failed to set jump list data.");
            }
        }
Ejemplo n.º 5
0
        public static void SetBootupStateRegistration(bool runOnBootup)
        {
            var startupPath  = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            var shortcutPath = Path.Combine(startupPath, "Playnite.lnk");

            if (runOnBootup)
            {
                FileSystem.DeleteFile(shortcutPath);

                var hideSplashScreenOption = new CmdLineOptions()
                {
                    HideSplashScreen = true
                };

                Programs.CreateShortcut(PlaynitePaths.DesktopExecutablePath, hideSplashScreenOption.ToString(), "", shortcutPath);
            }
            else
            {
                FileSystem.DeleteFile(shortcutPath);
            }
        }
Ejemplo n.º 6
0
        public void UpdateJumpList()
        {
            OnPropertyChanged(nameof(LastGames));
            var jumpList = new JumpList();

            foreach (var lastGame in LastGames)
            {
                var args = new CmdLineOptions()
                {
                    Start = lastGame.Id.ToString()
                }.ToString();
                JumpTask task = new JumpTask
                {
                    Title           = lastGame.Name,
                    Arguments       = args,
                    Description     = string.Empty,
                    CustomCategory  = "Recent",
                    ApplicationPath = PlaynitePaths.DesktopExecutablePath
                };

                if (lastGame.Icon?.EndsWith(".ico", StringComparison.OrdinalIgnoreCase) == true)
                {
                    task.IconResourcePath = Database.GetFullFilePath(lastGame.Icon);
                }
                else if (lastGame.PlayAction?.Type == GameActionType.File)
                {
                    task.IconResourcePath = lastGame.GetRawExecutablePath();
                }

                jumpList.JumpItems.Add(task);
                jumpList.ShowFrequentCategory = false;
                jumpList.ShowRecentCategory   = false;
            }

            JumpList.SetJumpList(Application.Current, jumpList);
        }