· 6 years ago · Sep 14, 2019, 01:32 AM
1'''
2 Script by Rocky5
3 Used to create static lists from your emulator and roms folder.
4 Atarijaguar have there roms placed inside there root directory.
5 NeoGeoCD must have its ISO files in folders inside its roms\system folder and the .cue file must match the name of the folder.
6 ( the script will generate static lists for emulators )
7'''
8import ast, fileinput, glob, itertools, re, operator, os, shutil, struct, sys, time, xbmc, xbmcgui, zipfile, filecmp
9from xbe import *
10## Start markings for the log file.
11print "| create_rom_lists.py loaded."
12try:
13 Manual_Scan = sys.argv[1:][0]
14 Full_Scan = sys.argv[2:][0]
15except:
16 Manual_Scan = "0"
17 Full_Scan = "0"
18pDialog = xbmcgui.DialogProgress()
19dialog = xbmcgui.Dialog()
20## Sets paths.
21Root_Directory = xbmc.translatePath("Special://root/")
22if xbmc.getCondVisibility( 'Skin.String(Custom_Emulator_Path)' ):
23 Emulator_Folder_Path = xbmc.getInfoLabel( 'Skin.String(Custom_Emulator_Path)' )
24else:
25 Emulator_Folder_Path = os.path.join( Root_Directory, '.emustation\\emulators\\' )
26if xbmc.getCondVisibility( 'Skin.String(Custom_Roms_Path)' ):
27 Roms_Folder_Path = xbmc.getInfoLabel( 'Skin.String(Custom_Roms_Path)' )
28else:
29 Roms_Folder_Path = os.path.join( Root_Directory, '.emustation\\roms\\' )
30if xbmc.getCondVisibility( 'Skin.String(Custom_Media_Path)' ):
31 Media_Folder_Path = xbmc.getInfoLabel( 'Skin.String(Custom_Media_Path)' )
32else:
33 Media_Folder_Path = os.path.join( Root_Directory, '.emustation\\media\\' )
34Synopsis_Path = os.path.join( Root_Directory, '.emustation\\synopsis\\' )
35Scripts_Path = os.path.join( Root_Directory, '.emustation\\scripts\\' )
36File_Types_Path = os.path.join( Root_Directory, '.emustation\\scripts\\file types\\' )
37## Grab extensions for roms via files in a folder, makes it very easy for people to add new rom extensions.
38if len(os.listdir( File_Types_Path )) > 0:
39 Extensions = str([f for f in os.listdir( File_Types_Path ) if os.path.isfile( os.path.join( File_Types_Path, f ) )]).replace(".ft","")
40 Extensions = ast.literal_eval(Extensions)
41else:
42 Extensions = [ "zip" ]
43# Extensions = [ "adf","md","xbg","lnx","a78","a52","dim","nds","t64","d64","int","tap","z80","tzx","zip","bin","ccd","cue","j64","img","iso","rom","n64","z64","smd","smc","gb","gbc","gba","nes","sms","swc","gg","a26","a78","col","lnx","sfc","sg","fig","vms","exe" ]
44## Modified by me. Original by chunk_1970 - http://forum.kodi.tv/showthread.php?tid=24666&pid=125356#pid125356
45def Extract_XbeInfo(FileName): ## Need to use this as the xbe.py Get_title misses letter and causes string issues, even when using .encode or .decode
46 if os.path.isfile(FileName) and FileName.endswith('.xbe'):
47 xbe = open(FileName,'rb')
48 # Get XbeId Data #
49 xbe.seek(0x104)
50 tLoadAddr = xbe.read(4)
51 xbe.seek(0x118)
52 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 XbeTitle = ''
62 for dta in struct.unpack(operator.repeat('H',40),xbe.read(0x0050)):
63 try :
64 if dta != 00: XbeTitle += str(unichr(dta))
65 except : pass
66 XbeDta = str( str(XbeTitle) + '|' + str(hex(IdData[0])[2:10]).lower().zfill(8) )
67 xbe.close()
68 return XbeDta
69def Get_Title_Letter(Title_Letter):
70 Xbox_Thumb_Folder = {}
71 Title_Letter = Title_Letter.lower().lstrip(' ')
72 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 = "#"
73 if Title_Letter.startswith("a"): Xbox_Thumb_Folder = "A"
74 if Title_Letter.startswith("b"): Xbox_Thumb_Folder = "B"
75 if Title_Letter.startswith("c"): Xbox_Thumb_Folder = "C"
76 if Title_Letter.startswith("d"): Xbox_Thumb_Folder = "D"
77 if Title_Letter.startswith("e"): Xbox_Thumb_Folder = "E"
78 if Title_Letter.startswith("f"): Xbox_Thumb_Folder = "F"
79 if Title_Letter.startswith("g"): Xbox_Thumb_Folder = "G"
80 if Title_Letter.startswith("h"): Xbox_Thumb_Folder = "H"
81 if Title_Letter.startswith("i"): Xbox_Thumb_Folder = "I"
82 if Title_Letter.startswith("j"): Xbox_Thumb_Folder = "J"
83 if Title_Letter.startswith("k"): Xbox_Thumb_Folder = "K"
84 if Title_Letter.startswith("l"): Xbox_Thumb_Folder = "L"
85 if Title_Letter.startswith("m"): Xbox_Thumb_Folder = "M"
86 if Title_Letter.startswith("n"): Xbox_Thumb_Folder = "N"
87 if Title_Letter.startswith("o"): Xbox_Thumb_Folder = "O"
88 if Title_Letter.startswith("p"): Xbox_Thumb_Folder = "P"
89 if Title_Letter.startswith("q"): Xbox_Thumb_Folder = "Q"
90 if Title_Letter.startswith("r"): Xbox_Thumb_Folder = "R"
91 if Title_Letter.startswith("s"): Xbox_Thumb_Folder = "S"
92 if Title_Letter.startswith("t"): Xbox_Thumb_Folder = "T"
93 if Title_Letter.startswith("u"): Xbox_Thumb_Folder = "U"
94 if Title_Letter.startswith("v"): Xbox_Thumb_Folder = "V"
95 if Title_Letter.startswith("w"): Xbox_Thumb_Folder = "W"
96 if Title_Letter.startswith("x"): Xbox_Thumb_Folder = "X"
97 if Title_Letter.startswith("y"): Xbox_Thumb_Folder = "Y"
98 if Title_Letter.startswith("z"): Xbox_Thumb_Folder = "Z"
99 return Xbox_Thumb_Folder
100def Main_Code():
101 ## These are outside the loop so they don't reset every time.
102 ## Set the dialog create & found roms var.
103 CreateDialog = 1
104 Found_Roms = 0
105 intialrun = 0
106 Use_NoIntroNames = 0
107 _Resources = 0
108 Allow_Xbox_Overwrite = 0
109 ## Check if _emulators directory is selected instead of the emulator its self.
110 if os.path.isdir( Emulator_Folder_Path ):
111 ## Parse all folder in the Emulators_Path
112 if not os.path.isdir( os.path.join( Emulator_Folder_Path, "xbox" ) ): os.makedirs( os.path.join( Emulator_Folder_Path, "xbox" ) )
113 for Emu_Folder in sorted( os.listdir( Emulator_Folder_Path ) ):
114 ## Set a load of variable.
115 CountList = 0; JumpList = 0; Jump_Counter = 8000
116 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;
117 Parse_CUE_CCD_ISO_File = 0; Parse_CUE_ZIP_ISO_ADF_File = 0; Parse_ISO_BIN_IMG_File = 0; Parse_CUE_File = 0; Parse_CCD_File = 0; Parse_ISO_File = 0; Parse_FBL_TXT = 0; Parse_Xbox_Games = 0; Parse_N64_TXT = 0; N64ID = "0"; FBA_Rom_Name = ""; Change_FBL_Rom_Path = 0; Change_Mame_Rom_Path = 0; Change_N64_Rom_Path = 0; Change_NeoGeoCD_Rom_Path = 0;
118 RomListCount = 0; RenameCount = 0; ArtworkCount = 0; ZipCount = 0;
119 Write_List_File = 1
120 Emu_XBE = "default.xbe"
121 Game_Directories = [ "E:\\Games\\", "F:\\Games\\", "G:\\Games\\", "E:\\Games1\\", "F:\\Games1\\", "G:\\Games1\\" ]
122 if ManualScan:
123 Select_Emu_Folder = dialog.select( "SELECT A SYSTEM",sorted( os.listdir( Emulator_Folder_Path ) ) )
124 if Select_Emu_Folder == -1: return
125 ## Set Emulators and Roms folder paths.
126 Emu_Path = os.path.join( Emulator_Folder_Path, sorted( os.listdir( Emulator_Folder_Path ) )[Select_Emu_Folder] )
127 Emu_Name = os.path.split(Emu_Path)[1]
128 Roms_Folder = os.path.join( Roms_Folder_Path, sorted( os.listdir( Emulator_Folder_Path ) )[Select_Emu_Folder] )
129 ## Convert Q:\\ to a direct path.
130 if Emu_Path.startswith("Q:\\"): Emu_Path = Emu_Path.replace( "Q:\\", Root_Directory )
131 ## Check for a default .xbe in the emulator path you selected.
132 if os.path.isfile( os.path.join( Emu_Path, "default.xbe" ) ) or Emu_Name == "xbox":
133 pass
134 else:
135 dialog.ok("ERROR","","No default.xbe found in this directory")
136 return Main_Code()
137 else:
138 ## Set emu_path/name variable for autoscan mode.
139 Emu_Path = os.path.join( Emulator_Folder_Path, Emu_Folder )
140 Emu_Name = os.path.split(Emu_Path)[1]
141 Roms_Folder = os.path.join( Roms_Folder_Path,Emu_Name )
142 if intialrun == 0:
143 intialrun = 1
144 ## 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.
145 if not Emu_Name == "xbox" and dialog.yesno("ROM DISPLAY NAMES","Do you want to use the names stored in the","synopsis files instead of the roms filenames?","If you select no, rom filenames will be used.") == 1:
146 Use_NoIntroNames = 1
147 if Emu_Name == "xbox" or Full_Scan == "auto":
148 if dialog.yesno("XBOX ARTWORK","Do you want to use _resources folders for art?","If you select no, covers will display your default.tbn","or an image will be extracted from the game xbe."): _Resources = 1
149 if dialog.yesno("UPDATE XBOX ARTWORK?","Selecting yes, will update any artwork that","differs from the currently cached artwork.","Selecting no will add only new artwork."): Allow_Xbox_Overwrite = 1
150 ## Set tbn and gameslist path variable.
151 Media_Path = os.path.join( Media_Folder_Path, Emu_Name )
152 Games_List_Path = os.path.join( Root_Directory, '.emustation\\gamelists', Emu_Name )
153 ## If genesis emulator is selected or found use megadrive synopsis files.
154 if Emu_Name == "genesis":
155 Synopsis_Zip = os.path.join( os.path.join( Synopsis_Path, 'megadrive' ) ) + '.zip'
156 elif Emu_Name == "famicom":
157 Synopsis_Zip = os.path.join( os.path.join( Synopsis_Path, 'nes' ) ) + '.zip'
158 elif Emu_Name == "tg16":
159 Synopsis_Zip = os.path.join( os.path.join( Synopsis_Path, 'pcengine' ) ) + '.zip'
160 elif Emu_Name == "tg-cd":
161 Synopsis_Zip = os.path.join( os.path.join( Synopsis_Path, 'pce-cd' ) ) + '.zip'
162 else:
163 Synopsis_Zip = os.path.join( os.path.join( Synopsis_Path, Emu_Name ) ) + '.zip'
164 if not Emu_Name == "xbox":
165 if not os.path.isdir( os.path.join( Media_Path,'boxart' ) ): os.makedirs( os.path.join( Media_Path,'boxart' ) )
166 if not os.path.isdir( os.path.join( Media_Path,'boxart3d' ) ): os.makedirs( os.path.join( Media_Path,'boxart3d' ) )
167 if not os.path.isdir( os.path.join( Media_Path,'logo' ) ): os.makedirs( os.path.join( Media_Path,'logo' ) )
168 if not os.path.isdir( os.path.join( Media_Path,'mix' ) ): os.makedirs( os.path.join( Media_Path,'mix' ) )
169 if not os.path.isdir( os.path.join( Media_Path,'videos' ) ): os.makedirs( os.path.join( Media_Path,'videos' ) )
170 if not os.path.isdir( os.path.join( Media_Path,'screenshots' ) ): os.makedirs( os.path.join( Media_Path,'screenshots' ) )
171 ## Check to see if the emulator is one of the below so I can change it rom type or path.
172 if Emu_Name == "fba" or Emu_Name == "fbl" or Emu_Name == "fblc" or Emu_Name == "fbaxxx":
173 Change_FBL_Rom_Path = 1
174 Parse_FBL_TXT = 1
175 elif Emu_Name == "amiga":
176 Parse_CUE_ZIP_ISO_ADF_File = 1
177 elif Emu_Name == "atarijaguar":
178 Roms_Folder = os.path.join( Emu_Path, 'roms' )
179 elif Emu_Name == "mame":
180 Change_Mame_Rom_Path = 1
181 elif Emu_Name == "n64":
182 Parse_N64_TXT = 1
183 Change_N64_Rom_Path = 1
184 elif Emu_Name == "neogeocd":
185 Change_NeoGeoCD_Rom_Path = 1
186 elif Emu_Name == "pce-cd":
187 Parse_CUE_File = 1
188 elif Emu_Name == "tg-cd":
189 Parse_CUE_File = 1
190 elif Emu_Name == "saturn":
191 Parse_CUE_CCD_ISO_File = 1
192 elif Emu_Name == "segacd":
193 Parse_CUE_File = 1
194 elif Emu_Name == "psx":
195 Parse_CUE_CCD_ISO_File = 1
196 elif Emu_Name == "xbox":
197 Parse_Xbox_Games = 1
198 Xbox_Games_Folder = "Z:\\temp\\xbox game list"
199 Roms_Folder = Xbox_Games_Folder
200 else:
201 pass
202 if Parse_CUE_File: Rom_Type_Total = (len(glob.glob1(Roms_Folder,'*.cue')))
203 if Parse_CUE_CCD_ISO_File: Rom_Type_Total = (len(glob.glob1(Roms_Folder,'*.cue')) + len(glob.glob1(Roms_Folder,'*.ccd')) + len(glob.glob1(Roms_Folder,'*.iso')))
204 if Parse_CUE_ZIP_ISO_ADF_File: 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')))
205 ## Convert Q:\\ to a direct path
206 if Roms_Folder.startswith("Q:\\"): Roms_Folder = Roms_Folder.replace( "Q:\\", Root_Directory )
207 ## Check to see if the emulators = rom folder is empty and exit if it is.
208 ## below slower than just doing what I do below.
209 # if len(os.walk(Roms_Folder).next()[2]) > 0:
210 if len(os.listdir( Roms_Folder )) > 0 or Emu_Name == "xbox":
211 ## Check to see if vars are the value I need and create a new dialog.
212 if CreateDialog == 1:
213 #CreateDialog = 0
214 if ManualScan:
215 pDialog.create( "MANUAL SCAN MODE","Initializing" )
216 else:
217 pDialog.create( "AUTO SCAN MODE","Initializing" )
218 pDialog.update(0,'Creating [B][UPPERCASE]' + Emu_Name + '[/UPPERCASE][/B] Rom list','','This can take some time, please be patient.')
219 ## Checking for .png artwork files and changing them to .jpg.
220 if not Emu_Name == "xbox":
221 for dirName, subdirList, fileList in os.walk( Media_Path ):
222 pDialog.update(0,'Checking [B]' + Emu_Name + '[/B] artwork.','','This can take some time, please be patient.' )
223 for PNGs in fileList:
224 if PNGs.endswith('.png'):
225 if os.path.isfile( os.path.join( dirName,PNGs[:-4] + '.jpg' ) ):
226 os.remove( os.path.join( dirName,PNGs[:-4] + '.jpg' ) )
227 os.rename( os.path.join( dirName,PNGs ),os.path.join( dirName,PNGs[:-4] + '.jpg' ))
228 pDialog.update((ArtworkCount * 100) / len( os.listdir( Media_Path ) ),'Checking [B]' + Emu_Name + '[/B] artwork file extensions.','[B]' + PNGs + '[/B]' ,'This can take some time, please be patient.' )
229 ArtworkCount = ArtworkCount + 1
230 ## Checking filenames case and not leading with capital renaming it to do so.
231 if not Emu_Name == "xbox" 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":
232 pDialog.update(0,'Checking [B]' + Emu_Name + '[/B] Rom filename casing.','','This can take some time, please be patient.' )
233 for Roms in sorted( os.listdir( Roms_Folder ) ):
234 Items_Full_Path = os.path.join( Roms_Folder, Roms )
235 if Items_Full_Path != os.path.join( Roms_Folder, Roms.lower() ):
236 #if Items_Full_Path != os.path.join( Roms_Folder, Roms.capitalize() ):
237 tempname = Items_Full_Path[:-1]
238 if not os.path.isfile( tempname ):
239 os.rename( Items_Full_Path, tempname )
240 os.rename( tempname, os.path.join( Roms_Folder, Roms.lower() ) )
241 #os.rename( tempname, os.path.join( Roms_Folder, Roms.capitalize() ) )
242 pDialog.update((RenameCount * 100) / len( os.listdir( Roms_Folder ) ),'Lower-casing rom names.','[B]' + Roms + '[/B]' ,'This can take some time, please be patient.' )
243 RenameCount = RenameCount + 1
244 ## Setting a var again :/
245 Found_Roms = 1
246 ## Check if fbl was found and change its rom path to where the roms are located.
247 if Change_FBL_Rom_Path == 1:
248 if os.path.isfile(os.path.join( Emu_Path, 'Path.ini')):
249 for line in fileinput.input(os.path.join( Emu_Path, 'Path.ini'), inplace=1):
250 if 'ROMPath1=' in line:
251 line = line = 'ROMPath1=' + Roms_Folder + '\n'
252 print line,
253 Change_FBL_Rom_Path = 0
254 else:
255 with open(os.path.join( Emu_Path, 'Path.ini'), "w") as outputfblfile:
256 WriteFblFile = fbl_config % ( Roms_Folder )
257 outputfblfile.write( WriteFBlFile )
258 Change_FBL_Rom_Path = 0
259 ## Check if mame was found and change it rom path to where the roms are located.
260 if Change_Mame_Rom_Path == 1:
261 if not os.path.isdir(os.path.join( Emu_Path, "system")):
262 os.makedirs( os.path.join( Emu_Path, "system") )
263 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") )
264 if os.path.isfile(os.path.join( Emu_Path, "system\\MAMEoX.ini")):
265 for line in fileinput.input(os.path.join( Emu_Path, "system\\MAMEoX.ini"), inplace=1):
266 if 'RomsPath0 = ' in line:
267 line = line = 'RomsPath0 = ' + Roms_Folder + '\n'
268 print line,
269 Change_Mame_Rom_Path = 0
270 else:
271 with open( os.path.join( Emu_Path, "system\\MAMEoX.ini"), "w") as outputmamefile:
272 WriteMameFile = mame_config % ( Roms_Folder )
273 outputmamefile.write( WriteMameFile )
274 Change_Mame_Rom_Path = 0
275 ## Creating Xbox game list so its in alphabetical order.
276 if Parse_Xbox_Games == 1:
277 if os.path.isdir( Roms_Folder ): shutil.rmtree( Roms_Folder )
278 if not os.path.isdir( Roms_Folder ): os.makedirs( Roms_Folder )
279 previouse_title = ""
280 dup_count = 1
281 altnumb = 1
282 for Game_Dirs in Game_Directories:
283 if os.path.isdir( Game_Dirs ):
284 for Item in sorted([f for f in os.listdir( Game_Dirs )]):
285 pDialog.update(0,'Sorting List Order & Artwork For [B][UPPERCASE]' + Emu_Name + '[/UPPERCASE][/B] Games','[B][UPPERCASE]' + Item + '[/UPPERCASE][/B]','This can take some time, please be patient.')
286 if os.path.isdir(os.path.join( Game_Dirs, Item)):
287 Game_Directory = os.path.join( Game_Dirs, Item )
288 if os.path.isfile( os.path.join( Game_Directory, "game.xbe" ) ):
289 XBEFile = os.path.join( Game_Directory, "game.xbe" )
290 else:
291 XBEFile = os.path.join( Game_Directory, "default.xbe" )
292 if os.path.isfile( XBEFile ):
293 _Resources_PosterFile = os.path.join( Game_Directory, "_resources\\artwork\\poster.jpg" )
294 _Resources_Poster3dFile = os.path.join( Game_Directory, "_resources\\artwork\\dual3d.png" )
295 _Resources_CDFile = os.path.join( Game_Directory, "_resources\\artwork\\cd.png" )
296 _Resources_CDPosterFile = os.path.join( Game_Directory, "_resources\\artwork\\cdposter.png" )
297 _Resources_IconFile = os.path.join( Game_Directory, "_resources\\artwork\\icon.png" )
298 _Resources_ThumbFile = os.path.join( Game_Directory, "_resources\\artwork\\thumb.jpg" )
299 _Resources_FanartFile = os.path.join( Game_Directory, "_resources\\artwork\\fanart.jpg" )
300 _Resources_BannerFile = os.path.join( Game_Directory, "_resources\\artwork\\banner.png" )
301 _Resources_OpenCaseFile = os.path.join( Game_Directory, "_resources\\artwork\\opencase.png" )
302 _Resources_Screenshot = os.path.join( Game_Directory, "_resources\\screenshots\\screenshot-1.jpg" )
303 _Resources_Synopsis = os.path.join( Game_Directory, "_resources\\default.xml" )
304 TBNFile = os.path.join( Game_Directory, "default.tbn" )
305 FanartFile = os.path.join( Game_Directory, "fanart.jpg" )
306 Emu_XBE = XBEFile
307 # 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
308 XBEInfo = Extract_XbeInfo( os.path.join( Game_Directory, "default.xbe" ) ).split('|')
309 XBETitle = XBEInfo[0].lstrip(' ')
310 XBEInfo = Extract_XbeInfo( XBEFile ).split('|')
311 XBEID = XBEInfo[1]
312 # use the folder name if the xbe title is corrupt or not there.
313 if XBETitle == "": XBETitle = Item.lstrip(' ')
314 XBETitle_List = xbmc.makeLegalFilename( Xbox_Games_Folder + '\\' + XBETitle.lower().replace('/','').replace('\\','').replace(' ','') )
315 # Get first letter of the games titleid and set a variable
316 Xbox_Thumb_Folder = Get_Title_Letter( XBETitle )
317 # Create folder structure for xbox games to speed up loading of images
318 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 ) )
319 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 ) )
320 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 ) )
321 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 ) )
322 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 ) )
323 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 ) )
324 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 ) )
325 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 ) )
326 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 ) )
327 if os.path.isfile( os.path.join( Roms_Folder, 'idlist.xml' ) ):
328 if str(XBEID) in open( os.path.join( Roms_Folder, 'idlist.xml' ) ).read():
329 XBEID = str(XBEID)+"_"+str(dup_count)
330 dup_count = dup_count+1
331 if _Resources == 0:
332 if os.path.isfile( TBNFile ):
333 # Default.tbn
334 if os.path.isfile( os.path.join( Media_Folder_Path + "xbox\\boxart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) ):
335 if Allow_Xbox_Overwrite == 1 and not filecmp.cmp( os.path.join( Media_Folder_Path + "xbox\\boxart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) , TBNFile, shallow=0 ):
336 shutil.copy2( TBNFile, os.path.join( Media_Folder_Path + "xbox\\boxart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) )
337 else:
338 shutil.copy2( TBNFile, os.path.join( Media_Folder_Path + "xbox\\boxart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) )
339 else:
340 # TITLEIMAGE
341 try:
342 XBE( XBEFile ).Get_title_image().Write_PNG( os.path.join( Media_Folder_Path + "xbox\\boxart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) )
343 except:
344 pass
345 if os.path.isfile( os.path.join( Media_Folder_Path + "xbox\\fanart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) ):
346 if os.path.isfile( FanartFile ):
347 if Allow_Xbox_Overwrite == 1 and not filecmp.cmp( os.path.join( Media_Folder_Path + "xbox\\fanart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) , FanartFile, shallow=0 ):
348 shutil.copy2( FanartFile, Media_Folder_Path + "xbox\\fanart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
349 else:
350 if os.path.isfile( FanartFile ):
351 shutil.copy2( FanartFile, Media_Folder_Path + "xbox\\fanart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
352 else:
353 # _Resources folder structure
354 # Poster
355 if os.path.isfile( os.path.join( Media_Folder_Path + "xbox\\boxart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) ):
356 #print XBEID + " baxart already present"
357 if os.path.isfile( _Resources_PosterFile ):
358 if Allow_Xbox_Overwrite == 1 and not filecmp.cmp( os.path.join( Media_Folder_Path + "xbox\\boxart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ), _Resources_PosterFile, shallow=0 ):
359 if os.path.isfile( _Resources_PosterFile ):
360 shutil.copy2( _Resources_PosterFile, Media_Folder_Path + "xbox\\boxart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
361 else:
362 if os.path.isfile( _Resources_PosterFile ):
363 shutil.copy2( _Resources_PosterFile, Media_Folder_Path + "xbox\\boxart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
364 # Default.tbn
365 elif os.path.isfile( TBNFile ):
366 shutil.copy2( TBNFile, Media_Folder_Path + "xbox\\boxart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
367 else:
368 # TITLEIMAGE
369 try:
370 XBE( XBEFile ).Get_title_image().Write_PNG( os.path.join( Media_Folder_Path + "xbox\\boxart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) )
371 except:
372 pass
373 # 3D Boxart
374 if os.path.isfile( os.path.join( Media_Folder_Path + "xbox\\boxart3d\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) ):
375 #print XBEID + " 3d boxart already present"
376 if os.path.isfile( _Resources_IconFile ):
377 if Allow_Xbox_Overwrite == 1 and not filecmp.cmp( os.path.join( Media_Folder_Path + "xbox\\boxart3d\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ), _Resources_IconFile, shallow=0 ):
378 if os.path.isfile( _Resources_IconFile ):
379 shutil.copy2( _Resources_IconFile, Media_Folder_Path + "xbox\\boxart3d\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
380 else:
381 if os.path.isfile( _Resources_IconFile ):
382 shutil.copy2( _Resources_IconFile, Media_Folder_Path + "xbox\\boxart3d\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
383 # CD
384 if os.path.isfile( os.path.join( Media_Folder_Path + "xbox\\disc\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) ):
385 #print XBEID + " cd already present"
386 if os.path.isfile( _Resources_CDFile ):
387 if Allow_Xbox_Overwrite == 1 and not filecmp.cmp( os.path.join( Media_Folder_Path + "xbox\\disc\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ), _Resources_CDFile, shallow=0 ):
388 if os.path.isfile( _Resources_CDFile ):
389 shutil.copy2( _Resources_CDFile, Media_Folder_Path + "xbox\\disc\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
390 else:
391 if os.path.isfile( _Resources_CDFile ):
392 shutil.copy2( _Resources_CDFile, Media_Folder_Path + "xbox\\disc\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
393 # Disc case
394 if os.path.isfile( os.path.join( Media_Folder_Path + "xbox\\cdposter\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) ):
395 #print XBEID + " disc case already present"
396 if os.path.isfile( _Resources_CDPosterFile ):
397 if Allow_Xbox_Overwrite == 1 and not filecmp.cmp( os.path.join( Media_Folder_Path + "xbox\\cdposter\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ), _Resources_CDPosterFile, shallow=0 ):
398 if os.path.isfile( _Resources_CDPosterFile ):
399 shutil.copy2( _Resources_CDPosterFile, Media_Folder_Path + "xbox\\cdposter\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
400 else:
401 if os.path.isfile( _Resources_CDPosterFile ):
402 shutil.copy2( _Resources_CDPosterFile, Media_Folder_Path + "xbox\\cdposter\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
403 # Dual 3D
404 if os.path.isfile( os.path.join( Media_Folder_Path + "xbox\\dual\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) ):
405 #print XBEID + " dual 3d already present"
406 if os.path.isfile( _Resources_Poster3dFile ):
407 if Allow_Xbox_Overwrite == 1 and not filecmp.cmp( os.path.join( Media_Folder_Path + "xbox\\dual\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ), _Resources_Poster3dFile, shallow=0 ):
408 if os.path.isfile( _Resources_Poster3dFile ):
409 shutil.copy2( _Resources_Poster3dFile, Media_Folder_Path + "xbox\\dual\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
410 else:
411 if os.path.isfile( _Resources_Poster3dFile ):
412 shutil.copy2( _Resources_Poster3dFile, Media_Folder_Path + "xbox\\dual\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
413 # Open Case
414 if os.path.isfile( os.path.join( Media_Folder_Path + "xbox\\opencase\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) ):
415 #print XBEID + " mix already present"
416 if os.path.isfile( _Resources_OpenCaseFile ):
417 if Allow_Xbox_Overwrite == 1 and not filecmp.cmp( os.path.join( Media_Folder_Path + "xbox\\opencase\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ), _Resources_OpenCaseFile, shallow=0 ):
418 if os.path.isfile( _Resources_OpenCaseFile ):
419 shutil.copy2( _Resources_OpenCaseFile, Media_Folder_Path + "xbox\\opencase\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
420 else:
421 if os.path.isfile( _Resources_OpenCaseFile ):
422 shutil.copy2( _Resources_OpenCaseFile, Media_Folder_Path + "xbox\\opencase\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
423 # Fanart
424 if os.path.isfile( os.path.join( Media_Folder_Path + "xbox\\fanart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) ):
425 #print XBEID + " fanart already present"
426 if os.path.isfile( _Resources_FanartFile ):
427 if Allow_Xbox_Overwrite == 1 and not filecmp.cmp( os.path.join( Media_Folder_Path + "xbox\\fanart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ), _Resources_FanartFile, shallow=0 ):
428 if os.path.isfile( _Resources_FanartFile ):
429 shutil.copy2( _Resources_FanartFile, Media_Folder_Path + "xbox\\fanart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
430 elif os.path.isfile( FanartFile ):
431 shutil.copy2( FanartFile, Media_Folder_Path + "xbox\\fanart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
432 else:
433 if os.path.isfile( _Resources_FanartFile ):
434 shutil.copy2( _Resources_FanartFile, Media_Folder_Path + "xbox\\fanart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
435 elif os.path.isfile( FanartFile ):
436 shutil.copy2( FanartFile, Media_Folder_Path + "xbox\\fanart\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
437 # Screenshots
438 if os.path.isfile( os.path.join( Media_Folder_Path + "xbox\\screenshots\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ) ):
439 #print XBEID + " screenshots already present"
440 if os.path.isfile( _Resources_Screenshot ):
441 if Allow_Xbox_Overwrite == 1 and not filecmp.cmp( os.path.join( Media_Folder_Path + "xbox\\screenshots\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" ), _Resources_Screenshot, shallow=0 ):
442 if os.path.isfile( _Resources_Screenshot ):
443 shutil.copy2( _Resources_Screenshot, Media_Folder_Path + "xbox\\screenshots\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
444 else:
445 if os.path.isfile( _Resources_Screenshot ):
446 shutil.copy2( _Resources_Screenshot, Media_Folder_Path + "xbox\\screenshots\\" + Xbox_Thumb_Folder + '\\' + XBEID + ".jpg" )
447 # Videos
448 for Files in glob.glob( os.path.join( Game_Directory, "_resources\\media\\*.*") ):
449 if os.path.isfile( os.path.join( Media_Folder_Path + "xbox\\videos\\" + Xbox_Thumb_Folder + '\\' + XBEID + os.path.splitext(Files)[1] ) ):
450 #print XBEID + " videos already present"
451 if os.path.isfile( Files ):
452 if Allow_Xbox_Overwrite == 1 and not filecmp.cmp( os.path.join( Media_Folder_Path + "xbox\\videos\\" + Xbox_Thumb_Folder + '\\' + XBEID + os.path.splitext(Files)[1] ), Files, shallow=0 ):
453 if os.path.isfile( Files ):
454 shutil.copy2( Files, Media_Folder_Path + "xbox\\videos\\" + Xbox_Thumb_Folder + '\\' + XBEID + os.path.splitext(Files)[1] )
455 else:
456 if os.path.isfile( Files ):
457 shutil.copy2( Files, Media_Folder_Path + "xbox\\videos\\" + Xbox_Thumb_Folder + '\\' + XBEID + os.path.splitext(Files)[1] )
458 with open( os.path.join( Roms_Folder, 'idlist.xml' ), "a") as idlistfile:
459 idlistoutput = str(XBEID)+"\n"
460 idlistfile.write( idlistoutput )
461 if previouse_title == XBETitle_List:
462 with open( XBETitle_List[:56] + "_alt"+str(altnumb)+".xbg","w") as ouput:
463 ouput.write(XBETitle + " ( Duplicate Name " + str(altnumb) + " )\n")
464 ouput.write(Emu_XBE + "\n")
465 ouput.write(Xbox_Thumb_Folder + "\n")
466 ouput.write(XBEID)
467 altnumb = altnumb+1
468 else:
469 with open( XBETitle_List[:61] + ".xbg","w") as ouput:
470 ouput.write(XBETitle + "\n")
471 ouput.write(Emu_XBE + "\n")
472 ouput.write(Xbox_Thumb_Folder + "\n")
473 ouput.write(XBEID)
474 previouse_title = XBETitle_List
475 ## Extracting the rom name files from the zip.
476 if Parse_FBL_TXT == 1:
477 if os.path.isfile( os.path.join( Emu_Path, "info\\FBL Rom Names.zip" ) ):
478 with zipfile.ZipFile( os.path.join( Emu_Path, "info\\FBL Rom Names.zip" ) ) as zip:
479 if not os.path.isdir( os.path.join( Emu_Path, "info\\rom names" ) ): os.makedirs( os.path.join( Emu_Path, "info\\rom names" ) )
480 if ZipCount == 0:
481 #pDialog.create( "EXTRACTING ZIP","","Please wait..." )
482 Total_TXT_Files = len( zip.namelist() ) or 1
483 Devide = 100.0 / Total_TXT_Files
484 Percent = 0
485 for item in zip.namelist():
486 Percent += Devide
487 pDialog.update( int( Percent ),'Extracting FBA, FBAXXX, FBL or FBLC rom names','This only happens once per update','' )
488 zip.extract( item, os.path.join( Emu_Path, "info\\rom names\\" ) )
489 ZipCount = 1
490 os.remove( os.path.join( Emu_Path, "info\\FBL Rom Names.zip" ) )
491 Roms_Folder = os.path.join( Emu_Path, "info\\rom names" )
492 ## Used to name the rom name files so I can sort them by alphabetical order properly. ( this is only used by me )
493 # for files in sorted( os.listdir( os.path.join( Emu_Path, "info\\rom names" ) ) ):
494 # try:
495 # with open( os.path.join( Emu_Path, "info\\rom names", files[:-3] + 'txt' ), 'r') as txt:
496 # FBA_Rom_Name_Full = txt.readline()[:-2]
497 # FBA_Rom_Name = FBA_Rom_Name_Full[:20]
498 # FBA_Rom_Name = FBA_Rom_Name.replace( ',','' ); FBA_Rom_Name = FBA_Rom_Name.replace( ':','' ); FBA_Rom_Name = FBA_Rom_Name.replace( ';','' ); FBA_Rom_Name = FBA_Rom_Name.replace( '/','' ); FBA_Rom_Name = FBA_Rom_Name.replace( '?','' ); FBA_Rom_Name = FBA_Rom_Name.replace( '+','' ); FBA_Rom_Name = FBA_Rom_Name.replace( '*','' ); FBA_Rom_Name = FBA_Rom_Name.replace( 'amp','' ); FBA_Rom_Name = FBA_Rom_Name.replace( ' ','' );
499 # FBA_Rom_Name = FBA_Rom_Name.lower()
500 # for line in txt: FBA_Rom_System_Full = '\n'+line
501 # if not os.path.isdir( "F:\\rom names" ): os.makedirs( "F:\\rom names" )
502 # with open( os.path.join( "F:\\rom names", FBA_Rom_Name + '--' + files[:-3] + 'zip' ), 'w') as txt:
503 # txt.write( FBA_Rom_Name_Full.lower() )
504 # txt.write( FBA_Rom_System_Full.lower() )
505 # pDialog.update((CountList * 100) / len(os.listdir( os.path.join( Emu_Path, 'info\\rom names' ) ) ),'Processing Rom name files',files,'This can take some time, please be patient.' )
506 # CountList = CountList + 1
507 # except: pass
508 # return
509 ## Check for previous layout xml and if it exists remove it.
510 if os.path.isdir( Games_List_Path ): shutil.rmtree( Games_List_Path )
511 if not os.path.isdir( Games_List_Path ): os.makedirs( Games_List_Path )
512 if Parse_Xbox_Games == 1 and os.path.isfile( os.path.join( Media_Folder_Path, "xbox\\GameNames.txt" ) ): os.remove( os.path.join( Media_Folder_Path, "xbox\\GameNames.txt" ) )
513 ## Write new gamelist xml header.
514 with open( os.path.join( Games_List_Path, 'gamelist.xml' ), "wb") as outputmenufile:
515 WriteMenuFile = menu_entry_header
516 outputmenufile.write( WriteMenuFile )
517 ## Listing the content of the roms folder for parsing.
518 for Items in sorted([f for f in os.listdir( Roms_Folder )]):
519 ## Checking the file I find, extension against my table.
520 if Items.lower().endswith(tuple(Extensions)) or Emu_Name == "neogeocd":
521 ## More vars being set.
522 Rom_Name = Items.lower()
523 Rom_Name_noext, Rom_Extension = os.path.splitext(Rom_Name)
524 if Emu_Name == "xbox":
525 with open(os.path.join( Xbox_Games_Folder, Rom_Name ), "r") as input:
526 Rom_Name_noext = input.readline()
527 Emu_XBE = input.readline()
528 skip = input.readline()
529 XBE_ID = input.readline()
530 JumpList_Name = Rom_Name_noext.lower()
531 if not xbmc.getCondVisibility( 'Skin.String(' + Emu_Name + '_artworkfolder)' ): xbmc.executebuiltin('Skin.SetString(' + Emu_Name + '_artworkfolder,boxart)')
532 Thumbnail = Rom_Name_noext + '.jpg'
533 ## Check if fba was found and parse the name text files to get the correct rom names and system types for the list.
534 if Parse_FBL_TXT == 1:
535 Rom_Name_Full = Rom_Name
536 Rom_Name_Beg = Rom_Name.split('--', 1)[0]
537 Rom_Name = Rom_Name.split('--', 1)[1]
538 Rom_Name_noext, Rom_Extension = os.path.splitext(Rom_Name)
539 Thumbnail = Rom_Name_noext + '.jpg'
540 if os.path.isfile( os.path.join( Roms_Folder_Path, Emu_Name, Rom_Name ) ) and os.path.isfile( os.path.join( Emu_Path, "info\\rom names", Rom_Name_Beg + '--' + Rom_Name ) ):
541 with open( os.path.join( Emu_Path, "info\\rom names", Rom_Name_Beg + '--' + Rom_Name ), 'r') as txt:
542 FBA_Rom_Name = txt.readline()[:-1]
543 #FBA_Rom_Name = FBA_Rom_Name.split('(', 1)[0]
544 #FBA_Rom_Name = FBA_Rom_Name.split('/', 1)[0]
545 for line in txt:
546 System_Name = line.lower()[:-2]
547 Emu_XBE = "default.xbe"
548 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"
549 if System_Name == "neo geo aes" or System_Name == "neo geo mvs": Emu_XBE = "neogeocps2.xbe"
550 if System_Name == "cps2": Emu_XBE = "neogeocps2.xbe"
551 if System_Name == "cave": Emu_XBE = "cave.xbe"
552 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"
553 if System_Name == "to": Emu_XBE = "taito.xbe"
554 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"
555 if System_Name == "de": Emu_XBE = "dataeast.xbe"
556 if System_Name == "kn": Emu_XBE = "konami.xbe"
557 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"
558 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"
559 if System_Name == "im": Emu_XBE = "irem.xbe"
560 JumpList_Name = Rom_Name_Full.lower()
561 Write_List_File = 1
562 elif Rom_Name == "isgsm.zip":
563 Write_List_File = 0
564 elif Rom_Name == "neogeo.zip":
565 Write_List_File = 0
566 elif Rom_Name == "nmk004.zip":
567 Write_List_File = 0
568 elif Rom_Name == "pgm.zip":
569 Write_List_File = 0
570 else:
571 Write_List_File = 0
572 ## Check if n64 was found and parse the names from surreal.ini if the roms match.
573 if Parse_N64_TXT == 1:
574 if os.path.isfile(os.path.join( Emu_Path, 'surreal.ini' )):
575 if Change_N64_Rom_Path == 1:
576 if os.path.isdir( 'E:\\TDATA\\64ce64ce' ): shutil.rmtree( 'E:\\TDATA\\64ce64ce' )
577 for line in fileinput.input( os.path.join( Emu_Path, 'surreal.ini' ), inplace=1):
578 if 'Rom Path=' in line:
579 line = line = 'Rom Path=' + Roms_Folder + '\n'
580 print line,
581 os.makedirs( 'E:\\TDATA\\64ce64ce' )
582 with open( os.path.join( 'E:\\TDATA\\64ce64ce\\surreal-ce.ini' ), "w") as outputn64file:
583 WriteN64File = n64_config % ( Roms_Folder )
584 outputn64file.write( WriteN64File )
585 Change_N64_Rom_Path = 0
586 Bypass_N64_Check = 0
587 ## Extracting the rom names from the ini.
588 N64linenumb = 1
589 foundN64line = 0
590 with open( os.path.join( Emu_Path, 'surreal.ini' ), 'r') as ini:
591 for line in itertools.islice(ini,0,None):
592 if line.lower().startswith('[dcbc50d1'): foundN64line = 1
593 if foundN64line == 1:
594 N64ID = str(line.lower())
595 N64ID = N64ID[1:]
596 N64ID1 = N64ID.split('-')[0]
597 N64ID2 = N64ID.split('-')[1]
598 File_Name = ini.next().replace('Game Name=','')[:-1]
599 File_Name = File_Name.lower()
600 if os.path.isdir( os.path.join( Emu_Path, 'media\\Cbagys3DArt' ) ):
601 if File_Name == "007 goldeneye (ultrahle)720pno" or Bypass_N64_Check == 1:
602 Bypass_N64_Check = 1
603 if Rom_Name_noext == File_Name:
604 N64_Rom_Name = ini.next().replace('Alternate Title=','')[:-1]
605 N64_Rom_Name = N64_Rom_Name.split(' (', 1)[0]
606 try:
607 ini.next() # skip the comment line
608 ini.next() # skip the blank line
609 except: pass
610 for N64_Thumb in os.listdir( os.path.join( Emu_Path, 'media\\Cbagys3DArt' ) ):
611 N64_Thumb = N64_Thumb.lower()
612 if N64ID1 in N64_Thumb or N64ID2 in N64_Thumb:
613 if not os.path.isdir( os.path.join( Synopsis_Path, Emu_Name ) ): os.makedirs( os.path.join( Synopsis_Path, Emu_Name ) )
614 N64_Thumb_Location = os.path.join( Emu_Path, 'media\\Cbagys3DArt', N64_Thumb )
615 #shutil.copy2( N64_Thumb_Location, "E:\\1\\" )
616 N64_Thumb_Destination = os.path.join( Media_Path, 'boxart', File_Name + '.jpg' )
617 if os.path.isfile( N64_Thumb_Location ) and not os.path.isfile( N64_Thumb_Destination ): shutil.copy2( N64_Thumb_Location, N64_Thumb_Destination )
618 for N64_Thumb in os.listdir( os.path.join( Emu_Path, 'media\\Movies' ) ):
619 N64_Thumb = N64_Thumb.lower()
620 if N64ID1 in N64_Thumb or N64ID2 in N64_Thumb:
621 if not os.path.isdir( os.path.join( Media_Path, 'videos' ) ): os.makedirs( os.path.join( Media_Path, 'videos' ) )
622 N64_Thumb_Location = os.path.join( Emu_Path, 'media\\Movies', N64_Thumb )
623 N64_Thumb_Destination = os.path.join( Media_Path, 'videos', File_Name + N64_Thumb[-4:] )
624 if os.path.isfile( N64_Thumb_Location ) and not os.path.isfile( N64_Thumb_Destination ): shutil.copy2( N64_Thumb_Location, N64_Thumb_Destination )
625 for N64_Synopsis in os.listdir( os.path.join( Emu_Path, 'media\\synopsis' ) ):
626 N64_Synopsis = N64_Synopsis.lower()
627 if N64ID1 in N64_Synopsis or N64ID2 in N64_Synopsis:
628 N64_Synopsis_Location = os.path.join( Emu_Path, 'media\\synopsis', N64_Synopsis[:-3] + 'txt' )
629 #shutil.copy2( N64_Synopsis_Location, "E:\\2\\" )
630 N64_Synopsis_Destination = os.path.join( Synopsis_Path, Emu_Name, File_Name + '.txt' )
631 #if os.path.isfile( N64_Synopsis_Location ) and not os.path.isfile( N64_Synopsis_Destination ):
632 if os.path.isfile( N64_Synopsis_Location ):
633 with open( N64_Synopsis_Location ) as readn64tmp:
634 readn64 = readn64tmp.read()
635 readn64 = readn64.strip()
636 with open( N64_Synopsis_Destination, 'w' ) as n64tmp:
637 amended_n64tmp = 'Name: ' + readn64
638 n64tmp.write(amended_n64tmp)
639 #if os.path.isfile( N64_Synopsis_Location ): shutil.copy2( N64_Synopsis_Location, N64_Synopsis_Destination )
640 else:
641 try:
642 ini.next() # skip the rom name
643 ini.next() # skip the comment line
644 ini.next() # skip the blank line
645 except: pass
646 else:
647 dialog.ok("ERROR","","This isn't [B]EarthWormsJames[/B][CR]N64 emulator best of compilation")
648 return
649 else:
650 dialog.ok("ERROR","","Reinstall the [B]EarthWormsJames[/B] N64 emulator.[CR]The Cbagys3DArt folder is missing.")
651 return
652 else:
653 ini.next()
654 N64linenumb += 1
655 if N64linenumb >= 30 and foundN64line == 0:
656 dialog.ok("ERROR","","Surreal.ini is corrupt or not formatted correctly[CR]Recopy/Download [B]EarthWormsJames[/B] N64 emulator")
657 return
658 else:
659 dialog.ok("ERROR","","Surreal.ini is missing from the","N64 Emulators directory")
660 return
661 ## Change neogeocd rom path.
662 if Change_NeoGeoCD_Rom_Path == 1:
663 if os.path.isfile(os.path.join( Emu_Path, "path.txt" )):
664 with open( os.path.join( os.path.join( Emu_Path, "path.txt" ) ), "w") as outputneogeocdfile:
665 WriteneogeocdFile = "rompath " + Roms_Folder + '\\\n'
666 outputneogeocdfile.write( WriteneogeocdFile )
667 Change_NeoGeoCD_Rom_Path = 0
668 else:
669 dialog.ok("ERROR","","path.txt is missing from the","Neogeocd Emulators directory")
670 return
671 ## Check for a synopsis zip for the current emulator.
672 if ZipCount == 0:
673 if os.path.isfile( Synopsis_Zip ):
674 ## Extracting the synopsis files from the zip.
675 with zipfile.ZipFile( Synopsis_Zip ) as zip:
676 if ZipCount == 0:
677 #pDialog.create( "EXTRACTING ZIP","","Please wait..." )
678 Total_TXT_Files = len( zip.namelist() ) or 1
679 Devide = 100.0 / Total_TXT_Files
680 Percent = 0
681 for item in zip.namelist():
682 Percent += Devide
683 pDialog.update( int( Percent ),'Extracting [B][UPPERCASE]' + Emu_Name + '[/UPPERCASE][/B] Synopsis files.',item,'' )
684 zip.extract( item, Synopsis_Path )
685 ZipCount = 1
686 os.remove( os.path.join( Synopsis_Zip ) )
687 else:
688 pass
689 ## Check for a synopsis file for the current emulator and parse it.
690 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'
691 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
692 try:
693 if Emu_Name == "genesis":
694 Synopsis_File = os.path.join( Synopsis_Path, "megadrive", Rom_Name_noext + '.txt' )
695 elif Emu_Name == "famicom":
696 Synopsis_File = os.path.join( Synopsis_Path, "nes", Rom_Name_noext + '.txt' )
697 elif Emu_Name == "tg16":
698 Synopsis_File = os.path.join( Synopsis_Path, "pcengine", Rom_Name_noext + '.txt' )
699 elif Emu_Name == "tg-cd":
700 Synopsis_File = os.path.join( Synopsis_Path, "pce-cd", Rom_Name_noext + '.txt' )
701 elif Emu_Name == "fbl" or Emu_Name == "fblc" or Emu_Name == "fbaxxx":
702 Synopsis_File = os.path.join( Synopsis_Path, "fba", Rom_Name_noext + '.txt' )
703 elif Emu_Name == "xbox":
704 if '_' in XBE_ID:
705 Synopsis_File = os.path.join( Synopsis_Path, "xbox", XBE_ID.split('_', 1)[0] + '.txt' )
706 else:
707 Synopsis_File = os.path.join( Synopsis_Path, "xbox", XBE_ID + '.txt' )
708 else:
709 Synopsis_File = os.path.join( Synopsis_Path, Emu_Name, Rom_Name_noext + '.txt' )
710 with open( Synopsis_File ) as input:
711 Synopsis = input.read()
712 Synopsis1 = Synopsis.split('_________________________', 1)[0]
713 Synopsis1 = Synopsis1.split('\n')
714 for _ in range(11):
715 for line in Synopsis1:
716 line = line.lower()
717 if line.startswith('name:') and Use_NoIntroNames == 1:
718 if Emu_Name == "fba" or Emu_Name == "fbl" or Emu_Name == "fblc" or Emu_Name == "fbaxxx":
719 FBA_Rom_Name = line.split(': ',1)[1]
720 Synopsis_nointroname_Set = 1
721 elif Emu_Name == "n64":
722 Rom_Name_noext = line.split(': ',1)[1]
723 if Rom_Name_noext.startswith('the'):
724 N64_Rom_Name = Rom_Name_noext[4:] + ', the'
725 # else:
726 # N64_Rom_Name = Rom_Name_noext.split(' (',1)[0]
727 Synopsis_nointroname_Set = 1
728 else:
729 Rom_Name_noext = line.split(': ',1)[1]
730 if Rom_Name_noext.startswith('the'):
731 Rom_Name_noext = Rom_Name_noext[4:] + ', the'
732 # else:
733 # Rom_Name_noext = Rom_Name_noext.split(' (',1)[0]
734 Synopsis_nointroname_Set = 1
735 elif Synopsis_nointroname_Set == 0:
736 pass
737 if Emu_Name == "xbox":
738 with open(os.path.join( Xbox_Games_Folder, Rom_Name ), "r") as input:
739 skip = input.readline()
740 skip = input.readline()
741 skip = input.readline()
742 Synopsis_filename = input.readline()
743 if '_' in Synopsis_filename:
744 Synopsis_filename = '[B]TITLEID:[/B][CR] ' + Synopsis_filename.split('_', 1)[0]
745 else:
746 Synopsis_filename = '[B]TITLEID:[/B][CR] ' + Synopsis_filename
747 else:
748 if line.startswith('filename:'):
749 Synopsis_filename = line.split(': ',1)[1]
750 Synopsis_filename = '[B]Filename:[/B][CR] ' + Synopsis_filename
751 Synopsis_filename_Set = 1
752 elif Synopsis_filename_Set == 0:
753 Synopsis_filename = '[B]Filename:[/B][CR] ' + Rom_Name
754 if line.startswith('rating:'):
755 Synopsis_rating = line.split(': ',1)[1]
756 Synopsis_rating = '[B]Rating:[/B][CR] ' + Synopsis_rating
757 Synopsis_rating_Set = 1
758 elif Synopsis_rating_Set == 0:
759 Synopsis_rating = '[B]Rating:[/B][CR] unknown'
760 if line.startswith('players:'):
761 Synopsis_players = line.split(': ',1)[1]
762 Synopsis_players = '[B]Players:[/B][CR] ' + Synopsis_players
763 Synopsis_players_Set = 1
764 elif Synopsis_players_Set == 0:
765 Synopsis_players = '[B]Players:[/B][CR] at least 1'
766 if line.startswith('genre:'):
767 Synopsis_genre = line.split(': ',1)[1]
768 Synopsis_genre = '[B]Genre:[/B][CR] ' + Synopsis_genre
769 Synopsis_genre_Set = 1
770 elif Synopsis_genre_Set == 0:
771 Synopsis_genre = '[B]Genre:[/B][CR] unknown'
772 if line.startswith('developer:'):
773 Synopsis_developer = line.split(': ',1)[1]
774 Synopsis_developer = '[B]Developer:[/B][CR] ' + Synopsis_developer
775 Synopsis_developer_Set = 1
776 elif Synopsis_developer_Set == 0:
777 Synopsis_developer = '[B]Developer:[/B][CR] unknown'
778 if line.startswith('publisher:'):
779 Synopsis_publisher = line.split(': ',1)[1]
780 Synopsis_publisher = '[B]Publisher:[/B][CR] ' + Synopsis_publisher
781 Synopsis_publisher_Set = 1
782 elif Synopsis_publisher_Set == 0:
783 Synopsis_publisher = '[B]Publisher:[/B][CR] unknown'
784 if line.startswith('release year:'):
785 Synopsis_release_year = line.split(': ',1)[1]
786 Synopsis_release_year = '[B]Released:[/B][CR] ' + Synopsis_release_year
787 Synopsis_release_year_Set = 1
788 elif Synopsis_release_year_Set == 0:
789 Synopsis_release_year = '[B]Released:[/B][CR] unknown'
790 Synopsis1 = Synopsis_release_year + '[CR]' + Synopsis_developer + '[CR]' + Synopsis_publisher + '[CR]' + Synopsis_genre + '[CR]' + Synopsis_players# + '[CR]' + Synopsis_filename
791 Synopsis2 = Synopsis.split('_________________________', 1)[1]
792 Synopsis2 = Synopsis2.strip('\n')
793 Synopsis2 = Synopsis2.replace( '\n', '[CR]' )
794 Synopsis2 = Synopsis2.replace( '&', '&' )
795 Synopsis2 = Synopsis2.replace( '>', '>' )
796 Synopsis2 = Synopsis2.replace( '<', '<' )
797 except:
798 if Emu_Name == "xbox":
799 with open(os.path.join( Xbox_Games_Folder, Rom_Name ), "r") as input:
800 skip = input.readline()
801 skip = input.readline()
802 skip = input.readline()
803 Synopsis_filename = input.readline()
804 if '_' in Synopsis_filename:
805 Synopsis_filename = '[B]TITLEID:[/B][CR] ' + Synopsis_filename.split('_', 1)[0]
806 else:
807 Synopsis_filename = '[B]TITLEID:[/B][CR] ' + Synopsis_filename
808 Synopsis1 = Synopsis_release_year + '[CR]' + Synopsis_developer + '[CR]' + Synopsis_publisher + '[CR]' + Synopsis_genre + '[CR]' + Synopsis_players# + '[CR]' + Synopsis_filename
809 Synopsis2 = ""
810 ## Fix labels that use only numbers, XBMC will use its internal labelling system if I don't.
811 if FBA_Rom_Name == "1942": FBA_Rom_Name = "1942 "
812 if Rom_Name_noext == "1942": Rom_Name_noext = "1942 "
813 if Rom_Name_noext == "1943": Rom_Name_noext = "1943 "
814 if Rom_Name_noext == "720": Rom_Name_noext = "720 "
815 ## Set Rom_Names for different types of CD images.
816 Rom_Name_ISO = Rom_Name[:-4] + ".iso"
817 Rom_Name_BIN = Rom_Name[:-4] + ".bin"
818 Rom_Name_IMG = Rom_Name[:-4] + ".img"
819 Rom_Name_CUE = Rom_Name[:-4] + ".cue"
820 Rom_Name_CCD = Rom_Name[:-4] + ".ccd"
821 Rom_Name_ZIP = Rom_Name[:-4] + ".zip"
822 Rom_Name_ADF = Rom_Name[:-4] + ".adf"
823 Rom_Path = Rom_Name
824 ## Check and parse the directory for iso files.
825 if Parse_ISO_File == 1:
826 if Items.endswith( '.iso' ):
827 Rom_Path = Rom_Name_ISO
828 Rom_Type_Total = Rom_Type_Total
829 Write_List_File = 1
830 else:
831 Write_List_File = 0
832 ## Check and parse the directory for cue files.
833 if Parse_CUE_File == 1:
834 if Items.endswith( '.cue' ):
835 Rom_Path = Rom_Name_CUE
836 Rom_Type_Total = Rom_Type_Total
837 Write_List_File = 1
838 else:
839 Write_List_File = 0
840 ## Check and parse the directory for bin/iso/img files.
841 if Parse_ISO_BIN_IMG_File == 1:
842 if Items.endswith( '.bin' ):
843 Rom_Path = Rom_Name_BIN
844 Rom_Type_Total = Rom_Type_Total
845 Write_List_File = 1
846 elif Items.endswith( '.img' ):
847 Rom_Path = Rom_Name_IMG
848 Rom_Type_Total = Rom_Type_Total
849 Write_List_File = 1
850 elif Items.endswith( '.iso' ):
851 Rom_Path = Rom_Name_ISO
852 Rom_Type_Total = Rom_Type_Total
853 Write_List_File = 1
854 else:
855 Write_List_File = 0
856 ## Check and parse the directory for cue/ccd/iso files.
857 if Parse_CUE_CCD_ISO_File == 1:
858 if Items.endswith( '.cue' ):
859 Rom_Path = Rom_Name_CUE
860 Rom_Type_Total = Rom_Type_Total
861 Write_List_File = 1
862 elif Items.endswith( '.ccd' ):
863 Rom_Path = Rom_Name_CCD
864 Rom_Type_Total = Rom_Type_Total
865 Write_List_File = 1
866 elif Items.endswith( '.iso' ):
867 Rom_Path = Rom_Name_ISO
868 Rom_Type_Total = Rom_Type_Total
869 if os.path.isfile( os.path.join( Roms_Folder,Rom_Path[:-4]+'.cue' ) ):
870 Write_List_File = 0
871 else:
872 Write_List_File = 1
873 else:
874 Write_List_File = 0
875 ## Check and parse the directory for cue/zip/adf/iso files.
876 if Parse_CUE_ZIP_ISO_ADF_File == 1:
877 if Items.endswith( '.cue' ):
878 Rom_Path = Rom_Name_CUE
879 Rom_Type_Total = Rom_Type_Total
880 Write_List_File = 1
881 elif Items.endswith( '.zip' ):
882 Rom_Path = Rom_Name_ZIP
883 Rom_Type_Total = Rom_Type_Total
884 Write_List_File = 1
885 elif Items.endswith( '.adf' ):
886 Rom_Path = Rom_Name_ADF
887 Rom_Type_Total = Rom_Type_Total
888 Write_List_File = 1
889 elif Items.endswith( '.iso' ):
890 Rom_Path = Rom_Name_ISO
891 Rom_Type_Total = Rom_Type_Total
892 if os.path.isfile( os.path.join( Roms_Folder,Rom_Path[:-4]+'.cue' ) ):
893 Write_List_File = 0
894 else:
895 Write_List_File = 1
896 else:
897 Write_List_File = 0
898 ## Create the rest of the layout xml file.
899 if Write_List_File:
900 ## Show the progress bar progress and write rom list file.
901 RomListCount = RomListCount + 1
902 with open( os.path.join( Games_List_Path, 'gamelist.xml' ), "a") as outputmenufile:
903 if Emu_Name == "fba" or Emu_Name == "fbl" or Emu_Name == "fblc" or Emu_Name == "fbaxxx":
904 pDialog.update((CountList * 100) / len(os.listdir( os.path.join( Roms_Folder_Path, Emu_Name ) )),'Creating [B][UPPERCASE]' + Emu_Name + '[/UPPERCASE][/B] Rom list',FBA_Rom_Name,'This can take some time, please be patient.' )
905 WriteMenuFile = menu_entry % (CountList,FBA_Rom_Name,Synopsis1,Synopsis2,Thumbnail,"[ArtworkFolder]",'RunScript( special://emustation_scripts/launcher.py,' + Emu_XBE + ',' + Rom_Name_noext + ',,' + str(CountList) + ' )',"ActivateWindow(1101)")
906 elif Emu_Name == "mame" or Emu_Name == "neogeocd":
907 pass
908 elif Emu_Name == "n64":
909 pDialog.update((CountList * 100) / len(os.listdir( Roms_Folder )),'Creating [B][UPPERCASE]' + Emu_Name + '[/UPPERCASE][/B] Rom list and copying media files',N64_Rom_Name,'This can take some time, please be patient.' )
910 WriteMenuFile = menu_entry % (CountList,N64_Rom_Name,Synopsis1,Synopsis2,Thumbnail,"[ArtworkFolder]",'RunScript( special://emustation_scripts/launcher.py,' + Emu_XBE + ',' + Rom_Path + ',,' + str(CountList) + ' )',"ActivateWindow(1101)")
911 elif Emu_Name == "amiga" or Emu_Name == "pce-cd" or Emu_Name == "psx" or Emu_Name == "tg-cd" or Emu_Name == "segacd":
912 pDialog.update((CountList * 100) / Rom_Type_Total,'Creating [B][UPPERCASE]' + Emu_Name + '[/UPPERCASE][/B] Rom list',Rom_Name_noext,'This can take some time, please be patient.' )
913 WriteMenuFile = menu_entry % (CountList,Rom_Name_noext,Synopsis1,Synopsis2,Thumbnail,"[ArtworkFolder]",'RunScript( special://emustation_scripts/launcher.py,' + Emu_XBE + ',' + Rom_Path + ',,' + str(CountList) + ' )',"ActivateWindow(1101)")
914 elif Emu_Name == "xbox":
915 with open(os.path.join( Xbox_Games_Folder, Rom_Name ), "r") as input:
916 GameTitle = input.readline()
917 GamePath = input.readline()
918 GameLetter = input.readline()
919 GameThumb = input.readline() + '.jpg'
920 with open( os.path.join( Media_Folder_Path, "xbox\\GameNames.txt" ),"a") as ouput:
921 ouput.write("Game Name: " + GameTitle + "SubFolder: " + GameLetter + "TitleID: " + GameThumb[:-4] + "\n\n")
922 pDialog.update((CountList * 100) / len(os.listdir( Roms_Folder )),'Creating [B][UPPERCASE]' + Emu_Name + '[/UPPERCASE][/B] Game list',GameTitle[:-1],'This can take some time, please be patient.' )
923 WriteMenuFile = menu_entry % (CountList,GameTitle[:-1],Synopsis1,Synopsis2,GameLetter[:-1]+'\\'+GameThumb,"[ArtworkFolder]",'RunScript( special://emustation_scripts/launcher.py,' + GamePath[:-1] + ',empty,,' + str(CountList) + ' )',"ActivateWindow(1101)")
924 else:
925 pDialog.update((CountList * 100) / len(os.listdir( Roms_Folder )),'Creating [B][UPPERCASE]' + Emu_Name + '[/UPPERCASE][/B] Rom list',Rom_Name_noext,'This can take some time, please be patient.' )
926 WriteMenuFile = menu_entry % (CountList,Rom_Name_noext,Synopsis1,Synopsis2,Thumbnail,"[ArtworkFolder]",'RunScript( special://emustation_scripts/launcher.py,' + Emu_XBE + ',' + Rom_Path + ',,' + str(CountList) + ' )',"ActivateWindow(1101)")
927 outputmenufile.write( WriteMenuFile )
928 ## Write favourites menu entries.
929 with open( os.path.join( Games_List_Path, 'favslist.xml' ), "a") as favsmenufile:
930 if Emu_Name == "fba" or Emu_Name == "fbl" or Emu_Name == "fblc" or Emu_Name == "fbaxxx":
931 WriteMenuFile = favourites_entry % (FBA_Rom_Name,Emu_XBE,Rom_Name_noext)
932 elif Emu_Name == "mame" or Emu_Name == "neogeocd":
933 pass
934 elif Emu_Name == "n64":
935 WriteMenuFile = favourites_entry % (N64_Rom_Name,Emu_XBE,Rom_Path)
936 elif Emu_Name == "xbox":
937 with open(os.path.join( Xbox_Games_Folder, Rom_Name ), "r") as input:
938 Rom_Name_noext = input.readline()
939 Emu_XBE = input.readline()
940 WriteMenuFile = favourites_entry % (Rom_Name_noext[:-1],Emu_XBE[:-1],"null")
941 else:
942 WriteMenuFile = favourites_entry % (Rom_Name_noext,Emu_XBE,Rom_Path)
943 favsmenufile.write( WriteMenuFile )
944 ## Write menu entry for quick jump.
945 with open( os.path.join( Games_List_Path, 'jumplist.xml' ), "a") as outputmenuselectfile:
946 if not Starts_with_0:
947 if JumpList_Name.startswith("#") or JumpList_Name.startswith("'") or JumpList_Name.startswith("0") or JumpList_Name.startswith("1") or JumpList_Name.startswith("2") or JumpList_Name.startswith("3") or JumpList_Name.startswith("4") or JumpList_Name.startswith("5") or JumpList_Name.startswith("6") or JumpList_Name.startswith("7") or JumpList_Name.startswith("8") or JumpList_Name.startswith("9"):
948 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"#","SetFocus(9000," + str(JumpList) + ")" )
949 Starts_with_0 = 1
950 Jump_Counter = Jump_Counter + 1
951 outputmenuselectfile.write( WriteSearchFile )
952 if not Starts_with_A:
953 if JumpList_Name.startswith("a"):
954 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"A","SetFocus(9000," + str(JumpList) + ")" )
955 Starts_with_A = 1
956 Jump_Counter = Jump_Counter + 1
957 outputmenuselectfile.write( WriteSearchFile )
958 if not Starts_with_B:
959 if JumpList_Name.startswith("b"):
960 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"B","SetFocus(9000," + str(JumpList) + ")" )
961 Starts_with_B = 1
962 Jump_Counter = Jump_Counter + 1
963 outputmenuselectfile.write( WriteSearchFile )
964 if not Starts_with_C:
965 if JumpList_Name.startswith("c"):
966 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"C","SetFocus(9000," + str(JumpList) + ")" )
967 Starts_with_C = 1
968 Jump_Counter = Jump_Counter + 1
969 outputmenuselectfile.write( WriteSearchFile )
970 if not Starts_with_D:
971 if JumpList_Name.startswith("d"):
972 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"D","SetFocus(9000," + str(JumpList) + ")" )
973 Starts_with_D = 1
974 Jump_Counter = Jump_Counter + 1
975 outputmenuselectfile.write( WriteSearchFile )
976 if not Starts_with_E:
977 if JumpList_Name.startswith("e"):
978 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"E","SetFocus(9000," + str(JumpList) + ")" )
979 Starts_with_E = 1
980 Jump_Counter = Jump_Counter + 1
981 outputmenuselectfile.write( WriteSearchFile )
982 if not Starts_with_F:
983 if JumpList_Name.startswith("f"):
984 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"F","SetFocus(9000," + str(JumpList) + ")" )
985 Starts_with_F = 1
986 Jump_Counter = Jump_Counter + 1
987 outputmenuselectfile.write( WriteSearchFile )
988 if not Starts_with_G:
989 if JumpList_Name.startswith("g"):
990 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"G","SetFocus(9000," + str(JumpList) + ")" )
991 Starts_with_G = 1
992 Jump_Counter = Jump_Counter + 1
993 outputmenuselectfile.write( WriteSearchFile )
994 if not Starts_with_H:
995 if JumpList_Name.startswith("h"):
996 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"H","SetFocus(9000," + str(JumpList) + ")" )
997 Starts_with_H = 1
998 Jump_Counter = Jump_Counter + 1
999 outputmenuselectfile.write( WriteSearchFile )
1000 if not Starts_with_I:
1001 if JumpList_Name.startswith("i"):
1002 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"I","SetFocus(9000," + str(JumpList) + ")" )
1003 Starts_with_I = 1
1004 Jump_Counter = Jump_Counter + 1
1005 outputmenuselectfile.write( WriteSearchFile )
1006 if not Starts_with_J:
1007 if JumpList_Name.startswith("j"):
1008 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"J","SetFocus(9000," + str(JumpList) + ")" )
1009 Starts_with_J = 1
1010 Jump_Counter = Jump_Counter + 1
1011 outputmenuselectfile.write( WriteSearchFile )
1012 if not Starts_with_K:
1013 if JumpList_Name.startswith("k"):
1014 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"K","SetFocus(9000," + str(JumpList) + ")" )
1015 Starts_with_K = 1
1016 Jump_Counter = Jump_Counter + 1
1017 outputmenuselectfile.write( WriteSearchFile )
1018 if not Starts_with_L:
1019 if JumpList_Name.startswith("l"):
1020 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"L","SetFocus(9000," + str(JumpList) + ")" )
1021 Starts_with_L = 1
1022 Jump_Counter = Jump_Counter + 1
1023 outputmenuselectfile.write( WriteSearchFile )
1024 if not Starts_with_M:
1025 if JumpList_Name.startswith("m"):
1026 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"M","SetFocus(9000," + str(JumpList) + ")" )
1027 Starts_with_M = 1
1028 Jump_Counter = Jump_Counter + 1
1029 outputmenuselectfile.write( WriteSearchFile )
1030 if not Starts_with_N:
1031 if JumpList_Name.startswith("n"):
1032 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"N","SetFocus(9000," + str(JumpList) + ")" )
1033 Starts_with_N = 1
1034 Jump_Counter = Jump_Counter + 1
1035 outputmenuselectfile.write( WriteSearchFile )
1036 if not Starts_with_O:
1037 if JumpList_Name.startswith("o"):
1038 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"O","SetFocus(9000," + str(JumpList) + ")" )
1039 Starts_with_O = 1
1040 Jump_Counter = Jump_Counter + 1
1041 outputmenuselectfile.write( WriteSearchFile )
1042 if not Starts_with_P:
1043 if JumpList_Name.startswith("p"):
1044 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"P","SetFocus(9000," + str(JumpList) + ")" )
1045 Starts_with_P = 1
1046 Jump_Counter = Jump_Counter + 1
1047 outputmenuselectfile.write( WriteSearchFile )
1048 if not Starts_with_Q:
1049 if JumpList_Name.startswith("q"):
1050 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"Q","SetFocus(9000," + str(JumpList) + ")" )
1051 Starts_with_Q = 1
1052 Jump_Counter = Jump_Counter + 1
1053 outputmenuselectfile.write( WriteSearchFile )
1054 if not Starts_with_R:
1055 if JumpList_Name.startswith("r"):
1056 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"R","SetFocus(9000," + str(JumpList) + ")" )
1057 Starts_with_R = 1
1058 Jump_Counter = Jump_Counter + 1
1059 outputmenuselectfile.write( WriteSearchFile )
1060 if not Starts_with_S:
1061 if JumpList_Name.startswith("s"):
1062 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"S","SetFocus(9000," + str(JumpList) + ")" )
1063 Starts_with_S = 1
1064 Jump_Counter = Jump_Counter + 1
1065 outputmenuselectfile.write( WriteSearchFile )
1066 if not Starts_with_T:
1067 if JumpList_Name.startswith("t"):
1068 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"T","SetFocus(9000," + str(JumpList) + ")" )
1069 Starts_with_T = 1
1070 Jump_Counter = Jump_Counter + 1
1071 outputmenuselectfile.write( WriteSearchFile )
1072 if not Starts_with_U:
1073 if JumpList_Name.startswith("u"):
1074 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"U","SetFocus(9000," + str(JumpList) + ")" )
1075 Starts_with_U = 1
1076 Jump_Counter = Jump_Counter + 1
1077 outputmenuselectfile.write( WriteSearchFile )
1078 if not Starts_with_V:
1079 if JumpList_Name.startswith("v"):
1080 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"V","SetFocus(9000," + str(JumpList) + ")" )
1081 Starts_with_V = 1
1082 Jump_Counter = Jump_Counter + 1
1083 outputmenuselectfile.write( WriteSearchFile )
1084 if not Starts_with_W:
1085 if JumpList_Name.startswith("w"):
1086 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"W","SetFocus(9000," + str(JumpList) + ")" )
1087 Starts_with_W = 1
1088 Jump_Counter = Jump_Counter + 1
1089 outputmenuselectfile.write( WriteSearchFile )
1090 if not Starts_with_X:
1091 if JumpList_Name.startswith("x"):
1092 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"X","SetFocus(9000," + str(JumpList) + ")" )
1093 Starts_with_X = 1
1094 Jump_Counter = Jump_Counter + 1
1095 outputmenuselectfile.write( WriteSearchFile )
1096 if not Starts_with_Y:
1097 if JumpList_Name.startswith("y"):
1098 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"Y","SetFocus(9000," + str(JumpList) + ")" )
1099 Starts_with_Y = 1
1100 Jump_Counter = Jump_Counter + 1
1101 outputmenuselectfile.write( WriteSearchFile )
1102 if not Starts_with_Z:
1103 if JumpList_Name.startswith("z"):
1104 WriteSearchFile = search_menu_entry % ( str(Jump_Counter),"Z","SetFocus(9000," + str(JumpList) + ")" )
1105 Starts_with_Z = 1
1106 Jump_Counter = Jump_Counter + 1
1107 outputmenuselectfile.write( WriteSearchFile )
1108 ## Add 1 to the Countlist and JumpList.
1109 CountList = CountList + 1
1110 JumpList = JumpList + 1
1111 ## Add the footer to the layout xml file.
1112 with open( os.path.join( Games_List_Path, 'gamelist.xml' ), "a") as outputmenufile:
1113 WriteMenuFile = menu_entry_footer
1114 outputmenufile.write( WriteMenuFile )
1115 else:
1116 if os.path.isdir( Games_List_Path ): shutil.rmtree( Games_List_Path )
1117 if ManualScan == 1:
1118 dialog.ok("Error","","No roms/images found for this system")
1119 return Main_Code()
1120 ## Set the rom count and remove any direct launch rom list.xml files.
1121 xbmc.executebuiltin('Skin.SetString('+ Emu_Name +'_games,'+ str( RomListCount ) + ')')
1122 if Emu_Name == "atarijaguar" or Emu_Name == "neogeocd":
1123 if os.path.isdir( Games_List_Path ): shutil.rmtree( Games_List_Path )
1124 if os.path.isdir( Media_Path ): shutil.rmtree( Media_Path )
1125 if Emu_Name == "mame":
1126 if os.path.isfile( os.path.join( Emu_Path, "system\\ROMS.list" )): os.remove( os.path.join( Emu_Path, "system\\ROMS.list" ))
1127 if os.path.isfile( os.path.join( Emu_Path, "system\\ROMS.metadata" )): os.remove( os.path.join( Emu_Path, "system\\ROMS.metadata" ))
1128 if os.path.isdir( Games_List_Path ): shutil.rmtree( Games_List_Path )
1129 if os.path.isdir( Media_Path ): shutil.rmtree( Media_Path )
1130 ## ManualMode - Set a property so I can run the next script without this one running on.
1131 if Found_Roms == 1 and ManualScan == 1:
1132 xbmcgui.Window(xbmcgui.getCurrentWindowId()).setProperty("MyScript.ExternalRunning", "True")
1133 ## Running the scan script to update the counters.
1134 xbmc.executebuiltin('RunScript(' + Scripts_Path + 'refresh_carousel.py,0,' + Emu_Name + ',0,0)' )
1135 ## Loop.
1136 while (xbmcgui.Window(xbmcgui.getCurrentWindowId()).getProperty("MyScript.ExternalRunning") == "True"):
1137 time.sleep(0.2)
1138 if os.path.isdir( os.path.join( Emulator_Folder_Path, "xbox" ) ): shutil.rmtree( os.path.join( Emulator_Folder_Path, "xbox" ) )
1139 pDialog.close()
1140 return
1141 ## AutoMode - Set a property so I can run the next script without this one running on.
1142 if Found_Roms == 1 and ManualScan == 0:
1143 xbmcgui.Window(xbmcgui.getCurrentWindowId()).setProperty("MyScript.ExternalRunning", "True")
1144 ## Running the scan script to update the counters.
1145 xbmc.executebuiltin('RunScript(' + Scripts_Path + 'refresh_carousel.py,scan_emus,0,0,0)' )
1146 ## Loop.
1147 while (xbmcgui.Window(xbmcgui.getCurrentWindowId()).getProperty("MyScript.ExternalRunning") == "True"):
1148 time.sleep(0.2)
1149 if os.path.isdir( os.path.join( Emulator_Folder_Path, "xbox" ) ): shutil.rmtree( os.path.join( Emulator_Folder_Path, "xbox" ) )
1150 else:
1151 if os.path.isdir( os.path.join( Emulator_Folder_Path, "xbox" ) ): shutil.rmtree( os.path.join( Emulator_Folder_Path, "xbox" ) )
1152 pDialog.close()
1153 return
1154menu_entry_header = '<content>\n<!--\nTags used in the xml files:\nname = $INFO[listitem.Label]\ndetails = $INFO[listitem.Label2]\nsynopsis = $INFO[listitem.ActualIcon]\nthumbnail = $INFO[listitem.Thumb]\nmediapath = $INFO[listitem.SortLetter]\n-->'
1155menu_entry = '\n <item id="%s">\n <name>%s</name>\n <details>%s</details>\n <synopsis>%s</synopsis>\n <thumbnail>%s</thumbnail>\n <mediapath>%s</mediapath>\n <onclick>%s</onclick>\n <onclick>%s</onclick>\n </item>'
1156menu_entry_footer = '\n</content>'
1157search_menu_entry = '<control type="button" id="%s">\n <label>[UPPERCASE]$LOCALIZE[31405][/UPPERCASE]</label>\n <label2>< [UPPERCASE]%s[/UPPERCASE] ></label2>\n <include>MenuButtonCommonValues</include>\n <onclick>Dialog.Close(1120)</onclick>\n <onclick>%s</onclick>\n</control>\n'
1158favourites_entry = '<favourites>%s|%s|%s</favourites>\n'
1159n64_config = '[Settings]\nskinname=Default\nonhd=true\nHideLaunchScreens=true\nEnableXMVPreview=false\nEnableVideoAudio=false\nEnableInfoPanel=false\nEnableBGMusic=false\nRandomBGMusic=false\nAudioBoost=false\nPathRoms=%s\\\nPathMedia=D:\Media\\\nPathSkins=D:\Skins\\\nPathSaves=D:\Saves\\\nPathScreenshots=D:\Screenshots\\'
1160mame_config = '[Directories]\nALTDrive = t\nC_Mapping = \\device\\harddisk0\\partition1\nE_Mapping = \\device\\harddisk0\\partition1\nF_Mapping = \\device\\harddisk0\\partition6\nG_Mapping = \\device\\harddisk0\\partition7\nH_Mapping = \\device\\cdrom0\nRomsPath0 = %s\nRomsPath1 = d:\\roms\nRomsPath2 = d:\\roms\nRomsPath3 = d:\\roms\nArtPath = d:\\artwork\nAudioPath = d:\\samples\nConfigPath = d:\\cfg\nGeneralPath = d:\\general\nHDImagePath = d:\\hdimages\nHiScoresPath = d:\\hiscores\nNVRamPath = d:\\nvram\nBackupPath = d:\\roms\\backup\nScreenshotPath = d:\\screenshots\nAutoBootSavePath = d:\\autobootsaves\n\n\n[General]\nbios = 0\nCheatsEnabled = 1\nCheatFilename = cheat.dat\nSkipDisclaimer = 1\nSkipGameInfo = 1\nSkipWarnings = 1\nScreenSaverTimeout = 10\n\n\n[Input]\nLightgun1_Left = 4294934529\nLightgun1_CenterX = 0\nLightgun1_Right = 32767\nLightgun1_Top = 32767\nLightgun1_CenterY = 0\nLightgun1_Bottom = 4294934529\nLightgun2_Left = 4294934529\nLightgun2_CenterX = 0\nLightgun2_Right = 32767\nLightgun2_Top = 32767\nLightgun2_CenterY = 0\nLightgun2_Bottom = 4294934529\nLightgun3_Left = 4294934529\nLightgun3_CenterX = 0\nLightgun3_Right = 32767\nLightgun3_Top = 32767\nLightgun3_CenterY = 0\nLightgun3_Bottom = 4294934529\nLightgun4_Left = 4294934529\nLightgun4_CenterX = 0\nLightgun4_Right = 32767\nLightgun4_Top = 32767\nLightgun4_CenterY = 0\nLightgun4_Bottom = 4294934529\n\n\n[Network]\nDisableNetworking = 0\nIPAddress = \nGateway = \nSubnet = \nNameServer = \n\n\n[ROMListOptions]\nDisplayMode = 1\nSortMode = 0\nShowROMStatus = 0\nShowFAVEStatus = 1\nHideFilteredROMs = 0\nFilterMode = 0\nCursorPosition = 0.000000\nPageOffset = 0.000000\nSuperscrollIndex = 0\n\n\n[SkinOptions]\nSelectedSkin = Original\n\n\n[Sound]\nSoundEnable = 1\nSampleRate = 44100\nUseSamples = 1\nUseFilter = 1\n\n\n[VMMOptions]\nForceVMM = 0\nThreshold = 4194304\nCommitSize = 1048576\nDistribute = 65535\n\n\n[VectorOptions]\nVectorWidth = 640\nVectorHeight = 480\nBeamWidth = 2\nFlickerEffect = 0.000000\nBeamIntensity = 1.500000\nTranslucency = 1\n\n\n[Video]\nVSYNC = 1\nThrottleFramerate = 1\nAspectRatioCorrection = 1\nMinificationFilter = 2\nMagnificationFilter = 2\nFrameskip = 4294967295\nGraphicsFilter = 0\nSoftDisplayFilter = 0\nFlickerFilter = 5\nScreenRotation = 0\nBrightness = 1.000000\nPauseBrightness = 0.650000\nGamma = 1.000000\nScreenUsage_X = 0.850000\nScreenUsage_Y = 0.850000\nScreenPos_X = 0.000000\nScreenPos_Y = 0.000000\nArtwork = 1\n\n\n'
1161fbl_config = 'UsePathINI=1\nROMPath1=D:\\roms\nROMPath2=\nROMPath3=\nROMPath4=\nROMPath5=\nROMPath6=\nROMPath7=\nROMPath8=\nD:\\artwork\\Shots 1\nD:\\artwork\\Shots 2\nD:\\artwork\\Shots 3\nD:\\artwork\\Shots 4\nD:\\artwork\\Shots 5\nD:\\artwork\\Shots 6\nD:\\artwork\\Shots 7\nD:\\artwork\\Shots 8\nD:\\nvram\nD:\\samples\nD:\\ini\nD:\\savestates\nD:\\config\nD:\\hiscores\nD:\\videos\n'
1162if Manual_Scan == "manual" :
1163 ManualScan = 1
1164 Main_Code()
1165if Full_Scan == "auto" :
1166 if dialog.yesno("QUESTION TIME","","Would you like to auto scan your roms?"):
1167 ManualScan = 0
1168 Main_Code()