2023-08-16 15:16:02 +03:30
|
|
|
package mobile
|
|
|
|
|
|
|
|
|
|
import (
|
2023-08-19 14:09:49 +03:30
|
|
|
"encoding/json"
|
|
|
|
|
"os"
|
2024-01-26 02:18:21 +01:00
|
|
|
"path/filepath"
|
2023-08-19 14:09:49 +03:30
|
|
|
|
2024-01-15 17:17:05 +03:30
|
|
|
"github.com/hiddify/libcore/config"
|
2023-12-21 11:10:14 +03:30
|
|
|
_ "github.com/sagernet/gomobile"
|
2023-08-19 14:09:49 +03:30
|
|
|
"github.com/sagernet/sing-box/option"
|
2023-08-16 15:16:02 +03:30
|
|
|
)
|
|
|
|
|
|
2023-09-22 23:25:38 +03:30
|
|
|
func Parse(path string, tempPath string, debug bool) error {
|
2024-01-15 17:59:45 +03:30
|
|
|
config, err := config.ParseConfig(tempPath, debug)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return os.WriteFile(path, config, 0777)
|
2023-08-19 14:09:49 +03:30
|
|
|
}
|
|
|
|
|
|
2023-09-01 14:52:30 +03:30
|
|
|
func BuildConfig(path string, configOptionsJson string) (string, error) {
|
2024-01-26 02:18:21 +01:00
|
|
|
os.Chdir(filepath.Dir(path))
|
2023-08-19 14:09:49 +03:30
|
|
|
fileContent, err := os.ReadFile(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
var options option.Options
|
|
|
|
|
err = options.UnmarshalJSON(fileContent)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
2024-01-15 17:17:05 +03:30
|
|
|
configOptions := &config.ConfigOptions{}
|
2023-09-01 14:52:30 +03:30
|
|
|
err = json.Unmarshal([]byte(configOptionsJson), configOptions)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", nil
|
2023-08-22 00:54:58 +03:30
|
|
|
}
|
2024-01-15 17:17:05 +03:30
|
|
|
return config.BuildConfigJson(*configOptions, options)
|
2023-08-16 15:16:02 +03:30
|
|
|
}
|