Skip to content

Commit

Permalink
Fix bugs occuring during tests and rename modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Drosaca committed Dec 16, 2023
1 parent d8491c8 commit 67696fb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
6 changes: 3 additions & 3 deletions functions/desktop.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package functions

import (
"appImageInstaller/desktopFile"
"appImageInstaller/structs"
"appImageInstaller/utils"
"appinstall/desktopFile"
"appinstall/structs"
"appinstall/utils"
"fmt"
"log"
)
Expand Down
6 changes: 3 additions & 3 deletions functions/image.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package functions

import (
"appImageInstaller/desktopFile"
"appImageInstaller/structs"
"appImageInstaller/utils"
"appinstall/desktopFile"
"appinstall/structs"
"appinstall/utils"
"fmt"
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module appImageInstaller
module appinstall
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
f "appImageInstaller/functions"
"appImageInstaller/manager"
"appImageInstaller/structs"
"appImageInstaller/utils"
f "appinstall/functions"
"appinstall/manager"
"appinstall/structs"
"appinstall/utils"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -121,7 +121,6 @@ func help() {
fmt.Println("(after install use sudo update-desktop-database to reload gnome icons)")
fmt.Println("other options [BETA]: ")
fmt.Println("-l #to list installed apps (from this tool only)")
fmt.Println(" #can also raise some errors about other desktop files")
fmt.Println(" ")
fmt.Println("-d appName #to delete the app (installed by this tool)")

Expand All @@ -133,7 +132,8 @@ func listing() error {
entries := m.List()
fmt.Println("Apps:")
for _, entry := range entries {
fmt.Println(entry.Category("Desktop Entry").Get("Name"))
name, _ := entry.Category("Desktop Entry").Get("Name")
fmt.Println(name)
}
return nil
}
Expand All @@ -160,7 +160,7 @@ func chooseScript() error {

func main() {

if len(os.Args) != 2 || os.Args[1] == "-h" {
if os.Args[1] == "-h" {
help()
os.Exit(0)
}
Expand Down
21 changes: 15 additions & 6 deletions manager/manager.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package manager

import (
"appImageInstaller/desktopFile"
"appImageInstaller/structs"
"appinstall/desktopFile"
"appinstall/structs"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
Expand Down Expand Up @@ -33,13 +34,21 @@ func (m *Manager) IsGeneratedDesktop(deskFile *desktopFile.DesktopFile) (bool, e
}

func (m *Manager) IsValidDesktop(deskFile *desktopFile.DesktopFile) (bool, error) {
if !deskFile.HasValues("Desktop Entry", []string{"Get", "Name", "Exec"}) {
if !deskFile.HasValues("Desktop Entry", []string{"Name", "Exec"}) {
return false, fmt.Errorf("missing basic values")
}
path, _ := deskFile.Category("Desktop Entry").Get("Exec")
cmd, _ := deskFile.Category("Desktop Entry").Get("Exec")
words := strings.Split(cmd, " ")
if len(words) == 0 {
return false, fmt.Errorf("no exec path")
}
path := words[0]
_, err := os.Stat(path)
if err != nil {
return false, fmt.Errorf("fail to find binary")
_, err = exec.LookPath(path)
if err != nil {
return false, fmt.Errorf("fail to find binary: ", path)
}
}
return true, nil
}
Expand All @@ -60,7 +69,7 @@ func (m *Manager) List() []*desktopFile.DesktopFile {
}
_, err = m.IsValidDesktop(deskFile)
if err != nil {
fmt.Println("Listing Error for file:", deskFilePath, " ", err)
//fmt.Println("Listing Error for file:", deskFilePath, " ", err)
continue
}
isGenerated, err := m.IsGeneratedDesktop(deskFile)
Expand Down

0 comments on commit 67696fb

Please sign in to comment.