use cache more modified files

so that the client dir never has to be written to
This commit is contained in:
aronwk-aaron 2022-12-17 01:47:10 -06:00
parent 0fea032938
commit 785357475d
4 changed files with 25 additions and 7 deletions

View File

@ -11,6 +11,7 @@ from flask_user import user_registered, current_user, user_logged_in
from flask_wtf.csrf import CSRFProtect from flask_wtf.csrf import CSRFProtect
from flask_apscheduler import APScheduler from flask_apscheduler import APScheduler
from app.luclient import register_luclient_jinja_helpers from app.luclient import register_luclient_jinja_helpers
import pathlib
from app.commands import ( from app.commands import (
init_db, init_db,
@ -101,6 +102,15 @@ def create_app():
register_blueprints(app) register_blueprints(app)
register_luclient_jinja_helpers(app) register_luclient_jinja_helpers(app)
# Extract the brickdb if it's not already extracted
materials = pathlib.Path(f'{app.config["CACHE_LOCATION"]}Materials.xml')
if not materials.is_file():
from zipfile import ZipFile
with ZipFile(f"{app.config['CLIENT_LOCATION']}res/brickdb.zip","r") as zip_ref:
zip_ref.extractall(app.config["CACHE_LOCATION"])
from shutil import copytree
copytree(f"{app.config['CLIENT_LOCATION']}res/brickprimitives", f"{app.config['CACHE_LOCATION']}brickprimitives")
return app return app
@ -269,6 +279,7 @@ def register_settings(app):
'USER_EMAIL_SENDER_EMAIL', 'USER_EMAIL_SENDER_EMAIL',
app.config['USER_EMAIL_SENDER_EMAIL'] app.config['USER_EMAIL_SENDER_EMAIL']
) )
if "ENABLE_CHAR_XML_UPLOAD" not in app.config: if "ENABLE_CHAR_XML_UPLOAD" not in app.config:
app.config['ENABLE_CHAR_XML_UPLOAD'] = False app.config['ENABLE_CHAR_XML_UPLOAD'] = False
app.config['ENABLE_CHAR_XML_UPLOAD'] = os.getenv( app.config['ENABLE_CHAR_XML_UPLOAD'] = os.getenv(
@ -290,6 +301,13 @@ def register_settings(app):
app.config['CD_SQLITE_LOCATION'] app.config['CD_SQLITE_LOCATION']
) )
if "CACHE_LOCATION" not in app.config:
app.config['CACHE_LOCATION'] = 'app/cache/'
app.config['CACHE_LOCATION'] = os.getenv(
'CACHE_LOCATION',
app.config['CACHE_LOCATION']
)
def gm_level(gm_level): def gm_level(gm_level):

View File

@ -42,7 +42,7 @@ def get_dds_as_png(filename):
with image.Image(filename=path) as img: with image.Image(filename=path) as img:
img.compression = "no" img.compression = "no"
img.save(filename='app/cache/' + filename.split('.')[0] + '.png') img.save(filename=current_app.config["CACHE_LOCATION"] + filename.split('.')[0] + '.png')
return send_file(cache) return send_file(cache)
@ -90,7 +90,7 @@ def get_icon_lot(id):
else: else:
return redirect(url_for('luclient.unknown')) return redirect(url_for('luclient.unknown'))
cache = f'app/cache/{filename.split(".")[0]}.png' cache = f'{current_app.config["CACHE_LOCATION"]}{filename.split(".")[0]}.png'
if not os.path.exists(cache): if not os.path.exists(cache):
root = f"{current_app.config['CLIENT_LOCATION']}res/" root = f"{current_app.config['CLIENT_LOCATION']}res/"
@ -117,7 +117,7 @@ def get_icon_iconid(id):
filename = filename.replace("..\\", "").replace("\\", "/") filename = filename.replace("..\\", "").replace("\\", "/")
cache = f'app/cache/{filename.split(".")[0]}.png' cache = f'{current_app.config["CACHE_LOCATION"]}{filename.split(".")[0]}.png'
if not os.path.exists(cache): if not os.path.exists(cache):
root = f"{current_app.config['CLIENT_LOCATION']}res/" root = f"{current_app.config['CLIENT_LOCATION']}res/"
@ -174,7 +174,7 @@ def dir_listing(req_path):
def unknown(): def unknown():
filename = "textures/ui/inventory/unknown.dds" filename = "textures/ui/inventory/unknown.dds"
cache = f'app/cache/{filename.split(".")[0]}.png' cache = f'{current_app.config["CACHE_LOCATION"]}{filename.split(".")[0]}.png'
if not os.path.exists(cache): if not os.path.exists(cache):
root = f"{current_app.config['CLIENT_LOCATION']}res/" root = f"{current_app.config['CLIENT_LOCATION']}res/"

View File

@ -460,7 +460,7 @@ def prebuilt(content, file_format, lod):
# else we handle getting the files for lddviewer # else we handle getting the files for lddviewer
elif file_format in ["obj", "mtl"]: elif file_format in ["obj", "mtl"]:
# check to see if the file exists # check to see if the file exists
cache = pathlib.Path(f'app/cache/BrickModels/{filename}.lod{lod}.{file_format}') cache = pathlib.Path(f'{current_app.config["CACHE_LOCATION"]}BrickModels/{filename}.lod{lod}.{file_format}')
if not cache.is_file(): if not cache.is_file():
# if not make it an store it for later # if not make it an store it for later
cache.parent.mkdir(parents=True, exist_ok=True) cache.parent.mkdir(parents=True, exist_ok=True)

View File

@ -969,8 +969,8 @@ def main(lxf_filename, obj_filename, lod="2"):
GEOMETRIEPATH = GEOMETRIEPATH + f"LOD{lod}/" GEOMETRIEPATH = GEOMETRIEPATH + f"LOD{lod}/"
converter = Converter() converter = Converter()
# print("Found DB folder. Will use this instead of db.lif!") # print("Found DB folder. Will use this instead of db.lif!")
setDBFolderVars(dbfolderlocation=f"{current_app.config['CLIENT_LOCATION']}res/", lod=lod) setDBFolderVars(dbfolderlocation=f"{current_app.config['CACHE_LOCATION']}", lod=lod)
converter.LoadDBFolder(dbfolderlocation=f"{current_app.config['CLIENT_LOCATION']}res/") converter.LoadDBFolder(dbfolderlocation=f"{current_app.config['CACHE_LOCATION']}")
converter.LoadScene(filename=lxf_filename) converter.LoadScene(filename=lxf_filename)
converter.Export(filename=obj_filename) converter.Export(filename=obj_filename)