-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Papermc arclight #1
Conversation
} | ||
return "", &VersionNotFoundErr{target} | ||
} | ||
DownloadPart: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Label 用全大写字母+下划线,另外,能不用goto就别用
} | ||
|
||
func (r *ArclightInstaller) Runbuilder(buildJar string, ExactDownloadName string, path string) (installed string, err error) { | ||
currentDir, err := os.Getwd() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getwd
和 .
一个意思,这里没有必要再获取一遍
if err != nil { | ||
return | ||
} | ||
serverDirectory := filepath.Join(currentDir, "server-"+ExactDownloadName[0:len(ExactDownloadName)-4]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要出现 len(ExactDownloadName)-4
这样需要联系方法外上下文的迷之操作
@@ -1,31 +1 @@ | |||
package main | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usage 太长,所以单放一个文件
@@ -193,3 +193,40 @@ func (c *HTTPClient) PostForm(url string, form url.Values) (res *http.Response, | |||
return c.Post(url, "application/x-www-form-urlencoded", | |||
strings.NewReader(formStr)) | |||
} | |||
|
|||
func (c *HTTPClient) DownloadDirect(url string, ExactDownloadeName string, cb DlCallback) (installed string, err error) { | |||
resp, err := http.Head(url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个用不到的操作是做甚的
} | ||
defer resp.Body.Close() | ||
filename := filepath.Base(url) | ||
flags := os.O_CREATE | os.O_WRONLY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flags 不用单列出一个变量,因为下面用不到,也不会被修改
defer resp.Body.Close() | ||
filename := filepath.Base(url) | ||
flags := os.O_CREATE | os.O_WRONLY | ||
f, err := os.OpenFile(filename, flags, 0666) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0666
不是安全的权限,改成0644
} | ||
defer f.Close() | ||
|
||
buf := make([]byte, 16*1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果是现make buffer就别make了,直接用io.Copy
} | ||
|
||
func (r *PapermcInstaller) GetInstallerVersions() (data []string, err error) { | ||
link := "https://api.papermc.io/v2/projects/paper" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
常量用 const, 另外你上面定义了 paperURL 这里为什么还要 hardcode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我的错。我不明白“url”的因素。我认为其他文件中引用了它们
if err = cmd.Run(); err != nil { | ||
return | ||
} | ||
installed = buildJar + "\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
installer 不换行啊,这是通知可能存在的父程序文件下载到哪里去了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
正确的。我没有意识到变量用作地址,只考虑输出
if err != nil { | ||
return data, err | ||
} | ||
for i := 0; i < len(releases); i += 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i += 1
就是 i++
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for i := 0; i < len(releases); i += 1 { | |
for _, release := range releases { |
if err != nil { | ||
return data, err | ||
} | ||
if year < 2024 || (year == 2024 && month < 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
year < 2024
是个什么操作????
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
判断是否过期,因为在2024.2月以前的所有构建都失效了,而且想不到比这样判断更好的方法了,就直接这样硬编码了
README.MD
Outdated
@@ -80,6 +82,12 @@ minecraft_installer -name minecraft_server -version 1.16.5 -server forge | |||
minecraft_installer -name minecraft_server -version 1.19.2 -server fabric -path server | |||
``` | |||
|
|||
```sh | |||
# Install papermc 1.14.4 server into {PATH}/server-1.14.4-{BUILDNUM}/{PAPERMC-INSTALLED-NAME}.jar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
格式错了,应该下载到提供的 name
参数那里去
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的我run所有文件再调试一下,之前不是太清楚命令行操作
} | ||
loger.Info("not find the suitable builder, the version should be included in the following list:") | ||
for i := 0; i < len(allVersions); i += 1 { | ||
if data[allVersions[i]].IsExpired == true { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么我还是能遇到 == true 这种操作 😓
if data[allVersions[i]].IsExpired == true { | |
if data[allVersions[i]].IsExpired { |
return data, err | ||
} | ||
|
||
func (r *ArclightInstaller) GetOnlyVersions(data map[string]ArclightRelease) (versions []string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetOnlyVersions
是干嘛的,如果是辅助函数那就不要放到 Installer 的方法里
} | ||
|
||
func (r *ArclightInstaller) GetOnlyVersions(data map[string]ArclightRelease) (versions []string) { | ||
for k := range data { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for k := range data { | |
for k, _ := range data { |
} | ||
goto DownloadPart | ||
} | ||
for i := 0; i < len(allVersions); i += 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for i := 0; i < len(allVersions); i += 1 { | |
for _, version := range allVersions { |
或者直接
for i := 0; i < len(allVersions); i += 1 { | |
for version, _ := range data { |
if err != nil { | ||
return data, err | ||
} | ||
for i := 0; i < len(releases); i += 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for i := 0; i < len(releases); i += 1 { | |
for _, release := range releases { |
func (r *ArclightInstaller) GetInstallerVersions() (map[string]ArclightRelease, error) { | ||
data := make(map[string]ArclightRelease) | ||
link := "https://api.github.com/repos/IzzelAliz/Arclight/releases" | ||
var releases []ArclightRelease |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var releases []ArclightRelease | |
var releases []*ArclightRelease |
DownloadPart: | ||
ExactDownloadeName := data[loader].Assets[0].AssetsName | ||
ArclightInstallerUrl := data[loader].Assets[0].DownloadUrl | ||
if data[loader].IsExpired == true { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你不能假设loader存在于data里
if data[loader].IsExpired == true { | |
if version, ok := data[loader]; ok && version.IsExpired { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
疏忽了
} | ||
|
||
func (r *ArclightInstaller) InstallWithLoader(path, name string, target string, loader string) (installed string, err error) { | ||
data, err := r.GetInstallerVersions() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data
这个名字太笼统了,换成 versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
@@ -83,7 +83,7 @@ minecraft_installer -name minecraft_server -version 1.19.2 -server fabric -path | |||
``` | |||
|
|||
```sh | |||
# Install papermc 1.14.4 server into {PATH}/server-1.14.4-{BUILDNUM}/{PAPERMC-INSTALLED-NAME}.jar | |||
# Install papermc 1.14.4 server into server/minecraft_server.jar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Install papermc 1.14.4 server into server/minecraft_server.jar | |
# Install papermc 1.14.4 server into minecraft_server.jar |
把papermc和arclight的下载器做好了,在readme里改了日志。本地都调试过了,papermc支持所有有的版本,arclight多加了一个判断并且告诉用户什么版本已经expired不能再选了(虽然强硬要选也会被驳回吧