private ConfigJsonObject ConvertToConfigJsonObject() { var o = new ConfigJsonObject { UseChnRoute = UseChnRoute, TapIntfaceName = TapIntfaceName, CurrentProfileName = CurrentProfileName, Profiles = new Dictionary <string, Profile.ProfileJsonObject>() }; foreach (var profile in Profiles) { o.Profiles.Add(profile.Key, profile.Value.ConverToJsonObject()); } return(o); }
private Config(ConfigJsonObject o) { UseChnRoute = false; //TODO: ADD CHNRoute Support TapIntfaceName = o.TapIntfaceName; CurrentProfileName = o.CurrentProfileName; Profiles = new Dictionary <string, Profile>(); if (o.Profiles != null) { foreach (var profileJsonObject in o.Profiles) { Profiles.Add(profileJsonObject.Key, new Profile(profileJsonObject.Value)); } } SaveVpnConfig(); }
public static Config FromFile() { if (File.Exists(ComponentPath.UserConfigPath)) { var json = File.ReadAllText(ComponentPath.UserConfigPath); var o = JSON.ToObject <ConfigJsonObject>(json); return(new Config(o)); } else { if (!File.Exists(ComponentPath.UserConfigPath) && !Directory.Exists(Path.GetDirectoryName(ComponentPath.UserConfigPath))) { Directory.CreateDirectory(Path.GetDirectoryName(ComponentPath.UserConfigPath)); } var o = new ConfigJsonObject { TapIntfaceName = "svTun" }; return(new Config(o)); } }