4 Star 31 Fork 3

rocket049/secret-diary

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
shortcut_windows.go 957 Bytes
一键复制 编辑 原始数据 按行查看 历史
rocket049 提交于 2019-07-18 09:06 +08:00 . 2019年 07月 18日 星期四 09:06:44 CST
package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
locale "github.com/rocket049/go-locale"
"github.com/skratchdot/open-golang/open"
"golang.org/x/text/encoding/simplifiedchinese"
)
func makeShortcut(force bool) error {
exe1, _ := os.Executable()
appdir := filepath.Dir(exe1)
appname := filepath.Join(appdir, "secret-diary.exe")
script := filepath.Join(appdir, "shortcut.vbs")
bat := filepath.Join(appdir, "shortcut.bat")
_, err := os.Lstat(bat)
if err == nil && force == false {
return err
}
writeBat(bat, "wscript", script, fmt.Sprintf(`/target:"%s"`, appname), "\r\nexit\r\n")
open.Start(bat)
return nil
}
func writeBat(bat string, msgs ...interface{}) {
var buf = []byte(fmt.Sprintln(msgs...))
var err error = nil
loc, _ := locale.DetectLocale()
switch loc {
case "zh_CN":
enc := simplifiedchinese.GB18030.NewEncoder()
buf, err = enc.Bytes(buf)
}
if err == nil {
ioutil.WriteFile(bat, buf, 0644)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rocket049/secret-diary.git
git@gitee.com:rocket049/secret-diary.git
rocket049
secret-diary
secret-diary
master

搜索帮助