POL_innoextract

Informations

Créateur Messages
Yepoleb Anonymous

Information

Cet installateur a été accepté par l'équipe.

Informations

Plate-formes :
Téléchargements : 12091
Wine: System

Retours d'expérience

Description

Extracts an Inno Setup file and moves the files to an install directory. This is especially useful to work around the GOG installer. Uses the innoextract tool from http://constexpr.org/innoextract/

Usage

  1. Ask for a setup file using the builtin functions
  2. Create the Wine-prefix
  3. Create a temporary directory
  4. Set the install location to a folder inside the Wine-prefix.
  5. Call this script
  6. Apply your own registry patch, if necessary
  7. Clean up temp directory

Parameters

POL_innoextract <setup_file> <temp_dir> <install_path> [additional_args]
  • setup_file: Path of the setup file
  • temp_dir: Path to the temporary directory, usually created using POL_System_TmpCreate
  • install_path: Install location of the game as a native path (don't use "C:\something"). Example: "${WINEPREFIX}/drive_c/GOG Games/RollerCoaster Tycoon Deluxe/"
  • additional_args: Additional arguments for the innoextract process. May be usefull for installers with .bin files.

 

Code source

#!/bin/bash
# Date : (2015-12-07 06-36)
# Last revision : (2015-12-19 18-28)
# Distribution used to test : Debian Sid (Unstable)
# Author : Gabriel Huber huberg18@gmail.com
# Script licence : GPL v.2

local INSTALLER_FILE="$1"
local TEMP_DIR="$2"
local INSTALL_PATH="$3"
local ADDITIONAL_ARGS="$4"

if [ ! "$INSTALLER_FILE" ]; then
    POL_Debug_Fatal "$(eval_gettext 'POL_innoextract failed: INSTALLER_FILE not set.')"
fi
if [ ! "$TEMP_DIR" ]; then
    POL_Debug_Fatal "$(eval_gettext 'POL_innoextract failed: TEMP_DIR not set.')"
fi
if [ ! "$INSTALL_PATH" ]; then
    POL_Debug_Fatal "$(eval_gettext 'POL_innoextract failed: INSTALL_PATH not set.')"
fi

# Check if we have innoextract
innoextract --version >/dev/null 2>&1
if [ $? -ne 0 ]; then
    POL_Debug_Fatal "$(eval_gettext 'Could not find innoextract binary. Install the "innoextract" package or see http://constexpr.org/innoextract for more information on how to install, then run the script again.')"
else
    POL_Debug_Message "Found innoextract"
fi

POL_SetupWindow_pulsebar "$(eval_gettext 'Extracting game files...')" "$TITLE"

# Extract installer data
local INNO_LOGFILE="${TEMP_DIR}/innoextract.log"
local LAST_PERCENTAGE="0"
# Fix return code for piped commands
set -o pipefail
# -e = extract, -q = quiet, -c = no color, -p = enable progress bar,
# -d = output directory
innoextract -e -q -c 0 -p 1 -d $ADDITIONAL_ARGS "$TEMP_DIR" \
        "$INSTALLER_FILE" 2>&1 | \
        tee "$INNO_LOGFILE" | \
        while read -d $'\r' input; do
    PERCENTAGE="$(echo "$input" | grep -o -P '\d+(?=\.\d+%)')"
    if [ "$PERCENTAGE" ] && [ "$PERCENTAGE" -ne "$LAST_PERCENTAGE" ]; then
        # Wait for the last pulse update to finish, so we don't spawn
        # too many processes
        wait
        # Run the command asyncronously because it takes about 300ms to finish
        POL_SetupWindow_pulse "$PERCENTAGE" &
        LAST_PERCENTAGE="$PERCENTAGE"
    fi
done

# Check return code of innoextract and show the logfile if it failed
if [ $? -ne 0 ]; then
   POL_SetupWindow_file "$(eval_gettext 'Failed to extract files. Is innoextract is up to date and the input file valid?')" "$TITLE" "$INNO_LOGFILE"
   POL_SetupWindow_Close
   exit $EXIT_ERROR
fi

# Some applications can have files with leading whitespace, which gets ignored
# by the installer. If you find a case where this is intentional, please
# notify me.

# Find files with leading whitespace characters
find "${TEMP_DIR}/app" -name " *" -print0 | \
        while read -d $'\0' FILENAME; do
    BASE="$(basename "$FILENAME")"
    DIR="$(dirname "$FILENAME")"
    # Replace leading whitespace with nothing
    BASE_TRIM="$(echo "$BASE" | sed -e 's/^ *//')"

    # Rename the file
    mv "$FILENAME" "${DIR}/${BASE_TRIM}"
done

# Remove the install folder if it exists
if [ -e "$INSTALL_PATH" ]; then
    rm -r "$INSTALL_PATH"
fi
# Make sure parent directory exists
mkdir -p "$(dirname "$INSTALL_PATH")"
# Move the app folder
mv "${TEMP_DIR}/app" "$INSTALL_PATH"

POL_Debug_Message "${INSTALLER_FILE} successfully installed to ${INSTALL_PATH}"

Contributions

Filters:

Contribuer
Membre Messages
Yepoleb Dimanche 3 Janvier 2016 à 1:13
Yepoleb Anonymous

Information

Cette mise à jour a été acceptée par l'équipe

Messages

TIL about the difference between single and double quotes.

  • Fixed issues where variables were not properly inserted
  • Added debug message at the bottom

Differences

@@ -66,10 +66,10 @@
 # Find files with leading whitespace characters
 find "${TEMP_DIR}/app" -name " *" -print0 | \
         while read -d $'\0' FILENAME; do
-    BASE="$(basename '$FILENAME')"
-    DIR="$(dirname '$FILENAME')"
+    BASE="$(basename "$FILENAME")"
+    DIR="$(dirname "$FILENAME")"
     # Replace leading whitespace with nothing
-    BASE_TRIM="$(echo '$BASE' | sed -e 's/^ *//')"
+    BASE_TRIM="$(echo "$BASE" | sed -e 's/^ *//')"
 
     # Rename the file
     mv "$FILENAME" "${DIR}/${BASE_TRIM}"
@@ -80,6 +80,8 @@
     rm -r "$INSTALL_PATH"
 fi
 # Make sure parent directory exists
-mkdir -p "$(dirname '$INSTALL_PATH')"
+mkdir -p "$(dirname "$INSTALL_PATH")"
 # Move the app folder
 mv "${TEMP_DIR}/app" "$INSTALL_PATH"
+
+POL_Debug_Message "${INSTALLER_FILE} successfully installed to ${INSTALL_PATH}"

Nouveau code source

#!/bin/bash
# Date : (2015-12-07 06-36)
# Last revision : (2015-12-19 18-28)
# Distribution used to test : Debian Sid (Unstable)
# Author : Gabriel Huber huberg18@gmail.com
# Script licence : GPL v.2

local INSTALLER_FILE="$1"
local TEMP_DIR="$2"
local INSTALL_PATH="$3"
local ADDITIONAL_ARGS="$4"

if [ ! "$INSTALLER_FILE" ]; then
    POL_Debug_Fatal "$(eval_gettext 'POL_innoextract failed: INSTALLER_FILE not set.')"
fi
if [ ! "$TEMP_DIR" ]; then
    POL_Debug_Fatal "$(eval_gettext 'POL_innoextract failed: TEMP_DIR not set.')"
fi
if [ ! "$INSTALL_PATH" ]; then
    POL_Debug_Fatal "$(eval_gettext 'POL_innoextract failed: INSTALL_PATH not set.')"
fi

# Check if we have innoextract
innoextract --version >/dev/null 2>&1
if [ $? -ne 0 ]; then
    POL_Debug_Fatal "$(eval_gettext 'Could not find innoextract binary. Install the "innoextract" package or see http://constexpr.org/innoextract for more information on how to install, then run the script again.')"
else
    POL_Debug_Message "Found innoextract"
fi

POL_SetupWindow_pulsebar "$(eval_gettext 'Extracting game files...')" "$TITLE"

# Extract installer data
local INNO_LOGFILE="${TEMP_DIR}/innoextract.log"
local LAST_PERCENTAGE="0"
# Fix return code for piped commands
set -o pipefail
# -e = extract, -q = quiet, -c = no color, -p = enable progress bar,
# -d = output directory
innoextract -e -q -c 0 -p 1 -d $ADDITIONAL_ARGS "$TEMP_DIR" \
        "$INSTALLER_FILE" 2>&1 | \
        tee "$INNO_LOGFILE" | \
        while read -d $'\r' input; do
    PERCENTAGE="$(echo "$input" | grep -o -P '\d+(?=\.\d+%)')"
    if [ "$PERCENTAGE" ] && [ "$PERCENTAGE" -ne "$LAST_PERCENTAGE" ]; then
        # Wait for the last pulse update to finish, so we don't spawn
        # too many processes
        wait
        # Run the command asyncronously because it takes about 300ms to finish
        POL_SetupWindow_pulse "$PERCENTAGE" &
        LAST_PERCENTAGE="$PERCENTAGE"
    fi
done

# Check return code of innoextract and show the logfile if it failed
if [ $? -ne 0 ]; then
   POL_SetupWindow_file "$(eval_gettext 'Failed to extract files. Is innoextract is up to date and the input file valid?')" "$TITLE" "$INNO_LOGFILE"
   POL_SetupWindow_Close
   exit $EXIT_ERROR
fi

# Some applications can have files with leading whitespace, which gets ignored
# by the installer. If you find a case where this is intentional, please
# notify me.

# Find files with leading whitespace characters
find "${TEMP_DIR}/app" -name " *" -print0 | \
        while read -d $'\0' FILENAME; do
    BASE="$(basename "$FILENAME")"
    DIR="$(dirname "$FILENAME")"
    # Replace leading whitespace with nothing
    BASE_TRIM="$(echo "$BASE" | sed -e 's/^ *//')"

    # Rename the file
    mv "$FILENAME" "${DIR}/${BASE_TRIM}"
done

# Remove the install folder if it exists
if [ -e "$INSTALL_PATH" ]; then
    rm -r "$INSTALL_PATH"
fi
# Make sure parent directory exists
mkdir -p "$(dirname "$INSTALL_PATH")"
# Move the app folder
mv "${TEMP_DIR}/app" "$INSTALL_PATH"

POL_Debug_Message "${INSTALLER_FILE} successfully installed to ${INSTALL_PATH}"

Réponses

Yepoleb Mercredi 23 Décembre 2015 à 5:22
Yepoleb Anonymous

Warning

Cette mise à jour n'a pas été approuvée par l'équipe.
Utilisez-la à vos risques et périls

Messages

  • Replaced all global variables with local
  • Replaced display_error with POL_Debug_Fatal
  • Added script name to error messages
  • Improved innoextract check
  • Removed the wait after the progress loop because all remaining threads should be killed automatically
  • Removed whitespace at line ends
  • Changed extraction error message

Differences

@@ -0,0 +1,85 @@
+#!/bin/bash
+# Date : (2015-12-07 06-36)
+# Last revision : (2015-12-19 18-28)
+# Distribution used to test : Debian Sid (Unstable)
+# Author : Gabriel Huber huberg18@gmail.com
+# Script licence : GPL v.2
+
+local INSTALLER_FILE="$1"
+local TEMP_DIR="$2"
+local INSTALL_PATH="$3"
+local ADDITIONAL_ARGS="$4"
+
+if [ ! "$INSTALLER_FILE" ]; then
+    POL_Debug_Fatal "$(eval_gettext 'POL_innoextract failed: INSTALLER_FILE not set.')"
+fi
+if [ ! "$TEMP_DIR" ]; then
+    POL_Debug_Fatal "$(eval_gettext 'POL_innoextract failed: TEMP_DIR not set.')"
+fi
+if [ ! "$INSTALL_PATH" ]; then
+    POL_Debug_Fatal "$(eval_gettext 'POL_innoextract failed: INSTALL_PATH not set.')"
+fi
+
+# Check if we have innoextract
+innoextract --version >/dev/null 2>&1
+if [ $? -ne 0 ]; then
+    POL_Debug_Fatal "$(eval_gettext 'Could not find innoextract binary. Install the "innoextract" package or see http://constexpr.org/innoextract for more information on how to install, then run the script again.')"
+else
+    POL_Debug_Message "Found innoextract"
+fi
+
+POL_SetupWindow_pulsebar "$(eval_gettext 'Extracting game files...')" "$TITLE"
+
+# Extract installer data
+local INNO_LOGFILE="${TEMP_DIR}/innoextract.log"
+local LAST_PERCENTAGE="0"
+# Fix return code for piped commands
+set -o pipefail
+# -e = extract, -q = quiet, -c = no color, -p = enable progress bar,
+# -d = output directory
+innoextract -e -q -c 0 -p 1 -d $ADDITIONAL_ARGS "$TEMP_DIR" \
+        "$INSTALLER_FILE" 2>&1 | \
+        tee "$INNO_LOGFILE" | \
+        while read -d $'\r' input; do
+    PERCENTAGE="$(echo "$input" | grep -o -P '\d+(?=\.\d+%)')"
+    if [ "$PERCENTAGE" ] && [ "$PERCENTAGE" -ne "$LAST_PERCENTAGE" ]; then
+        # Wait for the last pulse update to finish, so we don't spawn
+        # too many processes
+        wait
+        # Run the command asyncronously because it takes about 300ms to finish
+        POL_SetupWindow_pulse "$PERCENTAGE" &
+        LAST_PERCENTAGE="$PERCENTAGE"
+    fi
+done
+
+# Check return code of innoextract and show the logfile if it failed
+if [ $? -ne 0 ]; then
+   POL_SetupWindow_file "$(eval_gettext 'Failed to extract files. Is innoextract is up to date and the input file valid?')" "$TITLE" "$INNO_LOGFILE"
+   POL_SetupWindow_Close
+   exit $EXIT_ERROR
+fi
+
+# Some applications can have files with leading whitespace, which gets ignored
+# by the installer. If you find a case where this is intentional, please
+# notify me.
+
+# Find files with leading whitespace characters
+find "${TEMP_DIR}/app" -name " *" -print0 | \
+        while read -d $'\0' FILENAME; do
+    BASE="$(basename '$FILENAME')"
+    DIR="$(dirname '$FILENAME')"
+    # Replace leading whitespace with nothing
+    BASE_TRIM="$(echo '$BASE' | sed -e 's/^ *//')"
+
+    # Rename the file
+    mv "$FILENAME" "${DIR}/${BASE_TRIM}"
+done
+
+# Remove the install folder if it exists
+if [ -e "$INSTALL_PATH" ]; then
+    rm -r "$INSTALL_PATH"
+fi
+# Make sure parent directory exists
+mkdir -p "$(dirname '$INSTALL_PATH')"
+# Move the app folder
+mv "${TEMP_DIR}/app" "$INSTALL_PATH"

Nouveau code source

#!/bin/bash
# Date : (2015-12-07 06-36)
# Last revision : (2015-12-19 18-28)
# Distribution used to test : Debian Sid (Unstable)
# Author : Gabriel Huber huberg18@gmail.com
# Script licence : GPL v.2

local INSTALLER_FILE="$1"
local TEMP_DIR="$2"
local INSTALL_PATH="$3"
local ADDITIONAL_ARGS="$4"

if [ ! "$INSTALLER_FILE" ]; then
    POL_Debug_Fatal "$(eval_gettext 'POL_innoextract failed: INSTALLER_FILE not set.')"
fi
if [ ! "$TEMP_DIR" ]; then
    POL_Debug_Fatal "$(eval_gettext 'POL_innoextract failed: TEMP_DIR not set.')"
fi
if [ ! "$INSTALL_PATH" ]; then
    POL_Debug_Fatal "$(eval_gettext 'POL_innoextract failed: INSTALL_PATH not set.')"
fi

# Check if we have innoextract
innoextract --version >/dev/null 2>&1
if [ $? -ne 0 ]; then
    POL_Debug_Fatal "$(eval_gettext 'Could not find innoextract binary. Install the "innoextract" package or see http://constexpr.org/innoextract for more information on how to install, then run the script again.')"
else
    POL_Debug_Message "Found innoextract"
fi

POL_SetupWindow_pulsebar "$(eval_gettext 'Extracting game files...')" "$TITLE"

# Extract installer data
local INNO_LOGFILE="${TEMP_DIR}/innoextract.log"
local LAST_PERCENTAGE="0"
# Fix return code for piped commands
set -o pipefail
# -e = extract, -q = quiet, -c = no color, -p = enable progress bar,
# -d = output directory
innoextract -e -q -c 0 -p 1 -d $ADDITIONAL_ARGS "$TEMP_DIR" \
        "$INSTALLER_FILE" 2>&1 | \
        tee "$INNO_LOGFILE" | \
        while read -d $'\r' input; do
    PERCENTAGE="$(echo "$input" | grep -o -P '\d+(?=\.\d+%)')"
    if [ "$PERCENTAGE" ] && [ "$PERCENTAGE" -ne "$LAST_PERCENTAGE" ]; then
        # Wait for the last pulse update to finish, so we don't spawn
        # too many processes
        wait
        # Run the command asyncronously because it takes about 300ms to finish
        POL_SetupWindow_pulse "$PERCENTAGE" &
        LAST_PERCENTAGE="$PERCENTAGE"
    fi
done

# Check return code of innoextract and show the logfile if it failed
if [ $? -ne 0 ]; then
   POL_SetupWindow_file "$(eval_gettext 'Failed to extract files. Is innoextract is up to date and the input file valid?')" "$TITLE" "$INNO_LOGFILE"
   POL_SetupWindow_Close
   exit $EXIT_ERROR
fi

# Some applications can have files with leading whitespace, which gets ignored
# by the installer. If you find a case where this is intentional, please
# notify me.

# Find files with leading whitespace characters
find "${TEMP_DIR}/app" -name " *" -print0 | \
        while read -d $'\0' FILENAME; do
    BASE="$(basename '$FILENAME')"
    DIR="$(dirname '$FILENAME')"
    # Replace leading whitespace with nothing
    BASE_TRIM="$(echo '$BASE' | sed -e 's/^ *//')"

    # Rename the file
    mv "$FILENAME" "${DIR}/${BASE_TRIM}"
done

# Remove the install folder if it exists
if [ -e "$INSTALL_PATH" ]; then
    rm -r "$INSTALL_PATH"
fi
# Make sure parent directory exists
mkdir -p "$(dirname '$INSTALL_PATH')"
# Move the app folder
mv "${TEMP_DIR}/app" "$INSTALL_PATH"

Réponses

Samedi 26 Décembre 2015 à 15:52
* Added script name to error messages
That one is actually interesting, because at first I thought that since POL_Debug_Fatal displays the name of the function calling it, it was redundant.
But POL_Calls are not just function calls, and what POL_Debug_Fatal displays is that the error comes from within "source" function; That makes sense, and yet is not what one would expect, I wonder if that could be improved...

innoextract --version >/dev/null 2>&1
if [ $? -ne 0 ]; then ...
You can also just use
if innoextract --version >/dev/null 2>&1; then ...
We're so used to use "if" with "test" that we sometimes forget it's just a special case of the way "if" works...
Samedi 26 Décembre 2015 à 15:53
or rather in this case if ! innoextract --version >/dev/null 2>&1; then ...
Anonymous
Samedi 26 Décembre 2015 à 15:59
I know, but it's very hard to read, that's why I did it this way.
Yepoleb Lundi 21 Décembre 2015 à 5:38
Yepoleb Anonymous

Warning

Cette mise à jour n'a pas été approuvée par l'équipe.
Utilisez-la à vos risques et périls

Differences

@@ -0,0 +1,96 @@
+#!/bin/bash
+# Date : (2015-12-07 06-36)
+# Last revision : (2015-12-19 18-28)
+# Distribution used to test : Debian Sid (Unstable)
+# Author : Gabriel Huber huberg18@gmail.com
+# Script licence : GPL v.2
+
+INSTALLER_FILE="$1"
+TEMP_DIR="$2"
+INSTALL_PATH="$3"
+ADDITIONAL_ARGS="$4"
+
+display_error ()
+{
+    POL_SetupWindow_message "$1"
+    POL_SetupWindow_Close
+    exit $EXIT_ERROR
+}
+
+if [ ! "$INSTALLER_FILE" ]; then
+    display_error "$(eval_gettext 'Error: INSTALLER_FILE not set.')"
+fi
+if [ ! "$TEMP_DIR" ]; then
+    display_error "$(eval_gettext 'Error: TEMP_DIR not set.')"
+fi
+if [ ! "$INSTALL_PATH" ]; then
+    display_error "$(eval_gettext 'Error: INSTALL_PATH not set.')"
+fi
+
+# Check if we have innoextract
+if [! innoextract --version >/dev/null 2>&1 ]; then
+    display_error "$(eval_gettext 'Could not find innoextract binary. Install the \"innoextract\" package or see http://constexpr.org/innoextract for more information on how to install, then run the script again.')"
+else
+    POL_Debug_Message "Found innoextract"
+fi
+
+POL_SetupWindow_pulsebar "$(eval_gettext 'Extracting game files...')" "$TITLE"
+
+# Extract installer data
+INNO_LOGFILE="${TEMP_DIR}/innoextract.log"
+LAST_PERCENTAGE="0"
+# Fix return code for piped commands
+set -o pipefail
+# -e = extract, -q = quiet, -c = no color, -p = enable progress bar, 
+# -d = output directory
+innoextract -e -q -c 0 -p 1 -d $ADDITIONAL_ARGS "$TEMP_DIR" \
+	"$INSTALLER_FILE" 2>&1 | \
+        tee "$INNO_LOGFILE" | \
+        while read -d $'\r' input; do
+    PERCENTAGE="$(echo "$input" | grep -o -P '\d+(?=\.\d+%)')"
+    if [ "$PERCENTAGE" ] && [ "$PERCENTAGE" -ne "$LAST_PERCENTAGE" ]; then
+        # Wait for the last pulse update to finish, so we don't spawn 
+        # too many processes
+        wait
+        # Run the command asyncronously because it takes about 300ms to finish
+        POL_SetupWindow_pulse "$PERCENTAGE" &
+        LAST_PERCENTAGE="$PERCENTAGE"
+    fi
+done
+
+EXITCODE=$?
+# Wait for the last percentage update to finish
+wait
+
+echo "Exitcode ${EXITCODE}"
+# Check return code of innoextract and show the logfile if it failed
+if [ $EXITCODE -ne 0 ]; then
+   POL_SetupWindow_file "$(eval_gettext 'Failed to extract files. Check if innoextract is up to date and the input file is valid. Read logfile for more information:')" "$TITLE" "$INNO_LOGFILE"
+   POL_SetupWindow_Close
+   exit $EXIT_ERROR
+fi
+
+# Some applications can have files with leading whitespace, which gets ignored 
+# by the installer. If you find a case where this is intentional, please 
+# notify me.
+
+# Find files with leading whitespace characters. 
+find "${TEMP_DIR}/app" -name " *" -print0 | \
+        while read -d $'\0' FILENAME; do
+    BASE="$(basename '$FILENAME')"
+    DIR="$(dirname '$FILENAME')"
+    # Replace leading whitespace with nothing
+    BASE_TRIM="$(echo '$BASE' | sed -e 's/^ *//')"
+
+    # Rename the file
+    mv "$FILENAME" "${DIR}/${BASE_TRIM}"
+done
+
+# Remove the install folder if it exists
+if [ -e "$INSTALL_PATH" ]; then
+    rm -r "$INSTALL_PATH"
+fi
+# Make sure parent directory exists
+mkdir -p "$(dirname "$INSTALL_PATH")"
+# Move the app folder
+mv "${TEMP_DIR}/app" "$INSTALL_PATH"

Nouveau code source

#!/bin/bash
# Date : (2015-12-07 06-36)
# Last revision : (2015-12-19 18-28)
# Distribution used to test : Debian Sid (Unstable)
# Author : Gabriel Huber huberg18@gmail.com
# Script licence : GPL v.2

INSTALLER_FILE="$1"
TEMP_DIR="$2"
INSTALL_PATH="$3"
ADDITIONAL_ARGS="$4"

display_error ()
{
    POL_SetupWindow_message "$1"
    POL_SetupWindow_Close
    exit $EXIT_ERROR
}

if [ ! "$INSTALLER_FILE" ]; then
    display_error "$(eval_gettext 'Error: INSTALLER_FILE not set.')"
fi
if [ ! "$TEMP_DIR" ]; then
    display_error "$(eval_gettext 'Error: TEMP_DIR not set.')"
fi
if [ ! "$INSTALL_PATH" ]; then
    display_error "$(eval_gettext 'Error: INSTALL_PATH not set.')"
fi

# Check if we have innoextract
if [! innoextract --version >/dev/null 2>&1 ]; then
    display_error "$(eval_gettext 'Could not find innoextract binary. Install the \"innoextract\" package or see http://constexpr.org/innoextract for more information on how to install, then run the script again.')"
else
    POL_Debug_Message "Found innoextract"
fi

POL_SetupWindow_pulsebar "$(eval_gettext 'Extracting game files...')" "$TITLE"

# Extract installer data
INNO_LOGFILE="${TEMP_DIR}/innoextract.log"
LAST_PERCENTAGE="0"
# Fix return code for piped commands
set -o pipefail
# -e = extract, -q = quiet, -c = no color, -p = enable progress bar, 
# -d = output directory
innoextract -e -q -c 0 -p 1 -d $ADDITIONAL_ARGS "$TEMP_DIR" \
        "$INSTALLER_FILE" 2>&1 | \
        tee "$INNO_LOGFILE" | \
        while read -d $'\r' input; do
    PERCENTAGE="$(echo "$input" | grep -o -P '\d+(?=\.\d+%)')"
    if [ "$PERCENTAGE" ] && [ "$PERCENTAGE" -ne "$LAST_PERCENTAGE" ]; then
        # Wait for the last pulse update to finish, so we don't spawn 
        # too many processes
        wait
        # Run the command asyncronously because it takes about 300ms to finish
        POL_SetupWindow_pulse "$PERCENTAGE" &
        LAST_PERCENTAGE="$PERCENTAGE"
    fi
done

EXITCODE=$?
# Wait for the last percentage update to finish
wait

echo "Exitcode ${EXITCODE}"
# Check return code of innoextract and show the logfile if it failed
if [ $EXITCODE -ne 0 ]; then
   POL_SetupWindow_file "$(eval_gettext 'Failed to extract files. Check if innoextract is up to date and the input file is valid. Read logfile for more information:')" "$TITLE" "$INNO_LOGFILE"
   POL_SetupWindow_Close
   exit $EXIT_ERROR
fi

# Some applications can have files with leading whitespace, which gets ignored 
# by the installer. If you find a case where this is intentional, please 
# notify me.

# Find files with leading whitespace characters. 
find "${TEMP_DIR}/app" -name " *" -print0 | \
        while read -d $'\0' FILENAME; do
    BASE="$(basename '$FILENAME')"
    DIR="$(dirname '$FILENAME')"
    # Replace leading whitespace with nothing
    BASE_TRIM="$(echo '$BASE' | sed -e 's/^ *//')"

    # Rename the file
    mv "$FILENAME" "${DIR}/${BASE_TRIM}"
done

# Remove the install folder if it exists
if [ -e "$INSTALL_PATH" ]; then
    rm -r "$INSTALL_PATH"
fi
# Make sure parent directory exists
mkdir -p "$(dirname "$INSTALL_PATH")"
# Move the app folder
mv "${TEMP_DIR}/app" "$INSTALL_PATH"

Réponses

Mardi 22 Décembre 2015 à 11:53
My review:

INSTALLER_FILE="$1"
TEMP_DIR="$2"
INSTALL_PATH="$3"
ADDITIONAL_ARGS="$4"
Function scripts are sourced, it's recommended to declare those as local variables (using "local") to avoid collisions with calling script variables.

display_error ()
{
POL_SetupWindow_message "$1"
POL_SetupWindow_Close
exit $EXIT_ERROR
}
What about using POL_Debug_Fatal instead?

if [! innoextract --version >/dev/null 2>&1 ]; then
Did you test this line? [! gives a syntax error; Actually I think you don't need the square brackets in this case.

POL_Debug_Message "Found innoextract"
Shouldn't that be a fatal error too? The remaining of the function script cannot work correctly without innoextract.

POL_SetupWindow_file "$(eval_gettext 'Failed to extract files. Check if innoextract is up to date and the input file is valid. Read logfile for more information:')" "$TITLE" "$INNO_LOGFILE"
POL_SetupWindow_Close
exit $EXIT_ERROR
You probably missed this last place to use display_error or POL_Debug_Fatal
Anonymous
Mercredi 23 Décembre 2015 à 1:47
1. Thanks, I didn't know about local variables.
Anonymous
Mercredi 23 Décembre 2015 à 2:00
Oops, forgot I can't press enter in the comment window. New try:

1. Thanks, I didn't know about local variables.
2. I thought POL_Debug_Fatal works like POL_Debug_Message and silently logs to the terminal without displaying the error.
3. Yes, that's a very ugly line, I should have expected it to break.
4. There's an else before that line, it only executes if innoextract was found.
5. I'm using POL_SetupWindow_file to show the logfile, display_error uses POL_SetupWindow_message.

Thanks for your detailed feedback :)

This site allows content generated by members, and we promptly remove any content that infringes copyright according to our Terms of Service. To report copyright infringement, please send a notice to dmca-notice@playonlinux.com