Exemple #1
0
def main(*args):
    """JAM Extractor Menu"""
    colors.text('''
JAM Extractor 1.0.2
COPYRIGHT (C) 2012-2013: JrMasterModelBuilder''', color.FG_WHITE)
    logging.info("Display JAM Extractor menu to user")
    print('''
[e] Extract LEGO.JAM
[c] Compress LEGO.JAM
[q] Quit''')
    jam_opt = input("\n> ")

    # User wants to compress a JAM
    if jam_opt.lower() == "c":
        logging.info("User pressed '[c] Compress LEGO.JAM'")
        SelectDataFiles()

    # User wants to extract a JAM
    if jam_opt.lower() == "e":
        logging.info("User pressed '[e] Extract LEGO.JAM'")
        SelectJAMArchive()

    # Go back to PatchIt! menu
    else:
        PatchIt.main()
Exemple #2
0
def LOCOReadSettings():
    """Read PatchIt! LEGO LOCO settings"""
    # The settings file does not exist
    if not os.path.exists(
        os.path.join(const.settings_fol, const.LOCO_settings)
    ):
        logging.warning("LEGO LOCO Settings does not exist!")
        logging.info("Proceeding to write PatchIt! LEGO LOCO settings")
        LOCOWriteSettings()

    # The setting file does exist
    elif os.path.exists(os.path.join(const.settings_fol, const.LOCO_settings)):
        logging.info("LEGO LOCO Settings does exist")

        # The first-run check came back False,
        # Go write the settings so we don't attempt to read a blank file
        if not CheckLOCOSettings():
            logging.warning('''The first-run check came back False!
Writing LEGO LOCO settings so we don't read an empty file.''')
            LOCOWriteSettings()

        # The defined installation was not confirmed by LOCOGameCheck()
        if not LOCOGameCheck():

            # Use path defined in LOCOGameCheck() for messages
            logging.warning("LEGO LOCO installation was not found!".format(
                LOCO_path))
            root = Tk()
            root.withdraw()
            tk.messagebox.showerror("Invalid installation!",
                                    "Cannot find {0} installation at {1}"
                                    .format(const.LOCO_game, LOCO_path))
            root.destroy()

            # Go write the settings file
            logging.info("Proceeding to write PatchIt! LEGO LOCO settings")
            LOCOWriteSettings()

        # The defined installation was confirmed by LOCOGameCheck()
        else:
            logging.info("LEGO LOCO installation was found at {0}.".format(
                LOCO_path))
            print('\n{0} installation found at\n\n"{1}"\n\n{2}\n'.format(
                const.LOCO_game, LOCO_path, "Would you like to change this?"))
            change_loco_path = input(r"[Y\N] > ")

            # Yes, I want to change the defined installation
            if change_loco_path.lower() == "y":
                logging.info("User wants to change the LEGO LOCO installation")
                logging.info("Proceeding to write new LEGO LOCO settings")
                LOCOWriteSettings()

                # No, I do not want to change the defined installation
            else:
                logging.info('''User does not want to change the LEGO LOCO
                installation or pressed an undefined key''')
                PatchIt.main()
Exemple #3
0
    def Race(self):
        """I'll see you... at the finish line!"""
        # Get the installation path to Racers
        install_path = Racers.getRacersPath()
        logging.info("Reported LEGO Racers installation at {0}"
                     .format(install_path))
        # Run the game directly
        try:
            logging.info("Launching LEGO Racers...")
            os.chdir(install_path)
            subprocess.call(
                [os.path.join(install_path, self.__LRE), self.__novideo]
            )
            logging.shutdown()
            raise SystemExit(0)

        # Except LEGORacers.exe could not be found
        except FileNotFoundError:  # lint:ok
            logging.warning("LEGORacers.exe could not be found at {0}!"
                            .format(install_path))
            colors.text("\nLEGORacers.exe could not be found at \n\n{0}"
                  .format(install_path), color.FG_LIGHT_RED)

        # Except we need admin righs to do it
        except (OSError, PermissionError):  # lint:ok
            logging.exception('''Oops! Something went wrong! Here's what happened
''', exc_info=True)
            # Temp excuse since I can't get RunAsAdmin working
            # and I don't think I can sneak a registry string in
            # without having admin rights anyway.
            logging.warning("LEGO Racers cannot be launched at this time.")
            colors.text("\nLEGO Racers cannot be launched at this time.\n",
                        color.FG_LIGHT_RED)

        finally:
            time.sleep(1)
            PatchIt.main()
