Skip to content

Commit

Permalink
OOB Support - Flatpak & Wine
Browse files Browse the repository at this point in the history
Added oob support for default flatpak and wine paths
Added comments
  • Loading branch information
SnoutBug authored May 18, 2022
1 parent 2d3c2aa commit b7f79b6
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions auto_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']))

Expand All @@ -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'))
Expand All @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit b7f79b6

Please sign in to comment.