package main import ( "fmt" "log" "os" "os/exec" "regexp" "runtime" "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{} func getDataFromFile(path string) map[string]string { log.Println(regexp.MustCompile(`\.\w+$`).FindString(path)) switch extention := regexp.MustCompile(`\.\w+$`).FindString(path); extention { case ".exe": return getParamsFromExif(path) case ".msi": return getParamsFromMsi(path) } return make(map[string]string) } // 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() return splitData(e) } func splitData(commandOutput []byte) map[string]string { tags := make(map[string]string) spliter := regexp.MustCompile(`\r?\n`) crop := spliter.Split(string(commandOutput), -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 } func getParamsFromMsi(path string) map[string]string { if runtime.GOOS == "windows" { // orca :=os.Getenv("orca") // err:=os.Mkdir("tmpdir/extract", os.ModeAppend) // if err != nil { // log.Println("There was an error", err) // } // run:=exec.Command(orca, "-q", "-s", path, "-x", "tmpdir/extract") // run. } else { msiinfo := os.Getenv("msiinfo") e, _ := exec.Command(msiinfo, "export", path, "Property").Output() return splitData(e) } return make(map[string]string) }