In order to reduce the chances of duplicate filenames with those images greater than the Windows limit, my suggestion is to use the workbench name in conjunction with a bit of maths to arrive at a new 'storename'.
So my suggestion would be to change the section in addonmanager_workers.py at line 385 from:
Code: Select all
l = self.loadImages( message, self.repos[self.idx][1])
if l:
self.info_label.emit( l )
self.stop = True
def loadImages(self,message,url):
"checks if the given page contains images and downloads them"
# QTextBrowser cannot display online images. So we download them
# here, and replace the image link in the html code with the
# downloaded version
imagepaths = re.findall("<img.*?src=\"(.*?)\"",message)
if imagepaths:
storedimages = []
store = os.path.join(FreeCAD.getUserAppDataDir(),"AddonManager","Images")
if not os.path.exists(store):
os.makedirs(store)
for path in imagepaths:
origpath = path
if "?" in path:
# remove everything after the ?
path = path.split("?")[0]
if not path.startswith("http"):
path = getserver(url) + path
name = path.split("/")[-1]
if name and path.startswith("http"):
storename = os.path.join(store,name)
if not os.path.exists(storename):
to:
Code: Select all
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,wbName):
"checks if the given page contains images and downloads them"
# QTextBrowser cannot display online images. So we download them
# here, and replace the image link in the html code with the
# downloaded version
imagepaths = re.findall("<img.*?src=\"(.*?)\"",message)
if imagepaths:
storedimages = []
store = os.path.join(FreeCAD.getUserAppDataDir(),"AddonManager","Images")
if not os.path.exists(store):
os.makedirs(store)
for path in imagepaths:
origpath = path
if "?" in path:
# remove everything after the ?
path = path.split("?")[0]
if not path.startswith("http"):
path = getserver(url) + path
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):
I've done quite a bit of testing but if anyone else wants to give it a try (modified file attached) or if there's a much more slick solution to try then I can test.