Wrote my first install script for PlayOnLinux

I like to play games once in a while, but I don’t have Windows.
So like many other Linux gamers, I use Wine, but I like to have an overlay to keep things neat and organized, and thus I use PlayOnLinux.
PlayOnLinux comes with installation scripts so that the games will work right away without me having to fiddle around with a bunch of hacks to get it working, but as it turns out, the game I wanted to play (Civilization IV: Complete Edition) didn’t have an installation script that worked, so I decided to write my own and try to get it approved by the people at PlayOnLinux, and thus added to the software list of approved and signed scripts 🙂

It hasn’t been approved yet, but it’s getting there.
This is the script so far (fully working in this state).

Go to the link below for the newest development info

Another interesting thing to note, is that I am hosting the Civ IV patches myself that the script is downloading and installing, since I want to make sure that it’s always being hosted on a fast connection for everyone to use.

If anyone else need the patches for use outside of this script, you can download them below. (The patches below are no longer hosted by me!)

Civilization IV Patch 1.74
Civilization IV – Warlords Patch 2.13
Civilization IV – Beyond The Sword Patch 3.19

# Date : (2013-06-26)
# Last revision : (2013-07-23)
# Wine version used : 1.4.1
# Distribution used to test : xUbuntu 13.10
# Author : Jinny Ramsmark
# Licence : GPLv3
# Depend : msxml3, d3dx9

# This script was tested using the DVD version of `Civilization IV: Complete'
# version 1.74, bought in the Sweden in 2011.

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

TITLE="Civilization IV: Complete Edition"
TITLECIV="Civilization IV"
TITLEBTS="Civilization IV - Beyond The Sword"
TITLEW="Civilization IV - Warlords"
TITLECOL="Civilization IV - Colonization"
AUTHOR="Jinny Ramsmark"

POL_GetSetupImages "http://files.playonlinux.com/resources/setups/$PREFIX/top.jpg" "http://files.playonlinux.com/resources/setups/$PREFIX/left.jpg" "$TITLE"

POL_SetupWindow_SetID 1779

POL_SetupWindow_presentation "$TITLE" "Firaxis Games" "http://www.firaxis.com/" "$AUTHOR" "$PREFIX"
POL_Wine_SelectPrefix "$PREFIX"

POL_SetupWindow_InstallMethod "DVD,STEAM"

if [ "$INSTALL_METHOD" == "DVD" ]; then
    # Let the user select a DVD

    # Check if this DVD is the Civilization IV DVD
    POL_SetupWindow_check_cdrom "Autorun/Civ4Installer.ico"

# Set and install the correct Wine version

# Install DirectX9
POL_Call POL_Install_d3dx9

if [ "$INSTALL_METHOD" == "DVD" ]; then
    # Run installer
    POL_Wine_WaitBefore "$TITLECIV"
    POL_Wine start /unix "$CDROM/setup.exe"
    POL_Wine_WaitExit "$TITLECIV"

    #Patch Civilization IV: Beyond the sword to 3.19
    cd "$POL_USER_ROOT/tmp"
    POL_Download "http://ayu.alcor.se/files/Civ4BeyondTheSwordPatch3.19.exe" "c45f6e028f51db2386120a5861eabe7c"
    POL_Wine_WaitBefore "$TITLECIV"
    POL_Wine Civ4BeyondTheSwordPatch3.19.exe
    POL_Wine_WaitExit "$TITLECIV"
    POL_Call POL_Install_steam

    # Start steam, update it, and install the games
    cd "$WINEPREFIX/drive_c/$PROGRAMFILES/Steam"
    POL_Wine start /unix "Steam.exe" steam://install/$STEAM_ID_CIV
    POL_SetupWindow_message "$(eval_gettext 'Steam is about to perform an update.nAfter Steam finishes updating and shows you to the login interface, login and then let $TITLE install.nnWhen the installation is finished, press next (Do not close Steam)')" "$TITLECIV"

    POL_Wine start /unix "Steam.exe" steam://install/$STEAM_ID_W
    POL_SetupWindow_message "$(eval_gettext 'Steam is installing $TITLEW, press next when the installation is finished')" "$TITLECIV"

    POL_Wine start /unix "Steam.exe" steam://install/$STEAM_ID_BTS
    POL_SetupWindow_message "$(eval_gettext 'Steam is installing $TITLEBTS, press next when the installation is finished')" "$TITLECIV"

    POL_Wine start /unix "Steam.exe" steam://install/$STEAM_ID_COL
    POL_SetupWindow_message "$(eval_gettext 'Steam is installing $TITLECOL, please quit Steam properly when the installation is finished (make sure Steam is not still in the traybar) and then press next so that the installation script can continue.')" "$TITLECIV"
    POL_Wine_WaitExit "$TITLECIV"

# Install msxml3.msi
# Override for msxml3 is needed before the install
# The msvcr71 one is just there so that mods will work later on

POL_Wine_OverrideDLL "native" "msxml3"
POL_Wine_OverrideDLL "builtin" "msvcr71"
POL_Call POL_Install_msxml3

#Create shortcuts
if [ "$INSTALL_METHOD" == "STEAM" ]; then
    POL_Shortcut "Steam.exe" "$TITLECIV" "$TITLECIV.png" "-applaunch $STEAM_ID_CIV" "Game;StrategyGame;"
    POL_Shortcut "Steam.exe" "$TITLEBTS" "$TITLEBTS.png" "-applaunch $STEAM_ID_BTS" "Game;StrategyGame;"
    POL_Shortcut "Steam.exe" "$TITLEW" "$TITLEW.png" "-applaunch $STEAM_ID_W" "Game;StrategyGame;"
    POL_Shortcut "Steam.exe" "$TITLECOL" "$TITLECOL.png" "-applaunch $STEAM_ID_COL" "Game;StrategyGame;"
    POL_Shortcut "Steam.exe" "Steam - Civ IV" "" "" "Game;"
    POL_Shortcut "Civilization4.exe" "$TITLECIV" "$TITLECIV.png" "" "Game;StrategyGame;"
    POL_Shortcut "Civ4BeyondSword.exe" "$TITLEBTS" "$TITLEBTS.png" "" "Game;StrategyGame;"
    POL_Shortcut "Civ4Warlords.exe" "$TITLEW" "$TITLEW.png" "" "Game;StrategyGame;"

POL_SetupWindow_message "$(eval_gettext 'Installation finishednnThe game might crash on the first attempt, but no worries, just try one more time.')" "$TITLECIV"
exit 0

Java – 7zip unzip example

Used one of the examples in the 7zip Java bindings documentation to make this (I just modified it a little bit to actually write the unzipped data to the correct files as well, instead of just listing them). My wife needed this example so it was just something quick we threw together for a little experiment, but I thought I could put it here in case someone finds it and needs it.

Example output

   Hash   |    Size    | Filename
 CC27EAB9 |     199872 | oclHashcat-plus-0.14/cudaHashcat-plus32.bin
 B661FF80 |     202248 | oclHashcat-plus-0.14/cudaHashcat-plus64.bin
  BCFEDE0 |     224352 | oclHashcat-plus-0.14/oclHashcat-plus32.bin
 39C89963 |     218472 | oclHashcat-plus-0.14/oclHashcat-plus64.bin
 500CE011 |     222568 | oclHashcat-plus-0.14/vclHashcat-plus64.bin


package unzip;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Arrays;

import net.sf.sevenzipjbinding.ExtractOperationResult;
import net.sf.sevenzipjbinding.ISequentialOutStream;
import net.sf.sevenzipjbinding.ISevenZipInArchive;
import net.sf.sevenzipjbinding.SevenZip;
import net.sf.sevenzipjbinding.SevenZipException;
import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream;
import net.sf.sevenzipjbinding.simple.ISimpleInArchive;
import net.sf.sevenzipjbinding.simple.ISimpleInArchiveItem;

public class unzip {
	public static void main(String[] args) {

        RandomAccessFile randomAccessFile = null;
        ISevenZipInArchive inArchive = null;
        try {
            randomAccessFile = new RandomAccessFile("oclHashcat-plus-0.14.7z", "r");
            inArchive = SevenZip.openInArchive(null, // autodetect archive type
                    new RandomAccessFileInStream(randomAccessFile));

            // Getting simple interface of the archive inArchive
            ISimpleInArchive simpleInArchive = inArchive.getSimpleInterface();

            System.out.println("   Hash   |    Size    | Filename");

            for (final ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) {
                final int[] hash = new int[] { 0 };
                if (!item.isFolder()) {
                    ExtractOperationResult result;

                    final long[] sizeArray = new long[1];
                    result = item.extractSlow(new ISequentialOutStream() {
                        public int write(byte[] data) throws SevenZipException {
                        	//Write to file
                        	FileOutputStream fos;
							try {
								File file = new File(item.getPath());
								fos = new FileOutputStream(file);
							} catch (FileNotFoundException e) {
								// TODO Auto-generated catch block
							} catch (IOException e) {
								// TODO Auto-generated catch block

                            hash[0] ^= Arrays.hashCode(data); // Consume data
                            sizeArray[0] += data.length;
                            return data.length; // Return amount of consumed data
                    if (result == ExtractOperationResult.OK) {
                        System.out.println(String.format("%9X | %10s | %s", // 
                                hash[0], sizeArray[0], item.getPath()));
                    } else {
                        System.err.println("Error extracting item: " + result);
        } catch (Exception e) {
            System.err.println("Error occurs: " + e);
        } finally {
            if (inArchive != null) {
                try {
                } catch (SevenZipException e) {
                    System.err.println("Error closing archive: " + e);
            if (randomAccessFile != null) {
                try {
                } catch (IOException e) {
                    System.err.println("Error closing file: " + e);

Linux – VMware failed to build vmci & Enter license key button

So I was going to try installing VMWare 9 at work, but I had some trouble getting it to work at first, so I thought I could share the solutions I found around the net.

The first problem was that I was running on the 3.8.x kernel (3.8.0-26-generic #38-Ubuntu), and thus couldn’t rebuild the vmware modules (because of some bug it seems).
But after some Googling around, I managed to find a solution on another blog! 🙂

1. cd /usr/lib/vmware/modules/source
2. tar -xf vmci.tar
3. cd vmci-only
4. patch -p1 < ‘patchfile’
5. cd ..
6. tar -cf vmci.tar vmci-only/
7. vmware-modconfig –console –install-all
8. rm -rf vmci-only/

Download link: linux-3.8_vmci_pci_hotplug_struct.patch (Not hosted anymore!)


And the second problem was that I couldn’t enter the serial number for VMware 9 because the “enter license key” in the GUI of VMware.
The solution turned out to be rather simple though:

sudo /usr/lib/vmware/bin/vmware-vmx --new-sn xxxxxxxxxxxxxx

Replacing the xxxxxxxxxxxxxx with your key 🙂