|  | @@ -13,25 +13,40 @@ import (
 | 
	
		
			
				|  |  |  	"syscall"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	"v2ray.com/core"
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +	"v2ray.com/core/common/platform"
 | 
	
		
			
				|  |  |  	_ "v2ray.com/core/main/distro/all"
 | 
	
		
			
				|  |  |  )
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  var (
 | 
	
		
			
				|  |  | -	configFile string
 | 
	
		
			
				|  |  | +	configFile = flag.String("config", "", "Config file for V2Ray.")
 | 
	
		
			
				|  |  |  	version    = flag.Bool("version", false, "Show current version of V2Ray.")
 | 
	
		
			
				|  |  |  	test       = flag.Bool("test", false, "Test config file only, without launching V2Ray server.")
 | 
	
		
			
				|  |  |  	format     = flag.String("format", "json", "Format of input file.")
 | 
	
		
			
				|  |  |  	plugin     = flag.Bool("plugin", false, "True to load plugins.")
 | 
	
		
			
				|  |  |  )
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -func init() {
 | 
	
		
			
				|  |  | -	defaultConfigFile := ""
 | 
	
		
			
				|  |  | -	workingDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
 | 
	
		
			
				|  |  | -	if err == nil {
 | 
	
		
			
				|  |  | -		defaultConfigFile = filepath.Join(workingDir, "config.json")
 | 
	
		
			
				|  |  | +func fileExists(file string) bool {
 | 
	
		
			
				|  |  | +	info, err := os.Stat(file)
 | 
	
		
			
				|  |  | +	return err == nil && !info.IsDir()
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +func getConfigFilePath() string {
 | 
	
		
			
				|  |  | +	if len(*configFile) > 0 {
 | 
	
		
			
				|  |  | +		return *configFile
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	if workingDir, err := os.Getwd(); err == nil {
 | 
	
		
			
				|  |  | +		configFile := filepath.Join(workingDir, "config.json")
 | 
	
		
			
				|  |  | +		if fileExists(configFile) {
 | 
	
		
			
				|  |  | +			return configFile
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	if configFile := platform.GetConfigurationPath(); fileExists(configFile) {
 | 
	
		
			
				|  |  | +		return configFile
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | -	flag.StringVar(&configFile, "config", defaultConfigFile, "Config file for this Point server.")
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	return ""
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func GetConfigFormat() core.ConfigFormat {
 | 
	
	
		
			
				|  | @@ -46,9 +61,7 @@ func GetConfigFormat() core.ConfigFormat {
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func startV2Ray() (core.Server, error) {
 | 
	
		
			
				|  |  | -	if len(configFile) == 0 {
 | 
	
		
			
				|  |  | -		return nil, newError("config file is not set")
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | +	configFile := getConfigFilePath()
 | 
	
		
			
				|  |  |  	var configInput io.Reader
 | 
	
		
			
				|  |  |  	if configFile == "stdin:" {
 | 
	
		
			
				|  |  |  		configInput = os.Stdin
 |