The forum

[script] The Darkmod

Author Replies
b1k3rdude Friday 29 May 2015 at 14:38
b1k3rdude

Evening

One of forum members over on the darkmod forums has got a new script code for me to try out and he will have an updated version over the week once I have some feedback for him from the test run tomoz - 


#!/bin/bash
# Date : 2015-05-28
# Last revision : 2015-05-28
# Wine version used : 1.7.16
# Distribution used to test : Mac OS 10.9.5 
# Author : Freek 'Freyk' Borgerink
# Licence : GPL
 
[ "$PLAYONLINUX" = "" ] && exit 0
source "$PLAYONLINUX/lib/sources"
 
TITLE="The Dark Mod"
PREFIX="TheDarkMod"
EDITOR="Broken Glass Studios"
GAME_URL="http://www.thedarkmod.com"
AUTHOR="Freek 'Freyk' Borgerink"
WORKING_WINE_VERSION="1.7.16"

 # Starting the script
POL_SetupWindow_Init
 
# Starting debugging API
POL_Debug_Init
 
POL_SetupWindow_presentation "$TITLE" "$EDITOR" "$GAME_URL" "$AUTHOR" "$PREFIX"
 
# Setting prefix
POL_Wine_SelectPrefix "$PREFIX"
POL_Wine_PrefixCreate #"$WORKING_WINE_VERSION"


POL_SetupWindow_InstallMethod "DOWNLOAD,LOCAL"
if [ "$INSTALL_METHOD" = "LOCAL" ]
then
	#create prefix folder
    mkdir -p "$WINEPREFIX/drive_c/games/thedarkmod"
    cd "$WINEPREFIX/drive_c/games/thedarkmod"
    POL_SetupWindow_message "Please download the darkmod updater executable from www.thedarkmod.com" "$TITLE installation"
	POL_SetupWindow_browse "Please select the darkmod updater executable to run." "$TITLE installation"
	POL_Wine start /unix "$APP_ANSWER"
    cp "$APP_ANSWER" "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update.exe"
	#Create the shortcut for the updater
	POL_Shortcut "tdm_update.exe" "The Dark Mod Updater"
	touch "$WINEPREFIX/drive_c/games/thedarkmod/tdm.exe"
	POL_Shortcut "tdm.exe" "The Dark Mod"
fi

if [ "$INSTALL_METHOD" = "DOWNLOAD" ]
then
	#create prefix folder
	#Download tdm updater
	mkdir -p "$WINEPREFIX/drive_c/games/thedarkmod"
    cd "$WINEPREFIX/drive_c/games/thedarkmod"
	#Download tdm updater
	POL_Download "http://www.fidcal.com/darkuser/tdm_update_win.zip" "ff1b6d10c65970422206133e923cf36d"
	#Unpack the zipfile
	POL_System_ExtractSingleFile "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update_win.zip" "tdm_update.exe" "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update.exe"
    rm "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update_win.zip"
    #Create shortcut for updater
	POL_Shortcut "tdm_update.exe" "The Dark Mod Updater"
	touch "$WINEPREFIX/drive_c/games/thedarkmod/tdm.exe"
	POL_Shortcut "tdm.exe" "The Dark Mod" 
fi
 
 	#Run the updater
    INSTALLER="$WINEPREFIX/drive_c/games/thedarkmod/tdm_update.exe"
	POL_SetupWindow_wait "Installation in progress." "The Dark Mod installation"
	POL_Wine start /unix "$INSTALLER"
	POL_Wine_WaitExit "The Dark Mod Updater"
 
 
 POL_SetupWindow_message "Hello World!" "My first message"
 
POL_SetupWindow_Close
exit 0
petch Saturday 30 May 2015 at 11:47
petch

Hi,

Here's my review:

POL_Wine_PrefixCreate #"$WORKING_WINE_VERSION"

The Wine version declared is not used, if you really want to use the system installed version (not that I recommend that) remove $WORKING_WINE_VERSION declaration altogether.

POL_SetupWindow_message "Please download the darkmod updater executable from www.thedarkmod.com" "$TITLE installation"

