Skip to content

Commit 8a042fb

Browse files
author
root
committed
update
1 parent 24be8ff commit 8a042fb

File tree

2 files changed

+135
-59
lines changed

2 files changed

+135
-59
lines changed

.gitattributes

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Exclude files from exporting
2+
.gitattributes export-ignore
3+
.gitignore export-ignore
4+
# Enable syntax highlighting for files with `.gitattributes` extensions.
5+
*.gitattributes linguist-language=gitattributes
6+
# Auto detect text files and perform LF normalization
7+
*.bat text linguist-language=batch working-tree-encoding=GB2312 eol=crlf
8+
*.psl text linguist-language=PowerShell working-tree-encoding=GB2312 eol=crlf
9+
*.vbs text linguist-language=Visual-Basic-Script working-tree-encoding=GB2312 eol=crlf
10+
*.sh text linguist-language=bash working-tree-encoding=UTF-8 eol=lf
11+
12+
###############################################################################
13+
# Set default behavior to automatically normalize line endings.
14+
###############################################################################
15+
* text=auto
16+
###############################################################################
17+
# Set default behavior for command prompt diff.
18+
#
19+
# This is need for earlier builds of msysgit that does not have it on by
20+
# default for csharp files.
21+
# Note: This is only used by command line
22+
###############################################################################
23+
#*.cs diff=csharp
24+
###############################################################################
25+
# Set the merge driver for project and solution files
26+
#
27+
# Merging from the command prompt will add diff markers to the files if there
28+
# are conflicts (Merging from VS is not affected by the settings below, in VS
29+
# the diff markers are never inserted). Diff markers may cause the following
30+
# file extensions to fail to load in VS. An alternative would be to treat
31+
# these files as binary and thus will always conflict and require user
32+
# intervention with every merge. To do so, just uncomment the entries below
33+
###############################################################################
34+
#*.sln merge=binary
35+
#*.csproj merge=binary
36+
#*.vbproj merge=binary
37+
#*.vcxproj merge=binary
38+
#*.vcproj merge=binary
39+
#*.dbproj merge=binary
40+
#*.fsproj merge=binary
41+
#*.lsproj merge=binary
42+
#*.wixproj merge=binary
43+
#*.modelproj merge=binary
44+
#*.sqlproj merge=binary
45+
#*.wwaproj merge=binary
46+
###############################################################################
47+
# behavior for image files
48+
#
49+
# image files are treated as binary by default.
50+
###############################################################################
51+
*.gz binary
52+
*.7z binary
53+
*.zip binary
54+
*.png binary
55+
*.ico binary
56+
*.jpg binary
57+
*.psd binary
58+
*.gif binary
59+
###############################################################################
60+
# diff behavior for common document formats
61+
#
62+
# Convert binary document formats to text before diffing them. This feature
63+
# is only available from the command line. Turn it on by uncommenting the
64+
# entries below.
65+
###############################################################################
66+
#*.doc diff=astextplain
67+
#*.DOC diff=astextplain
68+
#*.docx diff=astextplain
69+
#*.DOCX diff=astextplain
70+
#*.dot diff=astextplain
71+
#*.DOT diff=astextplain
72+
#*.pdf diff=astextplain
73+
#*.PDF diff=astextplain
74+
#*.rtf diff=astextplain
75+
#*.RTF diff=astextplain
76+
#*.xlsx diff=xlsx

go_7z_pack.bat

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,49 @@
33

44
@ECHO OFF
55
color 0a
6-
Title GO打包工具 by:bajins.com
7-
:: 窗口高宽40*120
6+
Title GO打包工具 by:bajins.com
7+
:: 窗口高宽40*120
88
REG ADD "HKEY_CURRENT_USER\Console" /t REG_DWORD /v WindowSize /d 0x00280078 /f >nul
9-
:: 屏幕缓冲区高宽1000*120
9+
:: 屏幕缓冲区高宽1000*120
1010
REG ADD "HKEY_CURRENT_USER\Console" /t REG_DWORD /v ScreenBufferSize /d 0x03e80078 /f >nul
1111

1212
md "%~dp0$testAdmin$" 2>nul
1313
if not exist "%~dp0$testAdmin$" (
14-
echo bajins不具备所在目录的写入权限! >&2
14+
echo bajins不具备所在目录的写入权限! >&2
1515
exit /b 1
1616
) else rd "%~dp0$testAdmin$"
1717

18-
:: 开启延迟环境变量扩展
18+
:: 开启延迟环境变量扩展
1919
setlocal enabledelayedexpansion
2020

21-
:: %~f0 表示当前批处理的绝对路径,去掉引号的完整路径
21+
:: %~f0 表示当前批处理的绝对路径,去掉引号的完整路径
2222
cscript -nologo -e:jscript "%~f0" download7z
2323
if not "%errorlevel%" == "0" (
2424
@cmd /k
2525
goto :EXIT
2626
)
2727

28-
:: 需要打包的文件或文件夹
28+
:: 需要打包的文件或文件夹
2929
set files=pyutils static
3030
if "%files%" == "" (
31-
echo 请设置需要打包的静态文件或文件夹
31+
echo 请设置需要打包的静态文件或文件夹
3232
@cmd /k
3333
goto :EXIT
3434
)
3535

36-
:: 顺序循环,设置最后一个为当前目录
36+
:: 顺序循环,设置最后一个为当前目录
3737
for /f "delims=" %%i in ("%cd%") do set projectName=%%~ni
38-
:: 打包完成的文件命名后一部分,与前一部分进行组合
38+
:: 打包完成的文件命名后一部分,与前一部分进行组合
3939
set allList=darwin_386,darwin_amd64,freebsd_386,freebsd_amd64,freebsd_arm,
4040
set allList=%allList%netbsd_386,netbsd_amd64,netbsd_arm,openbsd_386,
4141
set allList=%allList%openbsd_amd64,windows_386.exe,windows_amd64.exe,
4242
set allList=%allList%linux_386,linux_amd64,linux_arm,linux_mips,
4343
set allList=%allList%linux_mips64,linux_mips64le,linux_mipsle,linux_s390x
4444

45-
:: 删除旧文件
45+
:: 删除旧文件
4646
for %%i in (%allList%) do (
4747
set binaryFile=%projectName%_%%i
48-
:: 如果二进制文件存在则删除
48+
:: 如果二进制文件存在则删除
4949
if exist "!binaryFile!" (
5050
del !binaryFile!
5151
)
@@ -61,15 +61,15 @@ for %%i in (%allList%) do (
6161
)
6262
)
6363

64-
:: 使用7z压缩
64+
:: 使用7z压缩
6565
for %%i in (%allList%) do (
6666
set binaryFile=%projectName%_%%i
67-
:: 编译生成二进制运行文件,分割设置GOOS和GOARCH
67+
:: 编译生成二进制运行文件,分割设置GOOS和GOARCH
6868
for /f "delims=_ tokens=1,2" %%j in ( "%%i" ) do (
6969
echo.
7070
echo.
7171
echo ::::::::::::::::::::::::::::::::::::::::::
72-
echo :::::: 编译!binaryFile! ::::::
72+
echo :::::: 编译!binaryFile! ::::::
7373
echo ::::::::::::::::::::::::::::::::::::::::::
7474
echo.
7575
set Arch=%%k
@@ -78,39 +78,39 @@ for %%i in (%allList%) do (
7878
)
7979
set GOOS=%%j
8080
set GOARCH=!Arch!
81-
echo 环境变量设置成功:!GOOS!------!GOARCH!
81+
echo 环境变量设置成功:!GOOS!------!GOARCH!
8282
echo.
8383
go build -ldflags=-w -i -o !binaryFile!
8484
)
85-
:: !!为setlocal EnableDelayedExpansion取变量的值
85+
:: !!为setlocal EnableDelayedExpansion取变量的值
8686
if not exist "!binaryFile!" (
87-
echo 打包失败,文件不存在
87+
echo 打包失败,文件不存在
8888
@cmd /k
8989
)
90-
:: 判断变量字符串中是否包含字符串
90+
:: 判断变量字符串中是否包含字符串
9191
echo %%i | findstr linux >nul && (
92-
:: 用7z压缩成tar
92+
:: 用7z压缩成tar
9393
7za a -ttar !binaryFile!.tar %files% !binaryFile!
94-
:: 用7z把tar压缩成gz
94+
:: 用7z把tar压缩成gz
9595
7za a -tgzip !binaryFile!.tar.gz !binaryFile!.tar
96-
:: 删除tar文件
96+
:: 删除tar文件
9797
del *.tar
9898
) || (
9999
set zipName=!binaryFile:.exe=!
100-
:: 用7z压缩文件为zip
100+
:: 用7z压缩文件为zip
101101
7za a !zipName!.zip %files% !binaryFile!
102102
)
103-
:: 删除二进制文件
103+
:: 删除二进制文件
104104
del !binaryFile!
105105
)
106106

