Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
lichuan committed Jan 5, 2022
1 parent 96cf852 commit 19b6506
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 18 deletions.
7 changes: 3 additions & 4 deletions app/app_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"harmonybinary/info"
"harmonybinary/pkg"
"harmonybinary/utils"
"io/ioutil"
"os"
"path"
)

func OpenFile(filepath string) (*info.App, error) {
Expand All @@ -29,9 +29,8 @@ func getHapFile(dir string) (filePath string, err error) {
return "", err
}
for _, f := range files {
fs, _ := ioutil.ReadFile(f)
fileType := utils.GetFileType(fs)
if fileType == pkg.FileTypeHap {
ext := path.Ext(f)
if ext == pkg.FileTypeHap {
return f, nil
}
}
Expand Down
12 changes: 7 additions & 5 deletions hap/hap_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"harmonybinary/info"
"harmonybinary/pkg"
"harmonybinary/utils"
"io/ioutil"
"os"
"path"
)

func OpenFile(filepath string) (*info.App, error) {
Expand All @@ -20,6 +20,9 @@ func OpenFile(filepath string) (*info.App, error) {
return nil, err
}
a, err := info.GetAppInfo(apkFilePath)
if err != nil {
return nil, err
}
return a, nil
}
func getApkFile(dir string) (filePath string, err error) {
Expand All @@ -28,10 +31,9 @@ func getApkFile(dir string) (filePath string, err error) {
return "", err
}
for _, f := range files {
f, _ := ioutil.ReadFile(f)
fileType := utils.GetFileType(f)
if fileType == pkg.FileTypeApk {
return fileType, nil
ext := path.Ext(f)
if ext == pkg.FileTypeApk {
return f, nil
}
}
return
Expand Down
6 changes: 3 additions & 3 deletions info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type App struct {
Perms []string `json:"perms"`
}

func GetAppInfo(apkFilePath string) (a *App, err error) {
func GetAppInfo(apkFilePath string) (*App, error) {
p, err := apk.OpenFile(apkFilePath)
if err != nil {
return nil, errors.New(fmt.Sprintf("打开apk(%s)出错:%s", apkFilePath, err.Error()))
Expand All @@ -35,7 +35,7 @@ func GetAppInfo(apkFilePath string) (a *App, err error) {
appLabel = ""
}
}
a.Name = appLabel
a := &App{Name: appLabel}
s, err := p.Manifest().VersionName.String()
if err == nil {
a.Version = s
Expand All @@ -55,5 +55,5 @@ func GetAppInfo(apkFilePath string) (a *App, err error) {
a.Perms = append(a.Perms, s2)
}
}
return
return a, nil
}
4 changes: 2 additions & 2 deletions pkg/code_type.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

const (
FileTypeHap = "hap"
FileTypeApk = "apk"
FileTypeHap = ".hap"
FileTypeApk = ".apk"
)
15 changes: 15 additions & 0 deletions test/app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package test

import (
"fmt"
"harmonybinary/app"
"testing"
)

func TestApp(t *testing.T) {
a, err := app.OpenFile("./123.app")
if err != nil {
fmt.Println(err)
}
fmt.Println(a)
}
4 changes: 2 additions & 2 deletions test/hap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package test

import (
"fmt"
"harmonybinary/app"
"harmonybinary/hap"
"testing"
)

func TestHap(t *testing.T) {
a, err := app.OpenFile("./c.hap")
a, err := hap.OpenFile("./c.hap")
if err != nil {
fmt.Println(err)
}
Expand Down
3 changes: 1 addition & 2 deletions utils/fileType.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
var fileTypeMap sync.Map

func init() {
fileTypeMap.Store("00736861706500636f6c", "apk") //apk (APK)
fileTypeMap.Store("504b03040a0000080000", "hap") //hap (HAP)
fileTypeMap.Store("504b03040a0000080000", "apk") //apk (APK)
fileTypeMap.Store("ffd8ffe000104a464946", "jpg") //JPEG (jpg)
fileTypeMap.Store("89504e470d0a1a0a0000", "png") //PNG (png)
fileTypeMap.Store("47494638396126026f01", "gif") //GIF (gif)
Expand Down

0 comments on commit 19b6506

Please sign in to comment.