mirror of
https://github.com/zu1k/nali.git
synced 2025-01-23 21:59:02 +08:00
mod qqwry download
This commit is contained in:
parent
11dd415c35
commit
342e49a642
@ -25,18 +25,13 @@ func NewQQwry(filePath string) QQwry {
|
|||||||
_, err := os.Stat(filePath)
|
_, err := os.Stat(filePath)
|
||||||
if err != nil && os.IsNotExist(err) {
|
if err != nil && os.IsNotExist(err) {
|
||||||
log.Println("文件不存在,尝试从网络获取最新纯真 IP 库")
|
log.Println("文件不存在,尝试从网络获取最新纯真 IP 库")
|
||||||
fileData, err = Download()
|
fileData, err = Download(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("纯真IP库下载失败,请手动下载解压后保存到本地: %s \n", filePath)
|
log.Printf("纯真IP库下载失败,请手动下载解压后保存到本地: %s \n", filePath)
|
||||||
log.Println("下载链接: https://qqwry.mirror.noc.one/qqwry.rar")
|
log.Println("下载链接: https://qqwry.mirror.noc.one/qqwry.rar")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
} else {
|
|
||||||
if err := ioutil.WriteFile(filePath, fileData, 0644); err == nil {
|
|
||||||
log.Printf("已将最新的 纯真IP库 保存到本地: %s ", filePath)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 打开文件句柄
|
|
||||||
fileInfo.FileBase, err = os.OpenFile(filePath, os.O_RDONLY, 0400)
|
fileInfo.FileBase, err = os.OpenFile(filePath, os.O_RDONLY, 0400)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -5,23 +5,38 @@ import (
|
|||||||
"compress/zlib"
|
"compress/zlib"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Download() (data []byte, err error) {
|
func Download(filePath string) (data []byte, err error) {
|
||||||
|
data, err = getData()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("纯真IP库下载失败,请手动下载解压后保存到本地: %s \n", filePath)
|
||||||
|
log.Println("下载链接: https://qqwry.mirror.noc.one/qqwry.rar")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = ioutil.WriteFile(filePath, data, 0644); err == nil {
|
||||||
|
log.Printf("已将最新的 纯真IP库 保存到本地: %s ", filePath)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getData() (data []byte, err error) {
|
||||||
resp, err := http.Get("https://qqwry.mirror.noc.one/qqwry.rar")
|
resp, err := http.Get("https://qqwry.mirror.noc.one/qqwry.rar")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
key, err := getCopyWriteKey()
|
key, err := getCopyWriteKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return unRar(body, key)
|
return unRar(body, key)
|
||||||
|
Loading…
Reference in New Issue
Block a user