public static void DownloadFile(string url, string path) { FileSystem.CreateFolder(Path.GetDirectoryName(path)); var webClient = new WebClient(); webClient.DownloadFile(url, path); }
public static void ConfigureCef() { FileSystem.CreateFolder(Paths.BrowserCachePath); var settings = new CefSettings(); settings.CefCommandLineArgs.Add("disable-gpu", "1"); settings.CefCommandLineArgs.Add("disable-gpu-compositing", "1"); settings.CachePath = Paths.BrowserCachePath; settings.PersistSessionCookies = true; settings.LogFile = Path.Combine(Paths.ConfigRootPath, "cef.log"); Cef.Initialize(settings); }
public static string GetCachedWebFile(string url) { if (string.IsNullOrEmpty(url)) { return(string.Empty); } var extension = Path.GetExtension(url); var md5 = url.MD5(); var cacheFile = Path.Combine(Paths.ImagesCachePath, md5 + extension); if (!File.Exists(cacheFile)) { FileSystem.CreateFolder(Paths.ImagesCachePath); try { DownloadFile(url, cacheFile); } catch (WebException e) { if (e.Response == null) { throw; } var response = (HttpWebResponse)e.Response; if (response.StatusCode != HttpStatusCode.NotFound) { throw; } else { return(string.Empty); } } } return(cacheFile); }
public void SaveSettings() { FileSystem.CreateFolder(Paths.ConfigRootPath); File.WriteAllText(Paths.ConfigFilePath, JsonConvert.SerializeObject(this, Formatting.Indented)); }
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)); } } }