support nativecode and icon checking
This commit is contained in:
parent
71c1312df9
commit
b3570772e7
1 changed files with 58 additions and 50 deletions
108
main.go
108
main.go
|
@ -101,6 +101,7 @@ type Release struct {
|
|||
PublishedAt *time.Time `json:"published_at,omitempty"`
|
||||
Author User `json:"author"`
|
||||
Assets []ReleaseAsset `json:"assets"`
|
||||
PreRelease bool `json:"prerelease"`
|
||||
}
|
||||
|
||||
type Repository struct {
|
||||
|
@ -195,40 +196,7 @@ func downloadAPK(url string, filePath string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func getResourceTypeId(resourceType string) int {
|
||||
switch resourceType {
|
||||
case "string":
|
||||
return 0
|
||||
case "drawable":
|
||||
return 1
|
||||
case "layout":
|
||||
return 2
|
||||
case "mipmap":
|
||||
return 3
|
||||
case "color":
|
||||
return 4
|
||||
case "id":
|
||||
return 5
|
||||
case "style":
|
||||
return 6
|
||||
case "anim":
|
||||
return 7
|
||||
case "menu":
|
||||
return 8
|
||||
case "xml":
|
||||
return 9
|
||||
case "raw":
|
||||
return 10
|
||||
case "font":
|
||||
return 11
|
||||
case "transition":
|
||||
return 12
|
||||
case "drawable-v21":
|
||||
return 13
|
||||
default:
|
||||
return -1 // Invalid resource type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func saveIconFile(f *apkparser.ZipReaderFile, packageName string) string {
|
||||
|
@ -243,6 +211,9 @@ func saveIconFile(f *apkparser.ZipReaderFile, packageName string) string {
|
|||
|
||||
iconPath := filepath.Join(packageName, "en-US")
|
||||
iconPath = filepath.Join(iconPath,"icon.png")
|
||||
if apkExists(iconPath) {
|
||||
return iconPath
|
||||
}
|
||||
// Create a new file to save the icon
|
||||
outFile, err := os.Create(iconPath)
|
||||
if err != nil {
|
||||
|
@ -268,6 +239,14 @@ func saveIconFile(f *apkparser.ZipReaderFile, packageName string) string {
|
|||
return iconPath
|
||||
}
|
||||
|
||||
func contains(slice []string, item string) bool {
|
||||
for _, s := range slice {
|
||||
if s == item {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
func processAPK(filePath string) Package {
|
||||
fmt.Printf("Processing APK: %s\n", filePath)
|
||||
var buf bytes.Buffer
|
||||
|
@ -331,7 +310,31 @@ func processAPK(filePath string) Package {
|
|||
log.Fatalf("Failed to calculate SHA-256 hash: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var directories []string
|
||||
|
||||
// Iterate through the files in the ZIP archive
|
||||
for _, file := range zipReader.File {
|
||||
// Check if the file is a directory and starts with 'lib/'
|
||||
if file.IsDir {
|
||||
// Check if the directory is directly under 'lib/'
|
||||
if strings.HasPrefix(file.Name, "lib/") && strings.Count(file.Name, "/") == 1 {
|
||||
// Extract the directory name without the 'lib/' prefix
|
||||
dirName := strings.TrimPrefix(file.Name, "lib/")
|
||||
directories = append(directories, strings.TrimSuffix(dirName, "/"))
|
||||
}
|
||||
} else {
|
||||
// If it's a file, check if it belongs to a directory under 'lib/'
|
||||
if strings.HasPrefix(file.Name, "lib/") {
|
||||
// Extract the directory name
|
||||
dirName := strings.Split(file.Name, "/")[1] // Get the first subdirectory under 'lib'
|
||||
if !contains(directories, dirName) {
|
||||
directories = append(directories, dirName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
packageInfo := Package{
|
||||
ApkName: filePath,
|
||||
VersionCode: manifest.VersionCode,
|
||||
|
@ -344,6 +347,7 @@ func processAPK(filePath string) Package {
|
|||
Hash: hash,
|
||||
HashType: "SHA-256",
|
||||
Size: fileInfo.Size(),
|
||||
NativeCode: directories,
|
||||
}
|
||||
|
||||
for i, perm := range manifest.UsesPermission {
|
||||
|
@ -387,31 +391,31 @@ func getFilenameFromURL(urlStr string) (string, error) {
|
|||
filename := path.Base(parsedURL.Path)
|
||||
return filename, nil
|
||||
}
|
||||
|
||||
|
||||
// Function to handle downloading and processing APKs from a release
|
||||
func handleRelease(release Release) []Package {
|
||||
var packages []Package
|
||||
for _, asset := range release.Assets {
|
||||
if !isAPK(asset.BrowserDownloadURL) {
|
||||
//fmt.Printf("Skipping non-APK file: %s\n", asset.BrowserDownloadURL)
|
||||
continue
|
||||
continue
|
||||
}
|
||||
|
||||
filePath,err := getFilenameFromURL(asset.BrowserDownloadURL)
|
||||
if apkExists(asset.BrowserDownloadURL) {
|
||||
fmt.Printf("APK already exists: %s\n", asset.BrowserDownloadURL)
|
||||
continue
|
||||
}
|
||||
|
||||
if apkExists(filePath) {
|
||||
fmt.Printf("APK already exists: %s\n", filePath)
|
||||
}else{
|
||||
err = downloadAPK(asset.BrowserDownloadURL, filePath)
|
||||
if err != nil {
|
||||
fmt.Printf("Error downloading APK: %v\n", err)
|
||||
os.Exit(1)
|
||||
continue
|
||||
}
|
||||
|
||||
packageInfo := processAPK(filePath)
|
||||
packages = append(packages,packageInfo)
|
||||
}
|
||||
packageInfo := processAPK(filePath)
|
||||
packages = append(packages,packageInfo)
|
||||
}
|
||||
|
||||
return packages
|
||||
}
|
||||
func getReleases(repo string) ([]Release, error) {
|
||||
|
@ -509,7 +513,7 @@ func signJarWithJarsigner(jarFile string, keystore string, password string, alia
|
|||
return err, string(output) // Возвращаем ошибку и вывод как строку
|
||||
}
|
||||
|
||||
func createAppFromReleases(releases []Release, repo string) (App, []Package,error) {
|
||||
func createAppFromReleases(releases []Release, repo string, index int) (App, []Package,error) {
|
||||
// Получаем информацию о репозитории
|
||||
repository, err := getRepositoryInfo(repo)
|
||||
if err != nil {
|
||||
|
@ -520,10 +524,12 @@ func createAppFromReleases(releases []Release, repo string) (App, []Package,erro
|
|||
if len(releases) == 0 {
|
||||
return App{}, []Package{}, nil
|
||||
}
|
||||
|
||||
release := releases[0]
|
||||
release := releases[index]
|
||||
packages := handleRelease(release)
|
||||
|
||||
if len(packages) == 0 {
|
||||
return createAppFromReleases(releases,repo,index+1)
|
||||
//return App{}, []Package{}, nil
|
||||
}
|
||||
app := App{
|
||||
AuthorName: release.Author.Login,
|
||||
Categories: []string{"fdroid"},
|
||||
|
@ -562,7 +568,7 @@ func main() {
|
|||
if _, err := toml.NewDecoder(file).Decode(&config); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
for _, source := range config.BinarySources {
|
||||
fmt.Printf("Processing %s\n",source)
|
||||
// Извлекаем имя репозитория из ссылки
|
||||
|
@ -585,12 +591,14 @@ for _, source := range config.BinarySources {
|
|||
|
||||
var app App
|
||||
fmt.Println("Creating app object from repository info and apk")
|
||||
app,app_packages, err := createAppFromReleases(releases,repo)
|
||||
app,app_packages, err := createAppFromReleases(releases,repo,0)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to create app from releases: ",err)
|
||||
}
|
||||
if len(app_packages) != 0 {
|
||||
apps = append(apps,app)
|
||||
packages[app_packages[0].PackageName] = append(packages[app_packages[0].PackageName], app_packages...)
|
||||
}
|
||||
}
|
||||
|
||||
index := Index {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue