From b7f79b6e753a18525a2cb1fe53cb06376b0c0b95 Mon Sep 17 00:00:00 2001 From: snoutie <71790678+SnoutBug@users.noreply.github.com> Date: Wed, 18 May 2022 15:21:16 +0200 Subject: [PATCH] OOB Support - Flatpak & Wine Added oob support for default flatpak and wine paths Added comments --- auto_update.py | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/auto_update.py b/auto_update.py index 1862518..8399899 100644 --- a/auto_update.py +++ b/auto_update.py @@ -8,36 +8,62 @@ import tarfile import hashlib -try: - installation = str(sys.argv[1]) -except: - installation = '/.steam/root/steamapps/compatdata/284160/pfx/drive_c/users/steamuser/AppData/Local/BeamNG.drive/' +home = os.path.expanduser("~") +steam = 'steamapps/compatdata/284160/pfx/drive_c/users/steamuser' +game = '/AppData/Local/BeamNG.drive/' + +custom = False tags = [] hash_table = [] +#Names of default maps in the GitHub repo default = ['etk', 'jri', 'utah', 'derby', 'hirochi', 'industrial', 'gridmap_v2', 'small_island',] -path = os.path.expanduser("~") + installation +try: + path = str(sys.argv[1]) + custom = True +except: + path = home + '/.steam/root/' + steam + game + if not os.path.exists(path): #Flatpak? + path = home + '/.var/app/com.valvesoftware.Steam/.steam/root/' + steam + game + if not os.path.exists(path): #Wine? + path = home + '/.wine/drive_c/users/' + os.getlogin() + game +#The path did not exist if not os.path.exists(path): - print('Please make sure that you entered the right path\npython3 auto_update.py PATH_TO_/AppData/Local/BeamNG.drive/') + print('\nWas looking for:') + if not custom: + print(' 1. STEAM .deb\n 2. STEAM flatpak\n 3. WINE "' + path + '"\nbut found nothing.') + print('\nTry adding the equivalent of %LOCALAPPDATA%\LOCAL\BEAMNG.DRIVE as a parameter\n or try the troubleshooting section of the guide.') + else: + print(' "' + path + '"\nbut found nothing.') + print('Verify that your path leads to %LOCALAPPDATA%\LOCAL\BEAMNG.DRIVE') + print('\n') quit() +#Get the current version to find the correct folder (I can see this breaking - would be better to use latest.lnk) with open(path + 'version.txt') as version_file: ver = version_file.read().split('.') - version = ver[0] + '.' + ver[1] + '/' + +#Path of mods folder mods = path + version + 'mods/' + +#Path to extract the cache to cache = path + version + 'temp/art/' +#Create folders if missing if not os.path.exists(cache + '/terrainMaterialCache'): os.makedirs(cache + '/terrainMaterialCache') +#Get installed mods with open(mods + 'db.json') as file: repodb = json.load(file) +#Get supported maps from GitHub response = requests.get('https://api.github.com/repos/snoutbug/beamng_terrainmaterialcache/tags').json() +#tag = mod_id for tag in response: tags.append(str(tag['name'])) @@ -55,6 +81,8 @@ def md5(fname): for dds in os.listdir(cache + 'terrainMaterialCache/'): hash_table.append(md5(cache + 'terrainMaterialCache/' + dds) + ' ' + dds) +#If a used mod is supported by the repo, then only download the textures when there is at least one +# texture missing or changed try: for mod in repodb['mods']: mod_id = str(repodb['mods'][mod]['modData'].get('resource_id')) @@ -78,6 +106,7 @@ def md5(fname): os.remove(filename) break #continue with next mod + #Same as mods but with different naming conventions print('\nLooking for default maps...') url = 'https://github.com/SnoutBug/BeamNG_terrainMaterialCache/releases/download/default/' for filename in default: @@ -99,6 +128,8 @@ def md5(fname): break #continue with next map print('All Done!') + +#Remove all partially downloaded files when cancelled except KeyboardInterrupt: try: os.remove(filename)