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)); } // 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.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.DeleteDirectory(diagTemp); }
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 }, { "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); }
public void SaveSettings() { FileSystem.CreateDirectory(Paths.ConfigRootPath); File.WriteAllText(Paths.ConfigFilePath, JsonConvert.SerializeObject(this, Formatting.Indented)); }
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)); // UWP app info if (Computer.WindowsVersion == WindowsVersion.Win10) { var uwpInfoPath = Path.Combine(diagTemp, "uwp.txt"); var uwpApps = Programs.GetUWPApps(); File.WriteAllText(uwpInfoPath, Serialization.ToJson(uwpApps, true)); archive.CreateEntryFromFile(uwpInfoPath, Path.GetFileName(uwpInfoPath)); } // Playnite info var playnitePath = Path.Combine(diagTemp, "playniteInfo.txt"); var playniteInfo = new Dictionary <string, object> { { "Version", Updater.GetCurrentVersion().ToString() }, { "Portable", PlayniteSettings.IsPortable }, { "Memory", (PlayniteProcess.WorkingSetMemory / 1024f) / 1024f }, { "Path", PlayniteProcess.Path }, { "Cmdline", PlayniteProcess.Cmdline } }; 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); }
public static void MigrateSettingsConfig() { void WriteConfig(string id, Dictionary <string, object> config) { var path = Path.Combine(PlaynitePaths.ExtensionsDataPath, id, "config.json"); if (!File.Exists(path)) { FileSystem.CreateDirectory(path); File.WriteAllText(path, JsonConvert.SerializeObject(config, Formatting.Indented)); } } try { if (!File.Exists(PlaynitePaths.ConfigFilePath)) { return; } var oldSettings = JsonConvert.DeserializeObject <Settings.OldSettings.Settings>(File.ReadAllText(PlaynitePaths.ConfigFilePath)); if (oldSettings.BattleNetSettings != null) { var config = new Dictionary <string, object>() { { "ImportInstalledGames", oldSettings.BattleNetSettings.IntegrationEnabled }, { "ImportUninstalledGames", oldSettings.BattleNetSettings.LibraryDownloadEnabled } }; WriteConfig("E3C26A3D-D695-4CB7-A769-5FF7612C7EDD", config); } if (oldSettings.OriginSettings != null) { var config = new Dictionary <string, object>() { { "ImportInstalledGames", oldSettings.OriginSettings.IntegrationEnabled }, { "ImportUninstalledGames", oldSettings.OriginSettings.LibraryDownloadEnabled } }; WriteConfig("85DD7072-2F20-4E76-A007-41035E390724", config); } if (oldSettings.GOGSettings != null) { var config = new Dictionary <string, object>() { { "ImportInstalledGames", oldSettings.GOGSettings.IntegrationEnabled }, { "ImportUninstalledGames", oldSettings.GOGSettings.LibraryDownloadEnabled }, { "StartGamesUsingGalaxy", oldSettings.GOGSettings.RunViaGalaxy } }; WriteConfig("AEBE8B7C-6DC3-4A66-AF31-E7375C6B5E9E", config); } if (oldSettings.SteamSettings != null) { var config = new Dictionary <string, object>() { { "ImportInstalledGames", oldSettings.SteamSettings.IntegrationEnabled }, { "ImportUninstalledGames", oldSettings.SteamSettings.LibraryDownloadEnabled }, { "PreferScreenshotForBackground", oldSettings.SteamSettings.PreferScreenshotForBackground }, { "ApiKey", oldSettings.SteamSettings.APIKey }, { "IsPrivateAccount", oldSettings.SteamSettings.PrivateAccount }, { "AccountId", oldSettings.SteamSettings.AccountId }, { "AccountName", oldSettings.SteamSettings.AccountName }, { "IdSource", oldSettings.SteamSettings.IdSource } }; WriteConfig("CB91DFC9-B977-43BF-8E70-55F46E410FAB", config); } if (oldSettings.UplaySettings != null) { var config = new Dictionary <string, object>() { { "ImportInstalledGames", oldSettings.UplaySettings.IntegrationEnabled } }; WriteConfig("C2F038E5-8B92-4877-91F1-DA9094155FC5", config); } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Failed to migrade plugin configuration."); } }
public static void CreateDiagPackage(string path) { var diagTemp = Path.Combine(Paths.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(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)) { FileSystem.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"); FileSystem.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)); } } }