Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fl-flint==0.8.1
50 changes: 41 additions & 9 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
from distutils.dir_util import copy_tree
import fnmatch

import flint as fl

build = {
# this is unused, it merely explains how build.json is structured
# since JSON doesn't allow comments.

# path and dest are relative to the root input and output directories
"fl_path": "C:/Users/AUDUNVN/AppData/Local/Discovery Freelancer 4.88.1",

# files to copy into the output folder
"files": [
{
Expand Down Expand Up @@ -70,19 +72,22 @@

build_input_dir = Path("update")


def get_freelancer_path(search_dir):
output_path = ""
for root, dirs, files in os.walk(search_dir):
for dirname in fnmatch.filter(dirs, "Discovery Freelancer*"):
output_path = os.path.join(root, dirname)
return(output_path)
return (output_path)


def copy_file(*args, **kwargs):
dest_path = PurePath(args[1])
new_path = dest_path.parent / dest_path.name.lower()
src = args[0]
shutil.copy2(src, new_path, **kwargs)


def lowercase_rename(dir):
# renames all subfolders of dir, not including dir itself
def rename_all(root, items):
Expand All @@ -97,6 +102,7 @@ def rename_all(root, items):
rename_all(root, dirs)
rename_all(root, files)


def copy_into_existing_dir(src, dst):
if not os.path.exists(dst):
os.makedirs(dst)
Expand All @@ -109,11 +115,13 @@ def copy_into_existing_dir(src, dst):
if not os.path.exists(d) or os.stat(s).st_mtime - os.stat(d).st_mtime > 1:
shutil.copy2(s, d)


def copy(src, dest):
src_path = Path(src)
if src_path.is_dir():
try:
shutil.copytree(src, dest, ignore=shutil.ignore_patterns('BASES', 'BASE_INTERIORS', 'MODELS', '*.txm'), copy_function=copy_file)
shutil.copytree(src, dest, ignore=shutil.ignore_patterns('BASES', 'BASE_INTERIORS', 'MODELS', '*.txm'),
copy_function=copy_file)
except OSError as e:
if e.errno == errno.EEXIST:
copy_into_existing_dir(src, dest)
Expand All @@ -124,20 +132,41 @@ def copy(src, dest):
else:
print("Could not copy " + str(src) + " to " + str(dest) + "!")


def format_infocards(out_dir):
print("Formatting infocards.txt")

input_name = build_input_dir / "infocards.txt"
out_name = out_dir / 'infocards.txt'

with codecs.open(input_name, 'r', encoding='utf-8') as in_file, \
codecs.open(out_name, 'w', encoding='utf-8') as out_file:
codecs.open(out_name, 'w', encoding='utf-8') as out_file:
out_text = ''.join(in_file.readlines()[1:])
out_text = out_text.replace("\r\n\r\n", "\r\n")
out_text = out_text.replace("\r\nNAME\r\n", "\r\n")
out_text = out_text.replace("\r\nINFOCARD\r\n", "\r\n")
out_file.write(out_text)


def read_all_dlls():
"""Read all string resources from all DLLs.
This is a bit hacky since there's no built-in way to do this with flint. Look up the first resource in each
DLL to force flint to parse the file and add its contents to resource_table."""
result = {}
for i in fl.paths.dlls:
fl.formats.dll.lookup(i * 65536)
result.update(fl.formats.dll.resource_table[i])
return result


def dump_resources(filename: str):
"""Dump all string resources to a text file."""
resources = read_all_dlls()
pairs = (f'{id_}\n{text.strip()}\n' for id_, text in resources.items())
with open(filename, 'w') as f:
f.writelines(pairs)


def build_update():
config = build

Expand All @@ -152,24 +181,26 @@ def build_update():
print("Discovery install directory not found, aborting")
sys.exit()
fl_path = Path(found_fl_path)

fl.set_install_path(str(fl_path))

print("Freelancer directory set to \"" + str(fl_path) + "\"")

out_dir = Path(input("Set output directory: "))
os.mkdir(out_dir)

print("Run FL Path Generator (in the utils folder) on the FL installation in the \"" + str(fl_path) + "\" folder")
print("Run FLInfocardIE. Save infocards.txt into the \"" + str(build_input_dir) + "\" folder")
input("Press Enter to continue once you're done...")
print("Dumping resources")
dump_resources('update/infocards.txt')

format_infocards(out_dir)

print("Copying directories")
for directory in config["directories"]:
src_path = fl_path / directory["path"]
out_path = out_dir / directory["dest"]
print("Copying " + str(src_path) + " to " + str(out_path))
copy(src_path, out_path)

print("Copying files")
for file in config["files"]:
src_path = fl_path / file["path"]
Expand All @@ -185,4 +216,5 @@ def build_update():

print("Done! Now open index.html and set the dataRootPath variable to the \"" + str(out_dir) + "\" folder")


build_update()