예제 #1
0
func Migrate() {
	firstRun := filepath.Join(config.Get().Info.Path, ".firstrun")
	if _, err := os.Stat(firstRun); err == nil {
		return
	}
	file, _ := os.Create(firstRun)
	defer file.Close()

	log.Info("Preparing for first run")

	// Remove the cache
	log.Info("Clearing cache")
	os.RemoveAll(filepath.Join(config.Get().Info.Profile, "cache"))

	log.Info("Creating Quasar Repository Addon")
	if err := repository.MakeQuasarRepositoryAddon(); err != nil {
		log.Errorf("Unable to create repository addon: %s", err)
	} else {
		log.Info("Updating Kodi Addon Repositories")
		xbmc.UpdateAddonRepos()
	}
}
예제 #2
0
파일: main.go 프로젝트: scakemyer/quasar
func main() {
	// Make sure we are properly multithreaded.
	runtime.GOMAXPROCS(runtime.NumCPU())

	// logging.SetFormatter(logging.MustStringFormatter("%{time:2006-01-02 15:04:05}  %{level:.4s}  %{module:-15s}  %{message}"))
	logging.SetFormatter(logging.MustStringFormatter(
		`%{color}%{level:.4s}  %{module:-12s} ▶ %{shortfunc:-15s}  %{color:reset}%{message}`,
	))
	logging.SetBackend(logging.NewLogBackend(os.Stdout, "", 0))

	for _, line := range strings.Split(QuasarLogo, "\n") {
		log.Info(line)
	}
	log.Infof("Version: %s Go: %s", util.Version, runtime.Version())

	conf := config.Reload()

	ensureSingleInstance()
	Migrate()

	// xbmc.CloseAllDialogs()

	log.Infof("Addon: %s v%s", conf.Info.Id, conf.Info.Version)

	btService := bittorrent.NewBTService(*makeBTConfiguration(conf))

	var shutdown = func() {
		log.Info("Shutting down...")
		btService.Close()
		log.Info("Bye bye")
		os.Exit(0)
	}

	var watchParentProcess = func() {
		for {
			// did the parent die? shutdown!
			if os.Getppid() == 1 {
				log.Warning("Parent shut down. Me too.")
				go shutdown()
				break
			}
			time.Sleep(1 * time.Second)
		}
	}
	go watchParentProcess()

	http.Handle("/", api.Routes(btService))
	http.Handle("/files/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		handler := http.StripPrefix("/files/", http.FileServer(bittorrent.NewTorrentFS(btService, config.Get().DownloadPath)))
		handler.ServeHTTP(w, r)
	}))
	http.Handle("/reload", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		btService.Reconfigure(*makeBTConfiguration(config.Reload()))
	}))
	http.Handle("/shutdown", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		shutdown()
	}))

	xbmc.Notify("Quasar", "LOCALIZE[30208]", config.AddonIcon())

	log.Info("Updating Kodi Addon Repositories")
	xbmc.UpdateAddonRepos()

	xbmc.ResetRPC()

	http.ListenAndServe(":"+strconv.Itoa(config.ListenPort), nil)
}