107-
:: 编译完成清理缓存
107+
:: 编译完成清理缓存
108108
go clean -cache
109109

110110
goto :EXIT
111111

112112
:EXIT
113-
:: 结束延迟环境变量扩展和命令执行
113+
:: 结束延迟环境变量扩展和命令执行
114114
endlocal&exit /b %errorlevel%
115115
*/
116116

@@ -119,7 +119,7 @@ endlocal&exit /b %errorlevel%
119119

120120
var Argv = WScript.Arguments;
121121
for (i = 0; i < Argv.length; i++) {
122-
WScript.Echo("参数:", Argv(i));
122+
WScript.Echo("参数:", Argv(i));
123123
}
124124

125125
if (Argv.length > 0) {
@@ -128,33 +128,33 @@ if (Argv.length > 0) {
128128
download7z();
129129
break;
130130
default:
131-
WScript.Echo("双击执行即可!");
131+
WScript.Echo("双击执行即可!");
132132
}
133-
// 正常退出
133+
// 正常退出
134134
WScript.Quit(0);
135135
}
136136

137137

138138
/**
139-
* HTTP请求
140-
* 查看方法属性:New-Object -ComObject "WinHttp.WinHttpRequest.5.1" | Get-Member
139+
* HTTP请求
140+
* 查看方法属性:New-Object -ComObject "WinHttp.WinHttpRequest.5.1" | Get-Member
141141
*
142142
* @param method GET,POST
143-
* @param url 请求地址
143+
* @param url 请求地址
144144
* @param dataType "",text,stream,xml,json
145-
* @param data 数据,{key:value}格式
146-
* @param contentType 发送的数据类型:multipart/form-data、
147-
* application/x-www-form-urlencoded(默认)、text/plain
145+
* @param data 数据,{key:value}格式
146+
* @param contentType 发送的数据类型:multipart/form-data、
147+
* application/x-www-form-urlencoded(默认)、text/plain
148148
* @returns {string|Document|any}
149149
*/
150150
function request(method, url, dataType, data, contentType) {
151151
if (url == "" || url == null || url.length <= 0) {
152-
throw new Error("请求url不能为空!");
152+
throw new Error("请求url不能为空!");
153153
}
154154
if (method == "" || method == null || method.length <= 0) {
155155
method = "GET";
156156
} else {
157-
// 把字符串转换为大写
157+
// 把字符串转换为大写
158158
method = method.toUpperCase();
159159
}
160160
if (contentType == "" || contentType == null || contentType.length <= 0) {
@@ -185,31 +185,31 @@ function request(method, url, dataType, data, contentType) {
185185
}
186186
}
187187
XMLHTTP.SetTimeouts(0, 1800000, 1800000, 1800000);
188-
//将对象转化成为querystring形式
188+
//将对象转化成为querystring形式
189189
var paramarray = [];
190190
for (key in data) {
191191
paramarray.push(key + "=" + data[key]);
192192
}
193193
var params = paramarray.join("&");
194194
switch (method) {
195195
case "POST":
196-
// 0异步、1同步
196+
// 0异步、1同步
197197
XMLHTTP.Open(method, url, 0);
198198
XMLHTTP.SetRequestHeader("CONTENT-TYPE", contentType);
199199
XMLHTTP.Send(params);
200200
break;
201201
default:
202-
// 默认GET请求
202+
// 默认GET请求
203203
if (params == "" || params.length == 0 || params == null) {
204-
// 0异步、1同步
204+
// 0异步、1同步
205205
XMLHTTP.Open(method, url, 0);
206206
} else {
207207
XMLHTTP.Open(method, url + "?" + params, 0);
208208
}
209209
XMLHTTP.SetRequestHeader("CONTENT-TYPE", contentType);
210210
XMLHTTP.Send();
211211
}
212-
// 把字符串转换为小写
212+
// 把字符串转换为小写
213213
dataType = dataType.toLowerCase();
214214
switch (dataType) {
215215
case "text":
@@ -228,30 +228,30 @@ function request(method, url, dataType, data, contentType) {
228228

229229

230230
/**
231-
* 下载文件
232-
* 查看方法属性:New-Object -ComObject "ADODB.Stream" | Get-Member
231+
* 下载文件
232+
* 查看方法属性:New-Object -ComObject "ADODB.Stream" | Get-Member
233233
*
234234
* @param url
235-
* @param directory 文件存储目录
236-
* @param filename 文件名,为空默认截取url中的文件名
235+
* @param directory 文件存储目录
236+
* @param filename 文件名,为空默认截取url中的文件名
237237
* @returns {string}
238238
*/
239239
function download(url, directory, filename) {
240240
if (url == "" || url == null || url.length <= 0) {
241-
throw new Error("请求url不能为空!");
241+
throw new Error("请求url不能为空!");
242242
}
243243
if (directory == "" || directory == null || directory.length <= 0) {
244-
throw new Error("文件存储目录不能为空!");
244+
throw new Error("文件存储目录不能为空!");
245245
}
246246
var fso = new ActiveXObject("Scripting.FileSystemObject");
247-
// 如果目录不存在
247+
// 如果目录不存在
248248
if (!fso.FolderExists(directory)) {
249-
// 创建目录
249+
// 创建目录
250250
var strFolderName = fso.CreateFolder(directory);
251251
}
252252
if (filename == "" || filename == null || filename.length <= 0) {
253253
filename = url.substring(url.lastIndexOf("/") + 1);
254-
// 去掉文件名的特殊符号(包括之前的)字符
254+
// 去掉文件名的特殊符号(包括之前的)字符
255255
filename = filename.replace(/^.*(\&|\=|\?|\/)/ig, "");
256256
}
257257
var path = directory + "\\" + filename;
@@ -262,21 +262,21 @@ function download(url, directory, filename) {
262262
ADO.Write(request("GET", url, ""));
263263
ADO.SaveToFile(path, 2);
264264
ADO.Close();
265-
// 如果文件不存在
265+
// 如果文件不存在
266266
if (!fso.FileExists(path)) {
267-
throw new Error("文件下载失败");
267+
throw new Error("文件下载失败");
268268
}
269269
return path;
270270
}
271271

272272
/**
273-
* 下载7-Zip
273+
* 下载7-Zip
274274
*
275-
* @param mode 下载模式:默认0不覆盖下载,1覆盖下载
275+
* @param mode 下载模式:默认0不覆盖下载,1覆盖下载
276276
*/
277277
function download7z(mode) {
278278
var shell = new ActiveXObject("WScript.shell");
279-
// 执行7z命令判断是否存在
279+
// 执行7z命令判断是否存在
280280
if (shell.Run("cmd /c 7za", 0, true) == 0 && (!mode || mode == 0)) {
281281
return;
282282
}
@@ -294,7 +294,7 @@ function download7z(mode) {
294294
var url = "https://www.7-zip.org/download.html";
295295
filename = reg.exec(request("get", url, "text", "", ""));
296296
}
297-
// 当前文件所在目录
297+
// 当前文件所在目录
298298
var dir = fso.GetFile(WScript.ScriptFullName).ParentFolder;
299299
var msi = dir + '\\' + filename;
300300
if (fso.FileExists(msi)) {
@@ -305,7 +305,7 @@ function download7z(mode) {
305305
fso.DeleteFolder(zipDir);
306306
}
307307
download("https://www.7-zip.org/a/" + filename, dir, filename);
308-
// 解压msi文件
308+
// 解压msi文件
309309
shell.Run('msiexec /a "' + msi + '" /qn TARGETDIR="' + zipDir + '"', 0, true);
310310
fso.CopyFile(dir + "\\7zip\\Files\\7-Zip\\7z.exe", exe);
311311
fso.CopyFile(dir + "\\7zip\\Files\\7-Zip\\7z.dll", dll);
@@ -317,7 +317,7 @@ function download7z(mode) {
317317
fso.DeleteFile(exetra);
318318
}
319319
download("https://www.7-zip.org/a/" + filename, dir, filename);
320-
// -aoa解压并覆盖文件,-o参数必须与值之间不能有空格
320+
// -aoa解压并覆盖文件,-o参数必须与值之间不能有空格
321321
shell.Run('7z x -aoa "' + exetra + '" -o"' + storage + '" 7za.exe 7za.dll', 0, true);
322322
fso.DeleteFile(exetra);
323323
}

0 commit comments

Comments
 (0)