· 2 months ago · Jul 13, 2025, 01:06 PM
1import ast,datetime,fileinput,glob,itertools,random,operator,os,shutil,string,struct,sys,time,xbmc,xbmcgui,zipfile
2from xbe import *
3try:
4 Manual_Scan = sys.argv[1:][0]
5 Full_Scan = sys.argv[2:][0]
6except:
7 Manual_Scan = "0"
8 Full_Scan = "0"
9pDialog = xbmcgui.DialogProgress()
10dialog = xbmcgui.Dialog()
11
12
13## Sets paths.
14Root_Directory = xbmc.translatePath("Special://root/")
15if xbmc.getCondVisibility('Skin.String(Custom_Emulator_Path)'):
16 print("BBDebug1 : got custom emu path of " + xbmc.getInfoLabel('Skin.String(Custom_Emulator_Path)'))
17 Emulator_Folder_Path = xbmc.getInfoLabel('Skin.String(Custom_Emulator_Path)')
18else:
19 print("BBDebug1 : using defualt emu path of " + os.path.join(Root_Directory,'emustation\\emulators\\'))
20 Emulator_Folder_Path = os.path.join(Root_Directory,'emustation\\emulators\\')
21if xbmc.getCondVisibility('Skin.String(Custom_Roms_Path)'):
22 Roms_Folder_Path = xbmc.getInfoLabel('Skin.String(Custom_Roms_Path)')
23else:
24 Roms_Folder_Path = os.path.join(Root_Directory,'emustation\\roms\\')
25if xbmc.getCondVisibility('Skin.String(Custom_Media_Path)'):
26 Media_Folder_Path = xbmc.getInfoLabel('Skin.String(Custom_Media_Path)')
27else:
28 Media_Folder_Path = os.path.join(Root_Directory,'emustation\\media\\')
29
30Synopsis_Path = os.path.join(Root_Directory,'emustation\\synopsis\\')
31Scripts_Path = os.path.join(Root_Directory,'emustation\\scripts\\')
32File_Types_Path = os.path.join(Root_Directory,'emustation\\scripts\\rom_extensions\\')
33Custom_Scan_INI = os.path.join(Root_Directory,'emustation\\custom_scan_paths.ini')
34
35
36## Grab extensions for roms via files in a folder, makes it very easy for people to add new rom extensions.
37if len(os.listdir(File_Types_Path)) > 0:
38 Extensions = str([f for f in os.listdir(File_Types_Path) if os.path.isfile(os.path.join(File_Types_Path,f))]).replace(".ext","")
39 Extensions = ast.literal_eval(Extensions)
40else:
41 Extensions = [ "zip" ]
42
43
44## Modified by me. Original by chunk_1970 - http://forum.kodi.tv/showthread.php?tid=24666&pid=125356#pid125356
45def Extract_XbeInfo(FileName):
46 # Need to use this as the xbe.py Get_title misses letter and causes string issues, even when using .encode or .decode
47 XbeTitle = ''
48 if os.path.isfile(FileName) and FileName.endswith('.xbe'):
49 xbe = open(FileName,'rb')
50 # Get XbeId Data #
51 xbe.seek(0x104); tLoadAddr = xbe.read(4)
52 xbe.seek(0x118); tCertLoc = xbe.read(4)
53 LoadAddr = struct.unpack('L',tLoadAddr)
54 CertLoc = struct.unpack('L',tCertLoc)
55 CertBase = CertLoc[0] - LoadAddr[0]
56 CertBase += 8
57 IdStart = xbe.seek(CertBase)
58 tIdData = xbe.read(4)
59 IdData = struct.unpack('L',tIdData)
60 # Get Xbe Title #
61 for dta in struct.unpack(operator.repeat('H',40),xbe.read(0x0050)):
62 try :
63 if dta != 00: XbeTitle += str(unichr(dta))
64 except : pass
65 XbeDta = str(str(XbeTitle)+'|'+str(hex(IdData[0])[2:10]).lower().zfill(8))
66 xbe.close()
67 else:
68 XbeDta = str(XbeTitle+'|'+open(FileName).read()[:8].upper().lstrip().rstrip().zfill(8))
69 return XbeDta
70def Get_Title_Letter(Title_Letter):
71 Xbox_Thumb_Folder = {}
72 Title_Letter = Title_Letter.lower().lstrip(' ')
73 if Title_Letter.startswith("#") or Title_Letter.startswith("'") or Title_Letter.startswith("0") or Title_Letter.startswith("1") or Title_Letter.startswith("2") or Title_Letter.startswith("3") or Title_Letter.startswith("4") or Title_Letter.startswith("5") or Title_Letter.startswith("6") or Title_Letter.startswith("7") or Title_Letter.startswith("8") or Title_Letter.startswith("9"): Xbox_Thumb_Folder = "#"
74 if Title_Letter.startswith("a"): Xbox_Thumb_Folder = "A"
75 if Title_Letter.startswith("b"): Xbox_Thumb_Folder = "B"
76 if Title_Letter.startswith("c"): Xbox_Thumb_Folder = "C"
77 if Title_Letter.startswith("d"): Xbox_Thumb_Folder = "D"
78 if Title_Letter.startswith("e"): Xbox_Thumb_Folder = "E"
79 if Title_Letter.startswith("f"): Xbox_Thumb_Folder = "F"
80 if Title_Letter.startswith("g"): Xbox_Thumb_Folder = "G"
81 if Title_Letter.startswith("h"): Xbox_Thumb_Folder = "H"
82 if Title_Letter.startswith("i"): Xbox_Thumb_Folder = "I"
83 if Title_Letter.startswith("j"): Xbox_Thumb_Folder = "J"
84 if Title_Letter.startswith("k"): Xbox_Thumb_Folder = "K"
85 if Title_Letter.startswith("l"): Xbox_Thumb_Folder = "L"
86 if Title_Letter.startswith("m"): Xbox_Thumb_Folder = "M"
87 if Title_Letter.startswith("n"): Xbox_Thumb_Folder = "N"
88 if Title_Letter.startswith("o"): Xbox_Thumb_Folder = "O"
89 if Title_Letter.startswith("p"): Xbox_Thumb_Folder = "P"
90 if Title_Letter.startswith("q"): Xbox_Thumb_Folder = "Q"
91 if Title_Letter.startswith("r"): Xbox_Thumb_Folder = "R"
92 if Title_Letter.startswith("s"): Xbox_Thumb_Folder = "S"
93 if Title_Letter.startswith("t"): Xbox_Thumb_Folder = "T"
94 if Title_Letter.startswith("u"): Xbox_Thumb_Folder = "U"
95 if Title_Letter.startswith("v"): Xbox_Thumb_Folder = "V"
96 if Title_Letter.startswith("w"): Xbox_Thumb_Folder = "W"
97 if Title_Letter.startswith("x"): Xbox_Thumb_Folder = "X"
98 if Title_Letter.startswith("y"): Xbox_Thumb_Folder = "Y"
99 if Title_Letter.startswith("z"): Xbox_Thumb_Folder = "Z"
100 return Xbox_Thumb_Folder
101
102
103def Main_Code():
104## These are outside the loop so they don't reset every time.
105## Set the dialog create & found roms var.
106 CreateDialog = 1
107 intialrun = 0
108 global Found_Roms
109 Found_Roms = 0
110 Roms_Folder_Found = 0
111 Use_NoIntroNames = 0
112 _Resources = 0
113 _Resources_Videos = 0
114 Allow_Xbox_Overwrite = 0
115
116
117## Check if _emulators directory is selected instead of the emulator its self.
118 if os.path.isdir(Emulator_Folder_Path):
119 print("BBDebug2 : yeah ok it's a dir")
120
121
122## Parse all folder in the Emulators_Path
123 if not os.path.isdir(os.path.join(Emulator_Folder_Path,"xbox")): os.makedirs(os.path.join(Emulator_Folder_Path,"xbox"))
124 if not os.path.isdir(os.path.join(Emulator_Folder_Path,"ports")): os.makedirs(os.path.join(Emulator_Folder_Path,"ports"))
125 if not os.path.isdir(os.path.join(Emulator_Folder_Path,"homebrew")): os.makedirs(os.path.join(Emulator_Folder_Path,"homebrew"))
126 for Emu_Folder in sorted(os.listdir(Emulator_Folder_Path)):
127 print("BBDebug3 : doing emufolder " + Emu_Folder)
128## Set a load of variable.
129 CountList = 0; JumpList = 0; Jump_Counter = 8000
130 Starts_with_0 = 0; Starts_with_a = 0; Starts_with_b = 0; Starts_with_c = 0; Starts_with_d = 0; Starts_with_e = 0; Starts_with_f = 0; Starts_with_g = 0; Starts_with_h = 0; Starts_with_i = 0; Starts_with_j = 0; Starts_with_k = 0; Starts_with_l = 0; Starts_with_m = 0; Starts_with_n = 0; Starts_with_o = 0; Starts_with_p = 0; Starts_with_q = 0; Starts_with_r = 0; Starts_with_s = 0; Starts_with_t = 0; Starts_with_u = 0; Starts_with_v = 0; Starts_with_w = 0; Starts_with_x = 0; Starts_with_y = 0; Starts_with_z = 0;
131 Folderize_Images = 0; Parse_CUE_CCD_CHD_ISO_File = 0; Parse_CUE_ZIP_ISO_ADF_File = 0; Parse_ISO_BIN_IMG_File = 0; Parse_CUE_File = 0; Parse_SubFolder = 0; Parse_CCD_File = 0; Parse_ISO_File = 0; Parse_FBL_TXT = 0; Parse_FBL_MAME_TXT = 0; Parse_FBL_MAME_ROMS = 0; Parse_Xbox_Games = 0; Parse_N64_TXT = 0; N64ID = "0"; FBA_MAME_Rom_Name = ""; Change_FBL_Rom_Path = 0; Change_Mame_Rom_Path = 0; Change_N64_Rom_Path = 0; Change_NeoGeoCD_Rom_Path = 0; Name_File = 0; N64_Emu_Core = ''; N64_Video_Core = '';
132 RomListCount = 0; RenameCount = 0; ArtworkCount = 0; ExtractedZip = 0; Folderize_Counter = 0; Xbox_Game_Total = 0;
133 Write_List_File = 1
134 Previous_Letter = ""
135 WriteGamelistFile = []
136 WriteJumplistFile = []
137 WriteFavsMenuFile = []
138 RomSortFiles = []
139 Emu_XBE = "default.xbe"
140
141 Game_Directories = [ "E:\\Games\\","F:\\Games\\","G:\\Games\\" ]
142 Homebrew_Directories = [ "E:\\Homebrew\\","F:\\Homebrew\\","G:\\Homebrew\\" ]
143 Ports_Directories = [ "E:\\Ports\\","F:\\Ports\\","G:\\Ports\\" ]
144
145 # Will scan and use the paths found in custom_scan_paths.ini is present.
146 if os.path.isfile(Custom_Scan_INI):
147 Found_Games_Start = 0; Found_Homebrew_Start = 0; Found_Ports_Start = 0; linecount = 0;
148 with open(Custom_Scan_INI, 'r') as ini:
149 for line in itertools.islice(ini,0,None):
150 if line.lower().startswith('[games]'): Found_Games_Start = linecount+1
151 if line.lower().startswith('[homebrew]'): Found_Homebrew_Start = linecount+1
152 if line.lower().startswith('[ports]'): Found_Ports_Start = linecount+1
153 linecount = linecount+1
154 Game_Line_Total = Found_Homebrew_Start - Found_Games_Start
155 Homebrew_Line_Total = Found_Ports_Start - Found_Homebrew_Start
156 with open(Custom_Scan_INI, 'r') as Read_Settings:
157 Game_Directories = []
158 Config_Games = Read_Settings.readlines()[Found_Games_Start:Game_Line_Total]
159 for line in Config_Games:
160 Game_Directories.append(line.strip())
161 with open(Custom_Scan_INI, 'r') as Read_Settings:
162 Homebrew_Directories = []
163 Config_Homebrew = Read_Settings.readlines()[Found_Homebrew_Start:-Homebrew_Line_Total]
164 for line in Config_Homebrew:
165 Homebrew_Directories.append(line.strip())
166 with open(Custom_Scan_INI, 'r') as Read_Settings:
167 Ports_Directories = []
168 Config_Ports = Read_Settings.readlines()[Found_Ports_Start:]
169 for line in Config_Ports:
170 Ports_Directories.append(line.strip())
171
172 if ManualScan:
173 Select_Emu_Folder = dialog.select("SELECT A SYSTEM",sorted(os.listdir(Emulator_Folder_Path)))
174 if Select_Emu_Folder == -1: return
175
176
177## Set Emulators and Roms folder paths.
178 Emu_Path = os.path.join(Emulator_Folder_Path,sorted(os.listdir(Emulator_Folder_Path))[Select_Emu_Folder])
179 global Emu_Name
180 Emu_Name = os.path.split(Emu_Path)[1]
181 Roms_Folder = os.path.join(Roms_Folder_Path,sorted(os.listdir(Emulator_Folder_Path))[Select_Emu_Folder])
182
183
184## Convert Q:\\ to a direct path.
185 if Emu_Path.startswith("Q:\\"): Emu_Path = Emu_Path.replace("Q:\\",Root_Directory)
186
187
188## Check for a default .xbe in the emulator path you selected.
189 if os.path.isfile(os.path.join(Emu_Path,"default.xbe")) or Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
190 pass
191 else:
192 dialog.ok("ERROR","","No emulator found for this system")
193 return Main_Code()
194 else:
195
196
197## Set emu_path/name variable for autoscan mode.
198 Emu_Path = os.path.join(Emulator_Folder_Path,Emu_Folder)
199 Emu_Name = os.path.split(Emu_Path)[1]
200 Roms_Folder = os.path.join(Roms_Folder_Path,Emu_Name)
201 if intialrun == 0:
202 intialrun = 1
203
204
205## Check to see if vars are the value I need and create a new dialog.
206 if ManualScan:
207 pDialog.create("MANUAL SCAN MODE","Initializing")
208 else:
209 pDialog.create("AUTO SCAN MODE","Initializing")
210
211 print("BBDebug4 : emufolder " + Emu_Folder + ", emupath " + Emu_Path + ", emuname " + Emu_Name)
212
213## Ask the user if they want to use the internal names from the synopsis files and if they want to use _Resources folders for Xbox game artwork.
214 if xbmc.getCondVisibility('Skin.HasSetting(Use_Synopsis_Names)'): Use_NoIntroNames = 1
215 if Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew" or Full_Scan == "auto":
216 if xbmc.getCondVisibility('Skin.HasSetting(Use_Resources)'): _Resources = 1
217 if xbmc.getCondVisibility('Skin.HasSetting(_Resources_Videos)'): _Resources_Videos = 1
218 if xbmc.getCondVisibility('Skin.HasSetting(Use_Resources_Overwrite)'): Allow_Xbox_Overwrite = 1
219
220
221## Set tbn and gameslist path variable.
222 Media_Path = os.path.join(Media_Folder_Path,Emu_Name)
223 Games_List_Path = os.path.join(Root_Directory,'emustation\\gamelists',Emu_Name)
224
225
226## If genesis emulator is selected or found use megadrive synopsis files.
227 if Emu_Name == "genesis":
228 Synopsis_Zip = os.path.join(os.path.join(Synopsis_Path,'megadrive'))+'.zip'
229 elif Emu_Name == "famicom":
230 Synopsis_Zip = os.path.join(os.path.join(Synopsis_Path,'nes'))+'.zip'
231 elif Emu_Name == "tg16":
232 Synopsis_Zip = os.path.join(os.path.join(Synopsis_Path,'pcengine'))+'.zip'
233 elif Emu_Name == "tg-cd":
234 Synopsis_Zip = os.path.join(os.path.join(Synopsis_Path,'pce-cd'))+'.zip'
235 elif Emu_Name == "fba" or Emu_Name == "fbl" or Emu_Name == "fblc" or Emu_Name == "fbaxxx":
236 Synopsis_Zip = os.path.join(os.path.join(Synopsis_Path,'fbl'))+'.zip'
237 elif Emu_Name == "homebrew":
238 Synopsis_Zip = os.path.join(os.path.join(Synopsis_Path,'ports'))+'.zip'
239 else:
240 Synopsis_Zip = os.path.join(os.path.join(Synopsis_Path,Emu_Name))+'.zip'
241 if not Emu_Name == "xbox" and not Emu_Name == "ports" and not Emu_Name == "homebrew":
242 if not os.path.isdir(os.path.join(Media_Path,'boxart')): os.makedirs(os.path.join(Media_Path,'boxart'))
243 if not os.path.isdir(os.path.join(Media_Path,'boxart3d')): os.makedirs(os.path.join(Media_Path,'boxart3d'))
244 if not os.path.isdir(os.path.join(Media_Path,'logo')): os.makedirs(os.path.join(Media_Path,'logo'))
245 if not os.path.isdir(os.path.join(Media_Path,'mix')): os.makedirs(os.path.join(Media_Path,'mix'))
246 if not os.path.isdir(os.path.join(Media_Path,'videos')): os.makedirs(os.path.join(Media_Path,'videos'))
247 if not os.path.isdir(os.path.join(Media_Path,'screenshots')): os.makedirs(os.path.join(Media_Path,'screenshots'))
248
249
250## Check to see if the emulator is one of the below so I can change it rom type or path.
251 New_Roms_Folder = "Z:\\temp\\"+''.join(random.choice(string.ascii_lowercase) for i in range(30))
252 os.makedirs(New_Roms_Folder)
253 Parse_ROM_TXT = 1
254 if Emu_Name == "fba" or Emu_Name == "fbl" or Emu_Name == "fblc" or Emu_Name == "fbaxxx":
255 Change_FBL_Rom_Path = 1
256 Parse_FBL_MAME_TXT = 1
257 Parse_FBL_MAME_ROMS = 1
258 Parse_ROM_TXT = 0
259 elif Emu_Name == "mame":
260 Change_Mame_Rom_Path = 1
261 Parse_FBL_MAME_TXT = 1
262 Parse_FBL_MAME_ROMS = 1
263 Parse_ROM_TXT = 0
264 Emu_XBE = "autoload.xbe"
265 elif Emu_Name == "amiga":
266 Parse_CUE_ZIP_ISO_ADF_File = 1
267 Parse_ROM_TXT = 0
268 elif Emu_Name == "atarijaguar":
269 Roms_Folder = os.path.join(Emu_Path,'roms')
270 Parse_ROM_TXT = 0
271 elif Emu_Name == "n64":
272 print("BBDebug5 : n64 hit")
273 Parse_N64_TXT = 1
274 Change_N64_Rom_Path = 1
275 Parse_ROM_TXT = 0
276 elif Emu_Name == "neogeocd":
277 Change_NeoGeoCD_Rom_Path = 1
278 Parse_ROM_TXT = 0
279 elif Emu_Name == "pce-cd":
280 Parse_SubFolder = 1
281 Folderize_Images = 1
282 Parse_ROM_TXT = 0
283 elif Emu_Name == "tg-cd":
284 Parse_SubFolder = 1
285 Folderize_Images = 1
286 Parse_ROM_TXT = 0
287 elif Emu_Name == "saturn":
288 Parse_CUE_CCD_CHD_ISO_File = 1
289 Parse_ROM_TXT = 0
290 elif Emu_Name == "scummvm":
291 Real_Games_Folder = os.path.join(Emu_Path,'games')
292 Roms_Folder = os.path.join(Emu_Path,'svms')
293 Parse_SubFolder = 1
294 Parse_ROM_TXT = 0
295 elif Emu_Name == "segacd":
296 if xbmc.getCondVisibility('Skin.HasSetting(Use_SegaCD_ISO/MP3)'):
297 Parse_SubFolder = 1
298 Folderize_Images = 1
299 else:
300 Parse_CUE_CCD_CHD_ISO_File = 1
301 Parse_ROM_TXT = 0
302 elif Emu_Name == "psx":
303 Parse_CUE_CCD_CHD_ISO_File = 1
304 Parse_ROM_TXT = 0
305 elif Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
306 Xbox_Game_Total = 0
307 Parse_ROM_TXT = 0
308 Parse_Xbox_Games = 1
309 Xbox_Sort_Files = New_Roms_Folder
310 Roms_Folder = Xbox_Sort_Files
311 else:
312 pass
313 if Parse_SubFolder:
314 pDialog.update(0,'Checking [B]'+Emu_Name+'[/B] for folders','','This can take some time, please be patient.')
315 Rom_Type_Total = len(glob.glob(os.path.join(Roms_Folder,'*/')))
316 if Parse_CUE_File:
317 pDialog.update(0,'Calculating [B]'+Emu_Name+'[/B] file numbers','','This can take some time, please be patient.')
318 Rom_Type_Total = (len(glob.glob1(Roms_Folder,'*.cue')))
319 if Parse_CUE_CCD_CHD_ISO_File:
320 pDialog.update(0,'Calculating [B]'+Emu_Name+'[/B] file numbers','','This can take some time, please be patient.')
321 Rom_Type_Total = (len(glob.glob1(Roms_Folder,'*.cue'))+len(glob.glob1(Roms_Folder,'*.chd'))+len(glob.glob1(Roms_Folder,'*.ccd'))+len(glob.glob1(Roms_Folder,'*.iso')))
322 if Parse_CUE_ZIP_ISO_ADF_File:
323 pDialog.update(0,'Calculating [B]'+Emu_Name+'[/B] file numbers','','This can take some time, please be patient.')
324 Rom_Type_Total = (len(glob.glob1(Roms_Folder,'*.cue'))+len(glob.glob1(Roms_Folder,'*.zip'))++len(glob.glob1(Roms_Folder,'*.adf'))+len(glob.glob1(Roms_Folder,'*.iso')))
325
326## Convert Q:\\ to a direct path
327 if Roms_Folder.startswith("Q:\\"): Roms_Folder = Roms_Folder.replace("Q:\\",Root_Directory)
328
329
330## Check to see if the emulators = rom folder is empty and exit if it is.
331 if len(os.listdir(Roms_Folder_Path)) > 0: Roms_Folder_Found = 1
332 if Roms_Folder_Found == 1 and len(os.listdir(Roms_Folder)) > 0 or Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
333## Setting a var again :/
334 Found_Roms = 1
335## Check for emulator xbe and if not found show error, but proceed after prompt
336 if os.path.isfile(os.path.join(Emu_Path,"default.xbe")) or Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
337
338
339 ## Extracting the synopsis files from the zip.
340 if os.path.isfile(Synopsis_Zip):
341 if ExtractedZip == 0:
342 with zipfile.ZipFile(Synopsis_Zip) as zip:
343 #pDialog.create("EXTRACTING ZIP","","Please wait...")
344 Total_TXT_Files = len(zip.namelist()) or 1
345 Devide = 100.0 / Total_TXT_Files
346 Percent = 0
347 for item in zip.namelist():
348 pDialog.update(int(Percent),'Extracting [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Synopsis files','','This can take some time, please be patient.')
349 try:
350 zip.extract(item,Synopsis_Path)
351 Percent+= Devide
352 except:
353 print "Failed - "+item
354 ExtractedZip = 1
355 os.remove(os.path.join(Synopsis_Zip))
356
357 ## Patch scummvm xbe to load a different config and save as loader.xbe.
358 if Emu_Name == "scummvm":
359 if not os.path.isfile(os.path.join(Emu_Path,"loader.xbe")):
360 ScummvmXBECounter = 0
361 shutil.copy2(os.path.join(Emu_Path,"default.xbe"),os.path.join(Emu_Path,"loader.xbe"))
362 with open(os.path.join(Emu_Path,"loader.xbe"),"rb") as inputfile:
363 with open(os.path.join(Emu_Path,"loader.xbe" + ' patched'),"wb") as outputfile:
364 file_content = inputfile.read(1024*1024)
365 while file_content:
366 outputfile.write(file_content.replace('scummvm.ini','configs.ini'))
367 file_content = inputfile.read(1024*1024)
368 os.remove(os.path.join(Emu_Path,"loader.xbe"))
369 os.rename(os.path.join(Emu_Path,"loader.xbe"+' patched'),os.path.join(Emu_Path,"loader.xbe"))
370 pDialog.update((ScummvmXBECounter * 100) / 1,'Patching [B]'+Emu_Name+'[/B] XBE Files',os.path.basename("loader.xbe"),'This needs to be done')
371 ScummvmXBECounter = ScummvmXBECounter+1
372 ## Hacky way to move the rom back to the roms folder so when you scan in the roms you get them all.
373 ## This is like this so I can auto load a rom when you select it,unfortunately its a workaround for no command line launching.
374 if Emu_Name == "mame":
375 if not os.path.isfile(os.path.join(Emu_Path,"autoload.xbe")): dialog.ok("ERROR","[B]autoload.xbe[/B] is missing","Copy autoload.xbe to",Emu_Path); return
376 try:
377 for zip in os.listdir(os.path.join(Emu_Path,"autobootrom")):
378 if zip.endswith('.zip'): shutil.move(os.path.join(Emu_Path,"autobootrom\\"+zip),Roms_Folder)
379 except: pass
380 MameXBECounter = 0
381 XBE_Total = len(glob.glob(r''+Emu_Path+'/*.xbe'))
382 for XBE_File in glob.glob(r''+Emu_Path+'/*.xbe'):
383 with open(os.path.join(Emu_Path,XBE_File),"rb") as inputfile:
384 with open(os.path.join(Emu_Path,XBE_File + ' patched'),"wb") as outputfile:
385 file_content = inputfile.read(1024*1024)
386 while file_content:
387 Find_ExitLabel = file_content.find(b'\x4C\x00\x6F\x00\x61\x00\x64\x00\x69\x00\x6E\x00\x67\x00\x2E\x00\x20\x00\x50\x00\x6C\x00\x65\x00\x61\x00\x73\x00\x65\x00\x20\x00\x77\x00\x61\x00\x69\x00\x74\x00\x2E\x00\x2E\x00\x2E\x00')
388 if Find_ExitLabel:
389 file_content = file_content.replace(b'\x4C\x00\x6F\x00\x61\x00\x64\x00\x69\x00\x6E\x00\x67\x00\x2E\x00\x20\x00\x50\x00\x6C\x00\x65\x00\x61\x00\x73\x00\x65\x00\x20\x00\x77\x00\x61\x00\x69\x00\x74\x00\x2E\x00\x2E\x00\x2E\x00',b'\x52\x00\x65\x00\x74\x00\x75\x00\x72\x00\x6E\x00\x69\x00\x6E\x00\x67\x00\x20\x00\x74\x00\x6F\x00\x20\x00\x6D\x00\x65\x00\x6E\x00\x75\x00\x2E\x00\x2E\x00\x2E\x00\x00\x00\x00\x00\x00\x00')
390 Find_BarColour = file_content.find(b'\xC8\x78\x6E\xFF')
391 if Find_BarColour:
392 file_content = file_content.replace(b'\xC8\x78\x6E\xFF',b'\x00\x1E\xBE\xFF')
393 outputfile.write(file_content.replace('T:\\SYSTEM','D:\\system'))
394 file_content = inputfile.read(1024*1024)
395 os.remove(os.path.join(Emu_Path,XBE_File))
396 os.rename(os.path.join(Emu_Path,XBE_File+' patched'),os.path.join(Emu_Path,XBE_File))
397 pDialog.update((MameXBECounter * 100) / XBE_Total,'Patching [B]'+Emu_Name+'[/B] XBE Files',os.path.basename(XBE_File),'This needs to be done')
398 MameXBECounter = MameXBECounter+1
399 if os.path.isfile(os.path.join(Emu_Path,'skins/original/skin.ini')):
400 for line in fileinput.input(os.path.join(Emu_Path,'skins/original/skin.ini'),inplace=1):
401 if 'ProgressBar.BarColor =' in line:
402 line = line = 'ProgressBar.BarColor = 255 190 30 0\n'
403 print line,
404
405
406 ## Checking filenames case and not leading with capital renaming it to do so.
407 if not Emu_Name == "xbox" and not Emu_Name == "ports" and not Emu_Name == "homebrew" and not Emu_Name == "fba" and not Emu_Name == "fbl" and not Emu_Name == "fblc" and not Emu_Name == "fbaxxx" and not Emu_Name == "mame":
408 pDialog.update(0,'Checking [B]'+Emu_Name+'[/B] Rom filename & casing','','This can take some time, please be patient.')
409 for Roms in sorted(os.listdir(Roms_Folder)):
410 Items_Full_Path = os.path.join(Roms_Folder,Roms)
411 Items_Full_Path_Lower = os.path.join(Roms_Folder,Roms.lower())
412 if Items_Full_Path != os.path.join(Roms_Folder,Roms.lower()):
413 #if Items_Full_Path != os.path.join(Roms_Folder,Roms.capitalize()):
414 tempname = Items_Full_Path[:-1]+"_"
415 if not os.path.isfile(tempname):
416 os.rename(Items_Full_Path,tempname)
417 os.rename(tempname, os.path.join(Roms_Folder,Roms.lower()))
418 #os.rename(tempname, os.path.join(Roms_Folder,Roms.capitalize()))
419 pDialog.update((RenameCount * 100) / len(os.listdir(Roms_Folder)),'Lower-casing rom names','[B]'+Roms+'[/B]','This can take some time, please be patient.')
420 RenameCount = RenameCount+1
421 last_open_paren_index = Items_Full_Path_Lower.rfind('(')
422 if last_open_paren_index != -1:
423 # Check if ')' exists after the last '('
424 if ')' not in Items_Full_Path_Lower[last_open_paren_index:]:
425 base_name, extension = os.path.splitext(Items_Full_Path_Lower)
426 new_name = base_name[:last_open_paren_index].rstrip()
427 try:
428 os.rename(Items_Full_Path_Lower, new_name + extension)
429 except OSError:
430 new_name = base_name[:last_open_paren_index].rstrip() + "~"
431 os.rename(Items_Full_Path_Lower, new_name + extension)
432 base_name = os.path.join(Synopsis_Path,Emu_Name,os.path.basename(base_name)+'.txt')
433 new_name = os.path.join(Synopsis_Path,Emu_Name,os.path.basename(new_name)+'.txt')
434 if os.path.isfile(base_name):
435 os.rename(base_name, new_name)
436
437 ## Checking for .png artwork files and changing them to .jpg.
438 if not Emu_Name == "xbox" and not Emu_Name == "ports" and not Emu_Name == "homebrew":
439 pDialog.update(0,'Checking [B]'+Emu_Name+'[/B] artwork','','This can take some time, please be patient.')
440 ArtExt = ".png"
441 NewArtExt = ".jpg"
442 ArtworkTotal = len(glob.glob(os.path.join(Media_Path,'**/*'+ArtExt)))
443 for PNG_File in glob.glob(os.path.join(Media_Path,'**/*'+ArtExt)):
444 try:
445 os.rename(PNG_File,PNG_File[:-4]+NewArtExt)
446 except:
447 if os.path.isfile(PNG_File[:-4]+NewArtExt): os.remove(PNG_File[:-4]+NewArtExt); os.rename(PNG_File,PNG_File[:-4]+NewArtExt)
448 pDialog.update((ArtworkCount * 100) / ArtworkTotal,'Checking [B]'+Emu_Name+'[/B] artwork file extensions',''+str(ArtworkTotal - ArtworkCount)+' - images left','This can take some time, please be patient.')
449 ArtworkCount = ArtworkCount+1
450
451
452 ## Sort ISO/CUE files into folders along with the rest of its files
453 if Folderize_Images:
454 # Unfolderlize used by me for testing
455 # for folders in sorted([f for f in os.listdir(Roms_Folder) if os.path.isdir(os.path.join(Roms_Folder,f))]):
456 # for files in sorted([f for f in os.listdir(os.path.join(Roms_Folder,folders))]): shutil.move(os.path.join(Roms_Folder,folders,files),Roms_Folder)
457 # dialog.ok("","UnFolderized")
458 pDialog.update(0,'Checking [B]'+Emu_Name+'[/B] for files','','This can take some time, please be patient.')
459 if Emu_Name == "pce-cd" or Emu_Name == "tg-cd":
460 Glob_Type = ('*.cue')
461 Image_Type = ['.cue']
462 Folderize_File_Total = len(glob.glob(os.path.join(Roms_Folder,'*.cue')))
463 if Emu_Name == "segacd":
464 Glob_Type = ('*.iso','*.bin','*.img')
465 Image_Type = ['iso','bin','img']
466 Folderize_File_Total = len(glob.glob(os.path.join(Roms_Folder,'*.iso')))+len(glob.glob(os.path.join(Roms_Folder,'*.img')))+len(glob.glob(os.path.join(Roms_Folder,'*.bin')))
467 pDialog.update(0,'Folderizing [B]'+Emu_Name+'[/B]','','This can take some time, please be patient.')
468 for Glob_Type_Found in Glob_Type:
469 for ISOBINIMGMP3 in glob.glob1(Roms_Folder,Glob_Type_Found):
470 Folderize_Name = ''
471 if ISOBINIMGMP3.lower().endswith(tuple(Image_Type)):
472 Folderize_Name = ISOBINIMGMP3[:-4]
473 if not os.path.isdir(os.path.join(Roms_Folder,Folderize_Name)): os.makedirs(os.path.join(Roms_Folder,Folderize_Name))
474 for File_Name in glob.glob(os.path.join(Roms_Folder,Folderize_Name+'*')):
475 if os.path.isfile(File_Name):
476 if str(Folderize_Name) in File_Name and not str(Folderize_Name+'i') in File_Name and not str(Folderize_Name+'v') in File_Name and not str(Folderize_Name+'x') in File_Name:
477 shutil.move(os.path.join(Roms_Folder,File_Name),os.path.join(Roms_Folder,str(Folderize_Name)))
478 pDialog.update((Folderize_Counter * 100) / Folderize_File_Total,'Folderizing [B]'+Emu_Name+'[/B] Games[CR][B]'+Folderize_Name+'[/B]','','This can take some time, please be patient.')
479 Folderize_Counter = Folderize_Counter+1
480
481
482 ## Check if fbl was found and change its rom path to where the roms are located.
483 if Change_FBL_Rom_Path == 1:
484 if os.path.isfile(os.path.join(Emu_Path,'Path.ini')):
485 for line in fileinput.input(os.path.join(Emu_Path,'Path.ini'),inplace=1):
486 if 'ROMPath1=' in line:
487 line = line = 'ROMPath1='+Roms_Folder+'\n'
488 print line,
489 Change_FBL_Rom_Path = 0
490 else:
491 with open(os.path.join(Emu_Path,'Path.ini'),"w") as outputfblfile:
492 WriteFBLFile = fbl_config % (Roms_Folder)
493 outputfblfile.write(WriteFBLFile)
494 Change_FBL_Rom_Path = 0
495
496
497 ## Check if mame was found and change it rom path to where the roms are located.
498 if Change_Mame_Rom_Path == 1:
499 if not os.path.isdir(os.path.join(Emu_Path,"system")):
500 os.makedirs(os.path.join(Emu_Path,"system"))
501 if os.path.isfile(os.path.join(Emu_Path,"general\\DRIVERS.list")): shutil.copy2(os.path.join(Emu_Path,"general\\DRIVERS.list"),os.path.join(Emu_Path,"system"))
502 if os.path.isfile(os.path.join(Emu_Path,"system\\MAMEoX.ini")):
503 for line in fileinput.input(os.path.join(Emu_Path,"system\\MAMEoX.ini"),inplace=1):
504 if 'RomsPath0 = ' in line:
505 line = line = 'RomsPath0 = d:\\autobootrom\n'
506 if 'RomsPath3 = ' in line:
507 line = line = 'RomsPath3 = d:\\bios\n'
508 if 'CursorPosition = ' in line:
509 line = line = 'CursorPosition = 0.000000'
510 if 'PageOffset = ' in line:
511 line = line = 'PageOffset = 0.000000'
512 print line,
513 Change_Mame_Rom_Path = 0
514 else:
515 with open(os.path.join(Emu_Path,"system\\MAMEoX.ini"),"w") as outputmamefile:
516 WriteMameFile = mame_config % ("d:\\autobootrom")
517 outputmamefile.write(WriteMameFile)
518 Change_Mame_Rom_Path = 0
519
520
521 ## Creating Xbox game list so its in alphabetical order.
522 if Parse_Xbox_Games == 1:
523 if not os.path.isdir(Roms_Folder): os.makedirs(Roms_Folder)
524 XBEIDCheck = []
525 xbe_count = 1
526 dup_count = 1
527 if Emu_Name == "homebrew":
528 Game_Directories = Homebrew_Directories
529 Resource_Type = "homebrew"
530 elif Emu_Name == "ports":
531 Game_Directories = Ports_Directories
532 Resource_Type = "ports"
533 else:
534 Resource_Type = "xbox"
535 for Game_Dirs in Game_Directories:
536 if os.path.isdir(Game_Dirs):
537 for Item in sorted([f for f in os.listdir(Game_Dirs)]):
538 pDialog.update(0,'Sorting [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Games/Artwork','[UPPERCASE]'+Item+'[/UPPERCASE]','This can take some time, please be patient.')
539 if os.path.isdir(os.path.join(Game_Dirs,Item)):
540 Game_Directory = os.path.join(Game_Dirs,Item)
541 # print "Game being added = " + Game_Directory
542 if os.path.isfile(os.path.join(Game_Directory,"default_ffp.xbe")):
543 XBEFile = os.path.join(Game_Directory,"default_ffp.xbe")
544 else:
545 XBEFile = os.path.join(Game_Directory,"default.xbe")
546 if os.path.isfile(XBEFile):
547 _Resources_PosterFile = os.path.join(Game_Directory,"_resources\\artwork\\poster.jpg")
548 _Resources_Poster3dFile = os.path.join(Game_Directory,"_resources\\artwork\\dual3d.png")
549 _Resources_CDFile = os.path.join(Game_Directory,"_resources\\artwork\\cd.png")
550 _Resources_CDPosterFile = os.path.join(Game_Directory,"_resources\\artwork\\cdposter.png")
551 _Resources_IconFile = os.path.join(Game_Directory,"_resources\\artwork\\icon.png")
552 _Resources_ThumbFile = os.path.join(Game_Directory,"_resources\\artwork\\thumb.jpg")
553 _Resources_FanartFile = os.path.join(Game_Directory,"_resources\\artwork\\fanart.jpg")
554 _Resources_BannerFile = os.path.join(Game_Directory,"_resources\\artwork\\banner.png")
555 _Resources_OpenCaseFile = os.path.join(Game_Directory,"_resources\\artwork\\opencase.png")
556 _Resources_Screenshot = os.path.join(Game_Directory,"_resources\\screenshots\\screenshot-1.jpg")
557 _Resources_Synopsis = os.path.join(Game_Directory,"_resources\\default.xml")
558 if os.path.isfile(_Resources_PosterFile):
559 TBNFile = _Resources_PosterFile
560 else:
561 TBNFile = os.path.join(Game_Directory,"default.tbn")
562 if os.path.isfile(_Resources_FanartFile):
563 FanartFile = _Resources_FanartFile
564 else:
565 FanartFile = os.path.join(Game_Directory,"fanart.jpg")
566 Emu_XBE = XBEFile
567 # this is set to the default.xbe because some of the main game xbe files don't have names. Some games use default.xbe as the loader to game.xbe
568 XBEInfo = Extract_XbeInfo(XBEFile).split('|')
569 XBETitle = XBEInfo[0].lstrip(' ').lower()
570 # use the folder name if the xbe title is corrupt or not there.
571 if XBETitle == "": XBETitle = Item.lstrip(' ').lower()
572 if os.path.isfile(os.path.join(Game_Directory,"game.xbe")) and Resource_Type == "xbox":
573 XBEInfo = Extract_XbeInfo(os.path.join(Game_Directory,"game.xbe")).split('|')
574 if os.path.isfile(os.path.join(Game_Directory,"Override_TitleID.bin")):
575 with open(os.path.join(Game_Directory,"Override_TitleID.bin"),"r") as overridefile:
576 XBEID = overridefile.read()
577 else:
578 XBEID = XBEInfo[1]
579 # Grab synopsis names from the synopsis files for sorting of the list
580 if Use_NoIntroNames == 1:
581 if Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
582 if Emu_Name == "homebrew": Resource_Type = "ports"
583 Xbox_Synopsis_Name = os.path.join(Synopsis_Path,Resource_Type,XBEID+'.txt')
584 if os.path.isfile(Xbox_Synopsis_Name):
585 with open(Xbox_Synopsis_Name) as input:
586 for line in input:
587 if line.lower().startswith('name:'):
588 XBETitle = line.lower().strip().split(': ',1)[1]
589 break
590 if Emu_Name == "homebrew": Resource_Type = "homebrew"
591
592 if str(XBEID) in XBEIDCheck:
593 XBEID = str(XBEID)+"_"+str(dup_count)
594 XBEIDCheck.append(XBEID)
595 dup_count = dup_count+1
596
597 if xbmc.getCondVisibility('Skin.HasSetting(Remove_Articles_In_Name)'):
598 XBETitle = XBETitle.split(' (',1)[0]
599 if XBETitle.startswith('the') and xbmc.getCondVisibility('Skin.HasSetting(Ignore_The_In_Names)'):
600 XBETitle = XBETitle[4:]+', the'
601 XBETitle_List = xbmc.makeLegalFilename(Xbox_Sort_Files+'\\'+XBETitle.lower().replace('/','').replace('\\','').replace(' ',''))
602 # Get first letter of the games titleid and set a variable
603 Xbox_Thumb_Folder = Get_Title_Letter(XBETitle)
604 # Create folder structure for xbox games to speed up loading of images
605 if not os.path.isdir(os.path.join(Media_Path,'boxart',Xbox_Thumb_Folder)): os.makedirs(os.path.join(Media_Path,'boxart',Xbox_Thumb_Folder))
606 if not os.path.isdir(os.path.join(Media_Path,'boxart3d',Xbox_Thumb_Folder)): os.makedirs(os.path.join(Media_Path,'boxart3d',Xbox_Thumb_Folder))
607 if not os.path.isdir(os.path.join(Media_Path,'disc',Xbox_Thumb_Folder)): os.makedirs(os.path.join(Media_Path,'disc',Xbox_Thumb_Folder))
608 if not os.path.isdir(os.path.join(Media_Path,'cdposter',Xbox_Thumb_Folder)): os.makedirs(os.path.join(Media_Path,'cdposter',Xbox_Thumb_Folder))
609 if not os.path.isdir(os.path.join(Media_Path,'dual',Xbox_Thumb_Folder)): os.makedirs(os.path.join(Media_Path,'dual',Xbox_Thumb_Folder))
610 if not os.path.isdir(os.path.join(Media_Path,'fanart',Xbox_Thumb_Folder)): os.makedirs(os.path.join(Media_Path,'fanart',Xbox_Thumb_Folder))
611 if not os.path.isdir(os.path.join(Media_Path,'opencase',Xbox_Thumb_Folder)): os.makedirs(os.path.join(Media_Path,'opencase',Xbox_Thumb_Folder))
612 if not os.path.isdir(os.path.join(Media_Path,'screenshots',Xbox_Thumb_Folder)): os.makedirs(os.path.join(Media_Path,'screenshots',Xbox_Thumb_Folder))
613 if not os.path.isdir(os.path.join(Media_Path,'videos',Xbox_Thumb_Folder)): os.makedirs(os.path.join(Media_Path,'videos',Xbox_Thumb_Folder))
614
615 if _Resources == 0:
616 if os.path.isfile(TBNFile):
617 # Default.tbn
618 if os.path.isfile(os.path.join(Media_Folder_Path+Resource_Type+"\\boxart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")):
619 if Allow_Xbox_Overwrite == 1:
620 shutil.copy2(TBNFile,os.path.join(Media_Folder_Path+Resource_Type+"\\boxart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg"))
621 else:
622 shutil.copy2(TBNFile,os.path.join(Media_Folder_Path+Resource_Type+"\\boxart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg"))
623 else:
624 # TITLEIMAGE
625 try:
626 XBE(XBEFile).Get_title_image().Write_PNG(os.path.join(Media_Folder_Path+Resource_Type+"\\boxart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" ))
627 except: pass
628 if os.path.isfile(os.path.join(Media_Folder_Path+Resource_Type+"\\fanart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")):
629 if os.path.isfile(FanartFile):
630 if Allow_Xbox_Overwrite == 1:
631 shutil.copy2(FanartFile,Media_Folder_Path+Resource_Type+"\\fanart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )
632 else:
633 if os.path.isfile(FanartFile):
634 shutil.copy2(FanartFile,Media_Folder_Path+Resource_Type+"\\fanart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )
635 else:
636 # _Resources folder structure
637 # Poster
638 if os.path.isfile(os.path.join(Media_Folder_Path+Resource_Type+"\\boxart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")):
639 #print XBEID+" baxart already present"
640 if os.path.isfile(_Resources_PosterFile):
641 if Allow_Xbox_Overwrite == 1:
642 if os.path.isfile(_Resources_PosterFile):
643 shutil.copy2(_Resources_PosterFile,Media_Folder_Path+Resource_Type+"\\boxart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")
644 else:
645 if os.path.isfile(_Resources_PosterFile):
646 shutil.copy2(_Resources_PosterFile,Media_Folder_Path+Resource_Type+"\\boxart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")
647 # Default.tbn
648 elif os.path.isfile(TBNFile):
649 shutil.copy2(TBNFile,Media_Folder_Path+Resource_Type+"\\boxart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )
650 else:
651 # TITLEIMAGE
652 try:
653 XBE(XBEFile).Get_title_image().Write_PNG(os.path.join(Media_Folder_Path+Resource_Type+"\\boxart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" ))
654 except: pass
655 # 3D Boxart
656 if os.path.isfile(os.path.join(Media_Folder_Path+Resource_Type+"\\boxart3d\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )):
657 #print XBEID+" 3d boxart already present"
658 if os.path.isfile(_Resources_IconFile):
659 if Allow_Xbox_Overwrite == 1:
660 if os.path.isfile(_Resources_IconFile):
661 shutil.copy2(_Resources_IconFile,Media_Folder_Path+Resource_Type+"\\boxart3d\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")
662 else:
663 if os.path.isfile(_Resources_IconFile):
664 shutil.copy2(_Resources_IconFile,Media_Folder_Path+Resource_Type+"\\boxart3d\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")
665 # CD
666 if os.path.isfile(os.path.join(Media_Folder_Path+Resource_Type+"\\disc\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )):
667 #print XBEID+" cd already present"
668 if os.path.isfile(_Resources_CDFile):
669 if Allow_Xbox_Overwrite == 1:
670 if os.path.isfile(_Resources_CDFile):
671 shutil.copy2(_Resources_CDFile,Media_Folder_Path+Resource_Type+"\\disc\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )
672 else:
673 if os.path.isfile(_Resources_CDFile):
674 shutil.copy2(_Resources_CDFile,Media_Folder_Path+Resource_Type+"\\disc\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )
675 # Disc case
676 if os.path.isfile(os.path.join(Media_Folder_Path+Resource_Type+"\\cdposter\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )):
677 #print XBEID+" disc case already present"
678 if os.path.isfile(_Resources_CDPosterFile):
679 if Allow_Xbox_Overwrite == 1:
680 if os.path.isfile(_Resources_CDPosterFile):
681 shutil.copy2(_Resources_CDPosterFile,Media_Folder_Path+Resource_Type+"\\cdposter\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")
682 else:
683 if os.path.isfile(_Resources_CDPosterFile):
684 shutil.copy2(_Resources_CDPosterFile,Media_Folder_Path+Resource_Type+"\\cdposter\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")
685 # Dual 3D
686 if os.path.isfile(os.path.join(Media_Folder_Path+Resource_Type+"\\dual\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )):
687 #print XBEID+" dual 3d already present"
688 if os.path.isfile(_Resources_Poster3dFile):
689 if Allow_Xbox_Overwrite == 1:
690 if os.path.isfile(_Resources_Poster3dFile):
691 shutil.copy2(_Resources_Poster3dFile,Media_Folder_Path+Resource_Type+"\\dual\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")
692 else:
693 if os.path.isfile(_Resources_Poster3dFile):
694 shutil.copy2(_Resources_Poster3dFile,Media_Folder_Path+Resource_Type+"\\dual\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")
695 # Open Case
696 if os.path.isfile(os.path.join(Media_Folder_Path+Resource_Type+"\\opencase\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )):
697 #print XBEID+" mix already present"
698 if os.path.isfile(_Resources_OpenCaseFile):
699 if Allow_Xbox_Overwrite == 1:
700 if os.path.isfile(_Resources_OpenCaseFile):
701 shutil.copy2(_Resources_OpenCaseFile,Media_Folder_Path+Resource_Type+"\\opencase\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")
702 else:
703 if os.path.isfile(_Resources_OpenCaseFile):
704 shutil.copy2(_Resources_OpenCaseFile,Media_Folder_Path+Resource_Type+"\\opencase\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")
705 # Fanart
706 if os.path.isfile(os.path.join(Media_Folder_Path+Resource_Type+"\\fanart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")):
707 #print XBEID+" fanart already present"
708 if os.path.isfile(_Resources_FanartFile):
709 if Allow_Xbox_Overwrite == 1:
710 if os.path.isfile(_Resources_FanartFile):
711 shutil.copy2(_Resources_FanartFile,Media_Folder_Path+Resource_Type+"\\fanart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")
712 elif os.path.isfile(FanartFile):
713 shutil.copy2(FanartFile,Media_Folder_Path+Resource_Type+"\\fanart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )
714 else:
715 if os.path.isfile(_Resources_FanartFile):
716 shutil.copy2(_Resources_FanartFile,Media_Folder_Path+Resource_Type+"\\fanart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg")
717 elif os.path.isfile(FanartFile):
718 shutil.copy2(FanartFile,Media_Folder_Path+Resource_Type+"\\fanart\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )
719 # Screenshots
720 if os.path.isfile(os.path.join(Media_Folder_Path+Resource_Type+"\\screenshots\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )):
721 #print XBEID+" screenshots already present"
722 if os.path.isfile(_Resources_Screenshot):
723 if Allow_Xbox_Overwrite == 1:
724 if os.path.isfile(_Resources_Screenshot):
725 shutil.copy2(_Resources_Screenshot,Media_Folder_Path+Resource_Type+"\\screenshots\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )
726 else:
727 if os.path.isfile(_Resources_Screenshot):
728 shutil.copy2(_Resources_Screenshot,Media_Folder_Path+Resource_Type+"\\screenshots\\"+Xbox_Thumb_Folder+'\\'+XBEID+".jpg" )
729 # Videos
730 if _Resources_Videos:
731 found_video_xbox = 0
732 if os.path.isdir(os.path.join(Game_Directory,"_resources\\media\\")):
733 for Files in sorted(os.listdir(os.path.join(Game_Directory,"_resources\\media\\"))):
734 if os.path.isfile(os.path.join(Game_Directory,"_resources\\media\\",Files)):
735 if found_video_xbox == 0 and Files.endswith('.mp4'):
736 Video_File = os.path.join(Game_Directory,"_resources\\media\\",Files)
737 found_video_xbox = 1
738 if found_video_xbox == 0 and Files.endswith('.xmv'):
739 Video_File = os.path.join(Game_Directory,"_resources\\media\\",Files)
740 found_video_xbox = 1
741 else: found_video_xbox = 0
742 if found_video_xbox == 1:
743 if os.path.isfile(os.path.join(Media_Folder_Path+Resource_Type+"\\videos\\"+Xbox_Thumb_Folder+'\\'+XBEID+os.path.splitext(Video_File)[1])):
744 #print XBEID+" videos already present"
745 if Allow_Xbox_Overwrite == 1:
746 shutil.copy2(Video_File,Media_Folder_Path+Resource_Type+"\\videos\\"+Xbox_Thumb_Folder+'\\'+XBEID+os.path.splitext(Video_File)[1])
747 else:
748 shutil.copy2(Video_File,Media_Folder_Path+Resource_Type+"\\videos\\"+Xbox_Thumb_Folder+'\\'+XBEID+os.path.splitext(Video_File)[1])
749
750 RomSortFiles.append(XBETitle_List[:72]+"_"+str(xbe_count)+'~'+XBETitle.rstrip()+"\n" + Emu_XBE.rstrip()+"\n" + Xbox_Thumb_Folder.rstrip()+"\n" + XBEID.rstrip())
751 xbe_count = xbe_count+1
752 XBEIDCheck.append(XBEID)
753
754 pDialog.update(0,'Sorting [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Games/Artwork','[UPPERCASE]Preparing to build gamelist[/UPPERCASE]','This can take some time, please be patient.')
755 for listitems in RomSortFiles:
756 with open(os.path.join(listitems.split('~')[0]+'.xbg'),'w') as rominfo: rominfo.write(listitems.split('~')[1])
757
758
759 ## Parse rom names.txt and build a list
760 if Parse_FBL_MAME_ROMS == 1:
761 Rom_Count = 1
762 for Roms in sorted([f for f in os.listdir(Roms_Folder)]):
763 with open(os.path.join(Emu_Path,"info/rom names.txt")) as Names:
764 for line in Names:
765 if str("-"+Roms.lower()) in line:
766 Full_String = line.strip().lower()
767 File_Name = Full_String[1:].split('--',1)[0][:-4]
768 Synopsis_Set_1 = os.path.join(Synopsis_Path,Emu_Name,'set 1',File_Name+'.txt')
769 Synopsis_Set_2 = os.path.join(Synopsis_Path,Emu_Name,'set 2',File_Name+'.txt')
770 Rom_Name = Full_String.split('--',2)[1]
771 if Use_NoIntroNames == 1:
772 Synopsis_Set = "none"
773 if os.path.isfile(Synopsis_Set_1):
774 Synopsis_Set = Synopsis_Set_1
775 elif os.path.isfile(Synopsis_Set_2):
776 Synopsis_Set = Synopsis_Set_2
777 try:
778 with open(Synopsis_Set) as input:
779 for line in input.readlines():
780 if line.lower().startswith('name:'):
781 Rom_Name = line.split(': ',1)[1].strip()
782 Full_String = Full_String.split('--',1)[0]+'--'+Rom_Name+'--'+Full_String.split('--',2)[2]
783 except: pass
784 if xbmc.getCondVisibility('Skin.HasSetting(Remove_Articles_In_Name)'):
785 Rom_Name = Rom_Name.split(' (',1)[0]
786 if Rom_Name.startswith('the') and xbmc.getCondVisibility('Skin.HasSetting(Ignore_The_In_Names)'):
787 Rom_Name = Rom_Name[4:]+', the'
788 Save_Name = Rom_Name[:22]+'.'+File_Name+"_"+str(Rom_Count)
789 Save_Name = (Save_Name[:38]) if len(Save_Name) > 38 else Save_Name
790 Save_Name = Save_Name.replace('=','').replace('?','').replace(':','').replace(';','').replace('"','').replace('*','').replace('+','').replace(',','').replace('/','').replace('|','').lower()
791 RomSortFiles.append(os.path.join(New_Roms_Folder,Save_Name)+'~'+Full_String)
792 pDialog.update(0,'Sorting [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Roms','[UPPERCASE]'+File_Name+'[/UPPERCASE]','This can take some time, please be patient.')
793 Rom_Count = Rom_Count+1
794
795 pDialog.update(0,'Sorting [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Roms','[UPPERCASE]Preparing to build gamelist[/UPPERCASE]','This can take some time, please be patient.')
796 for listitems in RomSortFiles:
797 with open(os.path.join(listitems.split('~')[0]+'.zip'),'w') as rominfo: rominfo.write(listitems.split('~')[1])
798 Roms_Folder = New_Roms_Folder
799
800
801 if Parse_ROM_TXT == 1:
802 Rom_Count = 1
803 for File_Name in sorted([f for f in os.listdir(Roms_Folder)]):
804 File_Name_Original = File_Name.lower()
805 File_Name,Rom_Extension = os.path.splitext(File_Name_Original)
806 File_Name_noext,Rom_Extension = os.path.splitext(File_Name)
807 Synopsis_TXT = os.path.join(Synopsis_Path,Emu_Name,File_Name_noext+'.txt')
808 if Use_NoIntroNames == 1:
809 if os.path.isfile(Synopsis_TXT):
810 Synopsis_Set = Synopsis_TXT
811 with open(Synopsis_Set) as input:
812 for line in input.readlines():
813 if line.lower().startswith('name:'):
814 File_Name = line.split(': ',1)[1].strip()
815 break
816 if xbmc.getCondVisibility('Skin.HasSetting(Remove_Articles_In_Name)'):
817 File_Name = File_Name.split(' (',1)[0]
818 if File_Name.lower().startswith('the') and xbmc.getCondVisibility('Skin.HasSetting(Ignore_The_In_Names)'):
819 File_Name = File_Name[4:]+', the'
820 Save_Name = File_Name[:72]+"_"+str(Rom_Count)
821 Save_Name = (Save_Name[:38]) if len(Save_Name) > 38 else Save_Name
822 Save_Name = xbmc.makeLegalFilename(New_Roms_Folder+'\\'+Save_Name.lower().replace('/','').replace('\\','').replace(' ',''))
823 RomSortFiles.append(os.path.join(New_Roms_Folder,Save_Name)+'~'+File_Name_Original)
824 pDialog.update(0,'Sorting [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Roms','[UPPERCASE]'+File_Name+'[/UPPERCASE]','This can take some time, please be patient.')
825 Rom_Count = Rom_Count+1
826
827 pDialog.update(0,'Sorting [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Roms','[UPPERCASE]Preparing to build gamelist[/UPPERCASE]','This can take some time, please be patient.')
828 for listitems in RomSortFiles:
829 with open(os.path.join(listitems.split('~')[0]+'.zip'),'w') as rominfo: rominfo.write(listitems.split('~')[1])
830 Roms_Folder = New_Roms_Folder
831
832
833 ## Check for previous gamelist xml and if it exists remove it.
834 if os.path.isdir(Games_List_Path): shutil.rmtree(Games_List_Path)
835 if not os.path.isdir(Games_List_Path): os.makedirs(Games_List_Path)
836 if Parse_Xbox_Games == 1 and os.path.isfile(os.path.join(Media_Folder_Path,Resource_Type+"\\GameNames.txt")): os.remove(os.path.join(Media_Folder_Path,Resource_Type+"\\GameNames.txt"))
837
838 ## Listing the content of the roms folder for parsing.
839 for Items in sorted([f for f in os.listdir(Roms_Folder)]):
840
841
842 ## Checking the file I find,extension against my table.
843 if Items.lower().endswith(tuple(Extensions)) or Emu_Name == "neogeocd" or Parse_SubFolder == 1:
844
845
846 ## More vars being set.
847 Rom_Name = Items.lower()
848 Rom_Name_noext,Rom_Extension = os.path.splitext(Rom_Name)
849 if Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
850 with open(os.path.join(Xbox_Sort_Files,Rom_Name),"r") as input:
851 XBE_Name = input.readline().strip()
852 Emu_XBE = input.readline().strip()
853 Letter = input.readline().strip()
854 XBE_ID = input.readline().strip()
855 Rom_Name_noext = XBE_Name
856 if Xbox_Game_Total == 0: Xbox_Game_Total = len(os.listdir(Roms_Folder))
857 JumpList_Name = Rom_Name_noext.lower()
858 if not xbmc.getCondVisibility('Skin.String('+Emu_Name+'_artworkfolder)'): xbmc.executebuiltin('Skin.SetString('+Emu_Name+'_artworkfolder,boxart)')
859 Thumbnail = Rom_Name_noext+'.jpg'
860
861
862 ## Check if fba was found and parse the name text files to get the correct rom names and system types for the list.
863 if Parse_FBL_MAME_TXT == 1:
864 with open(os.path.join(Roms_Folder,Rom_Name),'r') as txt:
865 Full_String = txt.readline()
866 Rom_Name = Full_String[1:].split('--',1)[0]
867 FBA_MAME_Rom_Name = Full_String.split('--',2)[1].split('/',1)[0].replace('(','').replace(')','').strip()
868 Parent_Rom = Full_String.split('--',3)[2].strip()
869 System_Name = Full_String.split('--',3)[2].strip()
870 Rom_Name_noext,Rom_Extension = os.path.splitext(Rom_Name)
871 if Emu_Name == "mame":
872 if not Parent_Rom == "parent":
873 if 'clone' in FBA_MAME_Rom_Name.lower():
874 FBA_MAME_Rom_Name = FBA_MAME_Rom_Name+'-'+Rom_Name[:-4]
875 else:
876 FBA_MAME_Rom_Name = FBA_MAME_Rom_Name+' clone-'+Rom_Name[:-4]
877 Thumbnail = Parent_Rom+'.jpg'
878 else:
879 Thumbnail = Rom_Name_noext+'.jpg'
880 Mame_Rom_Name_noext = Rom_Name[:-4]+'--'+Full_String.split('--',3)[2].strip()
881 else:
882 Thumbnail = Rom_Name_noext+'.jpg'
883 FBL_Rom_Name_noext = Rom_Name[:-4].strip()
884 Emu_XBE = "default.xbe"
885 if System_Name == "psikyo 68ec020" or System_Name == "ps3-v1" or System_Name == "ps4" or System_Name == "ps5" or System_Name == "fg-3" or System_Name == "tecmo" or System_Name == "polygamemaster" or System_Name == "polygamemaster based" or System_Name == "ps5v2": Emu_XBE = "psykio.xbe"
886 if System_Name == "neo geo aes" or System_Name == "neo geo mvs": Emu_XBE = "neogeocps2.xbe"
887 if System_Name == "cps2": Emu_XBE = "neogeocps2.xbe"
888 if System_Name == "cave": Emu_XBE = "cave.xbe"
889 if System_Name == "toaplan gp9001 based" or System_Name == "toaplan bcu-2 / fcu-2 based" or System_Name == "dual toaplan gp9001 based": Emu_XBE = "toaplan.xbe"
890 if System_Name == "to": Emu_XBE = "taito.xbe"
891 if System_Name == "sk" or System_Name == "cps-3" or System_Name == "nmk16" or System_Name == "ssv" or System_Name == "wr" or System_Name == "th2" or System_Name == "wr2" or System_Name == "fg-2" or System_Name == "mega system 1" or System_Name == "sf" or System_Name == "kaneko 16-bit": Emu_XBE = "new.xbe"
892 if System_Name == "de": Emu_XBE = "dataeast.xbe"
893 if System_Name == "kn": Emu_XBE = "konami.xbe"
894 if System_Name == "system 16a" or System_Name == "system 16b" or System_Name == "system 18" or System_Name == "x-board" or System_Name == "y-board" or System_Name == "out run" or System_Name == "hang-on": Emu_XBE = "sega.xbe"
895 if System_Name == "jc" or System_Name == "unico" or System_Name == "ss" or System_Name == "f1gp" or System_Name == "newer seta" or System_Name == "pwr": Emu_XBE = "xtra.xbe"
896 if System_Name == "im": Emu_XBE = "irem.xbe"
897 JumpList_Name = FBA_MAME_Rom_Name.lower()
898 Write_List_File = 1
899
900 if Parse_ROM_TXT == 1:
901 with open(os.path.join(Roms_Folder,Rom_Name),'r') as txt:
902 Full_String = txt.readline()
903 JumpList_Name = Rom_Name_noext.lower()
904 Rom_Name = Full_String.strip()
905 Rom_Name_noext,Rom_Extension = os.path.splitext(Rom_Name)
906 Thumbnail = Rom_Name_noext+'.jpg'
907
908
909 ## Check if n64 was found and parse the names from surreal.ini if the roms match.
910 if Parse_N64_TXT == 1:
911 if os.path.isfile(os.path.join(Emu_Path,'surreal.ini')):
912 if Change_N64_Rom_Path == 1:
913 if os.path.isdir('E:\\TDATA\\64ce64ce'): shutil.rmtree('E:\\TDATA\\64ce64ce')
914 for line in fileinput.input(os.path.join(Emu_Path,'surreal.ini'),inplace=1):
915 if 'Rom Path=' in line:
916 line = line = 'Rom Path='+Roms_Folder+'\n'
917 print line,
918 os.makedirs('E:\\TDATA\\64ce64ce')
919 with open(os.path.join('E:\\TDATA\\64ce64ce\\surreal-ce.ini'),"w") as outputn64file:
920 WriteN64File = n64_config % (Roms_Folder)
921 outputn64file.write(WriteN64File)
922 Change_N64_Rom_Path = 0
923 Bypass_N64_Check = 0
924
925
926 ## Update the rom cache file so games actually load there saves.
927 if os.path.isfile(os.path.join(Emu_Path,'RomlistCache.dat')):
928 if not os.path.isdir('E:\\TDATA\\64ce64ce\Data'): os.makedirs('E:\\TDATA\\64ce64ce\\Data')
929 shutil.copy2(os.path.join(Emu_Path,'RomlistCache.dat'),'E:\\TDATA\\64ce64ce\\Data')
930 for line in fileinput.input('E:\\TDATA\\64ce64ce\\Data\\RomlistCache.dat',inplace=1):
931 if 'FileName=' in line:
932 line = line.replace('FileName=','FileName='+Roms_Folder)
933 print line,
934
935
936 ## Extracting the rom names from the ini.
937 N64linenumb = 1
938 foundN64line = 0
939 N64_Rom_CRC = ""
940 with open(os.path.join(Emu_Path,'surreal.ini'),'r') as ini:
941 for line in itertools.islice(ini,0,None):
942 if line.lower().startswith('[dcbc50d1'): foundN64line = 1
943 if foundN64line == 1:
944 N64ID = line.lower().strip()[1:-6]
945 N64ID1, N64ID2 = N64ID.split('-')
946 File_Name = ini.next().replace('Game Name=','').strip()
947 File_Name = File_Name.lower()
948 # Fixed names for roms not matching internal names, I don't do crc checks so this needs done.
949 if File_Name == "airboarderj (pj64x14-5.10)":
950 File_Name = "airboarderjap (pj64x14-5.10)"
951 if File_Name == "autolamborghini (pj64x14-612)":
952 File_Name = "autolamborghini (pj64x14-6.12)"
953 if File_Name == "duke nukem zh (1964-6.12)":
954 File_Name = "dukenukemzh (1964-6.12)"
955 if File_Name == "pokemonstadiumkazio (1964-5.60)":
956 File_Name = "pokemonstadiumkaizo (1964-5.60)"
957 if File_Name == "rakugakids (pj64x14-6.12)":
958 File_Name = "rakuga kids (pj64x14-6.12)"
959 if File_Name == "razorfreestylescooter (pj64x14-5.10)":
960 File_Name = "razor scooter (pj64x14-5.10)"
961 if File_Name == "scooby-doo (1964-612)":
962 File_Name = "scooby-doo (1964-6.12)"
963 if File_Name == "shufflepuckhomebrew (1964x11-6.11)":
964 File_Name = "shufflepuck (1964x11-6.11)"
965 if File_Name == "sm64 maker1.3 (pj64x14-5.10)":
966 File_Name = "supermariomaker1.3 (pj64x14-5.10)"
967 if File_Name == "sm64 ms (pj64x14-5.10)":
968 File_Name = "supermarioms hack (pj64x14-5.10)"
969 if File_Name == "sm64 ocarina (pj64x14-5.10)":
970 File_Name = "supermarioocarina (pj64x14-5.10)"
971 if File_Name == "sm64 od v5 (1964-5.10)":
972 File_Name = "supermarioodysseyv5 (1964-5.10)"
973 if File_Name == "sm64 sr (pj64x14-5.10)":
974 File_Name = "supermariosr hack (pj64x14-5.10)"
975 if File_Name == "snowboard kids 2 (1964-5.10)":
976 File_Name = "snowboard kids 2 (pj64x14-5.10)"
977 if File_Name == "space station sv (1964x11-5.31)":
978 File_Name = "spacestationsv (1964x11-5.31)"
979 if os.path.isdir(os.path.join(Emu_Path,'media\\Cbagys3DArt')):
980 if File_Name == "007 goldeneye (ultrahle)720pno" or Bypass_N64_Check == 1:
981 Bypass_N64_Check = 1
982 if Rom_Name_noext == File_Name:
983 N64_Rom_Name = ini.next().replace('Alternate Title=','').strip()
984 try:
985 ini.next() # skip the comment line
986 ini.next() # skip the blank line
987 except: pass
988
989 for N64_Saves in os.listdir(os.path.join(Emu_Path,'saves')):
990 N64_Saves = N64_Saves.lower()
991 if any(N64_ID in N64_Saves for N64_ID in (N64ID1, N64ID2)):
992 for N64_ID in (N64ID1, N64ID2):
993 ini_path = os.path.join(Emu_Path, 'saves', N64_ID, N64_ID + '.ini')
994 if os.path.isfile(ini_path):
995 N64_Rom_CRC = N64_ID
996 Thumbnail = N64_Rom_CRC+'.jpg'
997 break # Exit the loop after finding the first valid path
998
999 for N64_Thumb in os.listdir(os.path.join(Emu_Path,'media\\Cbagys3DArt')):
1000 N64_Thumb = N64_Thumb.lower()
1001 if any(N64_ID in N64_Thumb for N64_ID in (N64ID1, N64ID2)):
1002 if not os.path.isdir(os.path.join(Media_Path,'boxart')):
1003 os.makedirs(os.path.join(Media_Path,'boxart'))
1004 N64_Thumb_Location = os.path.join(Emu_Path,'media\\Cbagys3DArt',N64_Thumb)
1005 N64_Thumb_Destination = os.path.join(Media_Path,'boxart',N64_ID+'.jpg')
1006 if os.path.isfile(N64_Thumb_Location) and not os.path.isfile(N64_Thumb_Destination):
1007 shutil.copy2(N64_Thumb_Location,N64_Thumb_Destination)
1008
1009 for N64_Vids in os.listdir(os.path.join(Emu_Path,'media\\Movies')):
1010 N64_Vids = N64_Vids.lower()
1011 if any(N64_ID in N64_Vids for N64_ID in (N64ID1, N64ID2)):
1012 if not os.path.isdir(os.path.join(Media_Path,'videos')):
1013 os.makedirs(os.path.join(Media_Path,'videos'))
1014 N64_Thumb_Location = os.path.join(Emu_Path,'media\\Movies',N64_Vids)
1015 N64_Thumb_Destination = os.path.join(Media_Path,'videos',N64_ID+N64_Vids[-4:])
1016 if os.path.isfile(N64_Thumb_Location) and not os.path.isfile(N64_Thumb_Destination):
1017 shutil.copy2(N64_Thumb_Location,N64_Thumb_Destination)
1018 else:
1019 try:
1020 ini.next() # skip the rom name
1021 ini.next() # skip the comment line
1022 ini.next() # skip the blank line
1023 except: pass
1024 else:
1025 dialog.ok("ERROR","","This isn't [B]EarthWormsJames[/B][CR]N64 emulator best of compilation")
1026 return
1027 else:
1028 dialog.ok("ERROR","","Reinstall the [B]EarthWormsJames[/B] N64 emulator.[CR]The Cbagys3DArt folder is missing.")
1029 return
1030 else:
1031 ini.next()
1032 N64linenumb+= 1
1033 if N64linenumb >= 30 and foundN64line == 0:
1034 dialog.ok("ERROR","","Surreal.ini is corrupt or not formatted correctly[CR]Recopy/Download [B]EarthWormsJames[/B] N64 emulator")
1035 return
1036 else:
1037 dialog.ok("ERROR","","Surreal.ini is missing from the","N64 Emulators directory")
1038 return
1039
1040 ## Change neogeocd rom path.
1041 if Change_NeoGeoCD_Rom_Path == 1:
1042 if os.path.isfile(os.path.join(Emu_Path,"path.txt")):
1043 with open(os.path.join(os.path.join(Emu_Path,"path.txt")),"w") as outputneogeocdfile:
1044 WriteneogeocdFile = "rompath "+Roms_Folder+'\\\n'
1045 outputneogeocdfile.write(WriteneogeocdFile)
1046 Change_NeoGeoCD_Rom_Path = 0
1047 else:
1048 dialog.ok("ERROR","","path.txt is missing from the","Neogeocd Emulators directory")
1049 return
1050
1051 ## Change scummvm rom path.
1052 if Emu_Name == "scummvm":
1053 Write_List_File = 1
1054 Thumbnail = Items.split("-")[1][:-4]+'.jpg'
1055 SVM_Synopsis = Items.split("-")[1][:-4]
1056 SVM_File = Items
1057 SVMs_Game = ""
1058 Rom_Name = Items[:-4]
1059 Rom_Type_Total = Rom_Type_Total
1060 with open (os.path.join(Roms_Folder,SVM_File)) as svm:
1061 svm = svm.read()
1062 for line in svm.split('\n'):
1063 if 'description=' in line:
1064 Rom_Name_noext = line.split("=")[1].split(" (")[0]
1065 if 'path=' in line:
1066 SVMs_Game = line.split('games\\')[1].split('\\')[0]
1067 if not os.path.isdir(os.path.join(Real_Games_Folder,SVMs_Game)):
1068 print "Cant find " + SVMs_Game + " Folder"
1069 Write_List_File = 0
1070
1071
1072 ## Check for a synopsis file for the current emulator and parse it.
1073 Synopsis_filename = '[B]Filename:[/B][CR] '+Rom_Name; Synopsis_release_year = '[B]Released:[/B][CR] unknown '; Synopsis_players = '[B]Players:[/B][CR] at least 1'; Synopsis_genre = '[B]Genre:[/B][CR] unknown'; Synopsis_developer = '[B]Developer:[/B][CR] unknown'; Synopsis_publisher = '[B]Publisher:[/B][CR] unknown'; ynopsis_release_year = '[B]Released:[/B][CR] unknown'
1074 Synopsis_filename_Set = 0; Synopsis_nointroname_Set = 0; Synopsis_rating_Set = 0; Synopsis_players_Set = 0; Synopsis_genre_Set = 0; Synopsis_developer_Set = 0; Synopsis_publisher_Set = 0; Synopsis_release_year_Set = 0
1075 XBE_GameTitle = ""
1076 try:
1077 if Emu_Name == "genesis":
1078 Synopsis_File = os.path.join(Synopsis_Path,"megadrive",Rom_Name_noext+'.txt')
1079 elif Emu_Name == "famicom":
1080 Synopsis_File = os.path.join(Synopsis_Path,"nes",Rom_Name_noext+'.txt')
1081 elif Emu_Name == "n64":
1082 Synopsis_File = os.path.join(Synopsis_Path,"n64",N64_Rom_CRC+'.txt')
1083 elif Emu_Name == "tg16":
1084 Synopsis_File = os.path.join(Synopsis_Path,"pcengine",Rom_Name_noext+'.txt')
1085 elif Emu_Name == "tg-cd":
1086 Synopsis_File = os.path.join(Synopsis_Path,"pce-cd",Rom_Name_noext+'.txt')
1087 elif Emu_Name == "fbl" or Emu_Name == "fblc" or Emu_Name == "fbaxxx" or Emu_Name == "mame":
1088 Synopsis_Set_1 = os.path.join(Synopsis_Path,Emu_Name,'set 1',Thumbnail[:-4]+'.txt')
1089 Synopsis_Set_2 = os.path.join(Synopsis_Path,Emu_Name,'set 2',Thumbnail[:-4]+'.txt')
1090 Synopsis_File = "none"
1091 if os.path.isfile(Synopsis_Set_1):
1092 Synopsis_File = Synopsis_Set_1
1093 elif os.path.isfile(Synopsis_Set_2):
1094 Synopsis_File = Synopsis_Set_2
1095 elif Emu_Name == "scummvm":
1096 Synopsis_File = os.path.join(Synopsis_Path,"scummvm",SVM_Synopsis+'.txt')
1097 elif Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
1098 if Emu_Name == "homebrew": Resource_Type = "ports"
1099 if '_' in XBE_ID:
1100 Synopsis_File = os.path.join(Synopsis_Path,Resource_Type,XBE_ID.split('_',1)[0]+'.txt')
1101 else:
1102 Synopsis_File = os.path.join(Synopsis_Path,Resource_Type,XBE_ID+'.txt')
1103 if Emu_Name == "homebrew": Resource_Type = "homebrew"
1104 else:
1105 Synopsis_File = os.path.join(Synopsis_Path,Emu_Name,Rom_Name_noext+'.txt')
1106
1107 with open(Synopsis_File) as input:
1108 Synopsis = input.read()
1109 Synopsis1 = Synopsis.split('_________________________',1)[0]
1110 Synopsis1 = Synopsis1.split('\n')
1111 for _ in range(11):
1112 for line in Synopsis1:
1113 line = line.lower()
1114 if line.startswith('name:') and Use_NoIntroNames == 1:
1115 Synopsis_nointroname_Set = 1
1116 # if Emu_Name == "fba" or Emu_Name == "fbl" or Emu_Name == "fblc" or Emu_Name == "fbaxxx" or Emu_Name == "mame":
1117 # FBA_MAME_Rom_Name = line.split(': ',1)[1]
1118 # Synopsis_nointroname_Set = 1
1119 if Emu_Name == "n64":
1120 Rom_Name_noext = line.split(': ',1)[1]
1121 elif Emu_Name == "scummvm":
1122 pass
1123 elif Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
1124 XBE_GameTitle = line.split(': ',1)[1]
1125 else:
1126 Rom_Name_noext = line.split(': ',1)[1]
1127 elif Synopsis_nointroname_Set == 0:
1128 pass
1129 if Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
1130 Synopsis_filename = XBE_ID
1131 if '_' in Synopsis_filename:
1132 Synopsis_filename = '[B]TITLEID:[/B][CR] '+Synopsis_filename.split('_',1)[0]
1133 else:
1134 Synopsis_filename = '[B]TITLEID:[/B][CR] '+Synopsis_filename
1135 else:
1136 if line.startswith('filename:'):
1137 Synopsis_filename = line.split(': ',1)[1]
1138 Synopsis_filename = '[B]Filename:[/B][CR] '+Synopsis_filename
1139 Synopsis_filename_Set = 1
1140 elif Synopsis_filename_Set == 0:
1141 Synopsis_filename = '[B]Filename:[/B][CR] '+Rom_Name
1142 if line.startswith('rating:'):
1143 Synopsis_rating = line.split(': ',1)[1]
1144 Synopsis_rating = '[B]Rating:[/B][CR] '+Synopsis_rating
1145 Synopsis_rating_Set = 1
1146 elif Synopsis_rating_Set == 0:
1147 Synopsis_rating = '[B]Rating:[/B][CR] unknown'
1148 if line.startswith('players:'):
1149 Synopsis_players = line.split(': ',1)[1]
1150 Synopsis_players = '[B]Players:[/B][CR] '+Synopsis_players
1151 Synopsis_players_Set = 1
1152 elif Synopsis_players_Set == 0:
1153 Synopsis_players = '[B]Players:[/B][CR] at least 1'
1154 if line.startswith('genre:'):
1155 Synopsis_genre = line.split(': ',1)[1]
1156 Synopsis_genre = '[B]Genre:[/B][CR] '+Synopsis_genre
1157 Synopsis_genre_Set = 1
1158 elif Synopsis_genre_Set == 0:
1159 Synopsis_genre = '[B]Genre:[/B][CR] unknown'
1160 if line.startswith('developer:'):
1161 Synopsis_developer = line.split(': ',1)[1]
1162 Synopsis_developer = '[B]Developer:[/B][CR] '+Synopsis_developer
1163 Synopsis_developer_Set = 1
1164 elif Synopsis_developer_Set == 0:
1165 Synopsis_developer = '[B]Developer:[/B][CR] unknown'
1166 if line.startswith('publisher:'):
1167 Synopsis_publisher = line.split(': ',1)[1]
1168 Synopsis_publisher = '[B]Publisher:[/B][CR] '+Synopsis_publisher
1169 Synopsis_publisher_Set = 1
1170 elif Synopsis_publisher_Set == 0:
1171 Synopsis_publisher = '[B]Publisher:[/B][CR] unknown'
1172 if line.startswith('release year:'):
1173 Synopsis_release_year = line.split(': ',1)[1]
1174 Synopsis_release_year = '[B]Released:[/B][CR] '+Synopsis_release_year
1175 Synopsis_release_year_Set = 1
1176 elif Synopsis_release_year_Set == 0:
1177 Synopsis_release_year = '[B]Released:[/B][CR] unknown'
1178 Synopsis1 = Synopsis_release_year+'[CR]'+Synopsis_developer+'[CR]'+Synopsis_publisher+'[CR]'+Synopsis_genre+'[CR]'+Synopsis_players
1179 Synopsis2 = Synopsis.split('_________________________',1)[1]
1180 Synopsis2 = Synopsis2.strip('\n')
1181 Synopsis2 = Synopsis2.replace('\n','[CR]')
1182 Synopsis2 = Synopsis2.replace('&','&')
1183 Synopsis2 = Synopsis2.replace('>','>')
1184 Synopsis2 = Synopsis2.replace('<','<')
1185 except:
1186 if Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
1187 Synopsis_filename = XBE_ID
1188 if '_' in Synopsis_filename:
1189 Synopsis_filename = '[B]TITLEID:[/B][CR] '+Synopsis_filename.split('_',1)[0]
1190 else:
1191 Synopsis_filename = '[B]TITLEID:[/B][CR] '+Synopsis_filename
1192 Synopsis1 = Synopsis_release_year+'[CR]'+Synopsis_developer+'[CR]'+Synopsis_publisher+'[CR]'+Synopsis_genre+'[CR]'+Synopsis_players
1193 Synopsis2 = ""
1194
1195
1196 ## Edit labels as well as fix labels that use only numbers, XBMC will use its internal labelling system if I don't.
1197 if Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
1198 if Use_NoIntroNames == 0 or XBE_GameTitle == "":
1199 XBE_GameTitle = XBE_Name.lower()
1200 else:
1201 skip = ""
1202 GamePath = Emu_XBE
1203 GameLetter = Letter
1204 GameThumb = XBE_ID+'.jpg'
1205
1206 if xbmc.getCondVisibility('Skin.HasSetting(Remove_Articles_In_Name)'):
1207 XBE_GameTitle = XBE_GameTitle.split(' (',1)[0]
1208 if XBE_GameTitle.startswith('the') and xbmc.getCondVisibility('Skin.HasSetting(Ignore_The_In_Names)'):
1209 XBE_GameTitle = XBE_GameTitle[4:]+', the'
1210 if xbmc.getCondVisibility('Skin.HasSetting(Remove_Articles_In_Name)'):
1211 Rom_Name_noext = Rom_Name_noext.split(' (',1)[0]
1212 if Emu_Name == "n64":
1213 N64_Rom_Name = Rom_Name_noext
1214 if Rom_Name_noext.startswith('the') and xbmc.getCondVisibility('Skin.HasSetting(Ignore_The_In_Names)'):
1215 Rom_Name_noext = Rom_Name_noext[4:]+', the'
1216 if Emu_Name == "n64":
1217 N64_Rom_Name = Rom_Name_noext
1218
1219 Rom_Name_noext = string.capwords(Rom_Name_noext)
1220 FBA_MAME_Rom_Name = string.capwords(FBA_MAME_Rom_Name)
1221 if Emu_Name == "n64":
1222 N64_Rom_Name = string.capwords(N64_Rom_Name)
1223 XBE_GameTitle = string.capwords(XBE_GameTitle)
1224 if Rom_Name_noext.isdigit():
1225 Rom_Name_noext = Rom_Name_noext+" "
1226 if FBA_MAME_Rom_Name.isdigit():
1227 FBA_MAME_Rom_Name = FBA_MAME_Rom_Name+" "
1228
1229
1230 ## Set Rom_Names for different types of CD images.
1231 Rom_Name_ISO = Rom_Name[:-4]+".iso"
1232 Rom_Name_BIN = Rom_Name[:-4]+".bin"
1233 Rom_Name_IMG = Rom_Name[:-4]+".img"
1234 Rom_Name_CUE = Rom_Name[:-4]+".cue"
1235 Rom_Name_CCD = Rom_Name[:-4]+".ccd"
1236 Rom_Name_CHD = Rom_Name[:-4]+".chd"
1237 Rom_Name_ZIP = Rom_Name[:-4]+".zip"
1238 Rom_Name_ADF = Rom_Name[:-4]+".adf"
1239 Rom_Path = Rom_Name
1240
1241
1242 ## Check and parse the directory for segacd iso files.
1243 if Parse_SubFolder == 1:
1244 if Emu_Name == "pce-cd" or Emu_Name == "tg-cd":
1245 if os.path.isfile(os.path.join(Roms_Folder,Items,Items+'.cue')):
1246 Rom_Path = os.path.join(Items,Items+'.cue')
1247 Rom_Type_Total = Rom_Type_Total
1248 Write_List_File = 1
1249 else:
1250 Write_List_File = 0
1251 else:
1252 if os.path.isfile(os.path.join(Roms_Folder,Items,Items+'.iso')):
1253 Rom_Path = os.path.join(Items,Items+'.iso')
1254 Rom_Type_Total = Rom_Type_Total
1255 Write_List_File = 1
1256 elif os.path.isfile(os.path.join(Roms_Folder,Items,Items+'.bin')):
1257 Rom_Path = os.path.join(Items,Items+'.bin')
1258 Rom_Type_Total = Rom_Type_Total
1259 Write_List_File = 1
1260 elif os.path.isfile(os.path.join(Roms_Folder,Items,Items+'.img')):
1261 Rom_Path = os.path.join(Items,Items+'.img')
1262 Rom_Type_Total = Rom_Type_Total
1263 Write_List_File = 1
1264 elif Emu_Name == "scummvm":
1265 pass
1266 else:
1267 Write_List_File = 0
1268
1269
1270 ## Check and parse the directory for iso files.
1271 if Parse_ISO_File == 1:
1272 if Items.endswith('.iso'):
1273 Rom_Path = Rom_Name_ISO
1274 Rom_Type_Total = Rom_Type_Total
1275 Write_List_File = 1
1276 else:
1277 Write_List_File = 0
1278
1279
1280 ## Check and parse the directory for cue files.
1281 if Parse_CUE_File == 1:
1282 if Items.endswith('.cue'):
1283 Rom_Path = Rom_Name_CUE
1284 Rom_Type_Total = Rom_Type_Total
1285 Write_List_File = 1
1286 else:
1287 Write_List_File = 0
1288
1289
1290 ## Check and parse the directory for bin/iso/img files.
1291 if Parse_ISO_BIN_IMG_File == 1:
1292 if Items.endswith('.bin'):
1293 Rom_Path = Rom_Name_BIN
1294 Rom_Type_Total = Rom_Type_Total
1295 Write_List_File = 1
1296 elif Items.endswith('.img'):
1297 Rom_Path = Rom_Name_IMG
1298 Rom_Type_Total = Rom_Type_Total
1299 Write_List_File = 1
1300 elif Items.endswith('.iso'):
1301 Rom_Path = Rom_Name_ISO
1302 Rom_Type_Total = Rom_Type_Total
1303 Write_List_File = 1
1304 else:
1305 Write_List_File = 0
1306
1307
1308 ## Check and parse the directory for cue/ccd/iso files.
1309 if Parse_CUE_CCD_CHD_ISO_File == 1:
1310 if Items.endswith('.cue'):
1311 Rom_Path = Rom_Name_CUE
1312 Rom_Type_Total = Rom_Type_Total
1313 Write_List_File = 1
1314 elif Items.endswith('.ccd'):
1315 Rom_Path = Rom_Name_CCD
1316 Rom_Type_Total = Rom_Type_Total
1317 Write_List_File = 1
1318 elif Items.endswith('.chd'):
1319 Rom_Path = Rom_Name_CHD
1320 Rom_Type_Total = Rom_Type_Total
1321 Write_List_File = 1
1322 elif Items.endswith('.iso'):
1323 Rom_Path = Rom_Name_ISO
1324 Rom_Type_Total = Rom_Type_Total
1325 if os.path.isfile(os.path.join(Roms_Folder,Rom_Path[:-4]+'.cue')):
1326 Write_List_File = 0
1327 else:
1328 Write_List_File = 1
1329 else:
1330 Write_List_File = 0
1331
1332
1333 ## Check and parse the directory for cue/zip/adf/iso files.
1334 if Parse_CUE_ZIP_ISO_ADF_File == 1:
1335 if Items.endswith('.cue'):
1336 Rom_Path = Rom_Name_CUE
1337 Rom_Type_Total = Rom_Type_Total
1338 Write_List_File = 1
1339 elif Items.endswith('.zip'):
1340 Rom_Path = Rom_Name_ZIP
1341 Rom_Type_Total = Rom_Type_Total
1342 Write_List_File = 1
1343 elif Items.endswith('.adf'):
1344 Rom_Path = Rom_Name_ADF
1345 Rom_Type_Total = Rom_Type_Total
1346 Write_List_File = 1
1347 elif Items.endswith('.iso'):
1348 Rom_Path = Rom_Name_ISO
1349 Rom_Type_Total = Rom_Type_Total
1350 if os.path.isfile(os.path.join(Roms_Folder,Rom_Path[:-4]+'.cue')):
1351 Write_List_File = 0
1352 else:
1353 Write_List_File = 1
1354 else:
1355 Write_List_File = 0
1356
1357 ## Create the rest of the layout xml file.
1358 if Write_List_File:
1359 if CreateDialog: CreateDialog = 0; pDialog.update(0,'Building [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Game list','','This can take some time, please be patient.')
1360 ## Show the progress bar progress and write rom list file.
1361 RomListCount = RomListCount+1
1362 GamelistOuput = ""
1363
1364 # with open(os.path.join(Games_List_Path,'gamelist.xml'),"a") as outputmenufile:
1365 if Emu_Name == "fba" or Emu_Name == "fbl" or Emu_Name == "fblc" or Emu_Name == "fbaxxx":
1366 pDialog.update(
1367 (CountList * 100) / len(os.listdir(os.path.join(Roms_Folder_Path,Emu_Name))),
1368 'Building [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Game list',
1369 FBA_MAME_Rom_Name.upper(),
1370 'This can take some time, please be patient.'
1371 )
1372 GamelistOuput = menu_entry % (
1373 CountList,
1374 FBA_MAME_Rom_Name,
1375 Synopsis1,
1376 Synopsis2,
1377 Thumbnail,
1378 "[ArtworkFolder]",
1379 'RunScript(special://emustation_scripts/launcher.py,'+Emu_XBE+','+FBL_Rom_Name_noext+',,'+str(CountList)+')',
1380 "ActivateWindow(1101)"
1381 )
1382
1383 elif Emu_Name == "mame":
1384 pDialog.update(
1385 (CountList * 100) / len(os.listdir(os.path.join(Roms_Folder_Path,Emu_Name))),
1386 'Building [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Game list',
1387 FBA_MAME_Rom_Name.upper(),
1388 'This can take some time, please be patient.'
1389 )
1390 GamelistOuput = menu_entry % (
1391 CountList,
1392 FBA_MAME_Rom_Name,
1393 Synopsis1,Synopsis2,
1394 Thumbnail,
1395 "[ArtworkFolder]",
1396 'RunScript(special://emustation_scripts/launcher.py,'+Emu_XBE+','+Mame_Rom_Name_noext+',,'+str(CountList)+')',
1397 "ActivateWindow(1101)"
1398 )
1399
1400 elif Emu_Name == "neogeocd":
1401 pass
1402
1403 elif Emu_Name == "n64":
1404 pDialog.update(
1405 (CountList * 100) / len(os.listdir(Roms_Folder)),
1406 'Building [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Rom list & copying media files',
1407 N64_Rom_Name.upper(),
1408 'This can take some time, please be patient.'
1409 )
1410 GamelistOuput = menu_entry % (
1411 CountList,
1412 N64_Rom_Name,
1413 Synopsis1,
1414 Synopsis2,
1415 Thumbnail,
1416 "[ArtworkFolder]",
1417 'RunScript(special://emustation_scripts/launcher.py,'+Emu_XBE+','+Rom_Path+'-CRC-'+N64_Rom_CRC+',,'+str(CountList)+')',
1418 "ActivateWindow(1101)"
1419 )
1420
1421 elif Emu_Name == "amiga" or Emu_Name == "pce-cd" or Emu_Name == "psx" or Emu_Name == "tg-cd" or Emu_Name == "segacd":
1422 pDialog.update(
1423 (CountList * 100) / Rom_Type_Total,
1424 'Building [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Game list',
1425 Rom_Name_noext.upper(),
1426 'This can take some time, please be patient.'
1427 )
1428 GamelistOuput = menu_entry % (
1429 CountList,
1430 Rom_Name_noext,
1431 Synopsis1,
1432 Synopsis2,
1433 Thumbnail,
1434 "[ArtworkFolder]",
1435 'RunScript(special://emustation_scripts/launcher.py,'+Emu_XBE+','+Rom_Path+',,'+str(CountList)+')',
1436 "ActivateWindow(1101)"
1437 )
1438
1439 elif Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
1440 # with open(os.path.join(Games_List_Path,"artworkinfo.txt"),"a") as ouput:
1441 # ouput.write("Game Name: "+XBE_GameTitle+"\nSubFolder: "+GameLetter+"\nTitleID: "+GameThumb[:-4]+"\n\n")
1442
1443 pDialog.update(
1444 (CountList * 100) / Xbox_Game_Total,
1445 'Building [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Game list',
1446 XBE_GameTitle.upper(),
1447 'This can take some time, please be patient.'
1448 )
1449 GamelistOuput = menu_entry % (
1450 CountList,
1451 XBE_GameTitle,
1452 Synopsis1,
1453 Synopsis2,
1454 GameLetter+'\\'+GameThumb,
1455 "[ArtworkFolder]",
1456 'RunScript(special://emustation_scripts/launcher.py,'+GamePath+',empty,,'+str(CountList)+')',
1457 "ActivateWindow(1101)"
1458 )
1459
1460 else:
1461 pDialog.update(
1462 (CountList * 100) / len(os.listdir(Roms_Folder)),
1463 'Building [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Game list',
1464 Rom_Name_noext.upper(),
1465 'This can take some time, please be patient.'
1466 )
1467 GamelistOuput = menu_entry % (
1468 CountList,
1469 Rom_Name_noext,
1470 Synopsis1,
1471 Synopsis2,
1472 Thumbnail,
1473 "[ArtworkFolder]",
1474 'RunScript(special://emustation_scripts/launcher.py,'+Emu_XBE+','+Rom_Path+',,'+str(CountList)+')',
1475 "ActivateWindow(1101)"
1476 )
1477
1478 WriteGamelistFile.append(GamelistOuput)
1479
1480
1481 ## Write favourites menu entries.
1482
1483 if Emu_Name == "fba" or Emu_Name == "fbl" or Emu_Name == "fblc" or Emu_Name == "fbaxxx":
1484 FavsMenuFile = favourites_entry % (FBA_MAME_Rom_Name,Emu_XBE,FBL_Rom_Name_noext)
1485
1486 elif Emu_Name == "mame":
1487 FavsMenuFile = favourites_entry % (FBA_MAME_Rom_Name,Emu_XBE,Mame_Rom_Name_noext)
1488
1489 elif Emu_Name == "neogeocd":
1490 pass
1491
1492 elif Emu_Name == "n64":
1493 FavsMenuFile = favourites_entry % (N64_Rom_Name,Emu_XBE,Rom_Path+'-CRC-'+N64_Rom_CRC)
1494
1495 elif Emu_Name == "xbox" or Emu_Name == "ports" or Emu_Name == "homebrew":
1496 Rom_Name_noext = XBE_GameTitle
1497
1498 if Use_NoIntroNames == 0 or XBE_GameTitle == "":
1499 Rom_Name_noext = XBE_Name
1500 else:
1501 skip = ""
1502
1503 FavsMenuFile = favourites_entry % (Rom_Name_noext,Emu_XBE,"null")
1504
1505 else:
1506 FavsMenuFile = favourites_entry % (Rom_Name_noext,Emu_XBE,Rom_Path)
1507
1508 WriteFavsMenuFile.append(FavsMenuFile)
1509
1510
1511 ## Write menu entry for quick jump.
1512 Current_Letter = JumpList_Name.lower()[0]
1513 Write_Jump_File = 0
1514
1515 if Current_Letter.isalpha():
1516 Write_Jump_File = 1
1517 else:
1518 Current_Letter = "#"
1519 Write_Jump_File = 1
1520
1521 if Current_Letter == Previous_Letter:
1522 Write_Jump_File = 0
1523
1524 if Write_Jump_File:
1525 Previous_Letter = Current_Letter
1526 JumplistFile = search_menu_entry % (str(Jump_Counter),Current_Letter.upper(),"SetFocus(9000,"+str(JumpList)+")")
1527 Jump_Counter = Jump_Counter+1
1528 WriteJumplistFile.append(JumplistFile)
1529
1530
1531## Add 1 to the Countlist and JumpList.
1532 CountList = CountList+1
1533 JumpList = JumpList+1
1534
1535
1536## Add the footer to the layout xml file.
1537 with open(os.path.join(Games_List_Path,'gamelist.xml'),"w") as outputmenufile:
1538 outputmenufile.write(menu_entry_header + "".join(WriteGamelistFile) + menu_entry_footer)
1539
1540 with open(os.path.join(Games_List_Path,'jumplist.xml'),"w") as outputmenuselectfile:
1541 outputmenuselectfile.write("".join(WriteJumplistFile))
1542
1543 with open(os.path.join(Games_List_Path,'favslist.xml'),"w") as favsmenufile:
1544 favsmenufile.write("".join(WriteFavsMenuFile))
1545 else:
1546 dialog.ok("Error","No emulator found for [B]"+Emu_Name+"[/B]","This will be skipped, install the emulator","and manually scan after.")
1547 else:
1548 if os.path.isdir(Games_List_Path): shutil.rmtree(Games_List_Path)
1549 if ManualScan == 1:
1550 dialog.ok("Error","","No roms/images found for this system")
1551 return Main_Code()
1552 if Roms_Folder_Found == 0:
1553 dialog.ok("Error","","Roms folder is empty or custom path is not set.")
1554 return
1555
1556## Set the rom count and remove any direct launch rom list.xml files.
1557 pDialog.update(0,'Building [B][UPPERCASE]'+Emu_Name+'[/UPPERCASE][/B] Game list','Clearing Cache','This can take some time, please be patient.')
1558 xbmc.executebuiltin('Skin.SetString('+Emu_Name+'_games,'+str(RomListCount)+')')
1559 if os.path.isdir('Q:\\temp'): shutil.rmtree('Q:\\temp')
1560 if Emu_Name == "atarijaguar" or Emu_Name == "neogeocd":
1561 if os.path.isdir(Games_List_Path): shutil.rmtree(Games_List_Path)
1562 if os.path.isdir(Media_Path): shutil.rmtree(Media_Path)
1563
1564## ManualMode - Set a property so I can run the next script without this one running on.
1565 if Found_Roms == 1 and ManualScan == 1:
1566 xbmcgui.Window(xbmcgui.getCurrentWindowId()).setProperty("MyScript.ExternalRunning","True")
1567
1568
1569## Running the scan script to update the counters.
1570 xbmc.executebuiltin('RunScript('+Scripts_Path+'refresh_carousel.py,0,'+Emu_Name+',0,0)')
1571
1572## Loop.
1573 while (xbmcgui.Window(xbmcgui.getCurrentWindowId()).getProperty("MyScript.ExternalRunning") == "True"):
1574 time.sleep(0.2)
1575 if os.path.isdir(os.path.join(Emulator_Folder_Path,"xbox")): shutil.rmtree(os.path.join(Emulator_Folder_Path,"xbox"))
1576 if os.path.isdir(os.path.join(Emulator_Folder_Path,"ports")): shutil.rmtree(os.path.join(Emulator_Folder_Path,"ports"))
1577 if os.path.isdir(os.path.join(Emulator_Folder_Path,"homebrew")): shutil.rmtree(os.path.join(Emulator_Folder_Path,"homebrew"))
1578 pDialog.close()
1579 return
1580
1581## AutoMode - Set a property so I can run the next script without this one running on.
1582 if Found_Roms == 1 and ManualScan == 0:
1583 xbmcgui.Window(xbmcgui.getCurrentWindowId()).setProperty("MyScript.ExternalRunning","True")
1584
1585
1586## Running the scan script to update the counters.
1587 xbmc.executebuiltin('RunScript('+Scripts_Path+'refresh_carousel.py,scan_emus,0,0,0)')
1588
1589## Loop.
1590 while (xbmcgui.Window(xbmcgui.getCurrentWindowId()).getProperty("MyScript.ExternalRunning") == "True"):
1591 time.sleep(0.2)
1592 if os.path.isdir(os.path.join(Emulator_Folder_Path,"xbox")): shutil.rmtree(os.path.join(Emulator_Folder_Path,"xbox"))
1593 if os.path.isdir(os.path.join(Emulator_Folder_Path,"ports")): shutil.rmtree(os.path.join(Emulator_Folder_Path,"ports"))
1594 if os.path.isdir(os.path.join(Emulator_Folder_Path,"homebrew")): shutil.rmtree(os.path.join(Emulator_Folder_Path,"homebrew"))
1595 else:
1596 if os.path.isdir(os.path.join(Emulator_Folder_Path,"xbox")): shutil.rmtree(os.path.join(Emulator_Folder_Path,"xbox"))
1597 if os.path.isdir(os.path.join(Emulator_Folder_Path,"ports")): shutil.rmtree(os.path.join(Emulator_Folder_Path,"ports"))
1598 if os.path.isdir(os.path.join(Emulator_Folder_Path,"homebrew")): shutil.rmtree(os.path.join(Emulator_Folder_Path,"homebrew"))
1599 pDialog.close()
1600 return
1601
1602menu_entry_header = '''<content>
1603<!--
1604Tags used in the xml files:
1605name = $INFO[listitem.Label]
1606details = $INFO[listitem.Label2]
1607synopsis = $INFO[listitem.ActualIcon]
1608thumbnail = $INFO[listitem.Thumb]
1609mediapath = $INFO[listitem.SortLetter]
1610-->'''
1611menu_entry = '''
1612 <item id="%s">
1613 <name>%s</name>
1614 <details>%s</details>
1615 <synopsis>%s</synopsis>
1616 <thumbnail>%s</thumbnail>
1617 <mediapath>%s</mediapath>
1618 <onclick>Stop</onclick>
1619 <onclick>%s</onclick>
1620 <onclick>%s</onclick>
1621 </item>'''
1622menu_entry_footer = '''
1623</content>'''
1624search_menu_entry = '''<control type="button" id="%s">
1625 <label>[UPPERCASE]$LOCALIZE[31405][/UPPERCASE]</label>
1626 <label2>< [UPPERCASE]%s[/UPPERCASE] ></label2>
1627 <include>MenuButtonCommonValues</include>
1628 <onclick>Dialog.Close(1120)</onclick>
1629 <onclick>%s</onclick>
1630</control>
1631'''
1632favourites_entry = '<favourites>%s|%s|%s</favourites>'
1633n64_config = '''[Settings]
1634skinname=Default
1635onhd=true
1636HideLaunchScreens=true
1637EnableXMVPreview=false
1638EnableVideoAudio=false
1639EnableInfoPanel=false
1640EnableBGMusic=false
1641RandomBGMusic=false
1642AudioBoost=false
1643PathRoms=%s\\
1644PathMedia=D:\Media\\
1645PathSkins=D:\Skins\\
1646PathSaves=D:\Saves\\
1647PathScreenshots=D:\Screenshots\\'''
1648mame_config = '''[Directories]
1649ALTDrive = t
1650C_Mapping = \\device\\harddisk0\\partition1
1651E_Mapping = \\device\\harddisk0\\partition1
1652F_Mapping = \\device\\harddisk0\\partition6
1653G_Mapping = \\device\\harddisk0\\partition7
1654H_Mapping = \\device\\cdrom0
1655RomsPath0 = %s
1656RomsPath1 = d:\\roms
1657RomsPath2 = d:\\roms
1658RomsPath3 = d:\\bios
1659ArtPath = d:\\artwork
1660AudioPath = d:\\samples
1661ConfigPath = d:\\cfg
1662GeneralPath = d:\\general
1663HDImagePath = d:\\hdimages
1664HiScoresPath = d:\\hiscores
1665NVRamPath = d:\
1666vram
1667BackupPath = d:\\roms\\backup
1668ScreenshotPath = d:\\screenshots
1669AutoBootSavePath = d:\\autobootsaves
1670[General]
1671bios = 0
1672CheatsEnabled = 1
1673CheatFilename = cheat.dat
1674SkipDisclaimer = 1
1675SkipGameInfo = 1
1676SkipWarnings = 1
1677ScreenSaverTimeout = 10
1678[Input]
1679Lightgun1_Left = 4294934529
1680Lightgun1_CenterX = 0
1681Lightgun1_Right = 32767
1682Lightgun1_Top = 32767
1683Lightgun1_CenterY = 0
1684Lightgun1_Bottom = 4294934529
1685Lightgun2_Left = 4294934529
1686Lightgun2_CenterX = 0
1687Lightgun2_Right = 32767
1688Lightgun2_Top = 32767
1689Lightgun2_CenterY = 0
1690Lightgun2_Bottom = 4294934529
1691Lightgun3_Left = 4294934529
1692Lightgun3_CenterX = 0
1693Lightgun3_Right = 32767
1694Lightgun3_Top = 32767
1695Lightgun3_CenterY = 0
1696Lightgun3_Bottom = 4294934529
1697Lightgun4_Left = 4294934529
1698Lightgun4_CenterX = 0
1699Lightgun4_Right = 32767
1700Lightgun4_Top = 32767
1701Lightgun4_CenterY = 0
1702Lightgun4_Bottom = 4294934529
1703[Network]
1704DisableNetworking = 0
1705IPAddress =
1706Gateway =
1707Subnet =
1708NameServer =
1709[ROMListOptions]
1710DisplayMode = 1
1711SortMode = 4
1712ShowROMStatus = 0
1713ShowFAVEStatus = 1
1714HideFilteredROMs = 0
1715FilterMode = 0
1716CursorPosition = 0.000000
1717PageOffset = 0.000000
1718SuperscrollIndex = 0
1719[SkinOptions]
1720SelectedSkin = Original
1721[Sound]
1722SoundEnable = 1
1723SampleRate = 44100
1724UseSamples = 1
1725UseFilter = 1
1726[VMMOptions]
1727ForceVMM = 0
1728Threshold = 4194304
1729CommitSize = 1048576
1730Distribute = 65535
1731[VectorOptions]
1732VectorWidth = 640
1733VectorHeight = 480
1734BeamWidth = 2
1735FlickerEffect = 0.000000
1736BeamIntensity = 1.500000
1737Translucency = 1
1738[Video]
1739VSYNC = 1
1740ThrottleFramerate = 1
1741AspectRatioCorrection = 1
1742MinificationFilter = 2
1743MagnificationFilter = 2
1744Frameskip = 4294967295
1745GraphicsFilter = 0
1746SoftDisplayFilter = 0
1747FlickerFilter = 5
1748ScreenRotation = 0
1749Brightness = 1.000000
1750PauseBrightness = 0.650000
1751Gamma = 1.000000
1752ScreenUsage_X = 0.850000
1753ScreenUsage_Y = 0.850000
1754ScreenPos_X = 0.000000
1755ScreenPos_Y = 0.000000
1756Artwork = 1
1757'''
1758fbl_config = '''UsePathINI=1
1759ROMPath1=%s
1760ROMPath2=
1761ROMPath3=
1762ROMPath4=
1763ROMPath5=
1764ROMPath6=
1765ROMPath7=
1766ROMPath8=
1767D:\\artwork\\Shots 1
1768D:\\artwork\\Shots 2
1769D:\\artwork\\Shots 3
1770D:\\artwork\\Shots 4
1771D:\\artwork\\Shots 5
1772D:\\artwork\\Shots 6
1773D:\\artwork\\Shots 7
1774D:\\artwork\\Shots 8
1775D:\
1776vram
1777D:\\samples
1778D:\\ini
1779D:\\savestates
1780D:\\config
1781D:\\hiscores
1782D:\\videos
1783'''
1784
1785xbmc.executebuiltin('Dialog.Close(1101,true)')
1786
1787if ( __name__ == "__main__" ):
1788 start_time = time.time()
1789 if Manual_Scan == "manual" :
1790 ManualScan = 1
1791 Main_Code()
1792 if Full_Scan == "auto" :
1793 if dialog.yesno("FULL SCAN MODE","","Would you like to auto scan your roms?"):
1794 ManualScan = 0
1795 Main_Code()
1796
1797## Check if we are in a system menu or home screen and reload the system menu if it matches the scanned system.
1798 if not xbmc.getCondVisibility('Window.IsVisible(10000)') and Found_Roms == 1:
1799 print "You should be here"
1800 if Emu_Name == xbmc.getInfoLabel('Skin.String(emuname)'):
1801 xbmc.executebuiltin('Dialog.Close(1111,true)'); xbmc.executebuiltin('Dialog.Close(1114,true)')
1802 xbmc.executebuiltin('RunScript(special://emustation_scripts/menu_loader.py,'+xbmc.getInfoLabel('Skin.String(emuname)')+')')
1803
1804print "Unloaded create_rom_list.py - it took %s to complete" % str(datetime.timedelta(seconds=round(time.time() - start_time)))