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);
            }
        }
Exemple #2
0
        public static Game GetGameFromExecutable(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"Cannot create game from executable, {path} not found.");
            }

            var game = new Game();

            if (string.Equals(Path.GetExtension(path), ".lnk", StringComparison.OrdinalIgnoreCase))
            {
                var prog     = Programs.GetLnkShortcutData(path);
                var fileInfo = new FileInfo(prog.Path);
                if (!fileInfo.Exists && prog.Path.Contains("Program Files (x86)"))
                {
                    var newPath = prog.Path.Replace("Program Files (x86)", "Program Files");
                    if (File.Exists(newPath))
                    {
                        fileInfo = new FileInfo(newPath);
                        if (prog.WorkDir.Contains("Program Files (x86)"))
                        {
                            prog.WorkDir.Replace("Program Files (x86)", "Program Files");
                        }
                    }
                }

                game.Name             = Path.GetFileNameWithoutExtension(path);
                game.InstallDirectory = prog.WorkDir.IsNullOrEmpty() ? fileInfo.Directory.FullName : prog.WorkDir;
                game.PlayAction       = new GameAction()
                {
                    Type       = GameActionType.File,
                    WorkingDir = ExpandableVariables.InstallationDirectory,
                    Path       = fileInfo.FullName.Substring(game.InstallDirectory.Length).Trim(Path.DirectorySeparatorChar),
                    Arguments  = prog.Arguments
                };

                if (!prog.Icon.IsNullOrEmpty())
                {
                    var iconPath = Regex.Replace(prog.Icon, @",\d+$", "");
                    if (File.Exists(iconPath))
                    {
                        game.Icon = iconPath;
                    }
                    else if (iconPath.Contains("Program Files (x86)"))
                    {
                        iconPath = iconPath.Replace("Program Files (x86)", "Program Files");
                        if (File.Exists(iconPath))
                        {
                            game.Icon = iconPath;
                        }
                    }
                }
            }
            else
            {
                var file        = new FileInfo(path);
                var versionInfo = FileVersionInfo.GetVersionInfo(path);
                var programName = !string.IsNullOrEmpty(versionInfo.ProductName?.Trim()) ? versionInfo.ProductName : new DirectoryInfo(file.DirectoryName).Name;
                game.Name             = programName;
                game.InstallDirectory = file.DirectoryName;
                game.PlayAction       = new GameAction()
                {
                    Type       = GameActionType.File,
                    WorkingDir = ExpandableVariables.InstallationDirectory,
                    Path       = file.Name
                };
            };

            game.IsInstalled = true;
            return(game);
        }
Exemple #3
0
        public static Game GetGameFromExecutable(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"Cannot create game from executable, {path} not found.");
            }

            var game = new Game();

            if (string.Equals(Path.GetExtension(path), ".lnk", StringComparison.OrdinalIgnoreCase))
            {
                var prog     = Programs.GetLnkShortcutData(path);
                var fileInfo = new FileInfo(prog.Path);
                if (!fileInfo.Exists && prog.Path.Contains("Program Files (x86)"))
                {
                    var newPath = prog.Path.Replace("Program Files (x86)", "Program Files");
                    if (File.Exists(newPath))
                    {
                        fileInfo = new FileInfo(newPath);
                        if (prog.WorkDir.Contains("Program Files (x86)"))
                        {
                            prog.WorkDir.Replace("Program Files (x86)", "Program Files");
                        }
                    }
                }

                game.Name             = Path.GetFileNameWithoutExtension(path);
                game.InstallDirectory = prog.WorkDir.IsNullOrEmpty() ? fileInfo.Directory.FullName : prog.WorkDir;
                game.GameActions      = new System.Collections.ObjectModel.ObservableCollection <GameAction>
                {
                    new GameAction()
                    {
                        Type         = GameActionType.File,
                        WorkingDir   = ExpandableVariables.InstallationDirectory,
                        Path         = fileInfo.FullName.Substring(game.InstallDirectory.Length).Trim(Path.DirectorySeparatorChar),
                        Arguments    = prog.Arguments,
                        IsPlayAction = true,
                        Name         = game.Name
                    }
                };

                if (!prog.Icon.IsNullOrEmpty())
                {
                    var iconPath = Regex.Replace(prog.Icon, @",\d+$", "");
                    if (File.Exists(iconPath))
                    {
                        game.Icon = iconPath;
                    }
                    else if (iconPath.Contains("Program Files (x86)"))
                    {
                        iconPath = iconPath.Replace("Program Files (x86)", "Program Files");
                        if (File.Exists(iconPath))
                        {
                            game.Icon = iconPath;
                        }
                    }
                }
            }
            else if (string.Equals(Path.GetExtension(path), ".url", StringComparison.OrdinalIgnoreCase))
            {
                var urlData  = IniParser.Parse(File.ReadAllLines(path));
                var shortcut = urlData["InternetShortcut"];
                if (shortcut == null)
                {
                    throw new Exception("URL file doesn't have shortcut definition section.");
                }

                game.Name        = Path.GetFileNameWithoutExtension(path);
                game.Icon        = shortcut["IconFile"];
                game.GameActions = new System.Collections.ObjectModel.ObservableCollection <GameAction>
                {
                    new GameAction()
                    {
                        Type         = GameActionType.URL,
                        Path         = shortcut["URL"],
                        IsPlayAction = true,
                        Name         = game.Name
                    }
                };
            }
            else
            {
                var file        = new FileInfo(path);
                var versionInfo = FileVersionInfo.GetVersionInfo(path);
                var programName = !string.IsNullOrEmpty(versionInfo.ProductName?.Trim()) ? versionInfo.ProductName : new DirectoryInfo(file.DirectoryName).Name;
                game.Name             = programName;
                game.InstallDirectory = file.DirectoryName;
                game.GameActions      = new System.Collections.ObjectModel.ObservableCollection <GameAction>
                {
                    new GameAction()
                    {
                        Type         = GameActionType.File,
                        WorkingDir   = ExpandableVariables.InstallationDirectory,
                        Path         = file.Name,
                        IsPlayAction = true,
                        Name         = game.Name
                    }
                };
            };

            game.IsInstalled = true;
            return(game);
        }