Skip to content

Commit

Permalink
优化类库本地化资源存放
Browse files Browse the repository at this point in the history
# Release

## 优化
1. 优化类库本地化资源存放
2. Fix #10
  • Loading branch information
liesauer committed Aug 14, 2020
1 parent a77f3a4 commit 9aff99a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Change Log

### v1.2.9
#### 优化
1. 优化类库本地化资源存放
2. Fix #10

### v1.2.8
#### 修复
1. 修复没有指定`excludes`时所有文件都被忽略的问题
Expand Down
2 changes: 1 addition & 1 deletion Common/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PackageOutputPath>.nupkg</PackageOutputPath>
<Version>1.2.8</Version>
<Version>1.2.9</Version>

<Company>nulastudio</Company>
<Authors>LiesAuer</Authors>
Expand Down
2 changes: 1 addition & 1 deletion NetCoreBeautyNugetTest/NetCoreBeautyTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nulastudio.NetCoreBeauty" Version="1.2.8" />
<PackageReference Include="nulastudio.NetCoreBeauty" Version="1.2.9" />
</ItemGroup>

</Project>
48 changes: 47 additions & 1 deletion src/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,24 @@ func FixDeps(deps string) ([]string, string, string) {
return nil, "", ""
}

dir := filepath.Dir(deps)
resources := map[string][]string{}
if sdir, err := util.ReadAllDir(dir); err == nil {
for _, d := range sdir {
if files, err := util.ReadAllFile(filepath.Join(dir, d)); err == nil {
for _, file := range files {
if strings.HasSuffix(file, ".resources.dll") {
assembly := strings.TrimSuffix(file, ".resources.dll")
if _, ok := resources[assembly]; !ok {
resources[assembly] = make([]string, 0)
}
resources[assembly] = append(resources[assembly], d)
}
}
}
}
}

files := []string{}
rid := ""
fxrVersion := ""
Expand Down Expand Up @@ -535,16 +553,44 @@ func FixDeps(deps string) ([]string, string, string) {
"compile": 1,
"resources": 2,
}
assemblies := make([]string, 0)
for cname, segments := range components {
component := depsObj.(map[string]interface{})[cname]
if component == nil && cname == "resources" {
component = make(map[string]interface{})
}
if component != nil {
newComponent := make(map[string]interface{})
for k := range component.(map[string]interface{}) {
components := strings.Split(strings.ReplaceAll(k, "\\", "/"), "/")
length := len(components)
fileName := strings.Join(components[length-segments:], "/")
assembly := strings.TrimSuffix(fileName, ".dll")
files = append(files, fileName)
newComponent["./"+fileName] = make(map[string]interface{})
if cname == "runtime" {
assemblies = append(assemblies, assembly)
}
// resources不清空
if cname == "resources" {
newComponent["./"+fileName] = component.(map[string]interface{})[k]
} else {
newComponent["./"+fileName] = make(map[string]interface{})
}
}
if cname == "resources" {
for _, assembly := range assemblies {
if cultures, ok := resources[assembly]; ok {
for _, culture := range cultures {
k := "./" + culture + "/" + assembly + ".resources.dll"
if _, ok := newComponent[k]; !ok {
v := make(map[string]interface{})
v["locale"] = culture
newComponent[k] = v
files = append(files, strings.TrimPrefix(k, "./"))
}
}
}
}
}
depsObj.(map[string]interface{})[cname] = newComponent
}
Expand Down
29 changes: 29 additions & 0 deletions src/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package util
import (
"errors"
"io"
"io/ioutil"
"os"
"path/filepath"
)
Expand Down Expand Up @@ -43,3 +44,31 @@ func CopyFile(src string, des string) (written int64, err error) {

return io.Copy(desFile, srcFile)
}

func ReadAllDir(dir string) (paths []string, err error) {
fd, err := ioutil.ReadDir(dir)
paths = make([]string, 0)
if err != nil {
return paths, err
}
for _, fi := range fd {
if fi.IsDir() {
paths = append(paths, fi.Name())
}
}
return paths, nil
}

func ReadAllFile(dir string) (paths []string, err error) {
fd, err := ioutil.ReadDir(dir)
paths = make([]string, 0)
if err != nil {
return paths, err
}
for _, fi := range fd {
if !fi.IsDir() {
paths = append(paths, fi.Name())
}
}
return paths, nil
}

0 comments on commit 9aff99a

Please sign in to comment.