All user-oriented messages must support localization (http://wiki.playonlinux.com/index.php/Scripting_-_Chapter_10:_Script_Translation)

POL_SetupWindow_browse "Please select the darkmod updater executable to run." "$TITLE installation"

Use standard messages for standard cases to save on translators' work (http://wiki.playonlinux.com/index.php/Scripting_-_Chapter_9:_Standardization)

    POL_Wine start /unix "$APP_ANSWER"
...
    touch "$WINEPREFIX/drive_c/games/thedarkmod/tdm.exe"
    POL_Shortcut "tdm.exe" "The Dark Mod"

"start /unix" is usually unnecessary, and also makes POL_Wine non-blocking; Since it's not followed by POL_Wine_WaitExit "$TITLE", the script will continue before above command completes, which could explain the need for the "touch" command below?

    POL_SetupWindow_wait "Installation in progress." "The Dark Mod installation"

You can use POL_Wine_WaitBefore "$TITLE" instead, will save you the trouble for another message to localize.

POL_SetupWindow_message "Hello World!" "My first message"

Debugging leftover?

freyk Saturday 30 May 2015 at 17:07
freyk

Here is a update of the code.

- added some new install options

#!/bin/bash
# Date : 2015-05-28
# Last revision : 2015-05-30
# Wine version used : 1.7.16
# Distribution used to test : Mac OS 10.9.5
# Author : Freek 'Freyk' Borgerink
# Licence : GPL

[ "$PLAYONLINUX" = "" ] && exit 0
source "$PLAYONLINUX/lib/sources"

TITLE="The Dark Mod"
PREFIX="TheDarkMod"
EDITOR="Broken Glass Studios"
GAME_URL="http://www.thedarkmod.com"
AUTHOR="Freek 'Freyk' Borgerink"
WORKING_WINE_VERSION="1.7.16"

#md5hash of tdm_update_win.zip from the thedarkmod.com site
TDMWINUPDATEHASH="ff1b6d10c65970422206133e923cf36d"

################################
#clear script vars
RUNUPDATER="0"

 # Starting the script
POL_SetupWindow_Init

# Starting debugging API
POL_Debug_Init

POL_SetupWindow_presentation "$TITLE" "$EDITOR" "$GAME_URL" "$AUTHOR" "$PREFIX"

#Select the download method
POL_SetupWindow_menu "How would you like to install The Dark Mod?" "Install Method" "Online|Local updater zip|Local Standonlone zip" "|"
INSTALLMETHOD="$APP_ANSWER"

if [ "$INSTALLMETHOD" = "Online" ]
then
    #create prefix folder
    POL_Wine_SelectPrefix "$PREFIX"
    POL_Wine_PrefixCreate #"$WORKING_WINE_VERSION"
    Set_OS "win7"
    mkdir -p "$WINEPREFIX/drive_c/games/thedarkmod"
    cd "$WINEPREFIX/drive_c/games/thedarkmod"
    #Download tdm updater
    POL_Download "http://www.fidcal.com/darkuser/tdm_update_win.zip" "$TDMWINUPDATEHASH"
    #Unpack the zipfile
    POL_System_ExtractSingleFile "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update_win.zip" "tdm_update.exe" "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update.exe"
    rm "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update_win.zip"
    #Create shortcut for updater
    POL_Shortcut "tdm_update.exe" "The Dark Mod Updater"
    RUNUPDATER="1"
fi

if [ "$INSTALLMETHOD" = "Local updater zip" ]
then
    #create prefix folder
    POL_SetupWindow_message "Please download the darkmod updater executable from www.thedarkmod.com" "$TITLE installation"
    POL_SetupWindow_browse "Please select the darkmod updater executable to run." "$TITLE installation"
    # Setting prefix
    POL_Wine_SelectPrefix "$PREFIX"
    POL_Wine_PrefixCreate #"$WORKING_WINE_VERSION"
    mkdir -p "$WINEPREFIX/drive_c/games/thedarkmod"
    #Unpack the zipfile
    POL_System_ExtractSingleFile "$APP_ANSWER" "tdm_update.exe" "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update.exe"
    #Create the shortcut for the updater
    POL_Shortcut "tdm_update.exe" "The Dark Mod Updater"
    POL_SetupWindow_message "running updater" "Going to run the updater to download the files"
    RUNUPDATER="1"   
fi

if [ "$INSTALLMETHOD" = "Local Standonlone zip" ]
then
    #create prefix folder
    POL_SetupWindow_message "Please download the darkmod zip from www.thedarkmod.com" "$TITLE installation"
    POL_SetupWindow_browse "Please select the darkmod standaonline zip file to run." "$TITLE installation"
    # Setting prefix
    POL_Wine_SelectPrefix "$PREFIX"
    POL_Wine_PrefixCreate #"$WORKING_WINE_VERSION"
    mkdir -p "$WINEPREFIX/drive_c/games/thedarkmod"

    #Unpack the zipfile
    cd "$WINEPREFIX/drive_c/games/thedarkmod/"
    POL_System_unzip "$APP_ANSWER"

    #Create the shortcuts
    POL_Shortcut "tdm_update.exe" "The Dark Mod Updater"
    POL_Shortcut "tdm.exe" "The Dark Mod"
    POL_SetupWindow_menu "Run the updater to update the files?" "Run Updater" "Yes|No" "|"
    if [ "$APP_ANSWER" = "Yes" ]
    then
        RUNUPDATER="1"
    else
        RUNUPDATER="0"   
    fi
fi

#Setting wine stuff
Set_OS "win7"

if [ "$RUNUPDATER" = "1" ]
then
    POL_SetupWindow_message "Going to run the updater. In the updater click only on 'continue' or 'ok'. If the updater fails, close all the windows and run the updater again with the shortcut" "running updater"
     #Run the updater
    POL_SetupWindow_wait "The Dark Mod Updater in progress." "The Dark Mod Updater"
    POL_Wine start /unix "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update.exe"
    POL_Wine_WaitExit "The Dark Mod Updater"
fi

POL_SetupWindow_Close
exit 0

Edited by freyk

b1k3rdude Monday 1 June 2015 at 21:22
b1k3rdude

Right tested the latest version of your script -

Part 1 - http://youtu.be/_C2etVJvfHo

Part 2 - http://youtu.be/xAetSPOo5Kc

 

petch Monday 1 June 2015 at 23:11
petch

Most remarks apply to this second script too.

I'm not too sure about hijacking $INSTALLMETHOD instead of using standard POL_SetupWindow_InstallMethod either

freyk Monday 8 June 2015 at 10:17
freyk

Thanks for the advice,

I compared lots of code of other applications and games.
Here a my changes:

  • Used "eval_gettext" for the translation
  • Added a wine version for POL_Wine_PrefixCreate
  • Use "POL_Wine" to launch wine
  • Did not use "POL_SetupWindow_InstallMethod" because there are more installation methods
  • I choose to not  use the optional md5 checksum for POL_Download, so people dont have to change this script every time when there is a update for the updater 
  • And a added function for file presence check (cannot find a good pol-function for this one).
#!/bin/bash
# Date : 2015-05-28
# Last revision : 2015-06-07
# Wine version used : 1.7.16
# Distribution used to test : Mac OS 10.9.5
# Author : Freek 'Freyk' Borgerink
# Licence : GPL
 
[ "$PLAYONLINUX" = "" ] && exit 0
source "$PLAYONLINUX/lib/sources"
 
 
TITLE="The Dark Mod"
PREFIX="TheDarkMod"
EDITOR="Broken Glass Studios"
GAME_URL="http://www.thedarkmod.com"
AUTHOR="Freek 'Freyk' Borgerink"
WORKING_WINE_VERSION="1.7.16"
 
#md5hash of tdm_update_win.zip from the thedarkmod.com site
TDMWINUPDATERDOWNLOADLOCATION="http://www.fidcal.com/darkuser/tdm_update_win.zip"
#$TDMWINUPDATERHASH="ff1b6d10c65970422206133e923cf36d"
 
 
################################
 
#function to run the updater
function fncRunUpdater {
        POL_SetupWindow_message "$(eval_gettext 'Going to run the updater. In the updater click only on continue or ok.\nIf the updater fails, close all the windows and run the updater again with the shortcut.')" "$TITLE"
        cd "$WINEPREFIX/drive_c/games/thedarkmod"
         POL_SetupWindow_wait_next_signal "The Dark Mod Updater in progress." "$TITLE"
        #POL_Wine_WaitBefore "$TITLE"
        POL_Wine "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update.exe"
         #POL_SetupWindow_detect_exit
         POL_Wine_WaitExit "$TITLE"
}
 
#function to check if the dark mod executable is present
function fncFilePresenceCheck {
        FILE="$WINEPREFIX/drive_c/games/thedarkmod/TheDarkMod.exe"
        #POL_SetupWindow_message "$(eval_gettext 'Going to check the file presence of $FILE ')" "$TITLE"
        if [ -f $FILE ]; then
                #POL_SetupWindow_message "$(eval_gettext 'The Dark Mod Executable is present')" "$TITLE"
                POL_Shortcut "TheDarkMod.exe" "The Dark Mod"
        else
                POL_SetupWindow_message "$(eval_gettext 'The Dark Mod Executable is not present on your system\nPlease rerun the updater using the shortcut\nand create the shortcut mannualy')" "$TITLE"
        fi
}
 
#Starting the script
POL_SetupWindow_Init
 
#Starting debugging API
POL_Debug_Init
 
POL_SetupWindow_presentation "$TITLE" "$EDITOR" "$GAME_URL" "$AUTHOR" "$PREFIX"
 
#Select the download method.
#cant use POL_SetupWindow_InstallMethod, because there are more installation methods
POL_SetupWindow_menu "$(eval_gettext 'How would you like to install The Dark Mod?')" "Install Method" "Online|Local updater zip|Local Standonlone zip" "|"
INSTALLMETHOD="$APP_ANSWER"
 
if [ "$INSTALLMETHOD" = "Online" ]
then
        #create prefix folder
        POL_Wine_SelectPrefix "$PREFIX"
        POL_Wine_PrefixCreate "$WORKING_WINE_VERSION"
        mkdir -p "$WINEPREFIX/drive_c/games/thedarkmod"
    cd "$WINEPREFIX/drive_c/games/thedarkmod"
        #Download tdm updater
        POL_Download "$TDMWINUPDATERDOWNLOADLOCATION" #"$TDMWINUPDATERHASH"
        #Unpack the zipfile
        POL_System_ExtractSingleFile "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update_win.zip" "tdm_update.exe" "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update.exe"
    rm "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update_win.zip"
    #Create shortcut for updater
        POL_Shortcut "tdm_update.exe" "The Dark Mod Updater"
        fncRunUpdater
        fncFilePresenceCheck
fi
 
if [ "$INSTALLMETHOD" = "Local updater zip" ]
then
        #create prefix folder
    POL_SetupWindow_message "$(eval_gettext 'Please download the darkmod updater zip file from \n$GAME_URL')" "$TITLE"
        POL_SetupWindow_browse "$(eval_gettext 'Please select the darkmod updater zip file to run.\nIt must have the name tdm_update_win.zip')" "$TITLE"
        # Setting prefix
        POL_Wine_SelectPrefix "$PREFIX"
        POL_Wine_PrefixCreate "$WORKING_WINE_VERSION"
    mkdir -p "$WINEPREFIX/drive_c/games/thedarkmod"
    #Unpack the zipfile
        POL_System_ExtractSingleFile "$APP_ANSWER" "tdm_update.exe" "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update.exe"
        #Create the shortcuts
        POL_Shortcut "tdm_update.exe" "The Dark Mod Updater"
        fncRunUpdater
        fncFilePresenceCheck       
fi
 
if [ "$INSTALLMETHOD" = "Local Standonlone zip" ]
then
        POL_SetupWindow_message "$(eval_gettext 'Please download first The Dark Mod standalone release zip-file:\n\nTHE DARK MOD Version 2.0 - Standalone Release\n\nFrom sites like: \n$GAME_URL\nhttp://www.moddb.com\nhttp://www.google.com')" "$TITLE"
        POL_SetupWindow_browse "$(eval_gettext 'Please select the darkmod standalone release zip file to run.')" "$TITLE"
        #create prefix folder
        POL_Wine_SelectPrefix "$PREFIX"
        POL_Wine_PrefixCreate "$WORKING_WINE_VERSION"
    mkdir -p "$WINEPREFIX/drive_c/games/"
    #Unpack the zipfile
    cd "$WINEPREFIX/drive_c/games/"
        POL_System_unzip "$APP_ANSWER"
        #rename folder
        mv "$WINEPREFIX/drive_c/games/THE DARK MOD Version 2.0 - Standalone Release/" "$WINEPREFIX/drive_c/games/thedarkmod"
        #Set permissions
        chmod -R ug+rw "$WINEPREFIX/drive_c/games/thedarkmod"
        #set shortcut
        POL_Shortcut "TheDarkMod.exe" "The Dark Mod"
        POL_Shortcut "tdm_update.exe" "The Dark Mod Updater"
        POL_SetupWindow_menu "$(eval_gettext 'The 2.0 updater doesnt run on $WORKING_WINE_VERSION.\nWould you like that I download a newer version of the the updater\nand then update the files?')" "Run Updater" "Yes|No" "|"
        if [ "$APP_ANSWER" = "Yes" ]
        then
                POL_SetupWindow_message "$(eval_gettext 'Going Online to update the updater and run it.')" "$TITLE"
                cd "$WINEPREFIX/drive_c/games/thedarkmod"
                #Download tdm updater
                POL_Download "$TDMWINUPDATERDOWNLOADLOCATION" #"$TDMWINUPDATERHASH"
                #remove old updater
                rm "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update.exe"
                rm "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update.log"
                #Unpack the zipfile
                POL_System_ExtractSingleFile "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update_win.zip" "tdm_update.exe" "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update.exe"
            rm "$WINEPREFIX/drive_c/games/thedarkmod/tdm_update_win.zip"
                fncRunUpdater
        fi       
fi
 
#Setting wine stuff
Set_OS "win7"
 
#send end message
POL_SetupWindow_message "$(eval_gettext 'This is the end of the $TITLE installation script. \n\nFor more info, visit $GAME_URL')" "end"
POL_SetupWindow_Close
exit 0


 

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 dmcayonlinux.com