internal string GetPicUrl(bool forceError) { if (string.IsNullOrEmpty(CurrentPicture.Uri)) { string tempUrl = ""; HtmlDocument doc = new HtmlDocument(); doc.Load(podPagePath); HtmlNode node = doc.DocumentNode.SelectSingleNode("descendant::div[attribute::class='primary_photo']"); if (node != null) { HtmlNode imgNode = node.SelectSingleNode("descendant::img"); if (imgNode != null) { HtmlAttribute att = imgNode.Attributes["src"]; if (att != null) { tempUrl = att.Value; } } } if (string.IsNullOrEmpty(tempUrl)) { if (forceError) { PodUtil.Error("Not able to get picture url."); } CurrentPicture.Uri = ""; } else { CurrentPicture.Uri = "http:" + tempUrl; } } return(CurrentPicture.Uri); }
//internal string GenerateNewPodPicPath() //{ // //string s = Guid.NewGuid().ToString(); // //PodPicPath = podTempFolder + "\\" + s + ".jpg"; // //Properties.Settings.Default.LastPodPicPath = PodPicPath; // //Properties.Settings.Default.Save(); // //return PodPicPath; //} internal void GetPortalPage() { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(DefaultPortalUrl); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream responseStream = null; FileStream fileStream = null; try { responseStream = response.GetResponseStream(); long fileSize = response.ContentLength; fileStream = new FileStream(podPagePath, FileMode.OpenOrCreate, FileAccess.Write); int length = 1024; byte[] buffer = new byte[1025]; int bytesRead = 0; while ((bytesRead = responseStream.Read(buffer, 0, length)) > 0) { fileStream.Write(buffer, 0, bytesRead); } } catch (Exception e) { PodUtil.Error(e.Message); } finally { if (responseStream != null) { responseStream.Close(); } if (fileStream != null) { fileStream.Close(); } } previousPicture = CurrentPicture; acquireInfoFromLocalPage(); }
public static bool SetImage(string filePath) { try { RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); string wps = key.GetValue(WP_S).ToString(); if (wps != "0") { key.SetValue(WP_S, 0.ToString()); // 0 = original size } if (key.GetValue(WP_T).ToString() != 0.ToString()) { key.SetValue(WP_T, 0.ToString()); // 0 = no tile } } catch (Exception e) { PodUtil.Error(e.Message); return(false); } SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filePath, SPIF_UPDATEINIFILE); return(true); }