Example #1
0
File: Wallpaper.cs Project: v0l/whp
        public static void Set(Uri uri)
        {
            if (!Directory.Exists("C:\\WHP\\imgs"))
            {
                Directory.CreateDirectory("C:\\WHP\\imgs");
            }
            string path = uri.ToString().Substring(uri.ToString().LastIndexOf("/") + 1);
            string text = Path.Combine("C:\\WHP\\imgs", path);

            if (!File.Exists(text))
            {
                try
                {
                    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri.ToString());
                    httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36";
                    using (Stream responseStream = httpWebRequest.GetResponse().GetResponseStream())
                    {
                        using (FileStream fileStream = new FileStream(text, FileMode.Create, FileAccess.ReadWrite))
                        {
                            responseStream.CopyTo(fileStream);
                            fileStream.Flush();
                        }
                    }
                }
                catch
                {
                    return;
                }
            }
            Wallpaper.SystemParametersInfo(20, 0, text, 3);
        }
Example #2
0
        private static void t_Tick()
        {
            Rectangle bounds = Screen.PrimaryScreen.Bounds;
            string    doc    = Program.GetDoc(string.Format("http://alpha.wallhaven.cc/search?categories=111&purity=010&sorting=views&resolutions={0}&order=desc&page={1}", string.Format("{0}x{1}", bounds.Width, bounds.Height), 1));

            HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
            if (!string.IsNullOrEmpty(doc))
            {
                htmlDocument.LoadHtml(doc);
                string s    = htmlDocument.DocumentNode.SelectSingleNode("//span[contains(@class,'thumb-listing-page-num')]").NextSibling.InnerText.Substring(3);
                string doc2 = Program.GetDoc(string.Format("http://alpha.wallhaven.cc/search?categories=111&purity=010&sorting=views&resolutions={0}&order=desc&page={1}", string.Format("{0}x{1}", bounds.Width, bounds.Height), new Random().Next(int.Parse(s))));
                if (!string.IsNullOrEmpty(doc2))
                {
                    HtmlAgilityPack.HtmlDocument htmlDocument2 = new HtmlAgilityPack.HtmlDocument();
                    htmlDocument2.LoadHtml(doc2);
                    HtmlNodeCollection htmlNodeCollection = htmlDocument2.DocumentNode.SelectNodes("//figure");
                    HtmlNode           htmlNode           = htmlNodeCollection[new Random().Next(htmlNodeCollection.Count)];
                    Wallpaper.Set(new Uri(string.Format("http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-{0}.jpg", htmlNode.Attributes["data-wallpaper-id"].Value)));
                }
            }
        }