/// <summary>Add all entries, we selected to the Windows system.</summary>
        /// <param name="sender">Ignored</param>
        /// <param name="e">Ignored</param>
        public void AddEntriesToWindows(object sender, EventArgs e)
        {
            XmlSerializer xml                 = new XmlSerializer(typeof(WlanProfile));
            WlanProfile   profile             = new WlanProfile();
            String        xmlVersionOfProfile = null;
            StringWriter  writer              = null;

            WinWlan.SystemInterface system     = new WinWlan.SystemInterface();
            WinWlan.WlanInterface[] interfaces = system.Interfaces;
            if (interfaces.Length == 0)
            {
                return;
            }
            WinWlan.WlanInterface curInterface = interfaces[0];

            foreach (PwEntry entry in phHost.MainWindow.GetSelectedEntries())
            {
                profile.LoadFrom(phHost.Database, entry);

                if (!profile.IsValid)
                {
                    continue;
                }

                writer = new StringWriter();
                xml.Serialize(writer, profile);
                xmlVersionOfProfile = writer.ToString();
                curInterface.SetProfile(WinWlan.WlanProfileFlags.AllUser, xmlVersionOfProfile, true);
            }
        }
Esempio n. 2
0
        /// <summary>Reads all Wifi Profiles saved in the system (for any interface)</summary>
        /// <param name="slLogger">Where we log to (can be null)</param>
        /// <param name="totalProcents">If we parsed completely, how many (additional) procents of the
        /// total progress did we finish? (Senseless if slLogger = null)</param>
        /// <param name="minProcents">How many procents of the total progress were already finished</param>
        /// <returns>A map Wifi name => Wifi-connection information</returns>
        /// <remarks>Note that minProcents + totalProcents has to be less than or equal to 100.</remarks>
        public Dictionary <String, WlanProfile> GetSystemProfiles(IStatusLogger slLogger = null,
                                                                  double totalProcents   = 100, double minProcents = 0)
        {
            WinWlan.SystemInterface systemInterface = new WinWlan.SystemInterface();
            if (systemInterface.Interfaces.Length == 0)
            {
                return(null);
            }

            XmlSerializer xml = new XmlSerializer(typeof(WlanProfile));
            Dictionary <String, String>      xmls = null;
            Dictionary <String, WlanProfile> res  = new Dictionary <String, WlanProfile>();

            StringReader reader;
            WlanProfile  curProfile = null;

            foreach (WinWlan.WlanInterface wlanInterface in systemInterface.Interfaces)
            {
                xmls = wlanInterface.GetProfilesXmls();

                if (slLogger != null)
                {
                    minProcents += totalProcents / 2 / systemInterface.Interfaces.Length;
                    slLogger.SetProgress((uint)minProcents);
                }

                foreach (KeyValuePair <String, String> pair in xmls)
                {
                    reader     = new StringReader(pair.Value);
                    curProfile = (WlanProfile)xml.Deserialize(reader);

                    if (curProfile.IsValid)
                    {
                        res[pair.Key] = curProfile;
                    }

                    if (slLogger != null)
                    {
                        minProcents += totalProcents / 2 / systemInterface.Interfaces.Length / xmls.Count;
                        slLogger.SetProgress((uint)minProcents);
                    }
                }
            }

            return(res);
        }