#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Credit:
# Thanks to Zotan (DB and script), Big Poppa Panda, AnalogMan, F!rsT-S0uL
# Design inspiration: Lucas Rey's GUI (https://darkumbra.net/forums/topic/174470-app-cdnsp-gui-v105-download-nsp-gamez-using-a-gui/)
# Thanks to the developer(s) that worked on CDNSP_Next for the cert fix!
# Thanks to the help of devloper NighTime, kvn1351, gizmomelb, theLorknessMonster, vertigo
# CDNSP - GUI - Bob - v5
import sys
import time
import random
import gettext
import platform
import locale
import json
import os
__gui_version__ = "5.0.2"
__lang_version__ = "1.0.0"
global sys_locale
if platform.system() != 'Darwin':
sys_locale = locale.getdefaultlocale() # Detect system locale to fix Window size on Chinese Windows Computer
sys_locale = sys_locale[0]
else:
sys_locale = "Mac"
if sys_locale != "zh_CN":
main_win = "1076x684+100+100"
queue_win = "620x300+1177+100"
scan_win = "415x100+100+170"
base64_win = "497x100+95+176"
else:
main_win = "1250x684+100+100"
queue_win = "720x300+770+100"
scan_win = "420x85+100+100"
base64_win = "500x105+100+100"
config = {"Options": {
"Download_location": "",
"NSP_location": "",
"Game_location": "",
"NSP_repack": "True",
"Mute": "False",
"Titlekey_check": "True",
"noaria": "True",
"Disable_game_image": "False",
"Shorten": "False",
"Tinfoil": "False",
"SysVerZero": "False",
"Main_win": main_win,
"Queue_win": queue_win,
"Update_win": "600x400+120+200",
"Scan_win": scan_win,
"Base64_win": base64_win,
"Language": "en",
"Mode": "CDNSP",
"No_demo": "False",
"No_japanese_games": "False",
"Disable_description": "False"}
}
# Check if the GUI config JSON file has the needed keys
f = open("CDNSP-GUI-config.json", 'r')
f_load = json.load(f)
f.close()
if os.path.isfile("CDNSP-GUI-config.json"):
for json_key in config["Options"]:
if json_key not in f_load["Options"]:
print("Missing json key -",json_key,", it has been added in for you")
f_load["Options"][json_key] = config["Options"][json_key]
f = open("CDNSP-GUI-config.json", 'w')
json.dump(f_load, f, indent=4)
f.close()
else:
f = open("CDNSP-GUI-config.json", 'w')
json.dump(config, f, indent=4)
f.close()
f = open("CDNSP-GUI-config.json", 'r')
j = json.load(f)
try:
chosen_lang = j["Options"]["Language"]
except:
f.close()
j["Options"]["Language"] = "en" # Default to English language
with open("CDNSP-GUI-config.json", 'w') as f:
json.dump(j, f, indent=4)
f.close()
chosen_lang = "en"
def set_lang(default_lang = "en"):
try:
lang = gettext.translation('language', localedir='locales', languages=[default_lang])
lang.install()
print("Current language: {}".format(default_lang))
except:
lang = gettext.translation('language', localedir='locales', languages=["en"])
lang.install()
print("Language files not available yet!")
set_lang(chosen_lang)
if not os.path.isdir("Config"):
os.mkdir("Config")
build_text = _("\nBuilding the current state list... Please wait, this may take some time \
depending on how many games you have.")
# Check that user is using Python 3
if (sys.version_info > (3, 0)):
# Python 3 code in this block
pass
else:
# Python 2 code in this block
print(_("\n\nError - Application launched with Python 2, please install Python 3 and delete Python 2\n"))
time.sleep(1000)
sys.exit()
from tkinter import *
import os
from tkinter import messagebox
import tkinter.ttk as ttk
from importlib import util
import subprocess
import urllib.request
import pip
from pathlib import Path
def check_req_file(file):
if not os.path.exists(file):
url = 'https://raw.githubusercontent.com/Bob123a1/CDNSP-GUI-Files/master/{}'.format(file)
urllib.request.urlretrieve(url, file)
def install_module(module):
try:
subprocess.check_output("pip3 install {}".format(module), shell=True)
except:
print(_("Error installing {0}, close the application and you can install the module manually by typing in CMD: pip3 install {0}").format(module))
def add_to_installed(tid, ver):
print(tid, ver)
installed_tid = []
installed_ver = []
if os.path.isfile("Config/installed.txt"):
file = open("Config/installed.txt", "r", encoding="utf8")
for game in file.readlines():
installed_tid.append(game.split(",")[0].strip())
installed_ver.append(game.split(",")[1].strip())
file.close()
if tid in installed_tid:
if int(ver) > int(installed_ver[installed_tid.index(tid)]):
installed_ver[installed_tid.index(tid)] = ver
else:
installed_tid.append(tid)
installed_ver.append(ver)
file = open("Config/installed.txt", "w", encoding="utf8")
for i in range(len(installed_tid)):
file.write("{}, {}\n".format(installed_tid[i], installed_ver[i]))
file.close()
print(_("\nChecking if all required modules are installed!\n\n"))
try:
import requests
except ImportError:
install_module("requests")
import requests
try:
from tqdm import tqdm
except ImportError:
install_module("tqdm")
from tqdm import tqdm
try:
import unidecode
except ImportError:
install_module("unidecode")
import unidecode
try:
from PIL import Image, ImageTk
except ImportError:
install_module("Pillow")
from PIL import Image, ImageTk
try:
from bs4 import BeautifulSoup
except ImportError:
install_module("beautifulsoup4")
from bs4 import BeautifulSoup
try:
import ssl
except:
install_module("pyopenssl")
import ssl
ssl._create_default_https_context = ssl._create_unverified_context # Thanks to user rdmrocha on Github
req_file = ["CDNSPconfig.json", "keys.txt", "nx_tls_client_cert.pem", "titlekeys.txt",\
"titlekeys_overwrite.txt", "Nut_titlekeys.txt", "cert_dead.jpg"]
try:
for file in req_file:
check_req_file(file)
print(_("Everything looks good!"))
except Exception as e:
print(_("Unable to get required files! Check your internet connection: [{}]").format(str(e)))
# CDNSP script
import argparse
import base64
import platform
import re
import shlex
import xml.dom.minidom as minidom
import xml.etree.ElementTree as ET
from binascii import hexlify as hx, unhexlify as uhx
from io import TextIOWrapper
import os, sys
import subprocess
import urllib3
import json
import shutil
import argparse
import configparser
from hashlib import sha256
from struct import pack as pk, unpack as upk
from binascii import hexlify as hx, unhexlify as uhx
import xml.etree.ElementTree as ET, xml.dom.minidom as minidom
import re
import datetime
import calendar
import operator
import base64
import shlex
from distutils.version import StrictVersion as StrV
from tkinter import filedialog
import threading
sys_name = "Win"
global noaria
noaria = True
import webbrowser
titlekey_list = []
global tqdmProgBar
tqdmProgBar = True
sysver0 = False
#Global Vars
truncateName = False
tinfoil = False
enxhop = False
current_mode = ""
nsp_location = ""
import os, sys
import re
import shutil
import subprocess
import requests
import urllib3
import json
import argparse
import unicodedata as ud
import xml.etree.ElementTree as ET, xml.dom.minidom as