Browse Source

实现基本的备份功能

master
VIVIMAN 3 years ago
parent
commit
98aabdce34
  1. 34
      golang_learn/data_func/go_to_file/demo01/main.go
  2. 5
      golang_learn/data_func/go_to_windows/build.bat
  3. 83
      golang_learn/data_func/go_to_windows/main.go
  4. 23
      golang_learn/data_func/go_to_zip/demo4/main.go

34
golang_learn/data_func/go_to_file/demo01/main.go

@ -0,0 +1,34 @@
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"path"
)
func main() {
filename := "device/sdk/CMakeLists.txt"
filenameall := path.Base(filename)
filesuffix := path.Ext(filename)
fileprefix := filenameall[0 : len(filenameall)-len(filesuffix)]
//fileprefix, err := strings.TrimSuffix(filenameall, filesuffix)
fmt.Println("file name:", filenameall)
fmt.Println("file prefix:", fileprefix)
fmt.Println("file suffix:", filesuffix)
fmt.Println(path.Dir(filename))
pwd, _ := os.Getwd()
//获取文件或目录相关信息
fileInfoList, err := ioutil.ReadDir(pwd)
if err != nil {
log.Fatal(err)
}
fmt.Println(len(fileInfoList))
for i := range fileInfoList {
fmt.Println(fileInfoList[i].Name()) //打印当前文件或目录下的文件或目录名
}
}

5
golang_learn/data_func/go_to_windows/build.bat

@ -1,7 +1,6 @@
set GO111MODULE=on
set GOARCH=386
set releasedate=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
rsrc -manifest main.manifest -ico main.ico -o main.syso
go generate
go build -ldflags="-s -w -H=windowsgui -X 'main.MinVersion=1.0.0.1' -X 'main.PublishDate=%releasedate%'"
upx -9 ./go_to_windows.exe
go build -ldflags="-s -w -H=windowsgui" -o HyServer.exe
upx -9 ./HyServer.exe

83
golang_learn/data_func/go_to_windows/main.go

@ -1,11 +1,11 @@
// +build windows
//go:generate rsrc -ico main.ico -manifest main.manifest -o main.syso
package main
import (
"bufio"
"database/sql"
"errors"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/lxn/walk"
@ -15,10 +15,13 @@ import (
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
"io"
"io/fs"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"syscall"
"time"
@ -77,8 +80,20 @@ func init() {
func main() {
_ = getWindows()
if e := HasHzb(); e != nil {
walk.MsgBox(app.mw, "错误", "请先下载并安装 组工 软件,才可以正常使用软件!", walk.MsgBoxIconWarning)
OpenUrl("https://www.12371.cn/zgrjxz/gwywx/")
return
}
if e := InHzb(); e != nil {
walk.MsgBox(app.mw, "错误", "当前工具未在正确的位置,请将工具移至安装软件目录下(如:./hzb2020/HyServer.exe)!", walk.MsgBoxIconWarning)
return
}
walk.App().SetProductName(app.title)
walk.App().SetOrganizationName("网新")
walk.App().SetProductName("网新")
showMsg(fmt.Sprintf(" 当前获取的目录为:%s", path))
@ -620,16 +635,19 @@ func dbBak() {
QuerySQL(db, dir, "select * from a08 where a0000 in (select a0000 from a01 where status=1)", "a08", []string{})
QuerySQL(db, dir, "select * from a14 where a0000 in (select a0000 from a01 where status=1)", "a14", []string{})
QuerySQL(db, dir, "select * from a15 where a0000 in (select a0000 from a01 where status=1)", "a15", []string{})
QuerySQL(db, dir, "select * from a17 where a0000 in (select a0000 from a01 where status=1)", "a17", []string{})
QuerySQL(db, dir, "select * from a36 where a0000 in (select a0000 from a01 where status=1)", "a36", []string{})
QuerySQL(db, dir, "select * from a99z1 where a0000 in (select a0000 from a01 where status=1)", "a99z1", []string{})
QuerySQL(db, dir, "select * from a30 where a0000 in (select a0000 from a01 where status=1)", "a30", []string{})
QuerySQL(db, dir, "select * from a33 where a0000 in (select a0000 from a01 where status=1)", "a33", []string{})
QuerySQL(db, dir, "select * from a57 where a0000 in (select a0000 from a01 where status=1)", "a57", []string{})
QuerySQL(db, dir, "select * from a65 where a0000 in (select a0000 from a01 where status=1)", "a65", []string{})
QuerySQL(db, dir, "select * from a99z1 where a0000 in (select a0000 from a01 where status=1)", "a99z1", []string{})
QuerySQL(db, dir, "select * from b01", "b01", []string{})
// 处理照片信息
copyFileByA57(db, dir)
dirName := fmt.Sprintf("./%s", dir)
dirName := fmt.Sprintf("./%s/", dir)
fileName := fmt.Sprintf("%s.gz", dir)
// 进行压缩操作 并 删除压缩前目录
Zip(dirName, fileName)
@ -827,7 +845,7 @@ func QuerySQL(db *sql.DB, dir, sqlStr, tableName string, colNil []string) {
for i := range values {
scanArgs[i] = &values[i]
}
aa := ""
aa := fmt.Sprintf("truncate table %s;\n", tableName)
for rows.Next() {
_ = rows.Scan(scanArgs...)
key, value := "(", "("
@ -963,3 +981,60 @@ func Zip(srcDir string, zipFileName string) {
return nil
})
}
// open opens the specified URL in the default browser of the user.
func OpenUrl(url string) error {
var cmd string
var args []string
switch runtime.GOOS {
case "windows":
cmd = "cmd"
args = []string{"/c", "start"}
case "darwin":
cmd = "open"
default: // "linux", "freebsd", "openbsd", "netbsd"
cmd = "xdg-open"
}
args = append(args, url)
c := exec.Command(cmd, args...)
c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
return c.Start()
}
// hasHzb 判断软件是否安装
func HasHzb() error {
return nil
}
// inHzb 判断当前软件是否在正确的位置
func InHzb() error {
pwd, _ := os.Getwd()
// 判断依据 为是否存在 360se6、tools、Tomcat8 和 mysql 目录下
fileInfoList, _ := ioutil.ReadDir(pwd)
if Contains(fileInfoList, "360se6") == -1 {
return errors.New("目录错误")
}
if Contains(fileInfoList, "mysql") == -1 {
return errors.New("目录错误")
}
if Contains(fileInfoList, "tomcat8") == -1 {
return errors.New("目录错误")
}
if Contains(fileInfoList, "tools") == -1 {
return errors.New("目录错误")
}
return nil
}
func Contains(array []fs.FileInfo, val string) (index int) {
index = -1
for i := range array {
// fmt.Println(array[i].Name()) //打印当前文件或目录下的文件或目录名
if array[i].Name() == val {
index = i
return
}
}
return
}

23
golang_learn/data_func/go_to_zip/demo4/main.go

@ -1,15 +1,36 @@
package main
import (
"fmt"
"github.com/mzky/zip"
"io"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
func main() {
Zip("./", "aaa.gz")
// Zip("./", "aaa.gz")
// pwd,_ := os.Getwd()
pwd := "D://hzb2021"
// 判断依据 为是否存在 360se6、tools、Tomcat8 和 mysql 目录下
fileInfoList, _ := ioutil.ReadDir(pwd)
fmt.Print(Contains(fileInfoList, "tools"))
}
func Contains(array []fs.FileInfo, val string) (index int) {
index = -1
for i := range array {
// fmt.Println(array[i].Name()) //打印当前文件或目录下的文件或目录名
if array[i].Name() == val {
index = i
return
}
}
return
}
// Zip 打包成zip文件

Loading…
Cancel
Save