diff --git a/src/dblmapi_cli.py b/src/dblmapi_cli.py index 0fc5b48..a5ed28e 100644 --- a/src/dblmapi_cli.py +++ b/src/dblmapi_cli.py @@ -1,25 +1,43 @@ # dblmapi_cli.py +# Copyright (c) 2023-present mindsetpro import argparse -from dblmapi import process_file, zenkai_file +from colorama import init, Fore +from dblmapi import process_file, generate_csv_table, invert_bytes + +# Initialize colorama for cross-platform terminal color support +init(autoreset=True) def main(): - parser = argparse.ArgumentParser(description="dblmapi - A Python module for modding Dragon Ball Legends") - parser.add_argument("--t", dest="task", choices=["stars", "zenkai"], help="Specify the task (stars or zenkai)", required=True) - parser.add_argument("--f", dest="file_path", help="Specify the file path", required=True) - - args = parser.parse_args() + parser = argparse.ArgumentParser(description="CLI for modding DB Legends Game files") + parser.add_argument("--filename", help="Path to the DB Legends file", required=True) + parser.add_argument("--task", choices=["process_file", "invert"], help="Choose the mod to perform", required=True) + parser.add_argument("--gen-csv", action="store_true", help="Generate CSV table of file parts and descriptions") - with open(args.file_path, "rb") as file: - content = file.read() + args = parser.parse_args() - if args.task == "stars": - processed_content = process_file(content) - elif args.task == "zenkai": - processed_content = zenkai_file(content) + if args.gen_csv: + generate_csv_table() + print("CSV table generated successfully.") + return - with open("txt/zpower.txt", "wb") as processed_file: - processed_file.write(processed_content) + try: + with open(args.filename, "rb") as file: + file_content = file.read() + if args.task == "process_file": + processed_content = process_file(file_content) + with open(args.filename, "wb") as processed_file: + processed_file.write(processed_content) + print(f"File '{args.filename}' processed successfully.") + elif args.task == "invert": + inverted_content = invert_bytes(file_content) + with open(args.filename, "wb") as inverted_file: + inverted_file.write(inverted_content) + print(f"File '{args.filename}' inverted successfully.") + except FileNotFoundError: + print(Fore.RED + f"Error: File '{args.filename}' not found.") + except ValueError as e: + print(Fore.RED + f"Error: {e}") if __name__ == "__main__": main()