Add version check to package install

Add required_version and maximum_version checks to the install_package function to prevent incompatible packages from being installed on upgrade. e.g. widescreen package. A new argument is added to the function to override the version checks.

Also the commit contains some minor restructurings and corrections of indentations.

Implements #2690