forked from Voljega/ExoDOSConverter
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.py
More file actions
591 lines (478 loc) · 25.6 KB
/
util.py
File metadata and controls
591 lines (478 loc) · 25.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
import errno
import subprocess
import os.path
import platform
import collections
import shutil
from PIL import Image
import requests
import urllib.request
import urllib.parse
GUIString = collections.namedtuple('GUIString', 'id label help order')
confDir = r"conf"
confFilename = r"conf-{setKey}"
guiStringsFilename = r'gui-en-{setKey}.csv'
batocera = 'Batocera'
recalbox = 'Recalbox'
retropie = 'Retropie'
mister = 'MiSTer'
simplemenu = 'OpenDingux/SimpleMenu'
esoteric = 'OpenDingux/Esoteric'
retrobat = 'Retrobat'
emuelec = 'Emuelec'
conversionTypes = [batocera, recalbox, retropie, retrobat, emuelec, simplemenu, esoteric, mister]
EXODOS = 'eXoDOS v6'
EXOWIN3X = 'eXoWin3x v2'
C64DREAMS = 'C64 Dreams'
EXOAPPLEIIGS = 'eXoAppleIIGS'
EXOSCUMMVM = 'eXoScummVM'
exoVersions = [EXODOS, EXOWIN3X, EXOAPPLEIIGS, EXOSCUMMVM, C64DREAMS]
exoCollectionsDirs = {
EXODOS: {'rootDir': 'eXo', 'gamesDir': 'eXoDOS', 'gamesConfDir': '!dos', 'metadataId': 'MS-DOS', 'picId': 'MS-DOS'},
EXOWIN3X: {'rootDir': 'eXo', 'gamesDir': 'eXoWin3x', 'gamesConfDir': '!win3x', 'metadataId': 'Windows 3x', 'picId': 'Windows 3x'},
EXOAPPLEIIGS: {'rootDir': 'eXo', 'gamesDir': 'eXoAppleIIGS', 'gamesConfDir': '!appleiigs', 'metadataId': 'Apple IIGS', 'picId': 'Apple IIGS'},
EXOSCUMMVM: {'rootDir': 'eXo', 'gamesDir': 'eXoScummVM', 'gamesConfDir': '!ScummVM', 'metadataId': 'ScummVM', 'picId': 'ScummVM'},
C64DREAMS: {'rootDir': 'C64 Dreams', 'gamesDir': 'Games', 'gamesConfDir': None, 'metadataId': 'Games', 'picId': 'C64 Dreams'}
}
# TODO change
# need to check call to self.conversionConf['mapper'] et util.mappers everywhere in code
mappersMiSTeR = ['None']
mappersBatocera = ['None', 'mapper.map', 'padto.keys'] # retrobat too
mappersDefault = ['None', 'mapper.map'] # default choice except MiSTeR
mappersRecalbox = ['None', 'mapper.map', 'p2k']
theEyeUrl = 'https://the-eye.eu/public/Games/eXo/eXoDOS_v6r2/eXo/eXoDOS/'
misterCleanNameToGameDir = dict()
def getMapperValues(conversionType):
if conversionType == mister:
return mappersMiSTeR
elif conversionType == recalbox:
return mappersRecalbox
elif conversionType in [batocera, retrobat]:
return mappersBatocera
else:
return mappersDefault
def isWin3x(collectionVersion):
return collectionVersion == EXOWIN3X
def getCollectionRootDirToken(collection):
return exoCollectionsDirs[collection]['rootDir']
def getCollectionGamesDirToken(collection):
return exoCollectionsDirs[collection]['gamesDir']
def getCollectionMetadataDir(collectionDir):
metadataDir = os.path.join(collectionDir, 'xml', 'all')
if not os.path.exists(metadataDir):
metadataDir = os.path.join(collectionDir, 'Data', 'Platforms')
return metadataDir
def getCollectionGamesDir(collectionDir, collection):
return os.path.join(collectionDir, getCollectionRootDirToken(collection), getCollectionGamesDirToken(collection))
def getCollectionGamesConfDir(collectionDir, collection):
return os.path.join(getCollectionGamesDir(collectionDir, collection),
exoCollectionsDirs[collection]['gamesConfDir'] if collection != C64DREAMS else '')
def getCollectionUpdateDir(collectionDir, collection):
return os.path.join(collectionDir, getCollectionRootDirToken(collection), 'Update', exoCollectionsDirs[collection]['gamesConfDir'])
def getCollectionMetadataID(collection):
return exoCollectionsDirs[collection]['metadataId']
def getCollectionPicID(collection):
return exoCollectionsDirs[collection]['picId']
def getKeySetString(string, setKey):
return string.replace('{setKey}', setKey)
def getConfFilename(setKey):
return getKeySetString(confFilename, setKey) + '.conf'
def getConfBakFilename(setKey):
return getKeySetString(confFilename, setKey) + '.bak'
def getGuiStringsFilename(setKey):
return getKeySetString(guiStringsFilename, setKey)
def lines_that_contain(string, fp):
return [line for line in fp if string in line]
def callProcess(subProcessArgs,logger):
process = subprocess.Popen(subProcessArgs, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, universal_newlines=True)
logger.logProcess(process)
return process.wait()
def installAria2cWindows(exoCollectionDir, logger):
eXoUtilDir = os.path.join(exoCollectionDir, 'eXo', 'util')
subProcessArgs = [os.path.join(eXoUtilDir, "unzip.exe"), "-o", "-d",
eXoUtilDir, os.path.join(eXoUtilDir, "util.zip"), "aria.zip"]
exitCode = callProcess(subProcessArgs, logger)
# extract next file if succesful
if not exitCode:
subProcessArgs = [os.path.join(eXoUtilDir, "unzip.exe"), "-o",
"-d", eXoUtilDir, os.path.join(eXoUtilDir, "aria.zip"), "aria/*"]
exitCode = callProcess(subProcessArgs, logger)
def installAria2cLinux(exoCollectionDir, logger):
logger.log(" <Error> Installing aria2c for Linux not implemented yet",logger.ERROR)
def installAria2cMac(exoCollectionDir, logger):
logger.log(" <Error> Installing aria2c for Mac not implemented yet",logger.ERROR)
def installAria2c(exoCollectionDir, logger):
if platform.system() == 'Windows':
installAria2cWindows(exoCollectionDir, logger)
elif platform.system() == 'Linux':
installAria2cLinux(exoCollectionDir, logger)
elif platform.system() == 'Darwin':
installAria2cMac(exoCollectionDir, logger)
def downloadTorrent(gameZip, gameZipPath, exoCollectionDir, logger):
eXoDir = os.path.join(exoCollectionDir, 'eXo')
outputDir = os.path.join(eXoDir, "eXoDOS", "DOWNLOAD")
aria2cDir = os.path.join(exoCollectionDir, 'eXo', 'util', 'aria')
eXoTorrentIndex = os.path.join(aria2cDir, 'index.txt')
downloadFolderAlreadyExisted = False
downloadedSuccess = False
# try and install Aria2c(torrent downloader) based on platform.
if not os.path.exists(eXoTorrentIndex):
logger.log(" <WARNING> Missing index.txt from eXoDOS util.zip, attempting extraction.", logger.WARNING)
installAria2c(exoCollectionDir, logger)
# check again as we cannot assume the above succeeded, but if it did work we can then use the tool on a first run.
if os.path.exists(eXoTorrentIndex):
with open(eXoTorrentIndex, "r") as fp:
for line in lines_that_contain(gameZip, fp):
gameInfo = line.split(':')
# make our downloads DIR at the torrent will create files we Don't want due to chunk size
try:
os.mkdir(outputDir)
except OSError as e:
# continue if DOWNLOAD folder already exists.
if e.errno != errno.EEXIST:
raise
downloadFolderAlreadyExisted = True
logger.log(
f" <WARNING> {outputDir} already exists, will not remove when done.", logger.WARNING)
if platform.system() == 'Windows':
command = os.path.join(aria2cDir, 'aria2c.exe')
elif platform.system() == 'Linux':
command = os.path.join(aria2cDir, 'aria2c')
elif platform.system() == 'Darwin':
command = os.path.join(aria2cDir, 'aria2c')
subProcessArgs = [command, "--select-file=" + gameInfo[0], "--index-out="+gameInfo[0] + "=..\\" + gameZip, "--dir=" +
outputDir, "--file-allocation=none", "--allow-overwrite=true", "--seed-time=0", aria2cDir + "\\eXoDOS.torrent"]
logger.log(" Downloading... " + gameZip)
# run torrent downloader aria2c
# retry download a few times as the torrent sometimes ends up at 0 bytes
# didn't seem to help, but no reason to remove this code we will just retry 0 times
retryCount = 0
exitCode = -1
while (retryCount >= 0) and (not downloadedSuccess):
try:
if os.path.getsize(gameZipPath):
# TODO: Check against size in index.txt
downloadedSuccess = True
except OSError as e:
if e.errno != errno.ENOENT:
raise
exitCode = callProcess(subProcessArgs,logger)
retryCount -= 1
if exitCode == 0 and os.path.getsize(gameZipPath):
logger.log(" Download Succeeded!")
elif exitCode == 9:
logger.log(" <ERROR> Not enough disk Space!", logger.ERROR)
else:
logger.log(" Download Had Issues!", logger.ERROR)
# remove the outputDir if we created it... download would have been moved already
if not downloadFolderAlreadyExisted:
shutil.rmtree(outputDir)
return True
else:
logger.log(" <ERROR> Could not Install Torrent Tools!", logger.ERROR)
return downloadedSuccess
def downloadZip(gameZip, gameZipPath, logger):
response = requests.get(theEyeUrl + '/' + urllib.parse.quote(gameZip), stream=True,
headers={'User-agent': 'Mozilla/5.0'})
if response.status_code == 200:
totalSize = int(response.headers.get('content-length'))
rightSize = totalSize
typeSize = ['b', 'kb', 'mb', 'gb']
typeIndex = 0
printableSize = ''
while rightSize > 0 and typeIndex < len(typeSize):
printableSize = str(rightSize) + ' ' + typeSize[typeIndex]
rightSize = int(rightSize / 1024)
typeIndex = typeIndex + 1
logger.log(' Downloading %s of size %s' % (gameZip, printableSize))
with open(gameZipPath, 'wb') as f:
if totalSize is None:
f.write(response.content)
else:
downloaded = 0
totalSize = int(totalSize)
for data in response.iter_content(chunk_size=max(int(totalSize / 1000), 1024 * 1024)):
downloaded += len(data)
f.write(data)
done = int(50 * downloaded / totalSize)
logger.log('\r [{}{}]'.format(
'█' * done, '.' * (50 - done)), logger.INFO, True)
return True
else:
logger.log(
' <ERROR> error %s while downloading from web %s: %s' % (
response.status_code, gameZipPath, response.reason),
logger.ERROR)
return False
# Loads UI Strings
def loadUIStrings(scriptDir, guiStringsFile):
guiStrings = dict()
file = open(os.path.join(scriptDir, 'gui', guiStringsFile), 'r', encoding="utf-8")
order = 0
for line in file.readlines()[1:]:
confLine = line.split(";")
if len(confLine) == 3:
guiStrings[confLine[0]] = GUIString(confLine[0], confLine[1], confLine[2].rstrip('\n\r ').replace("#n","\n"), order)
order = order + 1
file.close()
return guiStrings
# Handle os escaping of path in local output dir
def localOSPath(path):
if platform.system() == 'Windows':
return path
else:
return path.replace('\\', '/')
# Resize image for opendingux
def resize(imgPath):
im = Image.open(imgPath)
height = 200
wpercent = (height / float(im.size[1]))
vsize = int((float(im.size[0]) * float(wpercent)))
im = im.resize((vsize, height), Image.ANTIALIAS)
im.save(imgPath, "PNG")
# Return full clean game name
def getCleanGameID(metadata, ext):
exceptions = ['ostealth']
if metadata.dosname in exceptions:
return metadata.metadataname.replace(':', ' -').replace('?', '').replace('!', '').replace('/', '-').replace('\\','-').replace('*', '_').replace('í', 'i') + ext
else:
cleanGameName = metadata.name.replace(':', ' -').replace('?', '').replace('!', '').replace('/', '-').replace('\\','-').replace('*', '_').replace('í', 'i')
return cleanGameName + ' (' + str(metadata.releaseyear) + ')' + ext
# Returns distrib roms directory prefix for mount command
def getRomsFolderPrefix(conversionType, conversionConf):
if conversionConf['useExpertMode']:
return conversionConf['mountPrefix']
elif conversionType == batocera:
return "/userdata/roms/dos"
elif conversionType == recalbox:
return "/recalbox/share/roms/dos"
elif conversionType == retropie:
return "/home/pi/RetroPie/roms/pc"
elif conversionType == retrobat:
return r"..\\..\\roms\\dos"
elif conversionType == emuelec:
return "/storage/roms/pcdata"
else:
return "."
# Checks validity of the collection path and its content
def isCollectionPath(collectionPath, collection):
# TODO needs to change xml criteria for v6 and C64Dreams
return os.path.isdir(collectionPath) and os.path.exists(getCollectionGamesDir(collectionPath, collection)) \
and os.path.exists(getCollectionGamesConfDir(collectionPath, collection)) \
and os.path.exists(getCollectionMetadataDir(collectionPath)) \
and os.path.exists(os.path.join(collectionPath, 'Images'))
def validCollectionPath(collectionPath):
if isCollectionPath(collectionPath, EXODOS):
return EXODOS
elif isCollectionPath(collectionPath, EXOWIN3X):
return EXOWIN3X
elif isCollectionPath(collectionPath, EXOAPPLEIIGS):
return EXOAPPLEIIGS
elif isCollectionPath(collectionPath, EXOSCUMMVM):
return EXOSCUMMVM
elif isCollectionPath(collectionPath, C64DREAMS):
return C64DREAMS
else:
return None
# Parse the collection static cache file to generate list of games
def fullnameToGameDir(collectionDir, scriptDir, collectionVersion, logger):
collectionCSVCachePath = os.path.join(scriptDir, 'data', collectionVersion.replace(' ', '') + '.csv')
if not os.path.exists(collectionCSVCachePath):
# Use when needing to rebuild collection (usually new releases)
buildCollectionCSV(scriptDir, getCollectionGamesConfDir(collectionDir, collectionVersion), collectionVersion, logger)
gameDict = dict()
collectFile = open(collectionCSVCachePath, 'r', encoding='utf-8')
for line in collectFile.readlines():
strings = line.split(';')
gameDict[strings[0]] = strings[1].rstrip('\n\r')
return gameDict
# Build games csv for a new/updated collection
def buildCollectionCSV(scriptDir, gamesConfDir, collectionVersion, logger):
collectionCSVFile = open(os.path.join(scriptDir, 'data', collectionVersion.replace(' ', '') + '.csv'), 'w', encoding='utf-8')
logger.log('Listing games in %s' % gamesConfDir, logger.WARNING)
games = [file for file in os.listdir(gamesConfDir) if os.path.isdir(os.path.join(gamesConfDir, file))]
for game in games: # games = list of folder in !dos dir
if os.path.isdir(os.path.join(gamesConfDir, game)):
if collectionVersion != C64DREAMS:
bats = [os.path.splitext(filename)[0] for filename in os.listdir(os.path.join(gamesConfDir, game)) if
os.path.splitext(filename)[-1].lower() == '.bat'
and not os.path.splitext(filename)[0].lower() == 'install'
and not os.path.splitext(filename)[0].lower() == 'exception']
if bats[0] == 'exception':
logger.log(' ' + bats[0] + '->' + game, logger.ERROR)
collectionCSVFile.write(bats[0] + ';' + game + '\n')
else:
if not game.startswith('!'):
collectionCSVFile.write(game + ';' + game + '\n')
collectionCSVFile.close()
# Finds pic for a game in the three pics caches
def findMedia(name, cache):
boxfrontCache, boxbackCache, box3DCache, fanartboxfrontCache, fanartboxbackCache, discCache, bannerCache, gametitleCache, gameplayCache = cache
boxfront = findPics(name, boxfrontCache)
if boxfront is None:
boxfront = findPics(name, fanartboxfrontCache)
elif boxfront is None:
boxfront = findPics(name, gametitleCache)
elif boxfront is None:
boxfront = findPics(name, gameplayCache)
boxback = findPics(name, boxbackCache)
if boxback is None:
boxback = findPics(name, fanartboxbackCache)
box3D = findPics(name, box3DCache)
disc = findPics(name, discCache)
banner = findPics(name, bannerCache)
gametitle = findPics(name, gametitleCache)
gameplay = findPics(name, gameplayCache)
return boxfront, boxback, box3D, disc, banner, gametitle, gameplay
# Finds pic for a game in the three pics caches
def findPics(name, cache):
# Some special chars name in metadata have a clean name for the picture
specialCharsGame = {'Pył': 'Pyl'}
gameName = name if name not in specialCharsGame.keys() else specialCharsGame[name]
pic = findPic(gameName, cache, '.jpg')
pic = pic if pic is not None else findPic(gameName, cache, '.png')
pic = pic if pic is not None else findPic(gameName, cache, '.gif')
return pic
def cleanPicName(picName):
return picName.replace(':', '_').replace("'", '_').replace('?','_').replace('é','e').replace('*','_').replace('/','_').lower()
# Finds pic with ext for a game in the pics cache
def findPic(gameName, cache, ext):
imgName = cleanPicName(gameName + '-01' + ext)
imgNameAlt = cleanPicName(gameName + '-02' + ext)
imgPath = None
if imgName in cache:
imgPath = cache.get(imgName)
elif imgNameAlt in cache:
imgPath = cache.get(imgNameAlt)
return imgPath
# Constructs a specific pic cache
def buildPicCache(imageFolder, picCache, logger):
logger.log("Building cache %s" % picCache)
picCacheFile = open(picCache, 'w', encoding="utf-8")
cache = dict()
if os.path.exists(imageFolder):
rootImages = [file for file in os.listdir(imageFolder) if not os.path.isdir(os.path.join(imageFolder, file))]
subFolders = [file for file in os.listdir(imageFolder) if os.path.isdir(os.path.join(imageFolder, file))]
for image in rootImages:
cache[image.lower()] = os.path.join(imageFolder, image)
picCacheFile.write(image.lower() + "=" + image + '\n')
for subFolder in subFolders:
subFolderImages = [file for file in os.listdir(os.path.join(imageFolder, subFolder)) if
not os.path.isdir(file)]
for image in subFolderImages:
cache[image.lower()] = os.path.join(imageFolder, subFolder, image)
picCacheFile.write(image.lower() + "=" + os.path.join(subFolder, image) + '\n')
picCacheFile.close()
return cache
# Loads a specific pic cache
def loadPicCache(picCache, imageFolder, logger):
logger.log("Loading cache %s" % picCache)
picCacheFile = open(picCache, 'r', encoding="utf-8")
cache = dict()
for line in picCacheFile.readlines():
tokens = line.split("=")
cache[tokens[0]] = os.path.join(imageFolder, localOSPath(tokens[1].rstrip('\n\r ')))
picCacheFile.close()
return cache
def buildCache(scriptDir, collectionDir, collection, logger):
cacheDir = os.path.join(scriptDir, 'cache')
if not os.path.exists(cacheDir):
os.mkdir(cacheDir)
boxfrontCacheFile = os.path.join(cacheDir, '.%s-boxfrontCache' % collection.replace(' ', ''))
boxfrontImgFolder = os.path.join(collectionDir, 'Images', getCollectionPicID(collection), 'Box - Front')
boxfrontCache = loadPicCache(boxfrontCacheFile, boxfrontImgFolder, logger) if os.path.exists(boxfrontCacheFile) \
else buildPicCache(boxfrontImgFolder, boxfrontCacheFile, logger)
logger.log("boxfrontCache: %i entities" % len(boxfrontCache.keys()))
boxbackCacheFile = os.path.join(cacheDir, '.%s-boxbackCache' % collection.replace(' ', ''))
boxbackImgFolder = os.path.join(collectionDir, 'Images', getCollectionPicID(collection), 'Box - Back')
boxbackCache = loadPicCache(boxbackCacheFile, boxbackImgFolder, logger) if os.path.exists(boxbackCacheFile) \
else buildPicCache(boxbackImgFolder, boxbackCacheFile, logger)
logger.log("boxbackCache: %i entities" % len(boxbackCache.keys()))
box3DCacheFile = os.path.join(cacheDir, '.%s-box3DCache' % collection.replace(' ', ''))
box3DImgFolder = os.path.join(collectionDir, 'Images', getCollectionPicID(collection), 'Box - 3D')
box3DCache = loadPicCache(box3DCacheFile, box3DImgFolder, logger) if os.path.exists(box3DCacheFile) \
else buildPicCache(box3DImgFolder, box3DCacheFile, logger)
logger.log("box3DCache: %i entities" % len(box3DCache.keys()))
fanartboxfrontCacheFile = os.path.join(cacheDir, '.%s-boxfrontCache' % collection.replace(' ', ''))
fanartboxfrontImgFolder = os.path.join(collectionDir, 'Images', getCollectionPicID(collection), 'Fanart - Box - Front')
fanartboxfrontCache = loadPicCache(fanartboxfrontCacheFile, fanartboxfrontImgFolder, logger) if os.path.exists(fanartboxfrontCacheFile) \
else buildPicCache(fanartboxfrontImgFolder, fanartboxfrontCacheFile, logger)
logger.log("fanartboxfrontCache: %i entities" % len(fanartboxfrontCache.keys()))
fanartboxbackCacheFile = os.path.join(cacheDir, '.%s-boxbackCache' % collection.replace(' ', ''))
fanartboxbackImgFolder = os.path.join(collectionDir, 'Images', getCollectionPicID(collection), 'Fanart - Box - Back')
fanartboxbackCache = loadPicCache(fanartboxbackCacheFile, fanartboxbackImgFolder, logger) if os.path.exists(fanartboxbackCacheFile) \
else buildPicCache(fanartboxbackImgFolder, fanartboxbackCacheFile, logger)
logger.log("fanartboxbackCache: %i entities" % len(fanartboxbackCache.keys()))
discCacheFile = os.path.join(cacheDir, '.%s-discCache' % collection.replace(' ', ''))
discImgFolder = os.path.join(collectionDir, 'Images', getCollectionPicID(collection), 'Disc')
discCache = loadPicCache(discCacheFile, discImgFolder, logger) if os.path.exists(discCacheFile) \
else buildPicCache(discImgFolder, discCacheFile, logger)
logger.log("discCache: %i entities" % len(discCache.keys()))
bannerCacheFile = os.path.join(cacheDir, '.%s-bannerCache' % collection.replace(' ', ''))
bannerImgFolder = os.path.join(collectionDir, 'Images', getCollectionPicID(collection), 'Banner')
bannerCache = loadPicCache(bannerCacheFile, bannerImgFolder, logger) if os.path.exists(bannerCacheFile) \
else buildPicCache(bannerImgFolder, bannerCacheFile, logger)
logger.log("bannerCache: %i entities" % len(bannerCache.keys()))
gametitleCacheFile = os.path.join(cacheDir, '.%s-gametitleCache' % collection.replace(' ', ''))
gametitleImgFolder = os.path.join(collectionDir, 'Images', getCollectionPicID(collection), 'Screenshot - Game Title')
gametitleCache = loadPicCache(gametitleCacheFile, gametitleImgFolder, logger) if os.path.exists(gametitleCacheFile) \
else buildPicCache(gametitleImgFolder, gametitleCacheFile, logger)
logger.log("gametitleCache: %i entities" % len(gametitleCache.keys()))
gameplayCacheFile = os.path.join(cacheDir, '.%s-gameplayCache' % collection.replace(' ', ''))
gameplayImgFolder = os.path.join(collectionDir, 'Images', getCollectionPicID(collection), 'Screenshot - Gameplay')
gameplayCache = loadPicCache(gameplayCacheFile, gameplayImgFolder, logger) if os.path.exists(gameplayCacheFile) \
else buildPicCache(gameplayImgFolder, gameplayCacheFile, logger)
logger.log("gameplayCache: %i entities" % len(gameplayCache.keys()))
return boxfrontCache, boxbackCache, box3DCache, fanartboxfrontCache, fanartboxbackCache, discCache, bannerCache, gametitleCache, gameplayCache
# TODO reactivate in dedicated functionnality, handle properly at start of detection
def checkMultipleofSameGame(useGenreSubFolders, metadata, genre, game, gameDir, outputDir, logger):
wantedPath = os.path.join(outputDir, genre, gameDir) if useGenreSubFolders else os.path.join(outputDir,gameDir)
paths = {
'shortPath': os.path.join(outputDir,game + ".pc"),
'longPath': os.path.join(outputDir,getCleanGameID(metadata,".pc")),
'shortPathGenre': os.path.join(outputDir,genre,game + ".pc"),
'longPathGenre': os.path.join(outputDir,genre,getCleanGameID(metadata,".pc"))
}
totalExistingPaths = 0
for name,path in paths.items():
if os.path.exists(path):
totalExistingPaths += 1
logger.log(" Existing Path: " + path, level=logger.WARNING)
if totalExistingPaths > 1:
logger.log(" \tDue to not Clearing output folder you have...\n\t\t\t\t MULTIPLE COPIES.\n\t\tIf changing conversion type this may lead to bigger issues.",
level=logger.WARNING)
# TODO seems unused ?
def moveFolderifExist(useGenreSubFolders, metadata, genre, game, gameDir, outputDir, logger):
wantedPath = os.path.join(outputDir, genre, gameDir) if useGenreSubFolders else os.path.join(outputDir,gameDir)
paths = {
'shortPath': os.path.join(outputDir,game + ".pc"),
'longPath': os.path.join(outputDir,getCleanGameID(metadata,".pc")),
'shortPathGenre': os.path.join(outputDir,genre,game + ".pc"),
'longPathGenre': os.path.join(outputDir,genre,getCleanGameID(metadata,".pc"))
}
totalExistingPaths = 0
existingPath = []
for name,path in paths.items():
if os.path.exists(path):
existingPath.append(path)
totalExistingPaths += 1
logger.log(" Existing Path: " + path)
if totalExistingPaths > 1:
logger.log(" There can only be one, aborting auto rename.")
logger.log(" If no Errors, gamelist.xml will be accurate.")
for path in existingPath:
if path == wantedPath:
return True
# more than 1 path already, don't know what they want so create requested folder(will result in duplicates/triplicates/quad)
return False
elif totalExistingPaths == 0:
# game folder is non existent in any path, so create it.
return False
# only one existing path found rename it to wanted path
if wantedPath != existingPath[0]:
logger.log(" Moving Existing -> " + wantedPath)
shutil.move(existingPath[0],wantedPath)
# moved it so now its exists
return True
return True