Пример #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 (!string.IsNullOrEmpty(game.Icon) && Path.GetExtension(game.Icon) == ".ico")
                {
                    icon = Database.GetFullFilePath(game.Icon);
                }
                else if (game.PlayAction?.Type == GameActionType.File)
                {
                    icon = game.GetRawExecutablePath();
                }

                if (!File.Exists(icon))
                {
                    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);
            }
        }
Пример #2
0
        public static void CreateDiagPackage(string path, string userActionsDescription, DiagnosticPackageInfo packageInfo)
        {
            var diagTemp = Path.Combine(PlaynitePaths.TempPath, "diag");

            FileSystem.CreateDirectory(diagTemp, true);
            FileSystem.DeleteFile(path);

            ZipFile.CreateFromDirectory(diagTemp, path);
            using (FileStream zipToOpen = new FileStream(path, FileMode.Open))
            {
                using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
                {
                    // Package info
                    var packagePath = Path.Combine(diagTemp, DiagnosticPackageInfo.PackageInfoFileName);
                    File.WriteAllText(packagePath, Serialization.ToJson(packageInfo));
                    archive.CreateEntryFromFile(packagePath, Path.GetFileName(packagePath));

                    // Config
                    if (Directory.Exists(PlaynitePaths.ConfigRootPath))
                    {
                        foreach (var cfg in Directory.GetFiles(PlaynitePaths.ConfigRootPath, "*.json"))
                        {
                            var fileInfo = new FileInfo(cfg);
                            archive.CreateEntryFromFile(cfg, fileInfo.Name);
                        }
                    }

                    // Extension configs
                    if (Directory.Exists(PlaynitePaths.ExtensionsDataPath))
                    {
                        foreach (var cfg in Directory.GetFiles(PlaynitePaths.ExtensionsDataPath, "config.json", SearchOption.AllDirectories))
                        {
                            var fileInfo = new FileInfo(cfg);
                            archive.CreateEntryFromFile(cfg, Path.Combine("extensions", fileInfo.Directory.Name, fileInfo.Name));
                        }
                    }

                    // Installed extensions/themes
                    try
                    {
                        var extensionsPath = Path.Combine(diagTemp, "extensions.txt");
                        File.WriteAllText(extensionsPath, GetManifestInfo(PlaynitePaths.ExtensionsProgramPath, PlaynitePaths.ExtensionManifestFileName));
                        File.AppendAllText(extensionsPath, GetManifestInfo(PlaynitePaths.ThemesProgramPath, PlaynitePaths.ThemeManifestFileName));
                        if (!PlayniteSettings.IsPortable)
                        {
                            File.AppendAllText(extensionsPath, GetManifestInfo(PlaynitePaths.ExtensionsUserDataPath, PlaynitePaths.ExtensionManifestFileName));
                            File.AppendAllText(extensionsPath, GetManifestInfo(PlaynitePaths.ThemesUserDataPath, PlaynitePaths.ThemeManifestFileName));
                        }

                        archive.CreateEntryFromFile(extensionsPath, Path.GetFileName(extensionsPath));
                    }
                    catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
                    {
                        logger.Error(e, "Failed to package extensions list.");
                    }

                    // System Info
                    try
                    {
                        var infoPath = Path.Combine(diagTemp, "sysinfo.txt");
                        File.WriteAllText(infoPath, Serialization.ToJson(Computer.GetSystemInfo(), true));
                        archive.CreateEntryFromFile(infoPath, Path.GetFileName(infoPath));
                    }
                    catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
                    {
                        logger.Error(e, "Failed gather system info.");
                    }

                    // Uninstall regkey export
                    try
                    {
                        var regKeyPath = Path.Combine(diagTemp, "uninstall.txt");
                        var programs   = Programs.GetUnistallProgramsList();
                        File.WriteAllText(regKeyPath, Serialization.ToJson(programs, true));
                        archive.CreateEntryFromFile(regKeyPath, Path.GetFileName(regKeyPath));
                    }
                    catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
                    {
                        logger.Error(e, "Failed gather install app list.");
                    }

                    // UWP app info
                    try
                    {
                        if (Computer.WindowsVersion == WindowsVersion.Win10 || Computer.WindowsVersion == WindowsVersion.Win11)
                        {
                            var uwpInfoPath = Path.Combine(diagTemp, "uwp.txt");
                            var uwpApps     = Programs.GetUWPApps();
                            File.WriteAllText(uwpInfoPath, Serialization.ToJson(uwpApps, true));
                            archive.CreateEntryFromFile(uwpInfoPath, Path.GetFileName(uwpInfoPath));
                        }
                    }
                    catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
                    {
                        logger.Error(e, "Failed gather UWP install list.");
                    }

                    // Playnite info
                    var playnitePath = Path.Combine(diagTemp, "playniteInfo.txt");
                    var playniteInfo = new Dictionary <string, object>
                    {
                        { "Version", Updater.CurrentVersion.ToString() },
                        { "Portable", PlayniteSettings.IsPortable },
                        { "Memory", (PlayniteProcess.WorkingSetMemory / 1024f) / 1024f },
                        { "Path", PlayniteProcess.Path },
                        { "Cmdline", PlayniteProcess.Cmdline },
                        { "Elevated", PlayniteEnvironment.IsElevated },
                        { "Playnite.DesktopApp.exe_MD5", FileSystem.GetMD5(PlaynitePaths.DesktopExecutablePath) },
                        { "Playnite.FullscreenApp.exe_MD5", FileSystem.GetMD5(PlaynitePaths.FullscreenExecutablePath) },
                        { "Playnite.dll_MD5", FileSystem.GetMD5(PlaynitePaths.PlayniteAssemblyPath) },
                        { "Playnite.SDK.dll_MD5", FileSystem.GetMD5(PlaynitePaths.PlayniteSDKAssemblyPath) }
                    };

                    File.WriteAllText(playnitePath, Serialization.ToJson(playniteInfo, true));
                    archive.CreateEntryFromFile(playnitePath, Path.GetFileName(playnitePath));

                    // Program file list
                    try
                    {
                        var fileListPath = Path.Combine(diagTemp, "fileList.txt");
                        File.WriteAllText(fileListPath, string.Join(Environment.NewLine, GetPlayniteFilesList()));
                        archive.CreateEntryFromFile(fileListPath, Path.GetFileName(fileListPath));
                    }
                    catch (Exception e)
                    {
                        logger.Error(e, "Failed to pack app file list.");
                    }

                    // User actions description
                    if (!string.IsNullOrWhiteSpace(userActionsDescription))
                    {
                        var descriptionPath = Path.Combine(diagTemp, "userActions.txt");
                        File.WriteAllText(descriptionPath, userActionsDescription);
                        archive.CreateEntryFromFile(descriptionPath, Path.GetFileName(descriptionPath));
                    }

                    void addCefLog(string logPath, ZipArchive archiveObj)
                    {
                        try
                        {
                            var cefEntry = archive.CreateEntry(Path.GetFileName(logPath));
                            using (var cefS = new FileStream(logPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                                using (var writer = new StreamWriter(cefEntry.Open()))
                                {
                                    cefS.CopyTo(writer.BaseStream);
                                }
                        }
                        catch (Exception e)
                        {
                            logger.Error(e, "Failed to pack CEF log.");
                        }
                    }

                    // Add log files
                    foreach (var logFile in Directory.GetFiles(PlaynitePaths.ConfigRootPath, "*.log", SearchOption.TopDirectoryOnly))
                    {
                        if (Path.GetFileName(logFile) == "cef.log" || Path.GetFileName(logFile) == "debug.log")
                        {
                            addCefLog(logFile, archive);
                        }
                        else
                        {
                            archive.CreateEntryFromFile(logFile, Path.GetFileName(logFile));
                        }
                    }
                }
            }

            FileSystem.DeleteDirectory(diagTemp);
        }
Пример #3
0
        public static void CreateDiagPackage(string path, string userActionsDescription)
        {
            var diagTemp = Path.Combine(PlaynitePaths.TempPath, "diag");

            FileSystem.CreateDirectory(diagTemp, true);
            FileSystem.DeleteFile(path);

            ZipFile.CreateFromDirectory(diagTemp, path);
            using (FileStream zipToOpen = new FileStream(path, FileMode.Open))
            {
                using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
                {
                    // Add log files
                    foreach (var logFile in Directory.GetFiles(PlaynitePaths.ConfigRootPath, "*.log", SearchOption.TopDirectoryOnly))
                    {
                        if (Path.GetFileName(logFile) == "cef.log")
                        {
                            continue;
                        }

                        archive.CreateEntryFromFile(logFile, Path.GetFileName(logFile));
                    }

                    // Config
                    if (Directory.Exists(PlaynitePaths.ConfigRootPath))
                    {
                        foreach (var cfg in Directory.GetFiles(PlaynitePaths.ConfigRootPath, "*.json"))
                        {
                            var fileInfo = new FileInfo(cfg);
                            archive.CreateEntryFromFile(cfg, fileInfo.Name);
                        }
                    }

                    // Extension configs
                    if (Directory.Exists(PlaynitePaths.ExtensionsDataPath))
                    {
                        foreach (var cfg in Directory.GetFiles(PlaynitePaths.ExtensionsDataPath, "config.json", SearchOption.AllDirectories))
                        {
                            var fileInfo = new FileInfo(cfg);
                            archive.CreateEntryFromFile(cfg, Path.Combine("extensions", fileInfo.Directory.Name, fileInfo.Name));
                        }
                    }

                    // System Info
                    var infoPath = Path.Combine(diagTemp, "sysinfo.txt");
                    File.WriteAllText(infoPath, Serialization.ToJson(Computer.GetSystemInfo(), true));
                    archive.CreateEntryFromFile(infoPath, Path.GetFileName(infoPath));

                    // Uninstall regkey export
                    var regKeyPath = Path.Combine(diagTemp, "uninstall.txt");
                    var programs   = Programs.GetUnistallProgramsList();
                    File.WriteAllText(regKeyPath, Serialization.ToJson(programs, true));
                    archive.CreateEntryFromFile(regKeyPath, Path.GetFileName(regKeyPath));

                    // Playnite info
                    var playnitePath = Path.Combine(diagTemp, "playniteInfo.txt");
                    var playniteInfo = new Dictionary <string, object>
                    {
                        { "Version", Updater.GetCurrentVersion().ToString() },
                        { "Portable", PlayniteSettings.IsPortable }
                    };

                    File.WriteAllText(playnitePath, Serialization.ToJson(playniteInfo, true));
                    archive.CreateEntryFromFile(playnitePath, Path.GetFileName(playnitePath));

                    // User actions description
                    if (!string.IsNullOrWhiteSpace(userActionsDescription))
                    {
                        var descriptionPath = Path.Combine(diagTemp, "userActions.txt");
                        File.WriteAllText(descriptionPath, userActionsDescription);
                        archive.CreateEntryFromFile(descriptionPath, Path.GetFileName(descriptionPath));
                    }
                }
            }

            FileSystem.DeleteDirectory(diagTemp);
        }
Пример #4
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.ParseShortcut(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);
        }
Пример #5
0
        public static void CreateDiagPackage(string path)
        {
            var diagTemp = Path.Combine(Paths.TempPath, "diag");

            FileSystem.CreateFolder(diagTemp, true);
            FileSystem.DeleteFile(path);

            ZipFile.CreateFromDirectory(diagTemp, path);
            using (FileStream zipToOpen = new FileStream(path, FileMode.Open))
            {
                using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
                {
                    // Add log files
                    foreach (var logFile in Directory.GetFiles(Paths.ConfigRootPath, "*.log", SearchOption.TopDirectoryOnly))
                    {
                        if (Path.GetFileName(logFile) == "cef.log")
                        {
                            continue;
                        }

                        archive.CreateEntryFromFile(logFile, Path.GetFileName(logFile));
                    }


                    // Config
                    if (File.Exists(Paths.ConfigFilePath))
                    {
                        archive.CreateEntryFromFile(Paths.ConfigFilePath, Path.GetFileName(Paths.ConfigFilePath));
                    }

                    // Origin data
                    var originContentPath = Path.Combine(Providers.Origin.OriginPaths.DataPath, "LocalContent");
                    if (Directory.Exists(originContentPath))
                    {
                        AddFolderToZip(archive, "Origin", originContentPath, ".dat|.mfst", SearchOption.AllDirectories);
                    }

                    // GOG data
                    if (GogSettings.IsInstalled)
                    {
                        var dbPath = Path.Combine(GogSettings.DBStoragePath, "index.db");
                        if (File.Exists(dbPath))
                        {
                            archive.CreateEntryFromFile(dbPath, "index.db");
                        }
                    }

                    // Steam data
                    if (SteamSettings.IsInstalled)
                    {
                        foreach (var folder in (new SteamLibrary()).GetLibraryFolders())
                        {
                            var appsFolder = Path.Combine(folder, "steamapps");
                            AddFolderToZip(archive, "Steam", appsFolder, "appmanifest*", SearchOption.TopDirectoryOnly);
                        }

                        if (File.Exists(SteamSettings.LoginUsersPath))
                        {
                            archive.CreateEntryFromFile(SteamSettings.LoginUsersPath, "loginusers.vdf");
                        }
                    }

                    // dxdiag
                    var diagPath = Path.Combine(diagTemp, "dxdiag.txt");
                    Process.Start("dxdiag", "/dontskip /whql:off /t " + diagPath).WaitForExit();
                    archive.CreateEntryFromFile(diagPath, Path.GetFileName(diagPath));

                    // Uninstall regkey export
                    var regKeyPath = Path.Combine(diagTemp, "uninstall.json");
                    var programs   = Programs.GetUnistallProgramsList();
                    File.WriteAllText(regKeyPath, JsonConvert.SerializeObject(programs, Formatting.Indented));
                    archive.CreateEntryFromFile(regKeyPath, Path.GetFileName(regKeyPath));
                }
            }
        }
Пример #6
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);
        }