コード例 #1
0
        public static void CreateDiagPackage(string path)
        {
            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 (File.Exists(PlaynitePaths.ConfigFilePath))
                    {
                        archive.CreateEntryFromFile(PlaynitePaths.ConfigFilePath, Path.GetFileName(PlaynitePaths.ConfigFilePath));
                    }

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

                    // Uninstall regkey export
                    var regKeyPath = Path.Combine(diagTemp, "uninstall.txt");
                    var programs   = Programs.GetUnistallProgramsList();
                    File.WriteAllText(regKeyPath, Serialization.ToYaml(programs));
                    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.ToYaml(playniteInfo));
                    archive.CreateEntryFromFile(playnitePath, Path.GetFileName(playnitePath));
                }
            }

            FileSystem.DeleteFolder(diagTemp);
        }
コード例 #2
0
ファイル: Diagnostic.cs プロジェクト: wuhan890809/Playnite
        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
ファイル: Diagnostic.cs プロジェクト: tehrelt/Playnite
        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
ファイル: Diagnostic.cs プロジェクト: tjhrulz/Playnite
        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));
                }
            }
        }