Gamesaves2 (trainers pulled from maxconsole)
#1
i've the gamesaves.py script and updated it to pull trainers from trainers.maxconsole.com.

list is sorted descending by latest. so you'll always see the latest at the top of the list.

i tested it thoughroughly and the additions work great!

the saves were not touched.

credits for the rest of the script to the original author.

--martin.

i don't currently have a good place to put the script so i'm pasting the whole code here. i hope this isn't against the rules.

Quote:from string import *
import urllib, re, random, os
import xbmc, xbmcgui
import zipfile

try: emulating = xbmcgui.emulating
except: emulating = false

action_move_left       =  1
action_move_right      =  2
action_move_up         =  3
action_move_down       =  4
action_page_up         =  5
action_page_down       =  6
action_select_item     =  7
action_highlight_item  =  8
action_parent_dir      =  9
action_previous_menu   = 10
action_show_info       = 11
action_pause           = 12
action_stop            = 13
action_next_item       = 14
action_prev_item       = 15


#global variables
if emulating:
   root_dir = "q:\\download\\gamesaves\\"
   saves_dir = "q:\\download\\gamesaves\\"
   trainer_dir = "q:\\download\\gamesaves\\trainers"
else:
   root_dir = "q:\\scripts\\gamesaves\\"
   saves_dir = "e:\\"
   trainer_dir = "c:\\trainers\\"
   
searchurl = "http://www.xbox-saves.com/pafiledb/pafiledb.php?action=search&search=do&string="
downloadurl = "http://www.xbox-saves.com/pafiledb/pafiledb.php?action=download&id="
# trainerurl = "http://www.ek-clan.vxcomputers.com/trainers/"
trainerurl = "http://www.anime-gallore.com/files/"

class save:
def (self, name, id, desc):
self.name = name
self.id = id
self.desc = desc

class gamesaves(xbmcgui.window):
def (self):
if emulating: xbmcgui.window.(self)

self.x = ( float(self.getwidth())  / float(720) )
self.y = ( float(self.getheight()) / float(480) )
self.saves = []
self.status = "save"

if not os.path.exists(root_dir):
                os.makedirs(root_dir)

self.addcontrol(xbmcgui.controlimage(0,0,int(720*self.x),int(480*self.y), "background.png"))
self.list = xbmcgui.controllist(int(211*self.x), int(100*self.y), int(450*self.x), int(350*self.y))
               self.btnsearch  = xbmcgui.controlbutton(int(60*self.x), int(100*self.y), int(140*self.x), int(30*self.y), "search")    
               self.btnrestore = xbmcgui.controlbutton(int(60*self.x), int(132*self.y), int(140*self.x), int(30*self.y), "restore")    
               self.btnclear   = xbmcgui.controlbutton(int(60*self.x), int(164*self.y), int(140*self.x), int(30*self.y), "clear backup")    
               self.btntrainer = xbmcgui.controlbutton(int(60*self.x), int(228*self.y), int(140*self.x), int(30*self.y), "trainers")    
               self.btnoptions = xbmcgui.controlbutton(int(60*self.x), int(260*self.y), int(140*self.x), int(30*self.y), "options")    

self.addcontrol(self.list)
self.addcontrol(self.btnsearch)
self.addcontrol(self.btnrestore)
self.addcontrol(self.btnclear)
self.addcontrol(self.btntrainer)
self.addcontrol(self.btnoptions)

self.list.controlleft(self.btnsearch)

self.btnsearch.controlup(self.btnoptions)
self.btnsearch.controldown(self.btnrestore)
self.btnsearch.controlright(self.list)

self.btnrestore.controlup(self.btnsearch)
self.btnrestore.controldown(self.btnclear)
self.btnrestore.controlright(self.list)

self.btnclear.controlup(self.btnrestore)
self.btnclear.controldown(self.btntrainer)
self.btnclear.controlright(self.list)

self.btntrainer.controlup(self.btnclear)
self.btntrainer.controldown(self.btnoptions)
self.btntrainer.controlright(self.list)

self.btnoptions.controlup(self.btntrainer)
self.btnoptions.controldown(self.btnsearch)
self.btnoptions.controlright(self.list)

self.setfocus(self.btnsearch)

def onaction(self, action):
if action == action_previous_menu:
self.close()

def oncontrol(self, control):

if control == self.list:
index = self.list.getselectedposition()
print "list click: status is: " + self.status
if self.status == "save":
        self.downloadzip(downloadurl + self.saves[index].id)

        elif self.status == "trainer":
                               self.downloadfile(self.saves[index].id, self.saves[index].name)

                       zip = zipfile.zipfile(root_dir + self.saves[index].name, 'r')
                       self.unzip(zip)
                       zip.close()
self.message ("done. please try the game to ensure save/trainer is working.")

elif control == self.btnsearch:
                       self.status = "save"
                       self.list.reset()
                       self.saves[:] = []
keyboard = xbmc.keyboard("")
keyboard.domodal()
if (keyboard.isconfirmed()):

self.parsesearch(keyboard.gettext())
                               for i in self.saves:
                                       self.list.additem(i.name + " ::: " + i.desc)

               elif control == self.btnrestore:
                       self.restore()

               elif control == self.btnclear:
                       self.clear()

               elif control == self.btntrainer:
                       self.status = "trainer"
                       self.list.reset()
self.saves[:] = []
self.parsetrainer()
for i in self.saves:
                        self.list.additem(i.name + ' ::: ' + i.desc)

elif control == self.btnoptions:
                       if not emulating:
                               self.message ("please ensure input is accurate. use double forward slashes")
if os.path.exists("q:\\scripts\\gamesaves.py"):
f = open("q:\\scripts\\gamesaves.py", "r")
data = f.read()
f.close()
links = re.findall('trainer_dir = "(.+)"', data)
if emulating:
                                current = links[0]
                        else:
                                current = links[1]
                               
                        keyboard = xbmc.keyboard(current)
keyboard.domodal()

if (keyboard.isconfirmed()):
new = keyboard.gettext()
data = replace(data ,"trainer_dir = " + current, "trainer_dir = " + new)
f = open("gamesaves.py", "w")
f.write(data)
f.close()
                       if not emulating:
                               self.message ("done")

def message(self, messagetext):
dialog = xbmcgui.dialog()
dialog.ok(" gamesaves for xbmc", messagetext)

def unzip(self, zip):
if not emulating:
progress = xbmcgui.dialogprogress()
progress.create("gamesaves", "unzipping + backing up...")

               if self.status == "save":
                        for each in zip.namelist():
                               name = replace(each ,"/", "\\")
                               get_dir = re.search ('(.+)\\\\', name)
       
                               if not get_dir == none:
                                       dir_name = saves_dir + get_dir.group(1) + "\\"
           
                                       if not os.path.exists(dir_name):
                                               os.makedirs(dir_name)
               
                                       if not each.endswith("/"):
                                               if each.startswith("udata") or each.startswith("tdata"):
                                                       self.createbackup (saves_dir + name)
                                                       temp = open(saves_dir + name, "wb")
                                                       temp.write(zip.read(each))
                                                       temp.close()

               elif self.status == "trainer":
                       for each in zip.namelist():
                               temp = open(trainer_dir + each, "wb")
                               temp.write(zip.read(each))
                               temp.close()
                               if each.endswith(".nfo"):
                                       nfo = each
                        self.printnfo(nfo)

if not emulating:
progress.close()


def downloadzip(self, source):
if not emulating:
progress = xbmcgui.dialogprogress()
progress.create("gamesaves", "downloading save...")

f = urllib.urlopen(source)
               real = f.geturl()
               f.close()
real = replace (real, " ", "%20")
               dl = urllib.urlopener()
               dl.retrieve(real, root_dir + "temp.zip")
if not emulating:
progress.close()

def downloadfile(self, source, myfile):
if not emulating:
progress = xbmcgui.dialogprogress()
progress.create("gamesaves", "downloading file: " + myfile)

print "downloading file: " + myfile + " from source: " + source
f = urllib.urlopen(source)
               real = f.geturl()
               f.close()
real = replace (real, " ", "%20")
               dl = urllib.urlopener()
               dl.retrieve(real, root_dir + myfile)
if not emulating:
progress.close()

       def parsesearch(self, search):
if not emulating:
progress = xbmcgui.dialogprogress()
progress.create("gamesaves", "grabbing available saves...")
               search = replace(search," ", "%20")
               
url = searchurl + search
f = urllib.urlopen(url)
               data = f.read()
               f.close()

namesre    = re.compile ('pafiledb.php\?action=file&id=(.+?)">(.+?)<')
descripsre = re.compile ('<a class="smalltext">(.+)<')

names = namesre.findall(data)
descrips = descripsre.findall(data)

for name in names:
tmp = save (name[1], name[0], "")
self.saves.append (tmp)

for i in range (0, len(descrips)):
self.saves[i].desc = descrips[i]

if not emulating:
progress.close()

