forked from DreamOneX/PhoenixBuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
107 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"系统名": "Omega", | ||
"版本": "0.0.2", | ||
"自动升级识别号":542, | ||
"触发词": { | ||
"默认触发词": "omg", | ||
"允许的触发词": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package upgrade | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"path" | ||
"phoenixbuilder/omega/defines" | ||
"phoenixbuilder/omega/utils" | ||
"strings" | ||
) | ||
|
||
func checkMigrationVersion(root string) (int, error) { | ||
d := path.Join(root, "配置") | ||
entries, err := ioutil.ReadDir(d) | ||
if err != nil { | ||
return 0, err | ||
} | ||
for _, entry := range entries { | ||
if entry.Name() == "主系统.json" { | ||
p := path.Join(root, "配置", entry.Name()) | ||
c := &defines.OmegaConfig{} | ||
if err := utils.GetJsonData(p, c); err != nil { | ||
return 0, fmt.Errorf("读取[" + p + "]时出错" + err.Error()) | ||
} | ||
return c.MigrationVersion, nil | ||
} | ||
} | ||
return 0, fmt.Errorf("配置/主系统.json 未找到,配置文件夹可能损坏了") | ||
} | ||
|
||
func setMigrationVersion(root string, version int) error { | ||
d := path.Join(root, "配置") | ||
entries, err := ioutil.ReadDir(d) | ||
if err != nil { | ||
return err | ||
} | ||
for _, entry := range entries { | ||
if entry.Name() == "主系统.json" { | ||
p := path.Join(root, "配置", entry.Name()) | ||
c := &defines.OmegaConfig{} | ||
if err := utils.GetJsonData(p, c); err != nil { | ||
return fmt.Errorf("读取[" + p + "]时出错" + err.Error()) | ||
} | ||
c.MigrationVersion = version | ||
return utils.WriteJsonData(p, c) | ||
} | ||
} | ||
return fmt.Errorf("配置/主系统.json 未找到,配置文件夹可能损坏了") | ||
} | ||
|
||
func updateComponentConfig(root string, name string, handleFn func(c *defines.ComponentConfig)) error { | ||
d := path.Join(root, "配置") | ||
entries, err := ioutil.ReadDir(d) | ||
if err != nil { | ||
return err | ||
} | ||
for _, entry := range entries { | ||
if !strings.HasPrefix(entry.Name(), "组件") { | ||
continue | ||
} | ||
p := path.Join(root, "配置", entry.Name()) | ||
c := &defines.ComponentConfig{} | ||
if err := utils.GetJsonData(p, c); err != nil { | ||
return fmt.Errorf("读取[" + p + "]时出错" + err.Error()) | ||
} | ||
if c.Name != name { | ||
continue | ||
} | ||
handleFn(c) | ||
return utils.WriteJsonData(p, c) | ||
} | ||
return fmt.Errorf("配置/组件-" + name + ".json 未找到,配置文件夹可能损坏了") | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ func Upgrade() { | |
Policy_4(storageRoot) | ||
Policy_5(storageRoot) | ||
Policy_6(storageRoot) | ||
Policy_7(storageRoot) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package upgrade | ||
|
||
import "phoenixbuilder/omega/defines" | ||
|
||
func Policy_7(root string) { | ||
if version, err := checkMigrationVersion(root); err == nil && version < 542 { | ||
updateComponentConfig(root, "菜单显示", func(c *defines.ComponentConfig) { | ||
if s := c.Configs["目录结构"]; s != nil { | ||
if ts, success := s.([]interface{}); success { | ||
newTS := make([]interface{}, 0) | ||
for _, e := range ts { | ||
if te, success := e.(map[string]interface{}); success { | ||
if v, hasK := te["触发词"]; hasK { | ||
if tv, success := v.(string); success { | ||
if tv == "传送" { | ||
continue | ||
} | ||
} | ||
} | ||
} | ||
newTS = append(newTS, e) | ||
} | ||
c.Configs["目录结构"] = newTS | ||
} | ||
} | ||
}) | ||
setMigrationVersion(root, 542) | ||
} else if err != nil { | ||
panic(err) | ||
} | ||
} |