~welt/murse

ref: 5ceabbdffae9eff5c6e49608514a9685a37c8aba murse/flags.go -rw-r--r-- 2.1 KiB
5ceabbdfwelt Fix small oopsie a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main

import (
	"log"
	"os"
	"runtime"

	"github.com/jessevdk/go-flags"
)

var opt struct {
	Threads            int    `short:"t" short:"n" default:"0" description:"Number of threads to use. Don't touch this unless you know what you're doing. 0 = auto."`
	Directory          string `short:"d" short:"p" default:"./open_fortress" description:"Directory to download to or modify. Will be created if it doesn't already exist."`
	URL                string `short:"u" default:"https://svn.openfortress.fun/launcher/files/" description:"The URL for the launcher files."`
	OverwriteProtected bool   `short:"x" long:"cfg-overwrite" description:"Overwrite protected files (such as demos, modified .cfg files)."`
	IgnoreLockfile     bool   `short:"b" description:"Ignore the lockfile, in case the program was previously ungracefully killed."`
	// Backward compatibility flags
	DisableSigning bool `short:"z" long:"disable-signing" description:"Disable signature checks. Note that unlike ofatomic, we only check the file database's signature, so this should have no performance impact during file download."`
	DisableHashing bool `short:"#" long:"disable-hashing" description:"This is a dummy flag meant for compatability purposes."`
}

func init() {
	_, err := flags.Parse(&opt)
	if err != nil {
		os.Exit(1)
	}

	lmd = opt.Directory + "/.murse/local.json"
	lfd = opt.Directory + "/.murse/lockfile"
}

func init() {
	// We subtract one from the CPU count to leave thread(s) for the OS.
	// We set it to one on tri-core-or-less systems so pablo.gonzales2003's
	// Gateway netbook doesn't burn to a crisp.

	// We limit the automatic count to 6 so we don't burn OF's servers
	// to a crisp as well.

	if opt.Threads < 1 {
		switch {
		case runtime.NumCPU() > 6:
			opt.Threads = 6
		case runtime.NumCPU() < 3:
			opt.Threads = 1
		}
	}

	if opt.Threads > 6 {
		log.Println("!")
		log.Printf("WARNING: You are using %v threads. ", opt.Threads)
		log.Println("Please practice proper netiquette and make sure the")
		log.Println("place you're fetching from is okay with that many")
		log.Println("concurrent downloads going at once.")
		log.Println("!")
	}
}