private void UpdateMainModule_Callback(bool success, string fileName) { if (success) { if (Lib.IO.Compression.UnZip(Path.GetFullPath(fileName), Path.GetDirectoryName(Path.GetFullPath(fileName)))) { File.Delete(fileName); if (File.Exists("License.txt")) { File.Delete("License.txt"); } File.Move(@"Downloads\License.txt", "License.txt"); System.Diagnostics.Process.Start("Launcher.exe"); Global.Exit(); } else { MessageBox.Show("Extraction was corrupted or interrupted !", "Extraction", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static void Load() { Config currentConfig; if (!File.Exists("Network_Manager.xml") && File.Exists("Network_Manager.xml.tmp")) { File.Move("Network_Manager.xml.tmp", "Network_Manager.xml"); } if (File.Exists("Network_Manager.xml")) { try { XmlSerializer reader = new XmlSerializer(typeof(Config)); using (StreamReader file = new StreamReader("Network_Manager.xml")) { XmlReader xmlReader = XmlReader.Create(file); currentConfig = (Config)reader.Deserialize(xmlReader); //Config defaultConfig = new Config(); //currentConfig = (Config)CheckIfNull(typeof(Config), currentConfig, defaultConfig); // not needed, XML does a nice job } } catch { DialogResult result = MessageBox.Show("Configuration file was corrupted.\n\nDo you want to reset it to default and lose all configurations?", "Config File Corrupted", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification); if (result == DialogResult.No) { Global.Exit(); } currentConfig = new Config(); File.Delete("Network_Manager.xml"); } } else { currentConfig = new Config(); } // load defaults if null if (currentConfig.SavedRoutes.Nodes.Count == 0) { currentConfig.SavedRoutes.Nodes.Add(new SavedRouteGroup()); currentConfig.SavedRoutes.Nodes[0].Name = "<Root Group>"; } if (currentConfig.InterfaceProfiles.Count == 0) { InterfaceProfile profile = new InterfaceProfile(); profile.Name = "Google DNS"; profile.IPv4DnsAddresses.Add("8.8.8.8"); profile.IPv4DnsAddresses.Add("8.8.4.4"); profile.IPv6DnsAddresses.Add("2001:4860:4860::8888"); profile.IPv6DnsAddresses.Add("2001:4860:4860::8844"); currentConfig.InterfaceProfiles.Add(profile); profile = new InterfaceProfile(); profile.Name = "Comodo Secure DNS"; profile.IPv4DnsAddresses.Add("8.26.56.26"); profile.IPv4DnsAddresses.Add("8.20.247.20"); currentConfig.InterfaceProfiles.Add(profile); profile = new InterfaceProfile(); profile.Name = "OpenDNS"; profile.IPv4DnsAddresses.Add("208.67.222.222"); profile.IPv4DnsAddresses.Add("208.67.220.220"); profile.IPv6DnsAddresses.Add("2620:0:ccc::2"); profile.IPv6DnsAddresses.Add("2620:0:ccd::2"); currentConfig.InterfaceProfiles.Add(profile); } if (currentConfig.LoadBalancer.IPv4LocalAddresses.Count == 0) { currentConfig.LoadBalancer.IPv4LocalAddresses.Add(new NetworkInterface.IPHostAddress("192.168.200.2", "255.255.255.0")); } if (currentConfig.LoadBalancer.IPv4GatewayAddresses.Count == 0) { currentConfig.LoadBalancer.IPv4GatewayAddresses.Add(new NetworkInterface.IPGatewayAddress("192.168.200.1", 1)); } if (currentConfig.LoadBalancer.IPv4DnsAddresses.Count == 0) { currentConfig.LoadBalancer.IPv4DnsAddresses.Add("8.8.8.8"); } // legacy upgrade support if (File.Exists("Network_Manager.ini")) { // recover Gadget settings string gadgetX = Kernel32.IniReadValue("Gadget", "GadgetX", "Network_Manager.ini"); string gadgetY = Kernel32.IniReadValue("Gadget", "GadgetY", "Network_Manager.ini"); string alwaysOnTop = Kernel32.IniReadValue("Gadget", "AlwaysOnTop", "Network_Manager.ini"); string checkForUpdates = Kernel32.IniReadValue("Gadget", "CheckForUpdates", "Network_Manager.ini"); string maxVerticalSlots = Kernel32.IniReadValue("Gadget", "MaxVerticalSlots", "Network_Manager.ini"); string maxHorizontalSlots = Kernel32.IniReadValue("Gadget", "MaxHorizontalSlots", "Network_Manager.ini"); if (Regex.IsMatch(gadgetX, @"^\d+$") && Regex.IsMatch(gadgetY, @"^\d+$")) { currentConfig.Gadget.Location = new Point(int.Parse(gadgetX), int.Parse(gadgetY)); } if (Regex.IsMatch(alwaysOnTop, @"^(0|1)$")) { currentConfig.Gadget.AlwaysOnTop = alwaysOnTop == "1"; } if (Regex.IsMatch(checkForUpdates, @"^(0|1)$")) { currentConfig.Gadget.CheckForUpdates = checkForUpdates == "1"; } if (Regex.IsMatch(maxVerticalSlots, @"^\d$")) { currentConfig.Gadget.MaxVerticalSlots = int.Parse(maxVerticalSlots); } if (Regex.IsMatch(maxHorizontalSlots, @"^\d$")) { currentConfig.Gadget.MaxHorizontalSlots = int.Parse(maxHorizontalSlots); } // recover routes string routeNames = Kernel32.IniReadValue("Routes", "RouteNames", "Network_Manager.ini"); if (routeNames.Contains('#')) { SavedRouteGroup group = new SavedRouteGroup(); group.Name = "Legacy recovered routes"; foreach (string routeName in routeNames.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries)) { string[] sRoute = Kernel32.IniReadValue("Routes", routeName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries); SavedRouteItem route = new SavedRouteItem(); route.Name = routeName; try { route.Destination = sRoute[0]; route.Prefix = sRoute[1]; route.Gateway = sRoute[2]; route.InterfaceGuid = Guid.Empty; route.Metric = ushort.Parse(sRoute[4]); route.IPVersion = 4; group.Nodes.Add(route); } catch { } } ((SavedRouteGroup)currentConfig.SavedRoutes.Nodes[0]).Nodes.Add(group); } // recover interface profiles // complete profiles string completeProfileNames = Kernel32.IniReadValue("ConfigInterfaceProfiles", "CompleteProfileNames", "Network_Manager.ini"); foreach (string profileName in completeProfileNames.Split(new [] { '#' }, StringSplitOptions.RemoveEmptyEntries)) { if (currentConfig.InterfaceProfiles.Any(i => i.Name == profileName)) { continue; } string[] sProfile = Kernel32.IniReadValue("ConfigInterfaceProfiles", profileName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries); InterfaceProfile profile = new InterfaceProfile(); profile.Name = profileName; try { profile.IPv4LocalAddresses.Add(new NetworkInterface.IPHostAddress(sProfile[0], sProfile[1])); profile.IPv4GatewayAddresses.Add(new NetworkInterface.IPGatewayAddress(sProfile[2], ushort.Parse(sProfile[3]))); profile.IPv4DnsAddresses.Add(sProfile[5]); //profile.DhcpEnabled = (NetworkInterface.Dhcp)(int.Parse(sProfile[4]) + int.Parse(sProfile[6])); profile.InterfaceMetric = int.Parse(sProfile[7]); profile.NetbiosEnabled = (NetworkInterface.Netbios)(int.Parse(sProfile[7]) == 1 ? 1 : 2); currentConfig.InterfaceProfiles.Add(profile); } catch { } } // IP profiles string ipProfileNames = Kernel32.IniReadValue("ConfigInterfaceProfiles", "IpProfileNames", "Network_Manager.ini"); foreach (string profileName in ipProfileNames.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries)) { if (currentConfig.InterfaceProfiles.Any(i => i.Name == profileName)) { continue; } string[] sProfile = Kernel32.IniReadValue("ConfigInterfaceProfiles", profileName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries); InterfaceProfile profile = new InterfaceProfile(); profile.Name = profileName; try { profile.IPv4LocalAddresses.Add(new NetworkInterface.IPHostAddress(sProfile[0], sProfile[1])); profile.IPv4GatewayAddresses.Add(new NetworkInterface.IPGatewayAddress(sProfile[2], ushort.Parse(sProfile[3]))); currentConfig.InterfaceProfiles.Add(profile); } catch { } } // DNS profiles string dnsProfileNames = Kernel32.IniReadValue("ConfigInterfaceProfiles", "DnsProfileNames", "Network_Manager.ini"); foreach (string profileName in dnsProfileNames.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries)) { if (currentConfig.InterfaceProfiles.Any(i => i.Name == profileName)) { continue; } string[] sProfile = Kernel32.IniReadValue("ConfigInterfaceProfiles", profileName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries); InterfaceProfile profile = new InterfaceProfile(); profile.Name = profileName; try { profile.IPv4DnsAddresses.Add(sProfile[0]); currentConfig.InterfaceProfiles.Add(profile); } catch { } } // Settings profiles string settingsProfileNames = Kernel32.IniReadValue("ConfigInterfaceProfiles", "SettingsProfileNames", "Network_Manager.ini"); foreach (string profileName in settingsProfileNames.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries)) { if (currentConfig.InterfaceProfiles.Any(i => i.Name == profileName)) { continue; } string[] sProfile = Kernel32.IniReadValue("ConfigInterfaceProfiles", profileName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries); InterfaceProfile profile = new InterfaceProfile(); profile.Name = profileName; try { profile.InterfaceMetric = int.Parse(sProfile[7]); profile.NetbiosEnabled = (NetworkInterface.Netbios)(int.Parse(sProfile[7]) == 1 ? 2 : 0); currentConfig.InterfaceProfiles.Add(profile); } catch { } } try { File.Move("Network_Manager.ini", "Network_Manager.old.ini"); } catch { } } Global.Config = currentConfig; }