Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hzyitc committed Jun 29, 2022
1 parent f03c558 commit 448b888
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 40 deletions.
2 changes: 1 addition & 1 deletion amlCRC.go → AmlCRC/amlCRC.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package AmlImg
package AmlCRC

import "hash/crc32"

Expand Down
37 changes: 1 addition & 36 deletions cli/main.go → AmlImg.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,9 @@ import (
"os"
"strings"

"github.com/hzyitc/AmlImg"
"github.com/hzyitc/AmlImg/AmlImg"
)

var version = "v0.0.0"

func usage() {
print(os.Args[0] + " (" + version + ")\n")
print("Usage:\n")
print(" " + os.Args[0] + " unpack <img path> <extract dir path>\n")
print(" " + os.Args[0] + " pack <img path> <dir path>\n")
}

func main() {
if len(os.Args) != 4 {
usage()
return
}

switch os.Args[1] {
case "unpack":
os.MkdirAll(os.Args[3], 0755)

err := unpack(os.Args[2], os.Args[3])
if err != nil {
println(err.Error())
return
}

case "pack":
err := pack(os.Args[2], os.Args[3])
if err != nil {
println(err.Error())
return
}

}
}

func unpack(filePath, extractPath string) error {
img, err := AmlImg.NewReader(filePath, true)
if err != nil {
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion reader.go → AmlImg/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"io"
"os"

"github.com/hzyitc/AmlImg/AmlCRC"
)

type ImageReader struct {
Expand Down Expand Up @@ -42,7 +44,7 @@ func NewReader(path string, check bool) (*ImageReader, error) {
var buf [4096]byte
for {
n, err := file.Read(buf[:])
crc = AmlCRC(crc, buf[:n])
crc = AmlCRC.AmlCRC(crc, buf[:n])
if errors.Is(err, io.EOF) {
break
} else if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion writer.go → AmlImg/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"io"
"os"

"github.com/hzyitc/AmlImg/AmlCRC"
)

type ImageWriter struct {
Expand Down Expand Up @@ -125,7 +127,7 @@ func (w *ImageWriter) Write(path string, version uint32) error {
var buf [4096]byte
for {
n, err := file.Read(buf[:])
crc = AmlCRC(crc, buf[:n])
crc = AmlCRC.AmlCRC(crc, buf[:n])
if errors.Is(err, io.EOF) {
break
} else if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion buildAllPlatforms.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

PROGRAM="AmlImg"
CLI="./cli"
CLI="./"
OUTPUT="bin/"
LDFLAGS="-s -w"

Expand Down
39 changes: 39 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"os"
)

var version = "v0.0.0"

func usage() {
print(os.Args[0] + " (" + version + ")\n")
print("Usage:\n")
print(" " + os.Args[0] + " unpack <img path> <extract dir path>\n")
print(" " + os.Args[0] + " pack <img path> <dir path>\n")
}

func main() {
if len(os.Args) != 4 {
usage()
return
}

switch os.Args[1] {
case "unpack":
os.MkdirAll(os.Args[3], 0755)

err := unpack(os.Args[2], os.Args[3])
if err != nil {
println(err.Error())
return
}

case "pack":
err := pack(os.Args[2], os.Args[3])
if err != nil {
println(err.Error())
return
}
}
}

0 comments on commit 448b888

Please sign in to comment.