Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "github.com/Stonetium/stonetium"
- "github.com/Stonetium/stonetium/errs"
- "gopkg.in/qml.v1"
- "log"
- "os/exec"
- "runtime"
- "time"
- )
- type Game struct {
- ID string
- Name string
- Publisher string
- }
- /********************* Game list context variable*****************/
- type GameList struct {
- Games []stonetium.Game
- Len int
- }
- func (this *GameList) DownloadGame(gamePath string, gameToDownload stonetium.Game) bool {
- timeout := time.Duration(30) * time.Second
- if runtime.GOOS == "windows" {
- // download the windows version
- err := download(gamePath, "7eece863-48da-49f2-8aca-434866921952", timeout)
- if err != nil {
- log.Println(err)
- }
- } else if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
- // download the linux version
- err := download(gamePath, "1a92b42b-dd25-4de1-bd52-df4e51b2ea62", timeout)
- if err != nil {
- log.Println(errs.Stack(err))
- }
- }
- return true
- }
- func (this *GameList) GetGame(index int) stonetium.Game {
- return this.Games[index]
- }
- func (this *GameList) Populate(gameList []stonetium.Game) {
- this.Games = gameList
- this.Len = len(this.Games)
- qml.Changed(this, &this.Len)
- }
- func (this *GameList) PlayGame(executablePath string) {
- path, err := exec.LookPath(executablePath)
- if err != nil {
- log.Println("cannot find executable: " + executablePath)
- log.Println(errs.Stack(err))
- }
- cmd := exec.Command("")
- if runtime.GOOS == "darwin" { // osx
- cmd = exec.Command(executablePath)
- } else {
- cmd = exec.Command(path)
- }
- err = cmd.Run()
- if err != nil {
- log.Println("failed to run command: " + path)
- log.Println(errs.Stack(err))
- }
- }
- func download(string, string, time.Duration) error {
- // already written for us
- return nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement