Inside Mod Manager v12 Modinstaller

From TNG_Wiki
Jump to navigation Jump to search

Class Modinstaller

Concept

Modinstaller gets a parse table from Modparser, rearranges it in logical order, and uses it to install a mod.

A processing loop examines each record (row) in the parse table, looking for mkdir, copyfile, newfile, target, and location tags.

Create a folder

A mod may need to create a folder before a file can be copied to it and modified. So this directive comes first in the logically rearranged parse table, irregardless of where it appears in the mod configuration file.

Modinstaller attempts to create the requested folder if it does not already exist. If it does exist, it is treated as if Modinstaller had installed it.

File Operation

Because the mod may want to modify files after they are copied or created, these directives are next in the logically rearranged parse table and are processed at this point, no matter where they appear in the mod configuration file.

Target

When a target tag is found, the target file is opened and its contents are copied into a file buffer.

Location

When a location tag is found, the installer checks to see that there is an active target file buffer and gathers the target code and replacement code from the table.

Modinstaller makes the insertions/replacements in the buffer and moves on to the next location. If a new %target: keyword is encountered, the installer flushes the current buffer to its target file, and copies the new one to the buffer.

Modinstaller Functions

public function install( $cfgpath )

@param cfgpath: path to a mod configuration file

This is the main function for the Modinstaller class.

Counters Maintainted

  • $locations_required
  • $locations_installed
  • $newdirs_required
  • $newdirs_created
  • $newdirs_excused
  • $newfiles_required
  • $newfiles_created
  • $newfiles_excused
  • $copyfiles_required
  • $copyfiles_copied
  • $copyfiles_excused
  • $num_errors

Installation

  • We begin by getting a parse table for the $cfgpath and rearranging the tags into logical order for installation. Preparations are made to log all operations and counters are initialized to keep track of the result of of each operation, to compute final statistics and to determine final status for the log.
  • We use a "for" loop to run through the logically rearranged parse table looking at tags that require a modification to the TNG environment. When found, a switch() statement processes each tag according to its purpose. Each operation does its own logging.
  • 'mkdir' tags are processed first. We check to see if the folder exists and, if not, we create it using PHP function mkdir().
  • When a 'copyfile' or 'copyfile2' tag is encountered, we copy the file right then, unless it is flagged as protected and the file already exists in the destination location.
  • A 'newfile' tag is also handled immediately. If flagged as protected and the file already exists, it is counted as excused and will not be recreated. if the destination folder does not exist and the new file is flagged as optional, it is counted as excused and will not be created.
  • When a 'target' tag is encountered, we open the file and get its content into a file buffer. If another target file is currently open, we flush (save) the buffer content back to its target file before opening a new one.
  • When a 'location' tag is found, we modify on the open file buffer according to the nature of the optag.
  • If the modification is already installed, we accept it and move on. This might be the case for a protected file copy which was not removed when the mod was previously removed.
  • If not installed, we modify target code in the buffer per the optag.
  • After processing all rows in the parse table, this function compares counters to establish a final status and writes it to the log file. Determining the status is the same process used by Modlister. When control passes back to the mod listing the status should be the same as reported in the log.
  • Of course, every step of the way, the install() function checks for errors and reports them in the log.

public function batch_install( $cfgpathlist )

@param cfgpathlist: mod files to be installed.

This short function just runs a loop to install all the files in the $cfgpathlist using $this->install($cfgfile)

The $cfgpathlist is provided by the Modlister filter.

Inside Mod Manager v12 Directory

Chapters

Inside Mod Manager v12 (Home)

  1. Mod Manager and OOP
  2. Page Headings
  3. Main Script
  4. Class Modbase
  5. Class Modparser
  6. Class Modlister
  7. Class Modinstaller
  8. Class Modeditor
  9. Class Modremover
  10. Class Moddeleter
  11. Formulas
  12. Mod Options
  13. Mod Logging
  14. Tools
  15. Issues