public static WallpaperInfo GetFileInformation(string filePath) { filePath = filePath.ToLower(); WallpaperInfo wallpaperInfo = new WallpaperInfo(); string selectStatement = "SELECT * FROM Images WHERE FileLocation = '" + filePath + "'"; using var con = new SqliteConnection(DB_CONNNECTION_STRING); con.Open(); using var cmd = new SqliteCommand(selectStatement, con); using SqliteDataReader rdr = cmd.ExecuteReader(); wallpaperInfo.FileLocation = filePath; while (rdr.Read()) { wallpaperInfo.SourceLink = ParseReaderOrdinalString(rdr, 1); wallpaperInfo.Location = ParseReaderOrdinalString(rdr, 2); wallpaperInfo.Description = ParseReaderOrdinalString(rdr, 3); } con.Close(); return(wallpaperInfo); }
private bool WallpaperIsExists(WallpaperInfo wallpaperInfo) { if (!Directory.Exists(Path.Combine(ServiceInfo.WallpaperDirectory))) { Directory.CreateDirectory(Path.Combine(ServiceInfo.WallpaperDirectory)); } return(File.Exists(Path.Combine(ServiceInfo.WallpaperDirectory, wallpaperInfo.Name))); }
public EditWallpaperInfo(WallpaperInfo wallpaperInfo) { InitializeComponent(); this.CurrentWallpaperInfo = wallpaperInfo; this.lblFileLocation.Content = wallpaperInfo.FileLocation; this.txtLocation.Text = wallpaperInfo.Location; this.txtSourceLink.Text = wallpaperInfo.SourceLink; this.txtDescription.Text = wallpaperInfo.Description; }
private List <WallpaperInfo> GetWallpapers() { List <WallpaperInfo> wallpaperInfos = new List <WallpaperInfo>(); Resolution resolution = ServiceInfo.Resolution; do { logger.Log($"Founded Wallpaper Count:{wallpaperInfos.Count}"); if (wallpaperInfos.Count <= ServiceInfo.SearchLimit) { CURRENT_PAGE++; logger.Log($"Current Page Changed : {CURRENT_PAGE}"); } HtmlWeb web = new HtmlWeb(); var doc = web.Load(string.Format(WALLHAVEN_URL, CURRENT_PAGE)); var figures = doc.DocumentNode.SelectNodes("//figure"); foreach (var figure in figures) { Thread.Sleep(1000); HtmlDocument figureDocument = new HtmlDocument(); figureDocument.LoadHtml(figure.InnerHtml); var resolutionElement = figureDocument.DocumentNode.SelectSingleNode("//span[@class='wall-res']"); var resolutionElementContent = resolutionElement.InnerText.Trim().Split('x'); int width = int.Parse(resolutionElementContent[0]); int height = int.Parse(resolutionElementContent[1]); if (width != resolution.Width || height != resolution.Height) { continue; } var wallpaperPreviewElement = figureDocument.DocumentNode.SelectSingleNode("//a[@class='preview']"); var wallpaperPreviewHref = wallpaperPreviewElement.Attributes["href"].Value; var previewPage = web.Load(wallpaperPreviewHref); var downloadWallpaperElement = previewPage.DocumentNode.SelectSingleNode("//img[@id='wallpaper']"); var downloadWallpaperUrl = downloadWallpaperElement.Attributes["src"].Value; var wallpaperName = downloadWallpaperUrl.Substring(downloadWallpaperUrl.LastIndexOf("-") + 1); WallpaperInfo wallpaperInfo = new WallpaperInfo() { Name = wallpaperName, PreviewUrl = wallpaperPreviewHref, Resolution = new Resolution() { Width = width, Height = height }, Url = downloadWallpaperUrl }; wallpaperInfos.Add(wallpaperInfo); } } while (wallpaperInfos.Count <= ServiceInfo.SearchLimit); logger.Log($"{wallpaperInfos.Count} Wallpaper Found"); CURRENT_PAGE = 1; return(wallpaperInfos); }
public void SetWallpaper(WallpaperInfo wallpaperInfo) { RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); key.SetValue(@"WallpaperStyle", 2.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, Path.Combine(ServiceInfo.WallpaperDirectory, wallpaperInfo.Name), SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); logger.Log("Wallpaper Changed."); }
private void OpenCurrentWallpaperWindow(object sender, EventArgs e) { string curr_wall = WallpaperPather.GetCurrentWallpaper(); lblFolderSource.Content = Path.GetDirectoryName(curr_wall); lblFileSource.Content = Path.GetFileName(curr_wall); this.CurrentWallpaperInfo = SQLiteInfoExtracter.GetFileInformation(curr_wall); lblLocation.Content = this.CurrentWallpaperInfo.Location; txtbDescription.Text = this.CurrentWallpaperInfo.Description; this.CurrentWallpaperInfo.Save(); this.WindowIsOpen = true; this.Show(); }
private bool IsValidWallpaperInfo(WallpaperInfo wallpaperInfo) { var isValid = true; isValid &= wallpaperInfo.Id > 0; isValid &= !String.IsNullOrWhiteSpace(wallpaperInfo.Resolution); isValid &= wallpaperInfo.Thumbnail != null && !String.IsNullOrWhiteSpace(wallpaperInfo.Thumbnail.ToString()) && wallpaperInfo.Thumbnail.Scheme.StartsWith("http"); isValid &= wallpaperInfo.Source != null && !String.IsNullOrWhiteSpace(wallpaperInfo.Source.ToString()) && wallpaperInfo.Source.Scheme.StartsWith("http"); isValid &= !String.IsNullOrWhiteSpace(wallpaperInfo.FileName); if (wallpaperInfo.Source != null && wallpaperInfo.FileName != null) { isValid &= wallpaperInfo.Source.Segments.LastOrDefault() == wallpaperInfo.FileName; } return(isValid); }
private static WallpaperInfo Convert(ProjectInfo info) { if (info == null) { return(null); } var result = new WallpaperInfo() { Description = info.Description, File = info.File, Preview = info.Preview, Title = info.Title, Type = info.Type, Visibility = info.Visibility }; if (info.Tags != null) { info.Tags.ForEach(m => result.Tags += $"{m},"); } return(result); }
private static ProjectInfo Convert(WallpaperInfo info) { if (info == null) { return(null); } var result = new ProjectInfo() { Description = info.Description, File = info.File, Preview = info.Preview, Title = info.Title, Type = info.Type, Visibility = info.Visibility }; if (info.Tags != null) { result.Tags = info.Tags.Split(",").ToList(); } return(result); }
public override List <Model.WallpaperInfo> GetWallpaper() { List <Model.WallpaperInfo> wallpapers = new List <WallpaperInfo>(); string html = this.DownloadHeml(); Regex imageRegex = new Regex(@"<img[^>]*"); MatchCollection images = imageRegex.Matches(html); foreach (Match image in images) { try { string[] str = image.Value.Split(new Char[] { ' ', '=' }); WallpaperInfo wall = new WallpaperInfo(); wall.Title = str[4].Replace("\"", ""); wall.Url = str[2].Replace("\"", ""); wallpapers.Add(wall); } catch (Exception e) { } } return(wallpapers); }
private static async Task WriteInfo(WallpaperInfo wallpaperInfo, string destDir) { string destInfoPath = Path.Combine(destDir, "project.json"); await JsonHelper.JsonSerializeAsync(wallpaperInfo, destInfoPath); }
public static async Task <WallpaperModel> CreateLocalPack(string sourceFile, string previewPath, WallpaperInfo info, string destDir) { string oldInfoPath = Path.Combine(sourceFile, "project.json"); if (File.Exists(oldInfoPath)) { var existInfo = await JsonHelper.JsonDeserializeFromFileAsync <WallpaperInfo>(oldInfoPath); info.Description ??= existInfo.Description; info.File ??= existInfo.File; info.Preview ??= existInfo.Preview; info.Tags ??= existInfo.Tags; info.Title ??= existInfo.Title; info.Type ??= existInfo.Type; info.Visibility ??= existInfo.Visibility; await Task.Run(() => { IOHelper.CopyFolder(sourceFile, destDir); }); } else { await Task.Run(() => { IOHelper.CopyFileToDir(sourceFile, destDir); info.Preview = Path.GetFileName(previewPath); IOHelper.CopyFileToDir(previewPath, destDir); }); } await WriteInfo(info, destDir); return(new WallpaperModel() { Path = Path.Combine(destDir, info.File), Info = info }); }
public static async Task <WallpaperModel> EditLocalPack(string sourceFile, string previewPath, WallpaperInfo info, string destDir) { string oldInfoPath = Path.Combine(destDir, "project.json"); var oldInfo = await JsonHelper.JsonDeserializeFromFileAsync <WallpaperInfo>(oldInfoPath); string oldFile = null, oldPreview = null; if (oldInfo != null) { oldFile = Path.Combine(destDir, oldInfo.File); if (oldInfo.Preview != null) { oldPreview = Path.Combine(destDir, oldInfo.Preview ?? ""); } } if (NormalizePath(sourceFile) != NormalizePath(oldFile)) { await Task.Run(() => { File.Delete(oldFile); IOHelper.CopyFileToDir(sourceFile, destDir); }); } info.Preview = Path.GetFileName(previewPath); if (NormalizePath(oldPreview) != NormalizePath(previewPath)) { await Task.Run(() => { File.Delete(oldPreview); IOHelper.CopyFileToDir(previewPath, destDir); }); } await WriteInfo(info, destDir); return(new WallpaperModel() { Path = Path.Combine(destDir, info.File), Info = info }); }