Skip to content
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

Closed
wants to merge 6 commits into from
Closed

Papermc arclight #1

wants to merge 6 commits into from

Conversation

Fellsoul
Copy link

@Fellsoul Fellsoul commented Mar 7, 2024

把papermc和arclight的下载器做好了,在readme里改了日志。本地都调试过了,papermc支持所有有的版本,arclight多加了一个判断并且告诉用户什么版本已经expired不能再选了(虽然强硬要选也会被驳回吧

@zyxkad zyxkad self-requested a review March 7, 2024 22:22
}
return "", &VersionNotFoundErr{target}
}
DownloadPart:
Copy link
Member

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()
Copy link
Member

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])
Copy link
Member

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

Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

常量用 const, 另外你上面定义了 paperURL 这里为什么还要 hardcode

Copy link
Author

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

installer 不换行啊,这是通知可能存在的父程序文件下载到哪里去了

Copy link
Author

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i += 1 就是 i++

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

year < 2024 是个什么操作????

Copy link
Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

格式错了,应该下载到提供的 name 参数那里去

Copy link
Author

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么我还是能遇到 == true 这种操作 😓

Suggested change
if data[allVersions[i]].IsExpired == true {
if data[allVersions[i]].IsExpired {

return data, err
}

func (r *ArclightInstaller) GetOnlyVersions(data map[string]ArclightRelease) (versions []string) {
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for k := range data {
for k, _ := range data {

}
goto DownloadPart
}
for i := 0; i < len(allVersions); i += 1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for i := 0; i < len(allVersions); i += 1 {
for _, version := range allVersions {

或者直接

Suggested change
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var releases []ArclightRelease
var releases []*ArclightRelease

DownloadPart:
ExactDownloadeName := data[loader].Assets[0].AssetsName
ArclightInstallerUrl := data[loader].Assets[0].DownloadUrl
if data[loader].IsExpired == true {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你不能假设loader存在于data里

Suggested change
if data[loader].IsExpired == true {
if version, ok := data[loader]; ok && version.IsExpired {

Copy link
Author

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data 这个名字太笼统了,换成 versions

Copy link
Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Install papermc 1.14.4 server into server/minecraft_server.jar
# Install papermc 1.14.4 server into minecraft_server.jar

@Fellsoul Fellsoul closed this Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants