From b1e08edfbe25c3e53716efe8039b1227d0e25989 Mon Sep 17 00:00:00 2001 From: shenmo Date: Mon, 30 May 2022 22:44:37 +0800 Subject: [PATCH] =?UTF-8?q?=09=E6=96=B0=E6=96=87=E4=BB=B6=EF=BC=9A=20=20?= =?UTF-8?q?=20spark-dwine-helper/dwine-helper-backup/README.txt=20=09?= =?UTF-8?q?=E6=96=B0=E6=96=87=E4=BB=B6=EF=BC=9A=20=20=20spark-dwine-helper?= =?UTF-8?q?/dwine-helper-backup/run=5Fv4.sh=20=09=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=9A=20=20=20=20=20spark-dwine-helper/pkg/DEBIAN/control?= =?UTF-8?q?=20=09=E4=BF=AE=E6=94=B9=EF=BC=9A=20=20=20=20=20spark-dwine-hel?= =?UTF-8?q?per/pkg/opt/deepinwine/tools/spark=5Frun=5Fv4.sh=20=09=E6=96=B0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=9A=20=20=20spark-dwine-helper/spark=5F?= =?UTF-8?q?run=5Fcustom.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dwine-helper-backup/README.txt | 1 + .../dwine-helper-backup/run_v4.sh | 631 ++++++++++++++++++ spark-dwine-helper/pkg/DEBIAN/control | 2 +- .../pkg/opt/deepinwine/tools/spark_run_v4.sh | 43 +- spark-dwine-helper/spark_run_custom.sh | 405 +++++++++++ 5 files changed, 1072 insertions(+), 10 deletions(-) create mode 100644 spark-dwine-helper/dwine-helper-backup/README.txt create mode 100755 spark-dwine-helper/dwine-helper-backup/run_v4.sh create mode 100755 spark-dwine-helper/spark_run_custom.sh diff --git a/spark-dwine-helper/dwine-helper-backup/README.txt b/spark-dwine-helper/dwine-helper-backup/README.txt new file mode 100644 index 0000000..dc9983b --- /dev/null +++ b/spark-dwine-helper/dwine-helper-backup/README.txt @@ -0,0 +1 @@ +这是一个原版的run_v4留档,以后deepin更新的时候用来diff,这样转spark_run_v4会比较方便 \ No newline at end of file diff --git a/spark-dwine-helper/dwine-helper-backup/run_v4.sh b/spark-dwine-helper/dwine-helper-backup/run_v4.sh new file mode 100755 index 0000000..f9b230c --- /dev/null +++ b/spark-dwine-helper/dwine-helper-backup/run_v4.sh @@ -0,0 +1,631 @@ +#!/bin/bash + +# Copyright (C) 2016 Deepin, Inc. +# +# Author: Li LongYu +# Peng Hao + +WINEPREFIX="$HOME/.deepinwine/@public_bottle_name@" +APPDIR="/opt/deepinwine/apps/@public_bottle_name@" +APPVER="@deb_version_string@" +APPTAR="files.7z" +BOTTLENAME="" +WINE_CMD="deepin-wine" +LOG_FILE=$0 +PUBLIC_DIR="/var/public" + +SHELL_DIR=$(dirname $0) +SHELL_DIR=$(realpath "$SHELL_DIR") +if [ $SPECIFY_SHELL_DIR ]; then + SHELL_DIR=$SPECIFY_SHELL_DIR +fi + +if [ $APPRUN_CMD ]; then + WINE_CMD=$APPRUN_CMD +fi + +if [ $SPECIFY_SHELL_DIR ]; then + SHELL_DIR=$SPECIFY_SHELL_DIR +fi + +UsePublicDir() +{ + if [ -z "$USE_PUBLIC_DIR" ]; then + echo "Don't use public dir" + return 1 + fi + if [ ! -d "$PUBLIC_DIR" ];then + echo "Not found $PUBLIC_DIR" + return 1 + fi + if [ ! -r "$PUBLIC_DIR" ];then + echo "Can't read for $PUBLIC_DIR" + return 1 + fi + if [ ! -w "$PUBLIC_DIR" ];then + echo "Can't write for $PUBLIC_DIR" + return 1 + fi + if [ ! -x "$PUBLIC_DIR" ];then + echo "Can't excute for $PUBLIC_DIR" + return 1 + fi + + return 0 +} + +_DeleteRegistry() +{ + env WINEPREFIX="$WINEPREFIX" $WINE_CMD reg DELETE "$1" /f &> /dev/null +} + +init_log_file() +{ + if [ ! -d "$DEBUG_LOG" ];then + return + fi + + LOG_DIR=$(realpath $DEBUG_LOG) + if [ -d "$LOG_DIR" ];then + LOG_FILE="${LOG_DIR}/${LOG_FILE##*/}.log" + echo "" > "$LOG_FILE" + debug_log "LOG_FILE=$LOG_FILE" + fi +} + +debug_log_to_file() +{ + if [ -d "$DEBUG_LOG" ];then + echo -e "${1}" >> "$LOG_FILE" + fi +} + +debug_log() +{ + echo "${1}" +} + +HelpApp() +{ + echo " Extra Commands:" + echo " -r/--reset Reset app to fix errors" + echo " -e/--remove Remove deployed app files" + echo " -h/--help Show program help info" +} + +FixLink() +{ + if [ -d ${WINEPREFIX} ]; then + CUR_DIR=$PWD + cd "${WINEPREFIX}/dosdevices" + rm c: z: y: + ln -s -f ../drive_c c: + ln -s -f / z: + ln -s -f $HOME y: + cd $CUR_DIR + ls -l "${WINEPREFIX}/dosdevices" + fi +} + +DisableWrite() +{ + if [ -d "${1}" ]; then + chmod +w "${1}" + rm -rf "${1}" + fi + + mkdir "${1}" + chmod -w "${1}" +} + +is_autostart() +{ + AUTOSTART="/opt/deepinwine/tools/autostart" + if [ -f "$AUTOSTART.all" ]&&[ -f "/opt/apps/$1/files/run.sh" ];then + return 0 + fi + + if [ -f $AUTOSTART ];then + grep -c "$1" $AUTOSTART > /dev/null + return $? + fi + + return 1 +} + +#arg 1: windows process file path +#arg 2-*: windows process args +CallProcess() +{ + #get file full path + path="$1" + path=$(echo ${path/c:/${WINEPREFIX}/drive_c}) + path=$(echo ${path//\\/\/}) + + #kill bloack process + is_autostart $DEB_PACKAGE_NAME + autostart=$? + if [ $autostart -ne 0 ];then + $SHELL_DIR/kill.sh "$BOTTLENAME" block + fi + + #change current dir to excute path + path=$(dirname "$path") + cd "$path" + pwd + + #Set default mime type + if [ -n "$MIME_TYPE" ]; then + xdg-mime default "$DEB_PACKAGE_NAME".desktop "$MIME_TYPE" + fi + + debug_log_to_file "Starting process $* ..." + + env WINEPREFIX="$WINEPREFIX" $WINE_CMD "$@" & + + #start autobottle + if [ $autostart -eq 0 ];then + $SHELL_DIR/autostart_wine.sh $DEB_PACKAGE_NAME + fi +} + +CallZhuMu() +{ + #change current dir to excute path + path=$(dirname "$path") + cd "$path" + pwd + + #Set default mime type + if [ -n "$MIME_TYPE" ]; then + xdg-mime default "$DEB_PACKAGE_NAME".desktop "$MIME_TYPE" + fi + + debug_log_to_file "Starting process $* ..." + if [ -n "$2" ];then + env WINEPREFIX="$WINEPREFIX" $WINE_CMD "$1" "--url=$2" & + else + env WINEPREFIX="$WINEPREFIX" $WINE_CMD "$1" & + fi +} + +CallQQGame() +{ + debug_log "run $1" + $SHELL_DIR/kill.sh qqgame block + env WINEPREFIX="$WINEPREFIX" $WINE_CMD "$1" & +} + +CallQQ() +{ + if [ ! -f "$WINEPREFIX/../.QQ_run" ]; then + debug_log "first run time" + $SHELL_DIR/add_hotkeys + $SHELL_DIR/fontconfig + touch "$WINEPREFIX/../.QQ_run" + fi + + DisableWrite "${WINEPREFIX}/drive_c/Program Files/Tencent/QQ/Bin/QQLiveMPlayer" + DisableWrite "${WINEPREFIX}/drive_c/Program Files/Tencent/QQ/Bin/QQLiveMPlayer1" + DisableWrite "${WINEPREFIX}/drive_c/Program Files/Tencent/QzoneMusic" + + DisableWrite "${WINEPREFIX}/drive_c/Program Files/Tencent/QQBrowser" + DisableWrite "${WINEPREFIX}/drive_c/Program Files/Common Files/Tencent/QQBrowser" + DisableWrite "${WINEPREFIX}/drive_c/users/Public/Application Data/Tencent/QQBrowserBin" + DisableWrite "${WINEPREFIX}/drive_c/users/Public/Application Data/Tencent/QQBrowserDefault" + DisableWrite "${WINEPREFIX}/drive_c/users/${USER}/Application Data/Tencent/QQBrowserDefault" + + DisableWrite "${WINEPREFIX}/drive_c/users/Public/Application Data/Tencent/QQPCMgr" + DisableWrite "${WINEPREFIX}/drive_c/Program Files/Common Files/Tencent/QQPCMgr" + + DisableWrite "${WINEPREFIX}/drive_c/Program Files/Common Files/Tencent/HuaYang" + DisableWrite "${WINEPREFIX}/drive_c/users/${USER}/Application Data/Tencent/HuaYang" + + CallProcess "$@" +} + +CallTIM() +{ + if [ ! -f "$WINEPREFIX/../.QQ_run" ]; then + debug_log "first run time" + $SHELL_DIR/add_hotkeys + $SHELL_DIR/fontconfig + # If the bottle not exists, run reg may cost lots of times + # So create the bottle befor run reg + env WINEPREFIX="$WINEPREFIX" $WINE_CMD uninstaller --list + touch $WINEPREFIX/../.QQ_run + fi + + CallProcess "$@" + + #disable Tencent MiniBrowser + _DeleteRegistry "HKCU\\Software\\Tencent\\MiniBrowser" +} + +CallWeChat() +{ + export DISABLE_RENDER_CLIPBOARD=1 + CallProcess "$@" +} + +CallWangWang() +{ + chmod 700 "$WINEPREFIX/drive_c/Program Files/AliWangWang/9.12.10C/wwbizsrv.exe" + chmod 700 "$WINEPREFIX/drive_c/Program Files/Alibaba/wwbizsrv/wwbizsrv.exe" + if [ $# = 3 ] && [ -z "$3" ];then + EXEC_PATH="c:/Program Files/AliWangWang/9.12.10C/WWCmd.exe" + env WINEPREFIX="$WINEPREFIX" $WINE_CMD "$EXEC_PATH" "$2" & + else + CallProcess "$@" + fi +} + +CallWXWork() +{ + if [ -d "${WINEPREFIX}/drive_c/users/${USER}/Application Data/Tencent/WXWork/Update" ]; then + rm -rf "${WINEPREFIX}/drive_c/users/${USER}/Application Data/Tencent/WXWork/Update" + fi + if [ -d "${WINEPREFIX}/drive_c/users/${USER}/Application Data/Tencent/WXWork/upgrade" ]; then + rm -rf "${WINEPREFIX}/drive_c/users/${USER}/Application Data/Tencent/WXWork/upgrade" + fi + #Support use native file dialog + + CallProcess "$@" +} + +CallDingTalk() +{ + debug_log "run $1" + $SHELL_DIR/kill.sh DingTalk block + + CallProcess "$@" +} + +urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } + +CallMeiTuXiuXiu() +{ + #set -- "$1" "${2#file://*}" + local path=$(urldecode "$2") + path=${path/file:\/\//} + set -- "$1" $path + CallProcess "$@" +} + +CallFastReadPDF() +{ + #set -- "$1" "${2#file://*}" + local path=$(urldecode "$2") + path=${path/file:\/\//} + set -- "$1" $path + CallProcess "$@" +} + +CallEvernote() +{ + local path=$(urldecode "$2") + path=${path/file:\/\//} + set -- "$1" $path + CallProcess "$@" +} + +CallTencentVideo() +{ + if [ -f "${WINEPREFIX}/drive_c/Program Files/Tencent/QQLive/Upgrade.dll" ]; then + rm -rf "${WINEPREFIX}/drive_c/Program Files/Tencent/QQLive/Upgrade.dll" + fi + + CallProcess "$@" +} + +CallFoxmail() +{ + sed -i '/LogPixels/d' ${WINEPREFIX}/user.reg + CallProcess "$@" +} + +CallTHS() +{ + $SHELL_DIR/kill.sh ths block + + debug_log "Start run $1" + #get file full path + path="$1" + path=$(echo ${path/c:/${WINEPREFIX}/drive_c}) + path=$(echo ${path//\\/\/}) + + #kill bloack process + name="${path##*/}" + $SHELL_DIR/kill.sh "$name" block + + #change current dir to excute path + path=$(dirname "$path") + cd "$path" + pwd + + #Set default mime type + if [ -n "$MIME_TYPE" ]; then + xdg-mime default "$DEB_PACKAGE_NAME".desktop "$MIME_TYPE" + fi + + env WINEPREFIX="$WINEPREFIX" $WINE_CMD "$@" & +} + +CallQQGameV2() +{ + debug_log "run $1" + $SHELL_DIR/kill.sh QQMicroGameBox block + env WINEPREFIX="$WINEPREFIX" $WINE_CMD "$1" -action:force_download -appid:${2} -pid:8 -bin_version:1.1.2.4 -loginuin: & +} + +CallPsCs6() +{ + #get file full path + path="$1" + path=$(echo ${path/c:/${WINEPREFIX}/drive_c}) + path=$(echo ${path//\\/\/}) + + #kill bloack process + name="${path##*/}" + $SHELL_DIR/kill.sh "$name" block + + #change current dir to excute path + path=$(dirname "$path") + cd "$path" + pwd + + #Set default mime type + if [ -n "$MIME_TYPE" ]; then + xdg-mime default "$DEB_PACKAGE_NAME".desktop "$MIME_TYPE" + fi + + debug_log_to_file "Starting process $* ..." + + env WINEPREFIX="$WINEPREFIX" $WINE_CMD "$@" & +} + +#arg 1: exec file path +#arg 2: autostart ,or exec arg 1 +#arg 3: exec arg 2 +CallApp() +{ + FixLink + debug_log "CallApp $BOTTLENAME arg count $#: $*" + + case $BOTTLENAME in + "Deepin-WangWang") + CallWangWang "$@" + ;; + "Deepin-ZhuMu") + CallZhuMu "$@" + ;; + "Deepin-QQ") + CallQQ "$@" + ;; + "Deepin-TIM") + CallTIM "$@" + ;; + "Deepin-QQGame"*) + CallQQGame "$@" + ;; + "Deepin-ATM") + CallATM "$@" + ;; + "Deepin-WeChat") + CallWeChat "$@" + ;; + "Deepin-WXWork") + CallWXWork "$@" + ;; + "Deepin-Dding") + CallDingTalk "$@" + ;; + "Deepin-MTXX") + CallMeiTuXiuXiu "$@" + ;; + "Deepin-FastReadPDF") + CallFastReadPDF "$@" + ;; + "Deepin-Evernote") + CallEvernote "$@" + ;; + "Deepin-TencentVideo") + CallTencentVideo "$@" + ;; + "Deepin-Foxmail") + CallFoxmail "$@" + ;; + "Deepin-THS") + CallTHS "$@" + ;; + "Deepin-QQHlddz") + CallQQGameV2 "$1" 363 + ;; + "Deepin-QQBydr") + CallQQGameV2 "$1" 1104632801 + ;; + "Deepin-QQMnsj") + CallQQGameV2 "$1" 1105856612 + ;; + "Deepin-QQSszb") + CallQQGameV2 "$1" 1105640244 + ;; + "Deepin-CS6") + CallPsCs6 "$@" + ;; + *) + CallProcess "$@" + ;; + esac +} +ExtractApp() +{ + mkdir -p "$1" + 7z x "$APPDIR/$APPTAR" -o"$1" + mv "$1/drive_c/users/@current_user@" "$1/drive_c/users/$USER" + sed -i "s#@current_user@#$USER#" $1/*.reg + FixLink +} +DeployApp() +{ + ExtractApp "$WINEPREFIX" + + if UsePublicDir;then + chgrp -R users "$WINEPREFIX" + chmod -R 0775 "$WINEPREFIX" + fi + + echo "$APPVER" > "$WINEPREFIX/PACKAGE_VERSION" +} +RemoveApp() +{ + rm -rf "$WINEPREFIX" +} +ResetApp() +{ + debug_log "Reset $PACKAGENAME....." + read -p "* Are you sure?(Y/N)" ANSWER + if [ "$ANSWER" = "Y" -o "$ANSWER" = "y" -o -z "$ANSWER" ]; then + EvacuateApp + DeployApp + CallApp + fi +} +UpdateApp() +{ + if [ -f "$WINEPREFIX/PACKAGE_VERSION" ] && [ "$(cat "$WINEPREFIX/PACKAGE_VERSION")" = "$APPVER" ]; then + return + fi + if [ -d "${WINEPREFIX}.tmpdir" ]; then + rm -rf "${WINEPREFIX}.tmpdir" + fi + + case $BOTTLENAME in + "Deepin-Intelligent" | "Deepin-QQ" | "Deepin-TIM" | "Deepin-WeChat" | "Deepin-WXWork" | "Deepin-Dding") + rm -rf "$WINEPREFIX" + DeployApp + return + ;; + esac + + ExtractApp "${WINEPREFIX}.tmpdir" + $SHELL_DIR/updater -s "${WINEPREFIX}.tmpdir" -c "${WINEPREFIX}" -v + + if UsePublicDir;then + chgrp -R users "$WINEPREFIX" + chmod -R 0775 "$WINEPREFIX" + fi + + rm -rf "${WINEPREFIX}.tmpdir" + echo "$APPVER" > "$WINEPREFIX/PACKAGE_VERSION" +} +RunApp() +{ + progpid=$(ps -ef | grep "zenity --progress --title=${BOTTLENAME}" | grep -v grep) + debug_log "run ${BOTTLENAME} progress pid $progpid" + if [ -n "$progpid" ]; then + debug_log "$BOTTLENAME is running" + exit 0 + fi + if [ -d "$WINEPREFIX" ]; then + UpdateApp | progressbar "$BOTTLENAME" "更新$BOTTLENAME中..." + else + DeployApp | progressbar $BOTTLENAME "初始化$BOTTLENAME中..." + fi + CallApp "$@" +} + +CreateBottle() +{ + if [ -d "$WINEPREFIX" ]; then + UpdateApp + else + DeployApp + fi +} + +ParseArgs() +{ + if [ $# -eq 4 ];then + RunApp "$3" + elif [ $# -eq 5 ];then + RunApp "$3" "$5" + else + RunApp "$3" "$5" "$6" + fi +} + +init_log_file + +# Check if some visual feedback is possible +if command -v zenity >/dev/null 2>&1; then + progressbar() + { + WINDOWID="" zenity --progress --title="$1" --text="$2" --pulsate --width=400 --auto-close --no-cancel || + WINDOWID="" zenity --progress --title="$1" --text="$2" --pulsate --width=400 --auto-close + } + +else + progressbar() + { + cat - + } +fi + +if [ $# -lt 3 ]; then + debug_log "参数个数小于3个" + exit 0 +fi + +BOTTLENAME="$1" +WINEPREFIX="$HOME/.deepinwine/$1" + +if UsePublicDir;then + WINEPREFIX="$PUBLIC_DIR/$1" +fi + +APPDIR="/opt/apps/${DEB_PACKAGE_NAME}/files" +if [ -f "$APPDIR/files.md5sum" ];then + APPVER="$(cat $APPDIR/files.md5sum)" +else + APPVER="$2" +fi + +debug_log "Run $*" + +#执行lnk文件通过判断第5个参数是否是“/Unix”来判断 +if [ "$4" == "/Unix" ];then + RunApp "$3" "$4" "$5" + exit 0 +fi + +if [ $# -lt 4 ]; then + RunApp "$3" + exit 0 +fi +case $4 in + "-r" | "--reset") + ResetApp + ;; + "-c" | "--create") + CreateBottle + ;; + "-e" | "--remove") + RemoveApp + ;; + "-u" | "--uri") + ParseArgs "$@" + ;; + "-f" | "--file") + ParseArgs "$@" + ;; + "-h" | "--help") + HelpApp + ;; + *) + echo "Invalid option: $4" + echo "Use -h|--help to get help" + exit 1 + ;; +esac +exit 0 diff --git a/spark-dwine-helper/pkg/DEBIAN/control b/spark-dwine-helper/pkg/DEBIAN/control index 9e5acfc..9dc7861 100644 --- a/spark-dwine-helper/pkg/DEBIAN/control +++ b/spark-dwine-helper/pkg/DEBIAN/control @@ -1,5 +1,5 @@ Package: spark-dwine-helper -Version: 1.2 +Version: 1.3 Architecture: all Maintainer: shenmo Installed-Size: 2293 diff --git a/spark-dwine-helper/pkg/opt/deepinwine/tools/spark_run_v4.sh b/spark-dwine-helper/pkg/opt/deepinwine/tools/spark_run_v4.sh index 3dc7d08..0409d74 100755 --- a/spark-dwine-helper/pkg/opt/deepinwine/tools/spark_run_v4.sh +++ b/spark-dwine-helper/pkg/opt/deepinwine/tools/spark_run_v4.sh @@ -9,6 +9,7 @@ # Modifier: shenmo # # diff: Now will run set-dwine-scale.sh in stage RunApp before CallApp +# Deleted Deepin-* to simplify the script # WINEPREFIX="$HOME/.deepinwine/@public_bottle_name@" APPDIR="/opt/deepinwine/apps/@public_bottle_name@" @@ -58,12 +59,13 @@ UsePublicDir() return 0 } +########关于公共文件夹,暂时意义不明 _DeleteRegistry() { env WINEPREFIX="$WINEPREFIX" $WINE_CMD reg DELETE "$1" /f &> /dev/null } - +#########功能:删除注册表 init_log_file() { if [ ! -d "$DEBUG_LOG" ];then @@ -89,7 +91,7 @@ debug_log() { echo "${1}" } - +################log相关功能 HelpApp() { echo " Extra Commands:" @@ -97,7 +99,7 @@ HelpApp() echo " -e/--remove Remove deployed app files" echo " -h/--help Show program help info" } - +#############帮助文件 FixLink() { if [ -d ${WINEPREFIX} ]; then @@ -111,7 +113,7 @@ FixLink() ls -l "${WINEPREFIX}/dosdevices" fi } - +###########会在应用启动和解压时执行,驱动器绑定 DisableWrite() { if [ -d "${1}" ]; then @@ -122,7 +124,7 @@ DisableWrite() mkdir "${1}" chmod -w "${1}" } - +########如果有该文件夹则删除,然后再创建一个不允许写入的(这东西是被用在了QQ启动上,看来腾讯不怎么好对付) is_autostart() { AUTOSTART="/opt/deepinwine/tools/autostart" @@ -137,6 +139,9 @@ is_autostart() return 1 } +#########自动启动相关,等用到了再研究 +urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } +#######url转义 #arg 1: windows process file path #arg 2-*: windows process args @@ -173,6 +178,9 @@ CallProcess() $SHELL_DIR/autostart_wine.sh $DEB_PACKAGE_NAME fi } +###通用启动APP逻辑。对于没有被case捕捉的非适配APP,则直接执行此部分。似乎已经有了防止残留的功能 +###一些自定义的应用不会使用这个启动,而另一些则会调用这个 +###有设置mimetype和自动启动(这个暂时没分析)的功能 CallZhuMu() { @@ -234,7 +242,9 @@ CallTIM() if [ ! -f "$WINEPREFIX/../.QQ_run" ]; then debug_log "first run time" $SHELL_DIR/add_hotkeys +####似乎是给dde-control-center添加快捷键 $SHELL_DIR/fontconfig +####暂时无法得知用途和用法 # If the bottle not exists, run reg may cost lots of times # So create the bottle befor run reg env WINEPREFIX="$WINEPREFIX" $WINE_CMD uninstaller --list @@ -286,15 +296,19 @@ CallDingTalk() CallProcess "$@" } -urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } + CallMeiTuXiuXiu() { #set -- "$1" "${2#file://*}" local path=$(urldecode "$2") path=${path/file:\/\//} - set -- "$1" $path + set -- "$1" "$path" + if [ "$path" ];then CallProcess "$@" + else + CallProcess "$1" + fi } CallFastReadPDF() @@ -302,16 +316,25 @@ CallFastReadPDF() #set -- "$1" "${2#file://*}" local path=$(urldecode "$2") path=${path/file:\/\//} - set -- "$1" $path + set -- "$1" "$path" + if [ "$path" ];then CallProcess "$@" + else + CallProcess "$1" + fi } CallEvernote() { + #set -- "$1" "${2#file://*}" local path=$(urldecode "$2") path=${path/file:\/\//} - set -- "$1" $path + set -- "$1" "$path" + if [ "$path" ];then CallProcess "$@" + else + CallProcess "$1" + fi } CallTencentVideo() @@ -581,6 +604,8 @@ else } fi + +#####准备启动进程,分析在 https://shenmo7192.gitee.io/post/deepin-wine6%E7%9A%84run_v4%E8%84%9A%E6%9C%AC%E6%8E%A2%E7%B4%A2%E5%90%AF%E5%8A%A8%E6%96%B9%E5%BC%8F/ if [ $# -lt 3 ]; then debug_log "参数个数小于3个" exit 0 diff --git a/spark-dwine-helper/spark_run_custom.sh b/spark-dwine-helper/spark_run_custom.sh new file mode 100755 index 0000000..320a411 --- /dev/null +++ b/spark-dwine-helper/spark_run_custom.sh @@ -0,0 +1,405 @@ +#!/bin/bash + +# Copyright (C) 2016 Deepin, Inc. +# Copyright (C) 2022 The Spark Project +# +# Author: Li LongYu +# Peng Hao +# +# Modifier: shenmo +# +# diff: Now will run set-dwine-scale.sh in stage RunApp before CallApp +# Deleted Deepin-* to simplify the script +# +# +# +# 这是一个可以用于自定义的脚本,为了增加易读性,删除了大部分的case +# 请对照spark_run_v4.sh进行操作 +# 建议把文件名中的custom换成你的app名字(不要中文),方便维护和识别 +# +# +# +# +# +# +# +# + +WINEPREFIX="$HOME/.deepinwine/@public_bottle_name@" +APPDIR="/opt/deepinwine/apps/@public_bottle_name@" +APPVER="@deb_version_string@" +APPTAR="files.7z" +BOTTLENAME="" +WINE_CMD="deepin-wine" +LOG_FILE=$0 +PUBLIC_DIR="/var/public" + +SHELL_DIR=$(dirname $0) +SHELL_DIR=$(realpath "$SHELL_DIR") +if [ $SPECIFY_SHELL_DIR ]; then + SHELL_DIR=$SPECIFY_SHELL_DIR +fi + +if [ $APPRUN_CMD ]; then + WINE_CMD=$APPRUN_CMD +fi + +if [ $SPECIFY_SHELL_DIR ]; then + SHELL_DIR=$SPECIFY_SHELL_DIR +fi + +UsePublicDir() +{ + if [ -z "$USE_PUBLIC_DIR" ]; then + echo "Don't use public dir" + return 1 + fi + if [ ! -d "$PUBLIC_DIR" ];then + echo "Not found $PUBLIC_DIR" + return 1 + fi + if [ ! -r "$PUBLIC_DIR" ];then + echo "Can't read for $PUBLIC_DIR" + return 1 + fi + if [ ! -w "$PUBLIC_DIR" ];then + echo "Can't write for $PUBLIC_DIR" + return 1 + fi + if [ ! -x "$PUBLIC_DIR" ];then + echo "Can't excute for $PUBLIC_DIR" + return 1 + fi + + return 0 +} +########关于公共文件夹,暂时意义不明 + +_DeleteRegistry() +{ + env WINEPREFIX="$WINEPREFIX" $WINE_CMD reg DELETE "$1" /f &> /dev/null +} +#########功能:删除注册表 +init_log_file() +{ + if [ ! -d "$DEBUG_LOG" ];then + return + fi + + LOG_DIR=$(realpath $DEBUG_LOG) + if [ -d "$LOG_DIR" ];then + LOG_FILE="${LOG_DIR}/${LOG_FILE##*/}.log" + echo "" > "$LOG_FILE" + debug_log "LOG_FILE=$LOG_FILE" + fi +} + +debug_log_to_file() +{ + if [ -d "$DEBUG_LOG" ];then + echo -e "${1}" >> "$LOG_FILE" + fi +} + +debug_log() +{ + echo "${1}" +} +################log相关功能 +HelpApp() +{ + echo " Extra Commands:" + echo " -r/--reset Reset app to fix errors" + echo " -e/--remove Remove deployed app files" + echo " -h/--help Show program help info" +} +#############帮助文件 +FixLink() +{ + if [ -d ${WINEPREFIX} ]; then + CUR_DIR=$PWD + cd "${WINEPREFIX}/dosdevices" + rm c: z: y: + ln -s -f ../drive_c c: + ln -s -f / z: + ln -s -f $HOME y: + cd $CUR_DIR + ls -l "${WINEPREFIX}/dosdevices" + fi +} +###########会在应用启动和解压时执行,驱动器绑定 +DisableWrite() +{ + if [ -d "${1}" ]; then + chmod +w "${1}" + rm -rf "${1}" + fi + + mkdir "${1}" + chmod -w "${1}" +} +########如果有该文件夹则删除,然后再创建一个不允许写入的(这东西是被用在了QQ启动上,看来腾讯不怎么好对付) +is_autostart() +{ + AUTOSTART="/opt/deepinwine/tools/autostart" + if [ -f "$AUTOSTART.all" ]&&[ -f "/opt/apps/$1/files/run.sh" ];then + return 0 + fi + + if [ -f $AUTOSTART ];then + grep -c "$1" $AUTOSTART > /dev/null + return $? + fi + + return 1 +} +#########自动启动相关,等用到了再研究 +urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } +#######url转义 + +#arg 1: windows process file path +#arg 2-*: windows process args +CallProcess() +{ + #get file full path + path="$1" + path=$(echo ${path/c:/${WINEPREFIX}/drive_c}) + path=$(echo ${path//\\/\/}) + + #kill bloack process + is_autostart $DEB_PACKAGE_NAME + autostart=$? + if [ $autostart -ne 0 ];then + $SHELL_DIR/kill.sh "$BOTTLENAME" block + fi + + #change current dir to excute path + path=$(dirname "$path") + cd "$path" + pwd + + #Set default mime type + if [ -n "$MIME_TYPE" ]; then + xdg-mime default "$DEB_PACKAGE_NAME".desktop "$MIME_TYPE" + fi + + debug_log_to_file "Starting process $* ..." + + env WINEPREFIX="$WINEPREFIX" $WINE_CMD "$@" & + + #start autobottle + if [ $autostart -eq 0 ];then + $SHELL_DIR/autostart_wine.sh $DEB_PACKAGE_NAME + fi +} +###通用启动APP逻辑。对于没有被case捕捉的非适配APP,则直接执行此部分。似乎已经有了防止残留的功能 +###一些自定义的应用不会使用这个启动,而另一些则会调用这个 +###有设置mimetype和自动启动(这个暂时没分析)的功能 + + +####请在这里把CustomAPP换成你的APP名字 +####非常不建议直接使用CustomAPP,将来维护你自己都不知道哪个脚本给谁用了 +####不要用中文 +CallCustomAPP() +{ +###请在这里添加在CallProcess之前的脚本,即在启动应用前执行的。会在部署结束,启动应用前打开 + CallProcess "$@" +} + +#arg 1: exec file path +#arg 2: autostart ,or exec arg 1 +#arg 3: exec arg 2 +CallApp() +{ + FixLink + debug_log "CallApp $BOTTLENAME arg count $#: $*" + + case $BOTTLENAME in + "User-Custom") + #^---这里写你的容器名,就是解压到~/.deepinwine的那个文件夹名字 + CallCustomAPP "$@" + #^---这里要和之前的那个对应 + ;; + *) + CallProcess "$@" + #仍然保留对未适配的APP的兼容 + ;; + esac +} +ExtractApp() +{ + mkdir -p "$1" + 7z x "$APPDIR/$APPTAR" -o"$1" + mv "$1/drive_c/users/@current_user@" "$1/drive_c/users/$USER" + sed -i "s#@current_user@#$USER#" $1/*.reg + FixLink +} +DeployApp() +{ + ExtractApp "$WINEPREFIX" + + if UsePublicDir;then + chgrp -R users "$WINEPREFIX" + chmod -R 0775 "$WINEPREFIX" + fi + + echo "$APPVER" > "$WINEPREFIX/PACKAGE_VERSION" + +} +RemoveApp() +{ + rm -rf "$WINEPREFIX" +} +ResetApp() +{ + debug_log "Reset $PACKAGENAME....." + read -p "* Are you sure?(Y/N)" ANSWER + if [ "$ANSWER" = "Y" -o "$ANSWER" = "y" -o -z "$ANSWER" ]; then + EvacuateApp + DeployApp + CallApp + fi +} +UpdateApp() +{ + if [ -f "$WINEPREFIX/PACKAGE_VERSION" ] && [ "$(cat "$WINEPREFIX/PACKAGE_VERSION")" = "$APPVER" ]; then + return + fi + if [ -d "${WINEPREFIX}.tmpdir" ]; then + rm -rf "${WINEPREFIX}.tmpdir" + fi + + case $BOTTLENAME in + "Deepin-Intelligent" | "Deepin-QQ" | "Deepin-TIM" | "Deepin-WeChat" | "Deepin-WXWork" | "Deepin-Dding") + rm -rf "$WINEPREFIX" + DeployApp + return + ;; + esac + + ExtractApp "${WINEPREFIX}.tmpdir" + $SHELL_DIR/updater -s "${WINEPREFIX}.tmpdir" -c "${WINEPREFIX}" -v + + if UsePublicDir;then + chgrp -R users "$WINEPREFIX" + chmod -R 0775 "$WINEPREFIX" + fi + + rm -rf "${WINEPREFIX}.tmpdir" + echo "$APPVER" > "$WINEPREFIX/PACKAGE_VERSION" +} +RunApp() +{ + progpid=$(ps -ef | grep "zenity --progress --title=${BOTTLENAME}" | grep -v grep) + debug_log "run ${BOTTLENAME} progress pid $progpid" + if [ -n "$progpid" ]; then + debug_log "$BOTTLENAME is running" + exit 0 + fi + if [ -d "$WINEPREFIX" ]; then + UpdateApp | progressbar "$BOTTLENAME" "更新$BOTTLENAME中..." + else + DeployApp | progressbar $BOTTLENAME "初始化$BOTTLENAME中..." + fi +############# WARNING: Here is the modified content: Now will run set-dwine-scale.sh + /opt/durapps/spark-dwine-helper/set-dwine-scale.sh "$WINEPREFIX" + + CallApp "$@" +} + +CreateBottle() +{ + if [ -d "$WINEPREFIX" ]; then + UpdateApp + else + DeployApp + fi +} + +ParseArgs() +{ + if [ $# -eq 4 ];then + RunApp "$3" + elif [ $# -eq 5 ];then + RunApp "$3" "$5" + else + RunApp "$3" "$5" "$6" + fi +} + +init_log_file + +# Check if some visual feedback is possible +if command -v zenity >/dev/null 2>&1; then + progressbar() + { + WINDOWID="" zenity --progress --title="$1" --text="$2" --pulsate --width=400 --auto-close --no-cancel || + WINDOWID="" zenity --progress --title="$1" --text="$2" --pulsate --width=400 --auto-close + } + +else + progressbar() + { + cat - + } +fi + +if [ $# -lt 3 ]; then + debug_log "参数个数小于3个" + exit 0 +fi + +#####准备启动进程,分析在 https://shenmo7192.gitee.io/post/deepin-wine6%E7%9A%84run_v4%E8%84%9A%E6%9C%AC%E6%8E%A2%E7%B4%A2%E5%90%AF%E5%8A%A8%E6%96%B9%E5%BC%8F/ + +BOTTLENAME="$1" +WINEPREFIX="$HOME/.deepinwine/$1" + +if UsePublicDir;then + WINEPREFIX="$PUBLIC_DIR/$1" +fi + +APPDIR="/opt/apps/${DEB_PACKAGE_NAME}/files" +if [ -f "$APPDIR/files.md5sum" ];then + APPVER="$(cat $APPDIR/files.md5sum)" +else + APPVER="$2" +fi + +debug_log "Run $*" + +#执行lnk文件通过判断第5个参数是否是“/Unix”来判断 +if [ "$4" == "/Unix" ];then + RunApp "$3" "$4" "$5" + exit 0 +fi + +if [ $# -lt 4 ]; then + RunApp "$3" + exit 0 +fi +case $4 in + "-r" | "--reset") + ResetApp + ;; + "-c" | "--create") + CreateBottle + ;; + "-e" | "--remove") + RemoveApp + ;; + "-u" | "--uri") + ParseArgs "$@" + ;; + "-f" | "--file") + ParseArgs "$@" + ;; + "-h" | "--help") + HelpApp + ;; + *) + echo "Invalid option: $4" + echo "Use -h|--help to get help" + exit 1 + ;; +esac +exit 0