def createbackup(self, source):
               backuplog = open(root_dir + "backup.log", "a")
               backuplog.write (source)
               backuplog.write ("\n")
               
               self.filehandler (source, source + ".bak")
               backuplog.close()

       def filehandler (self, source, destination):
               if os.path.exists (source):
                       infile = open(source, "rb")
                       outfile = open(destination, "wb")
                       x = infile.read(10)
                       while x != "":
                               outfile.write(x)
                               x = infile.read(10)
                       infile.close()
                       outfile.close()
       
       def restore(self):
if not emulating:
progress = xbmcgui.dialogprogress()
progress.create("gamesaves", "restoring...")
backuplog = open(root_dir + "backup.log", "r")              
               
               data = backuplog.readline()
               while data != "":
                       data = replace (data, "\n", "")
                       if os.path.exists (data):
                               os.remove(data)
                               print "deleted " + data
                       self.filehandler (data + ".bak", data)
                       if os.path.exists (data + ".bak"):
                               os.remove(data + ".bak")
                               print "replaced with backup"
                       data = backuplog.readline()
               backuplog.close()
               new = open(root_dir + "backup.log", "w")
self.message ("files restored and backups cleared")
if not emulating:
progress.close()

       def clear(self):
if not emulating:
progress = xbmcgui.dialogprogress()
progress.create("gamesaves", "deleting backups...")
               backuplog = open(root_dir + "backup.log", "r")

               data = backuplog.read()
               while data != "":
                       data = replace (data, "\n", ".bak")
                       if os.path.exists (data):
                               os.path.remove(data)
data = backuplog.read()

               backuplog.close()
               new = open(root_dir + "backup.log", "w")
self.message ("backups cleared.")
if not emulating:
progress.close()

def parsetrainer(self):
if not emulating:
progress = xbmcgui.dialogprogress()
progress.create("gamesaves", "grabbing available trainers...")
               
trainerurl2 = 'http://trainers.maxconsole.com/index.php?order=mod&direction=0&directory=2.%20upload%20your%20evox%20trainer%20files'

f = urllib.urlopen(trainerurl2)
               data = f.read()
f.close()

xre = re.compile ('a href="javascript:popup\(\'(.+?)\'.+?\<br\>(.+?)\<\/font\>',re.s)

for m in xre.finditer(data):
tfile=m.group(1)
tnpdesc=m.group(2)
nc = re.compile ('[\n\t\r]')
tdesc = nc.sub('', tnpdesc)
tadd='http://trainers.maxconsole.com/index.php?action=downloadfile&filename=' + tfile + '&directory=2. upload your evox trainer files&'
address = replace(tadd,"%20", " ")
address = replace(address,"&", "&")

#print ">> " + tdesc + "<<"
tmp = save (tfile, address, tdesc)
self.saves.append (tmp)

if not emulating:
progress.close()

def parsetrainerorig(self):
if not emulating:
progress = xbmcgui.dialogprogress()
progress.create("gamesaves", "grabbing available trainers...")
               
f = urllib.urlopen(trainerurl)
               data = f.read()
               f.close()

xre = re.compile ('a href="(.+?)\.zip')

links = xre.findall(data)

for link in links:
address = replace(link,"%20", " ")
address = replace(address,"&", "&")
print address
tmp = save (address, "", "")
self.saves.append (tmp)

if not emulating:
progress.close()


               
       def printnfo(self, filename):
               f  = open (trainer_dir + filename)
               self.list.reset()
               data = f.readline()
               self.list.additem(data)
               print data
               while data != "":
                       self.list.additem(data)
                       data = f.readline()
                       print data
                       

w = gamesaves()
w.domodal()

del w
Reply
#2
the script apparently doesn't work if simply copy/pasted since some of the indents get messed up by the forum. so for those who don't want to fix the indents above i'll put a link to the script soon...

--martin.
Reply
#3
when you get it into a releasable state just throw it up on the download page here.

just remember to rar it up first and add a small screenshot if you can.
-ast
Reply
#4
oh cool... i uploaded it to the xbmc third party app page. it should show up there as soon as the admin looks it over and approves it.

thanks for the tip... and thanks thanks to kaer for this awesome script.

--martin.
Reply
#5
for some reason this script got uploaded to the xbmc xstream servers section instead of the scripts section of the download site
Reply
#6
couldn't find my old topic but well bump :p
i made some changes, small updates if anyone's interested.

http://xtreme.000k3.com
Reply

Logout Mark Read Team Forum Stats Members Help
Gamesaves2 (trainers pulled from maxconsole)0