package main

import (
	"RuleIniter/checker"
	"RuleIniter/conf"
	"RuleIniter/parser"
	"flag"
	"log"
)

var path = flag.String("conf", "/etc/V2bX/ruler.json", "config file path")

func Run() {
	log.Println("RuleIniter Ver", version)
	c := conf.New(*path)
	err := c.LoadConfig()
	if err != nil {
		log.Printf("load config error: %s", err)
		return
	}
	if c.Disable {
		log.Println("Disabled")
		return
	}
	if c.UpdateUrl != "" {
		err := Update(c.UpdateUrl, "/bin/ruler")
		if err != nil {
			log.Printf("Update program error: %s", err)
		}
	}
	ch := checker.New(&c.Checker)
	m, err := ch.GetNotUnlockList()
	if err != nil {
		log.Printf("some check error: %s\n", err)
	}
	log.Println("Can not unlock list:")
	log.Println("---------------------------")
	for k, v := range m {
		log.Println(k, "地区:")
		for _, s := range v {
			log.Println(s)
		}
		log.Println("-----------------------------")
	}
	p := parser.New(&c.Parser)
	err = p.Parse(m)
	if err != nil {
		log.Fatalf("parse error: %s", err)
	}
}
