added reading to the file, msi works on windows only. exe works if there is exiftool
This commit is contained in:
59
packages.go
59
packages.go
@@ -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)
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user