[AddonManager] Improve handling of Wb Readme images

...with particular regard to Windows character limit.
This commit is contained in:
Syres916
2019-06-20 09:21:19 +01:00
committed by Yorik van Havre
parent f58c20afec
commit cdcc647458

View File

@@ -316,6 +316,8 @@ class ShowWorker(QtCore.QThread):
desc = ""
# get the README if possible
u = urlopen(url+"/blob/master/README.md")
if not u:
u = urlopen(url+"/blob/master/Readme.md")
if u:
p = u.read()
if sys.version_info.major >= 3 and isinstance(p, bytes):
@@ -383,12 +385,12 @@ class ShowWorker(QtCore.QThread):
self.info_label.emit( message )
self.progressbar_show.emit(False)
l = self.loadImages( message, self.repos[self.idx][1] )
l = self.loadImages( message, self.repos[self.idx][1], self.repos[self.idx][0])
if l:
self.info_label.emit( l )
self.stop = True
def loadImages(self,message,url):
def loadImages(self,message,url,wbName):
"checks if the given page contains images and downloads them"
@@ -412,6 +414,9 @@ class ShowWorker(QtCore.QThread):
name = path.split("/")[-1]
if name and path.startswith("http"):
storename = os.path.join(store,name)
if len(storename) >= 260:
remainChars = 259 - (len(store) + len(wbName) + 1)
storename = os.path.join(store,wbName+name[-remainChars:])
if not os.path.exists(storename):
try:
u = urlopen(path)
@@ -419,7 +424,6 @@ class ShowWorker(QtCore.QThread):
u.close()
except:
print("AddonManager: Debug: Error retrieving image from",path)
return None
else:
f = open(storename,"wb")
f.write(imagedata)