import sys
import wupclient
if __name__ == '__main__':
installid = raw_input("VC lower ID (last 8 chars): ")
installLocation = raw_input("VC Location (NAND, USB): ")
if(installLocation.lower() == "nand"):
location = "mlc01"
elif(installLocation.lower() == "usb"):
location = "usb01"
else:
print("'" + installLocation + "' is not a suitable answer")
input()
sys.exit()
print("Connecting to wupserver")
w = wupclient.wupclient()
if(w.s == None):
print("Failed to connect to wupserver!")
exit()
print("Connected!")
wupclient.w = w
print("Mounting SD")
ret = wupclient.mount_sd()
if(ret == 0):
print("Failed to mount SD!")
else:
print("Mounted! Installing Haxchi from SD")
ret = w.cp("/vol/storage_sdcard/haxchi/rom.zip", "/vol/storage_" + location + "/usr/title/00050000/" + installid + "/content/0010/rom.zip")
if(ret == 0):
print("Failed to install Haxchi!")
else:
print("Installing Meta files")
ret = w.cpdir("/vol/storage_sdcard/haxchi/meta", "/vol/storage_" + location + "/usr/title/00050000/" + installid + "/meta")
if(ret == 0):
print("Failed to install Meta files!")
else:
print("Downloading meta.xml for modification")
ret = w.dl("/vol/storage_" + location + "/usr/title/00050000/" + installid + "/meta/meta.xml")
if(ret == 0):
print("Download failed!")
else:
customname = raw_input("Custom title name: ")
print("Modifying meta.xml")
linecount = 0
f1 = open('meta.xml', 'r')
f2 = open('meta.xml.tmp', 'w')
for line in f1:
linecount = linecount + 1
if(72 <= linecount <= 77 or 79 <= linecount <= 82):
customline = line[0:42] + customname + line[-15:]
f2.write(customline)
elif(linecount == 78 or linecount == 83):
customline = line[0:43] + customname + line[-16:]
f2.write(customline)
else:
f2.write(line)
f1.close()
f2.close()
print("Uploading modified meta.xml")
ret = w.up("meta.xml.tmp", "/vol/storage_" + location + "/usr/title/00050000/" + installid + "/meta/meta.xml")
if(ret == 0):
print("Meta.xml upload failed!")
else:
print("Attempting to upload config.txt")
ret = w.cp("/vol/storage_sdcard/haxchi/config.txt", "/vol/storage_" + location + "/usr/title/00050000/" + installid + "/content/config.ini")
if(ret == 0):
print("Config.ini upload failed, normal for older haxchi versions")
else:
print("Applying chmod to config.txt")
ret = w.chmod("/vol/storage_" + location + "/usr/title/00050000/" + installid + "/content/config.txt", 0x644)
if(ret != 0):
print("Install complete!")
else:
print("chmod failed!")
if(w.fsa_handle != None):
w.close(w.fsa_handle)
w.fsa_handle = None
if(w.s != None):
w.s.close()
w.s = None
print("Press enter to exit")
input()