Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import binascii,os,re,subprocess,sys,urllib,urllib2,zipfile
- def CRC32_from_file(filename):
- buf = open(filename,'rb').read()
- buf = (binascii.crc32(buf) & 0xFFFFFFFF)
- return "%08X" % buf
- ds_file = sys.argv[1]
- crc32 = CRC32_from_file(ds_file)
- print crc32
- req = urllib2.Request('http://nds.hordeofninjas.com/Header%20Fix/')
- opener = urllib2.build_opener()
- opener.addheaders =[('User-Agent','Mozilla/5.0 (Windows NT 6.2; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0'),
- ('Connection','keep-alive')]
- try:
- res = opener.open(req)
- except urllib2.HTTPError:
- httperror = 1
- exit
- html = res.read()
- link = re.findall("href=\"(.+?_Old-"+crc32+"_to.+)\">",html,re.IGNORECASE)
- try:
- link = 'http://nds.hordeofninjas.com/Header%20Fix/'+link.pop()
- except IndexError:
- print 'No patch found'
- sys.exit()
- file_name = link.split('/')[-1]
- file = open(file_name, 'wb')
- res = opener.open(link).read()
- file.write(res)
- file.close()
- zipfile.ZipFile(file_name).extractall()
- subprocess.call('del '+file_name, shell=True)
- patch = re.findall('(.+?)\.zip',file_name).pop()
- ds_file = re.findall('(.+?)\.nds',ds_file).pop()
- if os.path.exists(patch+'.xdelta3'):
- subprocess.call('xdelta30u.exe -d -s "'+ds_file+'.nds" "'+patch+'.xdelta3" "'+ds_file+'_patch.nds"', shell=True)
- subprocess.call('del '+patch+'.xdelta3', shell=True)
- elif os.path.exists(patch+'.xdelta'):
- subprocess.call('xdelta30u.exe -d -s "'+ds_file+'.nds" "'+patch+'.xdelta" "'+ds_file+'_patch.nds"', shell=True)
- subprocess.call('del '+patch+'.xdelta', shell=True)
- else:
- print crap
- print 'Done '+ds_file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement