Skip to content

Commit

Permalink
Simplify the whole application
Browse files Browse the repository at this point in the history
 * Removed the use of database(s) and its dependencies.

 * Added new "AddonVault"-struct that will hold the addons for easy
   access.

 * Added new config files for both system configurations and addons
   configuration - to be used instead of a database.

 * Updated FUTURE.md with new goals and plans - the top section about
   the updater is urgent changes as the updater is not working as
   intended right now.
  • Loading branch information
HansenChristoffer committed Sep 6, 2024
1 parent a12fa73 commit 90a7f14
Show file tree
Hide file tree
Showing 34 changed files with 526 additions and 1,191 deletions.
8 changes: 8 additions & 0 deletions .addonsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"name": "little-wigs",
"filename": "littlewigs",
"url": "https://www.curseforge.com/wow/addons/little-wigs",
"download_url": "https://www.curseforge.com/wow/addons/little-wigs/download/5693335"
}
]
10 changes: 10 additions & 0 deletions .systemsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"name": "extract.addon.path",
"path": "/home/miso/Games/battlenet/drive_c/Program Files (x86)/World of Warcraft/_retail_/Interface/AddOns"
},
{
"name": "browser.download.dir",
"path": "/home/miso/Downloads/goaddons_download"
}
]
22 changes: 14 additions & 8 deletions FUTURE.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# Future plans for GoAddons

## Tests
1. Some tests
2. aaaand some more test
3. and after that even more tests

## Make Docker dependency deprecated
1. Change from MySQL to a simple SQLite database that makes it easier to ship instead of requiring Docker.
2. Look into possibility of not requiring the Docker Chrome browser when downloading files.
## Fix the updater
1. For some reason the downloaded files are owned by ROOT:ROOT. This is not OK, they should be owned by current OS user (perhaps configurable?)
2. Make it non-parallel - there is no need for concurrency, there is risk for website throttling/blocking us plus extracting is fast enough as is
3. Make the extracting more simple - anything in the download volume that ends with .zip should be extracted and ultimately removed
4. Look into possibility of not requiring the Docker Chrome browser when downloading files - the fewer dependencies the better

## Refactoring and generic clean-up

1. Part of the clean-up and refactoring involves more restrict code styling and that is something that is coming!
*. Discuss the possibility of using formatters e.g. gofmt or perhaps Go linters?
2. Refactoring and making code easier to read and follow (the less jumping around the better)
3. Generic Clean-up and whatever that would entail!

## Config

1. Allow more configurations - perhaps look into some config lib that can help
2. Look into possibly leaving JSON for the config and instead use YAML

## Cli

1. Leave behind the current and basic CLI and look into uses something like ncurses or alternatives for it in Golang
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# GoAddons

GoAddons is a command-line interface (CLI) application designed to enhance the World of Warcraft (WoW) experience by simplifying the management of game addons. Leveraging the power of a database, GoAddons facilitates the effortless discovery, update, and management of WoW addons.
GoAddons is a command-line interface (CLI) application designed to enhance the World of Warcraft (WoW) experience by simplifying the management of game addons. GoAddons facilitates the effortless update and management of WoW addons.

## Features

- **Addon Management**: Easily list, search, add, or remove WoW addons to customize your gaming setup.
- **Updater Menu**: ~~Automatically checks and~~ updates your addons to the latest versions, ensuring you have the latest features and fixes.
- **Updater Menu**: Updates your addons to the latest versions, ensuring you have the latest features and fixes.
- **About**: Learn more about GoAddons.

## Getting Started
Expand All @@ -22,7 +22,7 @@ cd GoAddons
2. **Docker containers**:

Make sure you have Docker/Docker-engine and Docker-compose installed on your system. You will need to edit the docker-compose.yml file to fit your system.
The "kaasufouji-extract-volume" device path needs to be your systems path to your addons directory. Finally, change any [YOUR_HOST_NAME_HERE] to your actual user's name.
The "goaddons-extract-volume" device path needs to be your systems path to your addons directory. Finally, change any [YOUR_HOST_NAME_HERE] to your actual user's name.

Now, run the following command:

Expand Down Expand Up @@ -86,7 +86,7 @@ In the Addon Management menu, you can:

### Updater Menu

Start the updater ~~to check for~~ and apply updates to your addons.
Start the updater and apply updates to your addons.

### About

Expand Down
92 changes: 43 additions & 49 deletions cli/AddonManagement.go → cmp/cli/AddonManagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,22 @@ package cli
import (
"encoding/json"
"fmt"
"goaddons/database"
"goaddons/models"
"goaddons/utils"
"goaddons/cmp/models"
"goaddons/cmp/utils"
"goaddons/cmp/vault"
"log"
"strconv"
)

func ListAllAddons() {
utils.ClearScreen()
fmt.Printf(" »»» All Addons «««\n\n")

addons, err := database.GetAllAddons(db)
addonsVault, err := vault.GetInstance()
if err != nil {
log.Printf("cli.ListAllAddons :: Error while trying to get all addons -> %v\n", err)
return
}

if addons == nil || len(addons) == 0 {
return
}

b, err := json.MarshalIndent(addons, "", " ")
if err != nil {
log.Printf("cli.ListAllAddons :: Failed to marshal -> %v\n", err)
return
log.Fatalf("Error initializing AddonVault: %v", err)
}

if b != nil && utils.IsValidString(string(b)) {
fmt.Println(string(b))
}
addonsVault.Print()
}

func SearchForAddonByName() {
Expand All @@ -60,24 +46,25 @@ func SearchForAddonByName() {
}

// Search for and list addon, all by the argument 'name'
addons, err := database.GetAddonsByName(db, name)
addonsVault, err := vault.GetInstance()
if err != nil {
log.Printf("cli.SearchForAddonByName :: Error while getting addon... -> %v\n", err)
return
log.Fatalf("Was unable to get instance of AddonVault")
}

if addons == nil || len(addons) == 0 {
if addonsVault.Length() == 0 {
return
}

b, err := json.MarshalIndent(addons, "", " ")
if err != nil {
log.Printf("cli.SearchForAddonByName :: Failed to marshal -> %v\n", err)
return
}
for _, addon := range addonsVault.Addons {
if addon.Name == name {
b, err := json.MarshalIndent(addon, "", " ")
if err != nil {
log.Printf("Error marshalling addon to JSON: %v", err)
}

if b != nil && utils.IsValidString(string(b)) {
fmt.Println(string(b))
if b != nil && len(b) > 0 {
fmt.Println(string(b))
}
}
}
}

Expand All @@ -96,16 +83,24 @@ func AddNewAddon() {
fmt.Printf("\n Addon download URL\n > ")
addon.DownloadUrl = userInput("cli.AddNewAddon")

fmt.Printf("\n »»» New Addon ««« \n")
fmt.Printf(" Name: %s\n Filename: %s\n URL: %s\n DownloadURL: %s\n", addon.Name, addon.Filename,
addon.Url, addon.DownloadUrl)
fmt.Printf("\n Do you want to commit? [y/N]\n > ")
input := userInput("cli.AddNewAddon")

switch input {
case "Y", "y":
r, err := database.InsertAddon(db, addon)
addonsVault, err := vault.GetInstance()
if err != nil {
log.Printf("cli.addNewAddon :: Failed to insert addon(s)! -> %v\n", err)
log.Fatalf("Error initializing AddonVault: %v", err)
}
fmt.Printf(" Inserted total of %d addon(s) into TanukiDB!\n", r)

if err := addonsVault.Append(&addon); err != nil {
log.Printf("Error appending addon to vault: %v", err)
return
}
fmt.Printf(" Successfully inserted addon(s)!")
case "N", "n":
fmt.Println(" Stopped insertion of new addon(s)!")
default:
Expand All @@ -116,30 +111,29 @@ func AddNewAddon() {
func RemoveAddon() {
utils.ClearScreen()

fmt.Printf("\n »»» Remove addon «««\n\n Addon ID\n > ")
id := userInput("cli.RemoveAddon")

if !utils.IsValidString(id) {
log.Printf("cli.RemoveAddon :: The 'ID' argument is not valid! -> [%s]\n", id)
return
}
fmt.Printf("\n »»» Remove addon «««\n\n Addon name\n > ")
name := userInput("cli.RemoveAddon")

idNum, err := strconv.Atoi(id)
if err != nil {
log.Printf("cli.RemoveAddon :: Error while trying to convert ID to its decimal equivalent! -> %v\n", err)
if !utils.IsValidString(name) {
log.Printf("cli.RemoveAddon :: The 'name' argument is not valid! -> [%s]\n", name)
return
}

fmt.Printf("\n Will try to remove addon with the name: %s\n", name)
fmt.Printf("\n Do you want to commit? [y/N]\n > ")
input := userInput("cli.RemoveAddon")

switch input {
case "Y", "y":
r, err := database.RemoveAddonByID(db, idNum)
addonsVault, err := vault.GetInstance()
if err != nil {
log.Printf("cli.RemoveAddon :: Failed to remove addon(s)! -> %v\n", err)
log.Fatalf("Error initializing AddonVault: %v", err)
}
beenRemoved, err := addonsVault.Remove(name)
if beenRemoved {
fmt.Printf(" Successfully removed addon with name: %s", name)
} else {
fmt.Printf(" Failed to remove addon with name: %s -> %v\n", name, err)
}
fmt.Printf(" Removed total of %d addon(s) from TanukiDB!", r)
case "N", "n":
fmt.Println(" Stopped deletion of addon(s)!")
default:
Expand Down
31 changes: 6 additions & 25 deletions cli/core.go → cmp/cli/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@
package cli

import (
"database/sql"
"fmt"
"goaddons/database"
"goaddons/updater"
"goaddons/utils"
"log"
"goaddons/cmp/updater"
"goaddons/cmp/utils"
"goaddons/cmp/vault"
"os"
)

const (
databasePath string = "./bin/acd.db"
)

var db *sql.DB

func StartCli() {
utils.ClearScreen()
fmt.Printf(`
Expand Down Expand Up @@ -62,7 +54,7 @@ func StartCli() {

func addonManagement() {
utils.ClearScreen()
initDatabase() // init database connection if it is not already initialized
_, _ = vault.GetInstance()
fmt.Printf(`
»»» Addon Management «««
Expand Down Expand Up @@ -101,7 +93,7 @@ func addonManagement() {

func updaterMenu() {
utils.ClearScreen()
initDatabase() // init database connection if it is not already initialized
_, _ = vault.GetInstance()
fmt.Printf(`
»»» Updater Menu «««
Expand All @@ -113,7 +105,7 @@ func updaterMenu() {
if len(input) > 0 {
switch input {
case "1":
updater.StartUpdater(db)
updater.StartUpdater()
case "X", "x":
StartCli()
default:
Expand Down Expand Up @@ -152,17 +144,6 @@ func about() {
StartCli()
}

// initDatabase initializes the global database connection.
func initDatabase() {
if db == nil {
var err error
db, err = database.ConnectToServer(databasePath)
if err != nil {
log.Fatalf("cli:core.initDatabase():ConnectToServer(%s) -> %v", databasePath, err)
}
}
}

func terminate() {
os.Exit(0)
}
17 changes: 12 additions & 5 deletions models/DLog.go → cmp/models/Addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@

package models

type DLog struct {
Id int
RunId string
Url string
AddedAt []uint8
type Addon struct {
Name string `json:"name"`
Filename string `json:"filename"`
Url string `json:"url"`
DownloadUrl string `json:"download_url"`
}

func (a *Addon) Validate() bool {
if len(a.Name) == 0 || len(a.Filename) == 0 || len(a.Url) == 0 || len(a.DownloadUrl) == 0 {
return false
}
return true
}
4 changes: 4 additions & 0 deletions models/SystemConfig.go → cmp/models/SystemConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ type SystemConfig struct {
Name string
Path string
}

func NewSystemConfig(name string, path string) *SystemConfig {
return &SystemConfig{Name: name, Path: path}
}
Loading

0 comments on commit 90a7f14

Please sign in to comment.