Exemple #4
0
            level=logging.DEBUG,
            format="%(asctime)s : %(levelname)s : %(message)s",
            filename=os.path.join(logs_folder, 'PatchIt.log'),
            # "a" so the Logs is appended to and not overwritten
            # and is created if it does not exist
            filemode="a"
        )

    # -- End Logging Configuration -- #

    except PermissionError:  # lint:ok
        # User did not want to reload with Administrator rights
        if not runasadmin.AdminRun().launch(
                "PatchIt! does not have the user rights to operate!"):
            # Close PatchIt!
            raise SystemExit(0)


# ------------ End PatchIt! Logging Code ------------ #

if __name__ == "__main__":
    # Run PatchIt! Initialization
    appLoggingFolder()

    # Write window title (since there is no GUI in PatchIt! itself (yet))
    os.system("title {0} {1} {2}".format(
        const.app, const.majver, const.minver))
    PatchIt.info()
    PatchIt.args()
    PatchIt.preload()
Exemple #5
0
def LRWriteSettings():
    """Write PatchIt! LEGO Racers settings"""
    # Draw (then withdraw) the root Tk window
    logging.info("Drawing root Tk window")
    root = Tk()
    logging.info("Withdrawing root Tk window")
    root.withdraw()

    # Overwrite root display settings
    logging.info("Overwrite root Tk window settings to hide it")
    root.overrideredirect(True)
    root.geometry('0x0+0+0')

    # Show window again, lift it so it can receive the focus
    # Otherwise, it is behind the console window
    root.deiconify()
    root.lift()
    root.focus_force()

    # Select the LEGO Racers installation
    logging.info("Display folder dialog for LEGO Racers installation")
    new_racers_game = filedialog.askopenfilename(
        parent=root,
        title="Where is LEGORacers.exe",
        defaultextension=".exe",
        filetypes=[("LEGORacers.exe", "*.exe")]
    )

    # Get the directory the Exe is in
    new_racers_game = os.path.dirname(new_racers_game)

    # The user clicked the cancel button
    if not new_racers_game:
        # Give focus back to console window
        logging.info("Give focus back to console window")
        root.destroy()

        # Go back to the main menu
        logging.warning("User did not select a new LEGO Racers installation!")
        PatchIt.main()

    # The user selected a folder
    else:
        logging.info("User selected a new LEGO Racers installation at {0}"
                     .format(new_racers_game))

        # Give focus back to console window
        logging.info("Give focus back to console window")
        root.destroy()

        # Create Settings directory if it does not exist
        logging.info("Creating Settings directory")
        if not os.path.exists(const.settings_fol):
            os.mkdir(const.settings_fol)

        # Write settings, using UTF-8 encoding
        logging.info("Open 'Racers.cfg' for writing using UTF-8-NOBOM encoding")
        with open(os.path.join(const.settings_fol, const.LR_settings),
                  "wt", encoding="utf-8") as racers_file:

            # As partially defined in PatchIt! Dev-log #6
            # (http://wp.me/p1V5ge-yB)
            logging.info("Write line telling what program this file belongs to")
            racers_file.write("// PatchIt! V1.1.x LEGO Racers Settings\n")

            # Write brief comment explaining what the number means
            # "Ensures the first-run process will be skipped next time"
            logging.info("Write brief comment explaining what the number means")
            racers_file.write("# Ensures the first-run process will be skipped next time\n")
            logging.info("Write '1' to line 3 to skip first-run next time")
            racers_file.write("1\n")

            # Run check for 1999 or 2001 version of Racers
            logging.info("Run LRVerCheck() to find the version of LEGO Racers")
            LRVer = LRVerCheck(new_racers_game)

            logging.info("Write brief comment telling what version this is")
            racers_file.write("# Your version of LEGO Racers\n")
            logging.info("Write game version to fifth line")
            racers_file.write(LRVer)

            logging.info("Write brief comment explaining the folder path")
            racers_file.write("\n# Your LEGO Racers installation path\n")
            logging.info("Write new installation path to seventh line")
            racers_file.write(new_racers_game)

        # Log closure of file (although the with handle did it for us)
        logging.info("Closing Racers.cfg")
        logging.info("Proceeding to read LEGO Racers Settings")
        LRReadSettings()