# $Id: Portfile 67988 2010-05-23 20:17:47Z ryandesign@macports.org $

PortSystem                  1.0

name                        mystonline-wine
set my_name                 mystonline
version                     2010
revision                    2
platforms                   darwin
categories                  games x11
maintainers                 ryandesign
homepage                    http://mystonline.com/
dist_subdir                 ${my_name}
distfiles
extract.mkdir               yes

description                 Myst Online: URU Live Again

long_description            ${description} (MO:ULagain) running via Wine

depends_build               port:winetricks

depends_run                 path:bin/wine:wine-devel \
                            port:mystonline-bootstrap

set libexec_dir             ${prefix}/libexec/${name}
set share_dir               ${prefix}/share/${my_name}
set bootstrap_dir           ${share_dir}/bootstrap
set assets_dir              ${share_dir}/data
set wineprefix              ${share_dir}/wine
set app_name                "Myst Online (Wine)"
set app_package             ${applications_dir}/${app_name}.app

post-extract {
    xinstall -m 644 -W ${filespath} MOUL.sh chown-data.c ${worksrcpath}
}

post-patch {
    reinplace "s|@BOOTSTRAP_LAUNCHER@|${bootstrap_dir}/UruLauncher.exe|g" ${worksrcpath}/MOUL.sh
    reinplace "s|@LAUNCHER@|${assets_dir}/UruLauncher.exe|g" ${worksrcpath}/MOUL.sh
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/MOUL.sh
    reinplace "s|@APPLICATIONS_DIR@|${applications_dir}|g" ${worksrcpath}/MOUL.sh
    reinplace "s|@LIBEXEC@|${libexec_dir}|g" ${worksrcpath}/MOUL.sh
    reinplace "s|@WINEPREFIX@|${wineprefix}|g" ${worksrcpath}/MOUL.sh ${worksrcpath}/chown-data.c
    reinplace "s|@ASSETS@|${assets_dir}|g" ${worksrcpath}/chown-data.c
}

use_configure               no

build {
    # Create the wine prefix
    system "WINEPREFIX=${worksrcpath}/wineprefix ${prefix}/bin/wineprefixcreate -w"
    
    # Delete any temporary directory definitions; use the default C:\windows\temp
    reinplace -E {/^"TE?MP"=/d} ${worksrcpath}/wineprefix/user.reg
    
    # Map C:\windows\temp to /tmp so any temp files that get created
    # (e.g. by the PhysX installer) get cleaned up by Mac OS X as usual
    delete ${worksrcpath}/wineprefix/drive_c/windows/temp
    ln -s /tmp ${worksrcpath}/wineprefix/drive_c/windows/temp
    
    # If winetricks needs to download any files, put them where the other distfiles are
    if {![file exists ${distpath}/winetrickscache]} {
        ln -s . ${distpath}/winetrickscache
    }
    
    # Enable font antialiasing
    system "WINEPREFIX=${worksrcpath}/wineprefix HOME=${distpath} ${prefix}/bin/winetricks -q fontsmooth-rgb"
    
    # Delete dosdevices -- it might contain references to transient disks
    # the user happens to have mounted, and wine will recreate it anyway
    delete ${worksrcpath}/wineprefix/dosdevices
    
    # Link "Uru Live" to our assets dir
    set program_files "${worksrcpath}/wineprefix/drive_c/Program Files"
    file mkdir ${program_files}
    ln -s ${assets_dir} "${program_files}/Uru Live"
    
    # Build the chown wrapper program
    system "cd ${worksrcpath} && ${configure.cc} chown-data.c -o chown-data"
}

destroot {
    xinstall -d ${destroot}${libexec_dir} \
                ${destroot}${share_dir} \
                ${destroot}${app_package}/Contents/MacOS
    
    xinstall -m 4755 -W ${worksrcpath} chown-data ${destroot}${libexec_dir}
    
    xinstall -W ${worksrcpath} MOUL.sh ${destroot}${app_package}/Contents/MacOS/${app_name}
    
    copy ${worksrcpath}/wineprefix ${destroot}${wineprefix}
}

notes                       Welcome to Myst Online: Uru Live Again (MO:ULagain) \
                            \n\n* To play Myst Online, you need an account, which you can create for free by visiting \
                            ${homepage} and clicking Play. \
                            \n* Myst Online automatically updates itself. \
                            The first time you open Myst Online, it will download several gigabytes of game data. \
                            Be patient\; this will take some time. \
                            If you already have the game data from a non-MacPorts installation of Myst Online, \
                            you can save time by copying or moving it into ${assets_dir} \
                            \n\nThis version of Myst Online runs via Wine. \
                            Peculiarities of this method of running Myst Online include: \
                            \n* Don't click anywhere in the updater window. If you do, the window will follow the mouse \
                            cursor and will not go away. If you need to cancel the updater, press the Escape key. \
                            \n* The first time you log into Myst Online, you will be prompted to install PhysX. \
                            \n* The mouse cursor image is wrong. \
                            \n* To be able to look around by holding down the Command key while dragging, \
                            enable the \"Emulate three button mouse\" option in X11 preferences. \
                            \n* The menubar cannot be hidden. \
                            \n* The dock does not hide automatically. It can be hidden using the normal ways \
                            (e.g. Apple menu > Dock > Turn hiding on) but you may also want to move the dock \
                            to the side of the screen as otherwise it gets in the way of game play. \
                            \n* The game's dock icon keeps bouncing longer than it should, doesn't show that \
                            it's running even when it is, and doesn't bring the game to the front if you click it. \
                            \n* Accessing the dock icon's context menu doesn't let you quit the game normally, \
                            though it does let you force-quit it. \
                            \n* The application has a generic icon. \
                            \n* The game starts in fullscreen mode. If in fullscreen mode you access the game's \
                            graphics settings, you cannot return to the game\; you must force-quit. \
                            \n* To switch between fullscreen and windowed mode, use the checkbox in the graphics settings. \
                            \n* Intel GMA 950 integrated graphics cards are not supported. Some graphics including your avatar \
                            will not display correctly. \
                            \n* If sounds are distorted or nonexistent, install the sounddecompress port and follow the instructions. \
                            \n* The microphone cannot be used to talk to other players, though you can hear other players talking to you. \
                            \n* On Macs with NVIDIA graphics cards, water does not show up properly in Er'cana. \
                            \n* On Macs with NVIDIA graphics cards that have not upgraded to Mac OS X 10.6.3, \
                            Eder Kemo has severe performance problems. \
                            \n\nOther methods of running Myst Online on a Mac include the Cider version in the \
                            mystonline-cider port, and running the game in Windows via VMware, Parallels or Boot Camp. \
                            \n\nTo play Myst Online, open ${app_package}.

universal_variant           no

livecheck.type              none
