Created
August 10, 2019 18:57
-
-
Save thurask/94a2e08325acfcf4b6375ed0b2623579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import configparser | |
import os | |
import shutil | |
import winreg | |
def get_install_path(): | |
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Maxis\\The Sims 4") as winkey: | |
instpath = winreg.QueryValueEx(winkey, "Install Dir")[0] | |
inipath = os.path.join(instpath, "Game", "Bin", "Default.ini") | |
return inipath | |
def plumb_replace(instring): | |
tlist = list(instring) | |
tlist[18:22] = ["0", ".", "0", "0"] | |
newver = "".join(tlist) | |
return newver | |
def backup_config_file(inpath): | |
newpath = inpath.replace(".ini", ".ini.bak") | |
if os.path.exists(newpath): | |
os.remove(newpath) | |
shutil.copy(inpath, newpath) | |
def fix_config_file(inpath): | |
config = configparser.ConfigParser() | |
config.read(inpath) | |
backup_config_file(inpath) | |
pbb = config["PlumbBob"] | |
newsect = {key: plumb_replace(item) for key, item in pbb.items()} | |
pbb.update(newsect) | |
with open(inpath, "w") as outfile: | |
config.write(outfile) | |
def main(): | |
inpath = get_install_path() | |
fix_config_file(inpath) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment