Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.76 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "github.com/Stonetium/stonetium"
  5.     "github.com/Stonetium/stonetium/errs"
  6.     "gopkg.in/qml.v1"
  7.     "log"
  8.     "os/exec"
  9.     "runtime"
  10.     "time"
  11. )
  12.  
  13. type Game struct {
  14.     ID        string
  15.     Name      string
  16.     Publisher string
  17. }
  18.  
  19. /********************* Game list context variable*****************/
  20.  
  21. type GameList struct {
  22.     Games []stonetium.Game
  23.     Len   int
  24. }
  25.  
  26. func (this *GameList) DownloadGame(gamePath string, gameToDownload stonetium.Game) bool {
  27.     timeout := time.Duration(30) * time.Second
  28.  
  29.     if runtime.GOOS == "windows" {
  30.         // download the windows version
  31.         err := download(gamePath, "7eece863-48da-49f2-8aca-434866921952", timeout)
  32.         if err != nil {
  33.             log.Println(err)
  34.         }
  35.     } else if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
  36.         // download the linux version
  37.         err := download(gamePath, "1a92b42b-dd25-4de1-bd52-df4e51b2ea62", timeout)
  38.         if err != nil {
  39.             log.Println(errs.Stack(err))
  40.         }
  41.     }
  42.     return true
  43. }
  44.  
  45. func (this *GameList) GetGame(index int) stonetium.Game {
  46.     return this.Games[index]
  47. }
  48.  
  49. func (this *GameList) Populate(gameList []stonetium.Game) {
  50.     this.Games = gameList
  51.     this.Len = len(this.Games)
  52.     qml.Changed(this, &this.Len)
  53. }
  54.  
  55. func (this *GameList) PlayGame(executablePath string) {
  56.  
  57.     path, err := exec.LookPath(executablePath)
  58.     if err != nil {
  59.         log.Println("cannot find executable: " + executablePath)
  60.         log.Println(errs.Stack(err))
  61.     }
  62.     cmd := exec.Command("")
  63.     if runtime.GOOS == "darwin" { // osx
  64.         cmd = exec.Command(executablePath)
  65.     } else {
  66.         cmd = exec.Command(path)
  67.     }
  68.     err = cmd.Run()
  69.     if err != nil {
  70.         log.Println("failed to run command: " + path)
  71.         log.Println(errs.Stack(err))
  72.     }
  73.  
  74. }
  75.  
  76. func download(string, string, time.Duration) error {
  77.     // already written for us
  78.     return nil
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement