Skip to content

Commit

Permalink
#110 优化运行、更新的脚本逻辑,操作进一步小白化
Browse files Browse the repository at this point in the history
  • Loading branch information
nICEnnnnnnnLee committed Aug 20, 2022
1 parent ec5a477 commit ac1c4ef
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 15 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,24 @@ jobs:
rm -rf ./LICENSE
mkdir ./config/
mkdir ./LICENSE/
mv -f ./release/install.vbs .
mv -f ./release/run-UI.bat .
mv -f ./release/run-UI-debug.bat .
mv -f ./release/Create-Shortcut-on-Desktop-for-Linux.sh .
mv -f ./release/Create-Shortcut-on-Desktop-for-Mac.sh .
mv -f ./release/Create-Shortcut-on-Desktop-for-Win.vbs .
mv -f ./release/Double-Click-to-Run-for-Mac.command .
mv -f ./release/Double-Click-to-Run-for-Win.bat .
mv -f ./release/Double-Click-to-Run-for-Win-debug.bat .
mv -f ./release/uninstall.bat .
mv -f ./release/update.bat .
mv -f ./release/config/* ./config/
mv -f ./release/LICENSE/* ./LICENSE/
zip BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip INeedBiliAV.jar
zip -m BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip ./install.vbs
zip -m BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip ./run-UI.bat
zip -m BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip ./run-UI-debug.bat
zip -m BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip ./Create-Shortcut-on-Desktop-for-Linux.sh
zip -m BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip ./Create-Shortcut-on-Desktop-for-Mac.sh
zip -m BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip ./Create-Shortcut-on-Desktop-for-Win.vbs
zip -m BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip ./Double-Click-to-Run-for-Mac.command
zip -m BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip ./Double-Click-to-Run-for-Win.bat
zip -m BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip ./Double-Click-to-Run-for-Win-debug.bat
zip -m BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip ./uninstall.bat
zip -m BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip ./update.bat
zip -rm BilibiliDown.v${{steps.tag_latest.outputs.value}}.release.zip ./config/
Expand Down
9 changes: 9 additions & 0 deletions release/BilibiliDown.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Desktop Entry]
Encoding=UTF-8
Terminal=false
Name=BilibiliDown
Type=Application
Exec=java -Dfile.encoding=utf-8 -Dhttps.protocols=TLSv1.2 -jar /mnt/hgfs/workspace-java/BilibiliDown/release/INeedBiliAV.jar
Icon=/mnt/hgfs/workspace-java/BilibiliDown/release/config/favicon.ico
Categories=Application;Network;
Comment=BilibiliDown from https://github.com/nICEnnnnnnnLee/BilibiliDown
45 changes: 45 additions & 0 deletions release/Create-Shortcut-on-Desktop-for-Linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# cd 到脚本所在目录
cd $(dirname $0)
base_path=$(pwd)
echo "当前路径为${base_path}"

current_user=$(whoami)
echo "当前用户为${current_user}"

desktop_path="/home/${current_user}/desktop"
if [ ! -d desktop_path ]; then
desktop_path="/home/${current_user}/桌面"
fi
echo "当前桌面为${desktop_path}"

echo "[Desktop Entry]" > BilibiliDown.desktop
echo "Encoding=UTF-8" >> BilibiliDown.desktop
echo "Terminal=false" >> BilibiliDown.desktop
echo "Name=BilibiliDown" >> BilibiliDown.desktop
echo "Type=Application" >> BilibiliDown.desktop
echo "Exec=java -Dfile.encoding=utf-8 -Dhttps.protocols=TLSv1.2 -jar ${base_path}/INeedBiliAV.jar" >> BilibiliDown.desktop
echo "Icon=${base_path}/config/favicon.ico" >> BilibiliDown.desktop
echo "Categories=Application;Network; " >> BilibiliDown.desktop
echo "Comment=BilibiliDown from https://github.com/nICEnnnnnnnLee/BilibiliDown" >> BilibiliDown.desktop

# cat BilibiliDown.desktop
# chmod +x BilibiliDown.desktop
echo '在桌面上创建快捷方式'
cp -f ${base_path}/BilibiliDown.desktop ${desktop_path}/BilibiliDown.desktop

if test ! -x ${desktop_path}/BilibiliDown.desktop ; then
echo '为桌面快捷方式添加可执行权限'
sudo chmod +x ${desktop_path}/BilibiliDown.desktop
fi


echo '在启动栏创建快捷方式'
sudo cp -f ${base_path}/BilibiliDown.desktop /usr/share/applications/BilibiliDown.desktop
if test ! -x /usr/share/applications/BilibiliDown.desktop ; then
echo '为启动栏快捷方式添加可执行权限'
sudo chmod +x /usr/share/applications/BilibiliDown.desktop
fi


26 changes: 26 additions & 0 deletions release/Create-Shortcut-on-Desktop-for-Mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# cd 到脚本所在目录
cd $(dirname $0)
base_path=$(pwd)
echo "当前路径为${base_path}"

current_user=$(whoami)
echo "当前用户为${current_user}"

desktop_path="/Users/${current_user}/Desktop"
if [ ! -d desktop_path ]; then
desktop_path="/Users/${current_user}/桌面"
fi
echo "当前桌面路径为${desktop_path}"


if test ! -x ${base_path}/Double-Click-to-Run-for-Mac.command ; then
echo '为双击运行脚本添加可执行权限'
sudo chmod +x ${base_path}/Double-Click-to-Run-for-Mac.command
fi

echo '在桌面上创建快捷方式软链接'
ln -s ${base_path}/Double-Click-to-Run-for-Mac.command ${desktop_path}/BilibiliDown.link


Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Set WshShell = WScript.CreateObject("WScript.Shell")
strCurFolder = createobject("Scripting.FileSystemObject").GetFolder(".").Path '当前路径
strDesktop = WshShell.SpecialFolders("Desktop") '特殊文件夹“桌面”
'Rem 在桌面创建一个记事本快捷方式
'Rem 在桌面创建一个BilibiliDown快捷方式
set oShellLink = WshShell.CreateShortcut(strDesktop & "\Bili 下载器.lnk")
oShellLink.TargetPath = strCurFolder & "\run-UI.bat" '可执行文件路径
oShellLink.TargetPath = strCurFolder & "\Double-Click-to-Run-for-Win.bat" '可执行文件路径
oShellLink.Arguments = "" '程序的参数
oShellLink.WindowStyle = 7 '参数1默认窗口激活,参数3最大化激活,参数7最小化
oShellLink.Hotkey = "" '快捷键
oShellLink.IconLocation = strCurFolder &"\config\favicon.ico" '图标
oShellLink.Description = "Bili 下载器. Nicelee.top提供" '备注
oShellLink.Description = "Bili 下载器." '备注
oShellLink.WorkingDirectory = strCurFolder '起始位置
oShellLink.Save '创建保存快捷方式
5 changes: 5 additions & 0 deletions release/Double-Click-to-Run-for-Mac.command
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# cd 到脚本所在目录
cd $(dirname $0)
java -Dfile.encoding=utf-8 -Dhttps.protocols=TLSv1.2 -jar INeedBiliAV.jar
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
cd /d %~dp0
:: ½«¾«¼òjreдÈ뵱ǰ»·¾³µÄpath
:: set Path=D:\Program Files\Java\minimal-bilibilidown-jre\bin;%Path%
set Path=%~dp0minimal-bilibilidown-jre\bin\;%Path%
:: -Dhttps.protocols=TLSv1.2 https://bugs.openjdk.org/browse/JDK-8206923
java -Dfile.encoding=utf-8 -Dhttps.protocols=TLSv1.2 -jar INeedBiliAV.jar
Expand Down
File renamed without changes.
16 changes: 12 additions & 4 deletions src/nicelee/bilibili/util/VersionManagerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,28 @@ public static void RunCmdAndCloseApp(String code) {
CmdUtil.run(cmd);
}else {
System.out.println(System.getProperty("os.name").toLowerCase());
copy(VersionManagerUtil.class.getResourceAsStream("/resources/update.sh"), new File("update.sh"));
copy(VersionManagerUtil.class.getResourceAsStream("/resources/update.sh"), new File("update.sh"), false);
CmdUtil.run(new String[]{"chmod", "+x", "./update.sh"});
String cmd[] = { "./update.sh", "@" + code, pid, "bilibili.log" }; // 最后一个为log,可以为/dev/null
CmdUtil.run(cmd);
if(!CmdUtil.run(cmd)) {
JOptionPane.showMessageDialog(null, "update.sh运行失败。你需要赋予其可执行权限。\n请关闭程序,然后执行命令行:\nsudo chmod +x ./update.sh && ./update.sh", "!", JOptionPane.INFORMATION_MESSAGE);
return;
}
}
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
}
}

public static void copy(InputStream rSource, File dest) {
public static void copy(InputStream rSource, File dest, boolean override) {
try {
dest.delete();
if(dest.exists()) {
if(override)
dest.delete();
else
return;
}
RandomAccessFile rDest = new RandomAccessFile(dest, "rw");

byte[] buffer = new byte[1024*1024];
Expand Down

0 comments on commit ac1c4ef

Please sign in to comment.