|
From: <Sil...@us...> - 2010-04-26 22:42:51
|
Revision: 3545
http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=3545&view=rev
Author: SilentException
Date: 2010-04-26 22:42:45 +0000 (Mon, 26 Apr 2010)
Log Message:
-----------
Unified logging a bit
Removed compiler warnings
Added image id 102 - not mandatory - for comic language
Improved comic images downloading / showing
Modified Paths:
--------------
trunk/plugins/MyDailyComics/HTML/MyHtmlParser.cs
trunk/plugins/MyDailyComics/MyDailyComics.cs
trunk/plugins/MyDailyComics/MyXmlReader.cs
trunk/plugins/MyDailyComics/gui/Setup.cs
trunk/plugins/MyDailyComics/util/ComicHelper.cs
trunk/plugins/MyDailyComics/util/Log.cs
Modified: trunk/plugins/MyDailyComics/HTML/MyHtmlParser.cs
===================================================================
--- trunk/plugins/MyDailyComics/HTML/MyHtmlParser.cs 2010-04-26 20:17:13 UTC (rev 3544)
+++ trunk/plugins/MyDailyComics/HTML/MyHtmlParser.cs 2010-04-26 22:42:45 UTC (rev 3545)
@@ -109,12 +109,12 @@
}
catch (WebException e)
{
- Log.Error("MyComics: Can't download:" + e);
+ Log.Error("can't download:" + e);
return null;
}
catch (IOException e)
{
- Log.Error("MyComics: Can't download:" + e);
+ Log.Error("can't download:" + e);
return null;
}
finally
Modified: trunk/plugins/MyDailyComics/MyDailyComics.cs
===================================================================
--- trunk/plugins/MyDailyComics/MyDailyComics.cs 2010-04-26 20:17:13 UTC (rev 3544)
+++ trunk/plugins/MyDailyComics/MyDailyComics.cs 2010-04-26 22:42:45 UTC (rev 3545)
@@ -49,8 +49,8 @@
protected GUIImage imgComic = null; // comic image
[SkinControlAttribute(101)]
protected GUIImage imgBanner = null; // banner image
- //[SkinControlAttribute(102)]
- //protected GUIImage imgLanguage = null; // language image
+ [SkinControlAttribute(102)]
+ protected GUIImage imgLanguage = null; // language image
#endregion
@@ -62,7 +62,6 @@
private int _selectedComicIndex = -1;
private int _selectedDateIndex = -1;
- private string _imageDirectory = null;
#endregion
@@ -156,7 +155,7 @@
#region GUIWindow Members
public override bool Init()
{
- Log.Debug("Plugin loaded, version " + util.Constants.getVersion());
+ Log.Debug("plugin loaded, version " + util.Constants.getVersion());
return Load(GUIGraphicsContext.Skin + @"\MyDailyComics.xml");
}
@@ -223,7 +222,7 @@
}
}
- public string Title
+ new public string Title
{
get { return _title; }
set { _title = value; }
@@ -248,7 +247,7 @@
{
SelectedComic = _comics[0];
}
- catch (Exception ex) { }
+ catch { }
SelectedDate = DateTime.Today;
}
@@ -310,15 +309,20 @@
lock (this)
{
imgComic.Visible = false;
- //btnChangeComic.Label = comic.Name;
string tmp_url = ComicHelper.Instance.getComicUrl(comic, dt);
Log.Debug("trying to show url: " + tmp_url);
+ if (!ComicHelper.Instance.TryDisplayComic(tmp_url))
+ {
+ tmp_url = string.Empty;
+ }
+
imgComic.SetFileName(tmp_url);
imgComic.KeepAspectRatio = true;
imgComic.Refresh();
imgComic.Visible = true;
ShowBanner(comic);
+ ShowLanguageIcon(comic);
}
}
finally
@@ -330,19 +334,33 @@
private void ShowBanner(ComicStrip comic)
{
imgBanner.Visible = false;
+
+ string localName = string.Empty;
if (comic.Banner.Length > 0)
{
- //imgBanner.SetFileName(comic.Banner);
- string localName = ComicHelper.Instance.DownloadBanner(comic.Banner);
- if (!string.IsNullOrEmpty(localName))
- {
- imgBanner.SetFileName(localName);
- imgBanner.KeepAspectRatio = true;
- imgBanner.Refresh();
- imgBanner.Visible = true;
- }
+ localName = ComicHelper.Instance.DownloadBanner(comic.Banner);
}
+ imgBanner.SetFileName(localName);
+ imgBanner.KeepAspectRatio = true;
+ imgBanner.Refresh();
+ imgBanner.Visible = true;
}
+
+ private void ShowLanguageIcon(ComicStrip comic)
+ {
+ if (imgLanguage == null) return;
+
+ imgLanguage.Visible = false;
+
+ string languageIcon = Config.GetFolder(Config.Dir.Thumbs) + @"\MyDailyComics\Flags\" + comic.Language + @".png";
+ if (!File.Exists(languageIcon))
+ languageIcon = string.Empty;
+ imgLanguage.SetFileName(languageIcon);
+ imgLanguage.KeepAspectRatio = true;
+ imgLanguage.Refresh();
+ imgLanguage.Visible = true;
+ }
+
#endregion
}
}
Modified: trunk/plugins/MyDailyComics/MyXmlReader.cs
===================================================================
--- trunk/plugins/MyDailyComics/MyXmlReader.cs 2010-04-26 20:17:13 UTC (rev 3544)
+++ trunk/plugins/MyDailyComics/MyXmlReader.cs 2010-04-26 22:42:45 UTC (rev 3545)
@@ -137,7 +137,8 @@
}
catch (Exception ex)
{
- Log.Error("Error during reading comic.xml file: " + pathToXml);
+ Log.Error("error reading MyDailyComics.xml file: " + pathToXml);
+ Log.Error(ex.Message);
}
}
Modified: trunk/plugins/MyDailyComics/gui/Setup.cs
===================================================================
--- trunk/plugins/MyDailyComics/gui/Setup.cs 2010-04-26 20:17:13 UTC (rev 3544)
+++ trunk/plugins/MyDailyComics/gui/Setup.cs 2010-04-26 22:42:45 UTC (rev 3545)
@@ -186,7 +186,7 @@
{
ret = txt.Text.Trim();
}
- catch (Exception ex) { }
+ catch { }
return ret;
}
@@ -232,7 +232,7 @@
lstComics.Items.Insert(idx, cs);
lstComics.SelectedItem = cs;
}
- catch (Exception ex) { }
+ catch { }
break;
}
}
@@ -250,7 +250,7 @@
picComic.Image = img;
picComic.Refresh();
}
- catch (Exception ex)
+ catch
{
/* ignore */
}
@@ -281,7 +281,8 @@
}
catch (Exception ex)
{
- Log.Error("Could not load xml file: " + filename + ". Reason: " + ex.Message);
+ Log.Error("could not load XML file: " + filename);
+ Log.Error(ex.Message);
}
}
Modified: trunk/plugins/MyDailyComics/util/ComicHelper.cs
===================================================================
--- trunk/plugins/MyDailyComics/util/ComicHelper.cs 2010-04-26 20:17:13 UTC (rev 3544)
+++ trunk/plugins/MyDailyComics/util/ComicHelper.cs 2010-04-26 22:42:45 UTC (rev 3545)
@@ -46,6 +46,25 @@
return tmp_url;
}
+ public bool TryDisplayComic(string tmp_url)
+ {
+ try
+ {
+ HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(tmp_url);
+ request.Timeout = 5000; // 5 seconds in milliseconds
+ request.ReadWriteTimeout = 20000; // allow up to 20 seconds to elapse
+ // execute the request
+ HttpWebResponse response = (HttpWebResponse)request.GetResponse();
+ response.GetResponseStream();
+ return true;
+ }
+ catch (Exception ex)
+ {
+ Log.Debug("try to display comic failed: " + ex.Message);
+ return false;
+ }
+ }
+
public Image DisplayComic(string tmp_url)
{
Image imgComic = null;
@@ -58,11 +77,11 @@
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
imgComic = Image.FromStream(response.GetResponseStream());
}
- catch (WebException ex)
+ catch (WebException)
{
imgComic = Properties.Resources.comic_404;
}
- catch (Exception ex)
+ catch (Exception)
{
imgComic = Properties.Resources.comic_empty;
}
@@ -159,7 +178,6 @@
string localFileName = splits[splits.Length - 1];
localFilePath = MediaPortalHelper.ImageDirectory + GetSaveFilename(localFileName);
- Log.Debug("MyComics: load banner " + localFilePath);
if (!File.Exists(localFilePath))
{
WebClient client = new WebClient();
@@ -174,10 +192,11 @@
}
catch
{
+ Log.Debug("load banner exception with " + url);
return string.Empty;
}
-
-
+
+ Log.Debug("load banner: " + localFilePath);
return localFilePath;
}
Modified: trunk/plugins/MyDailyComics/util/Log.cs
===================================================================
--- trunk/plugins/MyDailyComics/util/Log.cs 2010-04-26 20:17:13 UTC (rev 3544)
+++ trunk/plugins/MyDailyComics/util/Log.cs 2010-04-26 22:42:45 UTC (rev 3545)
@@ -20,5 +20,9 @@
{
MediaPortal.GUI.Library.Log.Error(PREFIX + msg);
}
+ public static void Warn(string msg)
+ {
+ MediaPortal.GUI.Library.Log.Warn(PREFIX + msg);
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|