summarylogtreecommitdiffstats
path: root/run.sh
blob: 478386193ff5272d830bbeaab5c36b9ffe1a1682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/sh

version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }

PKG_NAME="__PKG_NAME__"
PKG_VER="__PKG_VER__"
BASEDIR="$HOME/.ftnn"
WINEPREFIX="$BASEDIR/wine"
FONTS_PATH="$WINEPREFIX/drive_c/windows/Fonts"
EXEC_PATH="c:/Program Files (x86)/FTNN/FTNN.exe"
EXEC_FILE="$WINEPREFIX/drive_c/Program Files (x86)/FTNN/FTNN.exe"
INSTALLER_PATH="/usr/share/$PKG_NAME/FTNN_INSTALLER_$PKG_VER.exe"
export MIME_TYPE=""
export APPRUN_CMD="wine"
DISABLE_ATTACH_FILE_DIALOG=""

OpenWinecfg()
{
    env WINEPREFIX=$WINEPREFIX $APPRUN_CMD winecfg
}

DeployApp()
{
    # backup fonts
    if [ -d "$FONTS_PATH" ];then
        mkdir -p $BASEDIR/tmp/font_backup
        cp $FONTS_PATH/* $BASEDIR/tmp/font_backup/
    fi

    # re-deploy bottle
    rm -rf "$WINEPREFIX"
    mkdir -p "$WINEPREFIX"

    # resolve CJK issue
    ln -sf "/usr/share/fonts/wenquanyi/wqy-microhei/wqy-microhei.ttc" "$FONTS_PATH/wqy-microhei.ttc"
    env WINEPREFIX=$WINEPREFIX $APPRUN_CMD start regedit.exe /usr/share/futu-ftnn-wine/cjk-font.reg

    # run installer
    env WINEPREFIX=$WINEPREFIX $APPRUN_CMD "$INSTALLER_PATH" "$@"

    # restore fonts
    if [ -d "$BASEDIR/tmp/font_backup" ];then
        cp -n $BASEDIR/tmp/font_backup/* $FONTS_PATH/
        rm -rf "$BASEDIR/tmp/font_backup"
    fi

    touch $WINEPREFIX/reinstalled
    cat $BASEDIR/files/files.md5sum > $WINEPREFIX/PACKAGE_VERSION
}

Run()
{
    if [ -z "$DISABLE_ATTACH_FILE_DIALOG" ];then
        export ATTACH_FILE_DIALOG=1
    fi

    if [ -n "$EXEC_PATH" ];then
        if [ ! -f "$WINEPREFIX/reinstalled" ];then
            DeployApp
        else
            # missing exec file
            if [ ! -f "$EXEC_FILE" ];then
                DeployApp
            fi

            env WINEPREFIX=$WINEPREFIX $APPRUN_CMD "$EXEC_PATH" "$@"
        fi
    else
        env WINEPREFIX=$WINEPREFIX $APPRUN_CMD "UnInstall.exe" "$@"
    fi
}

HelpApp()
{
	echo " Extra Commands:"
	echo " winecfg        Open winecfg"
	echo " -h/--help      Show program help info"
}

if [ -z $1 ]; then
	Run "$@"
	exit 0
fi
case $1 in
	"winecfg")
		OpenWinecfg
		;;
	"-h" | "--help")
		HelpApp
		;;
	*)
		Run "$@"
		;;
esac
exit 0