Пример #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);
            }
        }
Пример #2
0
        public async Task DownloadUpdate(UpdateManifest.Package package, Action <DownloadProgressChangedEventArgs> progressHandler)
        {
            if (updateManifest == null)
            {
                DownloadManifest();
            }

            if (File.Exists(updaterPath))
            {
                var md5 = FileSystem.GetMD5(updaterPath);
                if (md5 == package.Checksum)
                {
                    logger.Info("Update already downloaded skipping download.");
                    return;
                }
            }

            try
            {
                var downloadUrls = updateManifest.DownloadServers.Select(a => Url.Combine(a, updateManifest.LatestVersion.ToString(), package.FileName));
                await downloader.DownloadFileAsync(downloadUrls, updaterPath, progressHandler);

                var md5 = FileSystem.GetMD5(updaterPath);
                if (md5 != package.Checksum)
                {
                    throw new Exception($"Checksum of downloaded file doesn't match: {md5} vs {package.Checksum}");
                }
            }
            catch (Exception e)
            {
                logger.Warn(e, "Failed to download update file.");
                throw new Exception("Failed to download update file.");
            }
        }
Пример #3
0
        private bool VerifyUpdateFile(string checksum, string path)
        {
            var newMD5 = FileSystem.GetMD5(path);

            if (newMD5 != checksum)
            {
                logger.Error($"Checksum of downloaded file doesn't match: {newMD5} vs {checksum}");
                return(false);
            }

            return(true);
        }
Пример #4
0
        private bool VerifyUpdateFile(string checksum, string path)
        {
            var newMD5 = FileSystem.GetMD5(path);

            if (newMD5 != checksum)
            {
                logger.Error($"Checksum of downloaded file doesn't match: {newMD5} vs {checksum}");
                return(false);
            }

#if !DEBUG
            if (!SigningTools.IsTrusted(path))
            {
                return(false);
            }
#endif

            return(true);
        }
Пример #5
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);
        }