added reading to the file, msi works on windows only. exe works if there is exiftool

This commit is contained in:
2024-06-19 14:40:32 +03:00
parent aa41b83964
commit afa56cb83e
5 changed files with 101 additions and 16 deletions

View File

@@ -3,9 +3,10 @@ package main
import (
"fmt"
"log"
"regexp"
"os"
"os/exec"
"regexp"
"runtime"
"strconv"
)
@@ -65,21 +66,55 @@ type DownloadElements struct {
// 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{
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]}
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)
}