2016-10-04 15:42:36 +05:00
|
|
|
// URTator - Urban Terror server browser and game launcher, written in
|
|
|
|
// Go.
|
|
|
|
//
|
|
|
|
// Copyright (c) 2016, Stanslav N. a.k.a pztrn (or p0z1tr0n)
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under Terms and Conditions of GNU General Public License
|
|
|
|
// version 3 or any higher.
|
|
|
|
// ToDo: put full text of license here.
|
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
2018-11-10 13:21:53 +05:00
|
|
|
// stdlib
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
// local
|
|
|
|
"gitlab.com/pztrn/urtrator/cache"
|
|
|
|
"gitlab.com/pztrn/urtrator/clipboardwatcher"
|
|
|
|
"gitlab.com/pztrn/urtrator/colorizer"
|
|
|
|
"gitlab.com/pztrn/urtrator/configuration"
|
|
|
|
"gitlab.com/pztrn/urtrator/database"
|
|
|
|
"gitlab.com/pztrn/urtrator/eventer"
|
|
|
|
"gitlab.com/pztrn/urtrator/launcher"
|
|
|
|
"gitlab.com/pztrn/urtrator/requester"
|
|
|
|
"gitlab.com/pztrn/urtrator/timer"
|
|
|
|
"gitlab.com/pztrn/urtrator/translator"
|
|
|
|
|
|
|
|
// Github
|
|
|
|
"github.com/mattn/go-gtk/gtk"
|
2016-10-04 15:42:36 +05:00
|
|
|
)
|
|
|
|
|
|
|
|
type Context struct {
|
2018-11-10 13:21:53 +05:00
|
|
|
// Caching.
|
|
|
|
Cache *cache.Cache
|
|
|
|
// Clipboard watcher.
|
|
|
|
Clipboard *clipboardwatcher.ClipboardWatcher
|
|
|
|
// Colors parser and prettifier.
|
|
|
|
Colorizer *colorizer.Colorizer
|
|
|
|
// Configuration.
|
|
|
|
Cfg *configuration.Config
|
|
|
|
// Database.
|
|
|
|
Database *database.Database
|
|
|
|
// Eventer.
|
|
|
|
Eventer *eventer.Eventer
|
|
|
|
// Game launcher.
|
|
|
|
Launcher *launcher.Launcher
|
|
|
|
// Requester, which requests server's information.
|
|
|
|
Requester *requester.Requester
|
|
|
|
// Timer.
|
|
|
|
Timer *timer.Timer
|
|
|
|
// Translator.
|
|
|
|
Translator *translator.Translator
|
2016-10-04 15:42:36 +05:00
|
|
|
}
|
|
|
|
|
2016-10-06 22:19:03 +05:00
|
|
|
func (ctx *Context) Close() error {
|
2018-11-10 13:21:53 +05:00
|
|
|
fmt.Println("Closing URTrator...")
|
|
|
|
|
|
|
|
launched := ctx.Launcher.CheckForLaunchedUrbanTerror()
|
|
|
|
if launched != nil {
|
|
|
|
return errors.New("Urban Terror is launched!")
|
|
|
|
}
|
|
|
|
ctx.Cache.FlushProfiles(map[string]string{})
|
|
|
|
ctx.Cache.FlushServers(map[string]string{})
|
|
|
|
ctx.Database.Close()
|
|
|
|
|
|
|
|
// At last, close main window.
|
|
|
|
gtk.MainQuit()
|
|
|
|
return nil
|
2016-10-04 15:42:36 +05:00
|
|
|
}
|
|
|
|
|
2016-10-06 13:55:03 +05:00
|
|
|
func (ctx *Context) initializeCache() {
|
2018-11-10 13:21:53 +05:00
|
|
|
ctx.Cache = cache.New(ctx.Database, ctx.Eventer)
|
|
|
|
ctx.Cache.Initialize()
|
2016-10-11 13:14:08 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *Context) InitializeClipboardWatcher() {
|
2018-11-10 13:21:53 +05:00
|
|
|
ctx.Clipboard = clipboardwatcher.New(ctx.Cache, ctx.Eventer)
|
|
|
|
ctx.Clipboard.Initialize()
|
2016-10-06 13:55:03 +05:00
|
|
|
}
|
|
|
|
|
2016-10-05 20:46:02 +05:00
|
|
|
func (ctx *Context) initializeColorizer() {
|
2018-11-10 13:21:53 +05:00
|
|
|
ctx.Colorizer = colorizer.New()
|
|
|
|
ctx.Colorizer.Initialize()
|
2016-10-05 20:46:02 +05:00
|
|
|
}
|
|
|
|
|
2016-10-04 15:42:36 +05:00
|
|
|
func (ctx *Context) initializeConfig() {
|
2018-11-10 13:21:53 +05:00
|
|
|
ctx.Cfg = configuration.New()
|
|
|
|
ctx.Cfg.Initialize()
|
2016-10-04 15:42:36 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *Context) initializeDatabase() {
|
2018-11-10 13:21:53 +05:00
|
|
|
ctx.Database = database.New(ctx.Cfg)
|
|
|
|
ctx.Database.Initialize(ctx.Cfg)
|
|
|
|
ctx.Database.Migrate()
|
2016-10-04 15:42:36 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *Context) initializeEventer() {
|
2018-11-10 13:21:53 +05:00
|
|
|
ctx.Eventer = eventer.New()
|
|
|
|
ctx.Eventer.Initialize()
|
2016-10-04 15:42:36 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *Context) initializeLauncher() {
|
2018-11-10 13:21:53 +05:00
|
|
|
ctx.Launcher = launcher.New()
|
|
|
|
ctx.Launcher.Initialize()
|
2016-10-04 15:42:36 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *Context) initializeRequester() {
|
2018-11-10 13:21:53 +05:00
|
|
|
ctx.Requester = requester.New(ctx.Cache, ctx.Eventer, ctx.Cfg, ctx.Timer)
|
|
|
|
ctx.Requester.Initialize()
|
2016-10-04 15:42:36 +05:00
|
|
|
}
|
|
|
|
|
2016-12-13 08:01:48 +05:00
|
|
|
func (ctx *Context) initializeTimer() {
|
2018-11-10 13:21:53 +05:00
|
|
|
ctx.Timer = timer.New(ctx.Eventer, ctx.Cfg)
|
|
|
|
ctx.Timer.Initialize()
|
2016-12-13 08:01:48 +05:00
|
|
|
}
|
|
|
|
|
2017-02-09 01:16:51 +05:00
|
|
|
func (ctx *Context) initializeTranslator() {
|
2018-11-10 13:21:53 +05:00
|
|
|
ctx.Translator = translator.New(ctx.Cfg)
|
|
|
|
ctx.Translator.Initialize()
|
2017-02-09 01:16:51 +05:00
|
|
|
}
|
|
|
|
|
2016-10-04 15:42:36 +05:00
|
|
|
func (ctx *Context) Initialize() {
|
2018-11-10 13:21:53 +05:00
|
|
|
fmt.Println("Initializing application context...")
|
|
|
|
ctx.initializeColorizer()
|
|
|
|
ctx.initializeConfig()
|
|
|
|
ctx.initializeDatabase()
|
|
|
|
ctx.initializeTranslator()
|
|
|
|
ctx.initializeEventer()
|
|
|
|
ctx.initializeCache()
|
|
|
|
ctx.initializeLauncher()
|
|
|
|
ctx.initializeTimer()
|
|
|
|
ctx.initializeRequester()
|
2016-10-04 15:42:36 +05:00
|
|
|
}
|