Files
WingetRepoServer/packages.go

86 lines
2.2 KiB
Go

package main
import (
"fmt"
"log"
"regexp"
"os"
"os/exec"
"strconv"
)
// packages struct represents a package with its details.
type packages struct {
Id string
Name string
Version string
ExtraCommand *string
Tag string
Warning bool
Element *elements
}
// ConvertStringsToPackage converts a slice of strings to a packages struct.
// It returns an error if the input slice does not have exactly 6 elements or if the Warning value cannot be parsed as a boolean.
func ConvertStringsToPackage(strs []string) (packages, error) {
var pkg packages
if len(strs) != 6 {
return pkg, fmt.Errorf("input slice must have exactly 6 elements")
}
warning, err := strconv.ParseBool(strs[5])
if err != nil {
return pkg, fmt.Errorf("error parsing Warning value: %s", err)
}
return packages{
Id: strs[0],
Name: strs[1],
Version: strs[2],
ExtraCommand: &strs[3],
Tag: strs[4],
Warning: warning,
}, nil
}
// elements struct represents the elements of a the webpage.
type elements struct {
Title string
Header string
Help string
Packagename string
Packageversion string
Allow string
Warning string
Explain string
}
// DownloadElements struct represents the elements to be downloaded.
type DownloadElements struct {
ID string
Version *string
Counter int
}
// Printer struct is an empty struct. Its purpose is not clear from the provided code.
type Printer struct{}
// getParamsFromExif extracts EXIF parameters from a file at the given path using the exiftool command.
// It returns a map where the keys are the EXIF parameter names and the values are the corresponding EXIF parameter values.
func getParamsFromExif(path string) map[string]string{
exiftool := os.Getenv("exiftool")
e,_ := exec.Command(exiftool, "-f", path).Output()
tags:=make(map[string]string)
spliter:=regexp.MustCompile(`\r?\n`)
crop:=spliter.Split(string(e),-1)
head := regexp.MustCompile(`\s+:\s`)
for _,c := range crop{
if(len(c)>1){
data:=head.Split(c,-1)
log.Println("My Raw Data: ", c)
tags[data[0]]=data[1]}
}
log.Println(tags)
return tags
}