removed res folder; closes #32

This commit is contained in:
Felix Angell 2018-05-06 16:13:29 +01:00
parent 56c15a175a
commit b750eaf46b
10 changed files with 63 additions and 5 deletions

View File

@ -1,8 +1,11 @@
package cfg
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"regexp"
@ -34,6 +37,8 @@ var CONFIG_FULL_PATH string = ""
// rename/refactor due here too!
var configDirAbsPath string = ""
var ICON_DIR_PATH string = ""
// TODO we only had double key combos
// e.g. cmd+s. we want to handle things
// like cmd+alt+s
@ -198,6 +203,57 @@ func Setup() TomlConfig {
}
}
// ----
// downloads the icon from github
// and puts it into the phi-editor config folder.
ICON_DIR_PATH = filepath.Join(CONFIG_DIR, "icons")
if _, err := os.Stat(ICON_DIR_PATH); os.IsNotExist(err) {
if err := os.Mkdir(ICON_DIR_PATH, 0775); err != nil {
panic(err)
}
log.Println("setting up the icons folder")
// https://raw.githubusercontent.com/felixangell/phi/gh-pages/images/icon128.png
downloadIcon := func(iconSize int) {
log.Println("downloading the phi icon ", iconSize, "x", iconSize, " png image.")
file, err := os.Create(filepath.Join(ICON_DIR_PATH, fmt.Sprintf("icon%d.png", iconSize)))
defer file.Close()
if err != nil {
log.Println(err.Error())
return
}
// Generated by curl-to-Go: https://mholt.github.io/curl-to-go
resp, err := http.Get(fmt.Sprintf("https://raw.githubusercontent.com/felixangell/phi/gh-pages/images/icon%d.png", iconSize))
if err != nil {
log.Println("Failed to download icon", iconSize, "!", err.Error())
return
}
defer resp.Body.Close()
_, err = io.Copy(file, resp.Body)
if err != nil {
log.Println(err.Error())
}
}
size := 16
switch runtime.GOOS {
case "windows":
size = 64
case "darwin":
size = 512
case "linux":
size = 96
}
// download the icon and
// write it to the phi-editor folder.
downloadIcon(size)
}
// try make the syntax config folder.
if _, err := os.Stat(SYNTAX_CONFIG_DIR); os.IsNotExist(err) {
if err := os.Mkdir(SYNTAX_CONFIG_DIR, 0775); err != nil {

12
main.go
View File

@ -5,6 +5,7 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"
"runtime"
"time"
@ -86,19 +87,20 @@ func main() {
window.Create()
{
size := "16"
size := 16
switch runtime.GOOS {
case "windows":
size = "64"
size = 64
case "darwin":
size = "512"
size = 512
case "linux":
size = "96"
size = 96
default:
log.Println("unrecognized runtime ", runtime.GOOS)
}
icon, err := strife.LoadImage("./res/icons/icon" + size + ".png")
iconFile := fmt.Sprintf("icon%d.png", size)
icon, err := strife.LoadImage(filepath.Join(cfg.ICON_DIR_PATH, iconFile))
if err != nil {
log.Println("Failed to load icon ", err.Error())
} else {

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB