# Copyright (C) 2026 BoundWare LLC. All rights reserved.
# SnacTrac is licensed under the Apache License, Version 2.0
# See Licenses/LICENSE.txt for details.


import multiprocessing
import sys
import traceback
from pathlib import Path
from datetime import datetime
from program import *


# run main program and write crashes to a log
def main():

    try:
    
        program()

    except Exception:

        # get location of this program
        exe_dir = Path(sys.executable).parent if hasattr(sys, '_MEIPASS') else Path(__file__).parent
        data_dir = exe_dir / "Data"
        data_dir.mkdir(exist_ok=True)

        # write crash log
        time_stamp = datetime.now().strftime('%Y%m%d %H%M')
        log_path = data_dir / f"Crash Log {time_stamp}.txt"
        log_path.write_text(traceback.format_exc())
        sys.exit(1)

if __name__ == '__main__':

    # prevent duplicate instances of program
    multiprocessing.freeze_support()

    main()