2024-10-31 17:04:25 +00:00
|
|
|
//go:build windows
|
|
|
|
|
2024-08-31 16:01:58 +00:00
|
|
|
package proxy
|
|
|
|
|
2024-08-31 16:27:57 +00:00
|
|
|
import (
|
2024-11-01 15:32:45 +00:00
|
|
|
"log"
|
|
|
|
|
2024-08-31 16:27:57 +00:00
|
|
|
"github.com/Baipyrus/ProxySwitcher/util"
|
|
|
|
)
|
|
|
|
|
2024-09-24 12:40:42 +00:00
|
|
|
func Set(cfgPath string) {
|
2024-09-12 21:19:57 +00:00
|
|
|
proxy, _ := ReadSystemProxy()
|
2024-08-31 17:13:01 +00:00
|
|
|
// Set system proxy, if not already
|
2024-09-12 21:19:57 +00:00
|
|
|
if !proxy.Enabled {
|
|
|
|
SetSystemProxy(true)
|
2024-08-31 16:27:57 +00:00
|
|
|
}
|
|
|
|
|
2024-11-01 15:32:45 +00:00
|
|
|
var failed bool
|
2024-09-24 12:40:42 +00:00
|
|
|
configs, _ := util.ReadConfigs(cfgPath)
|
2024-08-31 16:27:57 +00:00
|
|
|
for _, config := range configs {
|
|
|
|
configCmd := config.Name
|
2024-08-31 17:13:01 +00:00
|
|
|
// Use command instead of name, if given
|
2024-08-31 16:27:57 +00:00
|
|
|
if config.Cmd != "" {
|
|
|
|
configCmd = config.Cmd
|
|
|
|
}
|
|
|
|
|
2024-10-01 18:09:54 +00:00
|
|
|
commands := generateCommands(configCmd, config.Set, proxy.Server)
|
2024-11-01 15:32:45 +00:00
|
|
|
failed = util.ExecCmds(commands)
|
2024-08-31 16:27:57 +00:00
|
|
|
}
|
|
|
|
|
2024-11-01 15:32:45 +00:00
|
|
|
// Additional feedback on error
|
|
|
|
if failed {
|
|
|
|
log.Printf("One or more commands failed to execute. Run command 'debug' to see more.\n")
|
|
|
|
}
|
2024-08-31 16:01:58 +00:00
|
|
|
}
|