support nativecode and icon checking
This commit is contained in:
parent
71c1312df9
commit
b3570772e7
1 changed files with 58 additions and 50 deletions
104
main.go
104
main.go
|
@ -101,6 +101,7 @@ type Release struct {
|
||||||
PublishedAt *time.Time `json:"published_at,omitempty"`
|
PublishedAt *time.Time `json:"published_at,omitempty"`
|
||||||
Author User `json:"author"`
|
Author User `json:"author"`
|
||||||
Assets []ReleaseAsset `json:"assets"`
|
Assets []ReleaseAsset `json:"assets"`
|
||||||
|
PreRelease bool `json:"prerelease"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
|
@ -195,40 +196,7 @@ func downloadAPK(url string, filePath string) error {
|
||||||
return err
|
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 {
|
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(packageName, "en-US")
|
||||||
iconPath = filepath.Join(iconPath,"icon.png")
|
iconPath = filepath.Join(iconPath,"icon.png")
|
||||||
|
if apkExists(iconPath) {
|
||||||
|
return iconPath
|
||||||
|
}
|
||||||
// Create a new file to save the icon
|
// Create a new file to save the icon
|
||||||
outFile, err := os.Create(iconPath)
|
outFile, err := os.Create(iconPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -268,6 +239,14 @@ func saveIconFile(f *apkparser.ZipReaderFile, packageName string) string {
|
||||||
return iconPath
|
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 {
|
func processAPK(filePath string) Package {
|
||||||
fmt.Printf("Processing APK: %s\n", filePath)
|
fmt.Printf("Processing APK: %s\n", filePath)
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
@ -332,6 +311,30 @@ func processAPK(filePath string) Package {
|
||||||
os.Exit(1)
|
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{
|
packageInfo := Package{
|
||||||
ApkName: filePath,
|
ApkName: filePath,
|
||||||
VersionCode: manifest.VersionCode,
|
VersionCode: manifest.VersionCode,
|
||||||
|
@ -344,6 +347,7 @@ func processAPK(filePath string) Package {
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
HashType: "SHA-256",
|
HashType: "SHA-256",
|
||||||
Size: fileInfo.Size(),
|
Size: fileInfo.Size(),
|
||||||
|
NativeCode: directories,
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, perm := range manifest.UsesPermission {
|
for i, perm := range manifest.UsesPermission {
|
||||||
|
@ -387,6 +391,8 @@ func getFilenameFromURL(urlStr string) (string, error) {
|
||||||
filename := path.Base(parsedURL.Path)
|
filename := path.Base(parsedURL.Path)
|
||||||
return filename, nil
|
return filename, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Function to handle downloading and processing APKs from a release
|
// Function to handle downloading and processing APKs from a release
|
||||||
func handleRelease(release Release) []Package {
|
func handleRelease(release Release) []Package {
|
||||||
var packages []Package
|
var packages []Package
|
||||||
|
@ -397,21 +403,19 @@ func handleRelease(release Release) []Package {
|
||||||
}
|
}
|
||||||
|
|
||||||
filePath,err := getFilenameFromURL(asset.BrowserDownloadURL)
|
filePath,err := getFilenameFromURL(asset.BrowserDownloadURL)
|
||||||
if apkExists(asset.BrowserDownloadURL) {
|
if apkExists(filePath) {
|
||||||
fmt.Printf("APK already exists: %s\n", asset.BrowserDownloadURL)
|
fmt.Printf("APK already exists: %s\n", filePath)
|
||||||
continue
|
}else{
|
||||||
}
|
|
||||||
|
|
||||||
err = downloadAPK(asset.BrowserDownloadURL, filePath)
|
err = downloadAPK(asset.BrowserDownloadURL, filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error downloading APK: %v\n", err)
|
fmt.Printf("Error downloading APK: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
continue
|
}
|
||||||
|
}
|
||||||
|
packageInfo := processAPK(filePath)
|
||||||
|
packages = append(packages,packageInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
packageInfo := processAPK(filePath)
|
|
||||||
packages = append(packages,packageInfo)
|
|
||||||
}
|
|
||||||
return packages
|
return packages
|
||||||
}
|
}
|
||||||
func getReleases(repo string) ([]Release, error) {
|
func getReleases(repo string) ([]Release, error) {
|
||||||
|
@ -509,7 +513,7 @@ func signJarWithJarsigner(jarFile string, keystore string, password string, alia
|
||||||
return err, string(output) // Возвращаем ошибку и вывод как строку
|
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)
|
repository, err := getRepositoryInfo(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -520,10 +524,12 @@ func createAppFromReleases(releases []Release, repo string) (App, []Package,erro
|
||||||
if len(releases) == 0 {
|
if len(releases) == 0 {
|
||||||
return App{}, []Package{}, nil
|
return App{}, []Package{}, nil
|
||||||
}
|
}
|
||||||
|
release := releases[index]
|
||||||
release := releases[0]
|
|
||||||
packages := handleRelease(release)
|
packages := handleRelease(release)
|
||||||
|
if len(packages) == 0 {
|
||||||
|
return createAppFromReleases(releases,repo,index+1)
|
||||||
|
//return App{}, []Package{}, nil
|
||||||
|
}
|
||||||
app := App{
|
app := App{
|
||||||
AuthorName: release.Author.Login,
|
AuthorName: release.Author.Login,
|
||||||
Categories: []string{"fdroid"},
|
Categories: []string{"fdroid"},
|
||||||
|
@ -585,12 +591,14 @@ for _, source := range config.BinarySources {
|
||||||
|
|
||||||
var app App
|
var app App
|
||||||
fmt.Println("Creating app object from repository info and apk")
|
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 {
|
if err != nil {
|
||||||
log.Fatal("Failed to create app from releases: ",err)
|
log.Fatal("Failed to create app from releases: ",err)
|
||||||
}
|
}
|
||||||
|
if len(app_packages) != 0 {
|
||||||
apps = append(apps,app)
|
apps = append(apps,app)
|
||||||
packages[app_packages[0].PackageName] = append(packages[app_packages[0].PackageName], app_packages...)
|
packages[app_packages[0].PackageName] = append(packages[app_packages[0].PackageName], app_packages...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
index := Index {
|
index := Index {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue