<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -59,7 +59,7 @@ def parse_page (data, chapter, chapter_num):
 def parse_image_url (data, page, page_num):
     soup = bs(data)
     image_url = soup.findAll(&quot;img&quot;, {&quot;id&quot;:&quot;mangaPage&quot;})[0][&quot;src&quot;].split(&quot;_&quot;)
-    image_count = int(image_url[-1].split(&quot;.&quot;)[0]) + page_num
+    image_count = int(image_url[-1].split(&quot;.&quot;)[0])# + page_num
     ext = image_url[-1].split(&quot;.&quot;)[1]
     image_url = &quot;%s_%s.%s&quot; % (image_url[0], str(image_count), ext)
 </diff>
      <filename>backends/MangaVolume.py</filename>
    </modified>
    <modified>
      <diff>@@ -86,10 +86,10 @@ class DownloadManager (threading.Thread):
         if not name:
             name = str(len(self.queue))
         self.queque[name] = (url, URL, CallBack)
-    def DirectDownload (self, url, URL, name=None):
+    def DirectDownload (self, url, URL, name=None, force_download=False):
         if not name:
             name = url
-        if name in self.completed:
+        if (name in self.completed) and (not force_download):
             return self.completed[name]
         if name in self.downloading:
             while name not in self.completed:</diff>
      <filename>gmangas/utils.py</filename>
    </modified>
    <modified>
      <diff>@@ -218,7 +218,7 @@ class Engine:
                 self._image = image = MyImage(_result, cdir(&quot;pixmaps&quot;, &quot;logo.png&quot;))
             except:
                 _result, old_result = self.LoadImage(id, value, use_cache=False)
-                self._image = image = MyImage(_result, cdir(&quot;pixmaps&quot;, &quot;logo.png&quot;))
+                self._image = image = MyImage(_result, cdir(&quot;pixmaps&quot;, &quot;logo.png&quot;), second_try=True)
             if old_result and (not image.big_image):
                 image.Merge(old_result)
             result = image, image.path
@@ -246,7 +246,7 @@ class Engine:
         if callback:
             callback(result)
         return result
-    def LoadImage (self, id, value, download_only=False, save=False, use_cache=True):
+    def LoadImage (self, id, value, download_only=False, save=False, use_cache=True, verbose=False):
         chapter_id = self.State[&quot;page&quot;][0]
         page = (self.Values[&quot;page&quot;][0][id], self.Values[&quot;page&quot;][1][id])
         values = map(lambda x: str(x[1]), (self.State[&quot;chapter&quot;],self.State[&quot;page&quot;],self.State[&quot;image&quot;]))
@@ -256,11 +256,13 @@ class Engine:
         if os.path.isfile(path) and use_cache:
             ext = &quot;&quot;
             result = [open(path, &quot;rb&quot;).read(), path, ext]
+            cached = True
         else:
             url = self.Values[&quot;chapter&quot;][1][chapter_id] + self.Values[&quot;page&quot;][1][id]
             pickle_path = (self.clear_url(url) + &quot;_IMGURL&quot;,)
             def Pickle_CallBack ():
                 data = self.__Download(url, info=&quot;image&quot;)
+                print url
                 if data == &quot;offline&quot;:
                     return data
                 return self.BackEnd.parse_image_url(data, page[1], int(id))
@@ -271,7 +273,8 @@ class Engine:
                     os.makedirs(os.path.dirname(path))
                 except OSError:
                     pass
-            data = DM.DirectDownload(image_url, self.URL)
+            data = DM.DirectDownload(image_url, self.URL, force_download=not use_cache)
+            cached = False
             ext = image_url.rsplit(&quot;.&quot;, 1)[-1]
             # -- #
             if data == &quot;offline&quot;:
@@ -293,8 +296,11 @@ class Engine:
                 old_result = cimg[id-1][0]
         cimg[id] = [result,self.State]
         
-        return [result, old_result]
-    
+        if verbose:
+            return [result, old_result, cached]
+        else:
+            return [result, old_result]
+        
     def __Download (self, url, ext=None, path=None, info=None):
         self.last_value_path = path = self.GetSavePath(self.clear_url(url))
         self.last_value_path_per_info[info] = path
@@ -324,6 +330,7 @@ class Engine:
 class BatchEngine (Engine):
     void = lambda *x:None
     auto_download = True
+    loaded_all = {}
     def __init__ (self, BackEnd):
         Engine.__init__(self, BackEnd)
     
@@ -333,14 +340,27 @@ class BatchEngine (Engine):
         self.continuous = continuous
         
     def DownloadChapter (self, chapter):
+        if chapter not in self.loaded_all:
+            self.loaded_all[chapter] = False
+        elif self.loaded_all[chapter]:
+            if hasattr(self.parent, &quot;gauge1&quot;):
+                wx.CallAfter(self.parent.gauge1.SetRange, 1)
+                wx.CallAfter(self.parent.gauge1.SetValue, 1)
+            return
         self.Load(&quot;page&quot;, chapter, self.void)
         if hasattr(self.parent, &quot;gauge1&quot;):
             wx.CallAfter(self.parent.gauge1.SetRange, (len(self.Values[&quot;page&quot;][0])))
         for img_id, img_value in enumerate(self.Values[&quot;page&quot;][0]):
+            self.loaded_all[chapter] = False
             if self.stopped or (not app.Running):
                 return
             self.State[&quot;image&quot;] = (img_id, img_value)
-            self.LoadImage(img_id, chapter[1], download_only=True, save=True)
+            result = self.LoadImage(img_id, chapter[1], download_only=True, save=True, verbose=True)
+            if result:
+                if result[2]:
+                    self.loaded_all[chapter] = True
+            else:
+                self.loaded_all[chapter] = False
             if not self.auto_download:
                 self.stopped = True
             if hasattr(self.parent, &quot;gauge1&quot;):</diff>
      <filename>gmangas2.py</filename>
    </modified>
    <modified>
      <diff>@@ -15,7 +15,10 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 
-from StringIO import StringIO
+try:
+    from cStringIO import StringIO
+except:
+    from StringIO import StringIO
 try:
     from PIL import Image, ImageEnhance, ImageDraw, ImageFont, ImageOps, ImageStat
     import PIL
@@ -25,6 +28,25 @@ import os
 
 import wx
 
+def ConvertWxImageToPil (image):
+    w, h = image.GetSize()
+    data = image.GetData()
+    
+    redImage = Image.new(&quot;L&quot;, (w, h))
+    redImage.fromstring(data[0::3])
+    greenImage = Image.new(&quot;L&quot;, (w, h))
+    greenImage.fromstring(data[1::3])
+    blueImage = Image.new(&quot;L&quot;, (w, h))
+    blueImage.fromstring(data[2::3])
+    
+    if image.HasAlpha():
+        alphaImage = Image.new(&quot;L&quot;, (w, h))
+        alphaImage.fromstring(image.GetAlphaData())
+        pil = Image.merge('RGBA', (redImage, greenImage, blueImage, alphaImage))
+    else:
+        pil = Image.merge('RGB', (redImage, greenImage, blueImage))
+    return pil
+
 class BackgroundImage:
     Image = None
     __Image = None
@@ -113,10 +135,24 @@ class MyImage_PIL:
     Image = None
     __Image = None
     rate = 100
-    def __init__ (self, res, logo):
+    error_logo = &quot;404.png&quot;
+    def __init__ (self, res, logo, second_try=False):
         self.logo = Image.open(logo)
         self.img, self.path, self.ext, self.text = res
-        self.raw1 = bmp = Image.open(StringIO(self.img))
+        img_data = StringIO(self.img)
+        img_data.seek(0)
+        try:
+            bmp = Image.open(img_data)
+        except:
+            try:
+                wximage = wx.ImageFromStream(img_data)
+                bmp = ConvertWxImageToPil(wximage)
+            except:
+                if second_try:
+                    bmp = Image.open(cdir(&quot;pixmaps&quot;, self.error_logo))
+                else:
+                    raise IOError, &quot;cannot identify image file&quot;
+        self.raw1 = bmp
         bitmap = Image.new(&quot;RGBA&quot;, bmp.size)
         bitmap.paste(bmp, None)
         self.Image = self.Image1 = self.__Annotate(bitmap, self.text)</diff>
      <filename>image.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>bc6a6a691714e8f60a4a9313c9277e681ffd1b1e</id>
    </parent>
  </parents>
  <author>
    <name>unknown</name>
    <email>lux@.(none)</email>
  </author>
  <url>http://github.com/luxkun/gmangas2/commit/9c0be1171b65502b3d7c27e1ef4f8907025c6d13</url>
  <id>9c0be1171b65502b3d7c27e1ef4f8907025c6d13</id>
  <committed-date>2009-07-05T04:28:11-07:00</committed-date>
  <authored-date>2009-07-05T04:28:11-07:00</authored-date>
  <message>Performance fix in DownloadChapter in the batchengine;mangavolume critical-bug fix;various</message>
  <tree>2c11eecfcdca9809cd605fc996b7076c44676d43</tree>
  <committer>
    <name>unknown</name>
    <email>lux@.(none)</email>
  </committer>
</commit>
