mirror of
https://github.com/DarkflameUniverse/NexusDashboard.git
synced 2024-11-21 21:17:23 +00:00
configurable client and sqlite
This commit is contained in:
parent
708fbfb9db
commit
3b5b478815
@ -5,7 +5,8 @@ from flask import (
|
|||||||
redirect,
|
redirect,
|
||||||
url_for,
|
url_for,
|
||||||
make_response,
|
make_response,
|
||||||
abort
|
abort,
|
||||||
|
current_app
|
||||||
)
|
)
|
||||||
from flask_user import login_required
|
from flask_user import login_required
|
||||||
from app.models import CharacterInfo
|
from app.models import CharacterInfo
|
||||||
@ -32,7 +33,7 @@ def get_dds_as_png(filename):
|
|||||||
cache = f'cache/{filename.split(".")[0]}.png'
|
cache = f'cache/{filename.split(".")[0]}.png'
|
||||||
|
|
||||||
if not os.path.exists(cache):
|
if not os.path.exists(cache):
|
||||||
root = 'app/luclient/res/'
|
root = f"{current_app.config['CLIENT_LOCATION']}res/"
|
||||||
|
|
||||||
path = glob.glob(
|
path = glob.glob(
|
||||||
root + f'**/{filename}',
|
root + f'**/{filename}',
|
||||||
@ -52,7 +53,7 @@ def get_dds(filename):
|
|||||||
if filename.split('.')[-1] != 'dds':
|
if filename.split('.')[-1] != 'dds':
|
||||||
return 404
|
return 404
|
||||||
|
|
||||||
root = 'app/luclient/res/'
|
root = f"{current_app.config['CLIENT_LOCATION']}res/"
|
||||||
|
|
||||||
dds = glob.glob(
|
dds = glob.glob(
|
||||||
root + f'**/{filename}',
|
root + f'**/{filename}',
|
||||||
@ -92,7 +93,7 @@ def get_icon_lot(id):
|
|||||||
cache = f'app/cache/{filename.split(".")[0]}.png'
|
cache = f'app/cache/{filename.split(".")[0]}.png'
|
||||||
|
|
||||||
if not os.path.exists(cache):
|
if not os.path.exists(cache):
|
||||||
root = 'app/luclient/res/'
|
root = f"{current_app.config['CLIENT_LOCATION']}res/"
|
||||||
try:
|
try:
|
||||||
pathlib.Path(os.path.dirname(cache)).resolve().mkdir(parents=True, exist_ok=True)
|
pathlib.Path(os.path.dirname(cache)).resolve().mkdir(parents=True, exist_ok=True)
|
||||||
with image.Image(filename=f'{root}{filename}'.lower()) as img:
|
with image.Image(filename=f'{root}{filename}'.lower()) as img:
|
||||||
@ -119,7 +120,7 @@ def get_icon_iconid(id):
|
|||||||
cache = f'app/cache/{filename.split(".")[0]}.png'
|
cache = f'app/cache/{filename.split(".")[0]}.png'
|
||||||
|
|
||||||
if not os.path.exists(cache):
|
if not os.path.exists(cache):
|
||||||
root = 'app/luclient/res/'
|
root = f"{current_app.config['CLIENT_LOCATION']}res/"
|
||||||
try:
|
try:
|
||||||
pathlib.Path(os.path.dirname(cache)).resolve().mkdir(parents=True, exist_ok=True)
|
pathlib.Path(os.path.dirname(cache)).resolve().mkdir(parents=True, exist_ok=True)
|
||||||
with image.Image(filename=f'{root}{filename}'.lower()) as img:
|
with image.Image(filename=f'{root}{filename}'.lower()) as img:
|
||||||
@ -137,14 +138,14 @@ def brick_list():
|
|||||||
brick_list = []
|
brick_list = []
|
||||||
if len(brick_list) == 0:
|
if len(brick_list) == 0:
|
||||||
suffixes = [".g", ".g1", ".g2", ".g3", ".xml"]
|
suffixes = [".g", ".g1", ".g2", ".g3", ".xml"]
|
||||||
res = pathlib.Path('app/luclient/res/')
|
res = pathlib.Path(f"{current_app.config['CLIENT_LOCATION']}res/")
|
||||||
# Load g files
|
# Load g files
|
||||||
for path in res.rglob("*.*"):
|
for path in res.rglob("*.*"):
|
||||||
if str(path.suffix) in suffixes:
|
if str(path.suffix) in suffixes:
|
||||||
brick_list.append(
|
brick_list.append(
|
||||||
{
|
{
|
||||||
"type": "file",
|
"type": "file",
|
||||||
"name": str(path.as_posix()).replace("app/luclient/res/", "")
|
"name": str(path.as_posix()).replace("{current_app.config['CLIENT_LOCATION']}res/", "")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
response = make_response(json.dumps(brick_list))
|
response = make_response(json.dumps(brick_list))
|
||||||
@ -156,7 +157,7 @@ def brick_list():
|
|||||||
@luclient_blueprint.route('/ldddb/<path:req_path>')
|
@luclient_blueprint.route('/ldddb/<path:req_path>')
|
||||||
def dir_listing(req_path):
|
def dir_listing(req_path):
|
||||||
# Joining the base and the requested path
|
# Joining the base and the requested path
|
||||||
rel_path = pathlib.Path(str(pathlib.Path(f'app/luclient/res/{req_path}').resolve()))
|
rel_path = pathlib.Path(str(pathlib.Path(f"{current_app.config['CLIENT_LOCATION']}res/{req_path}").resolve()))
|
||||||
# Return 404 if path doesn't exist
|
# Return 404 if path doesn't exist
|
||||||
if not rel_path.exists():
|
if not rel_path.exists():
|
||||||
return abort(404)
|
return abort(404)
|
||||||
@ -176,7 +177,7 @@ def unknown():
|
|||||||
cache = f'app/cache/{filename.split(".")[0]}.png'
|
cache = f'app/cache/{filename.split(".")[0]}.png'
|
||||||
|
|
||||||
if not os.path.exists(cache):
|
if not os.path.exists(cache):
|
||||||
root = 'app/luclient/res/'
|
root = f"{current_app.config['CLIENT_LOCATION']}res/"
|
||||||
try:
|
try:
|
||||||
pathlib.Path(os.path.dirname(cache)).resolve().mkdir(parents=True, exist_ok=True)
|
pathlib.Path(os.path.dirname(cache)).resolve().mkdir(parents=True, exist_ok=True)
|
||||||
with image.Image(filename=f'{root}{filename}'.lower()) as img:
|
with image.Image(filename=f'{root}{filename}'.lower()) as img:
|
||||||
@ -196,14 +197,14 @@ def get_cdclient():
|
|||||||
"""
|
"""
|
||||||
cdclient = getattr(g, '_cdclient', None)
|
cdclient = getattr(g, '_cdclient', None)
|
||||||
if cdclient is None:
|
if cdclient is None:
|
||||||
path = pathlib.Path('app/luclient/res/cdclient.sqlite')
|
path = pathlib.Path(f"{current_app.config['CD_SQLITE_LOCATION']}cdclient.sqlite")
|
||||||
if path.is_file():
|
if path.is_file():
|
||||||
cdclient = g._database = sqlite3.connect('app/luclient/res/cdclient.sqlite')
|
cdclient = g._database = sqlite3.connect(f"{current_app.config['CD_SQLITE_LOCATION']}cdclient.sqlite")
|
||||||
return cdclient
|
return cdclient
|
||||||
|
|
||||||
path = pathlib.Path('app/luclient/res/CDServer.sqlite')
|
path = pathlib.Path(f"{current_app.config['CD_SQLITE_LOCATION']}CDServer.sqlite")
|
||||||
if path.is_file():
|
if path.is_file():
|
||||||
cdclient = g._database = sqlite3.connect('app/luclient/res/CDServer.sqlite')
|
cdclient = g._database = sqlite3.connect(f"{current_app.config['CD_SQLITE_LOCATION']}CDServer.sqlite")
|
||||||
return cdclient
|
return cdclient
|
||||||
|
|
||||||
return cdclient
|
return cdclient
|
||||||
@ -237,7 +238,7 @@ def translate_from_locale(trans_string):
|
|||||||
locale_data = ""
|
locale_data = ""
|
||||||
|
|
||||||
if not locale:
|
if not locale:
|
||||||
locale_path = "app/luclient/locale/locale.xml"
|
locale_path = f"{current_app.config['CLIENT_LOCATION']}locale/locale.xml"
|
||||||
|
|
||||||
with open(locale_path, 'r') as file:
|
with open(locale_path, 'r') as file:
|
||||||
locale_data = file.read()
|
locale_data = file.read()
|
||||||
|
@ -69,8 +69,7 @@ def send():
|
|||||||
form.recipient.choices.append((character.id, character.name))
|
form.recipient.choices.append((character.id, character.name))
|
||||||
|
|
||||||
items = query_cdclient(
|
items = query_cdclient(
|
||||||
'Select id, name, displayName from Objects where type = ?',
|
'Select id, name, displayName from Objects where type = "Loot"'
|
||||||
["Loot"]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
|
@ -428,18 +428,20 @@ def decompress(data):
|
|||||||
|
|
||||||
def prebuilt(content, file_format, lod):
|
def prebuilt(content, file_format, lod):
|
||||||
# translate LOT to component id
|
# translate LOT to component id
|
||||||
# we need to get a type of 2 because reasons
|
# we need to get a type of 2 for the render component to find the filename
|
||||||
render_component_id = query_cdclient(
|
render_component_id = query_cdclient(
|
||||||
'select component_id from ComponentsRegistry where component_type = 2 and id = ?',
|
'select component_id from ComponentsRegistry where component_type = 2 and id = ?',
|
||||||
[content.lot],
|
[content.lot],
|
||||||
one=True
|
one=True
|
||||||
)[0]
|
)[0]
|
||||||
# find the asset from rendercomponent given the component id
|
# find the asset from rendercomponent given the component id
|
||||||
filename = query_cdclient(
|
filename = query_cdclient(
|
||||||
'select render_asset from RenderComponent where id = ?',
|
'select render_asset from RenderComponent where id = ?',
|
||||||
[render_component_id],
|
[render_component_id],
|
||||||
one=True
|
one=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# if we have a valie filename, coerce it
|
||||||
if filename:
|
if filename:
|
||||||
filename = filename[0].split("\\\\")[-1].lower().split(".")[0]
|
filename = filename[0].split("\\\\")[-1].lower().split(".")[0]
|
||||||
if "/" in filename:
|
if "/" in filename:
|
||||||
@ -447,25 +449,29 @@ def prebuilt(content, file_format, lod):
|
|||||||
else:
|
else:
|
||||||
return f"No filename for LOT {content.lot}"
|
return f"No filename for LOT {content.lot}"
|
||||||
|
|
||||||
lxfml = pathlib.Path(f'app/luclient/res/BrickModels/{filename.split(".")[0]}.lxfml')
|
# if we just want the lxfml, fine t and return it
|
||||||
|
lxfml = pathlib.Path(f'{current_app.config["CLIENT_LOCATION"]}res/BrickModels/{filename.split(".")[0]}.lxfml')
|
||||||
if file_format == "lxfml":
|
if file_format == "lxfml":
|
||||||
|
|
||||||
with open(lxfml, 'r') as file:
|
with open(lxfml, 'r') as file:
|
||||||
lxfml_data = file.read()
|
lxfml_data = file.read()
|
||||||
response = make_response(lxfml_data)
|
response = make_response(lxfml_data)
|
||||||
|
|
||||||
|
# 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
|
||||||
cache = pathlib.Path(f'app/cache/BrickModels/{filename}.lod{lod}.{file_format}')
|
cache = pathlib.Path(f'app/cache/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
|
||||||
cache.parent.mkdir(parents=True, exist_ok=True)
|
cache.parent.mkdir(parents=True, exist_ok=True)
|
||||||
try:
|
try:
|
||||||
ldd.main(str(lxfml.as_posix()), str(cache.with_suffix("").as_posix()), lod) # convert to OBJ
|
ldd.main(str(lxfml.as_posix()), str(cache.with_suffix("").as_posix()), lod) # convert to OBJ
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.error(f"ERROR on {cache}:\n {e}")
|
current_app.logger.error(f"ERROR on {cache}:\n {e}")
|
||||||
|
# then just read it
|
||||||
with open(str(cache.as_posix()), 'r') as file:
|
with open(str(cache.as_posix()), 'r') as file:
|
||||||
cache_data = file.read()
|
cache_data = file.read()
|
||||||
|
# and serve it
|
||||||
response = make_response(cache_data)
|
response = make_response(cache_data)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -7,6 +7,7 @@ import math
|
|||||||
import struct
|
import struct
|
||||||
import zipfile
|
import zipfile
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
|
from flask import current_app
|
||||||
|
|
||||||
PRIMITIVEPATH = '/Primitives/'
|
PRIMITIVEPATH = '/Primitives/'
|
||||||
GEOMETRIEPATH = PRIMITIVEPATH
|
GEOMETRIEPATH = PRIMITIVEPATH
|
||||||
@ -968,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="app/luclient/res/", lod=lod)
|
setDBFolderVars(dbfolderlocation=f"{current_app.config['CLIENT_LOCATION']}res/", lod=lod)
|
||||||
converter.LoadDBFolder(dbfolderlocation="app/luclient/res/")
|
converter.LoadDBFolder(dbfolderlocation=f"{current_app.config['CLIENT_LOCATION']}res/")
|
||||||
converter.LoadScene(filename=lxf_filename)
|
converter.LoadScene(filename=lxf_filename)
|
||||||
converter.Export(filename=obj_filename)
|
converter.Export(filename=obj_filename)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user