/// <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);
            }
        }
        /// <summary>
        /// When we open the menu of entires, then we allow to export to Windows or .xml files
        /// if only supported entries are chosen.
        /// </summary>
        /// <param name="sender">Ignored</param>
        /// <param name="e">Ignored</param>
        /// <remark>
        /// Hopefully a temporary way to solve the problem explained in <see cref="MSWifiImportPluginExt"/>
        /// </remark>
        public void AddExportToMenu(object sender, EventArgs e)
        {
            if (phHost.MainWindow.GetSelectedEntries() == null ||
                phHost.MainWindow.GetSelectedEntries().Length == 0)
            {
                return;
            }

            WlanProfile profile = new WlanProfile();

            // Check whether the entries are supported
            foreach (PwEntry entry in phHost.MainWindow.GetSelectedEntries())
            {
                if (!entry.Strings.Exists(FieldNames.SSIDHex))
                {
                    return;
                }

                profile.LoadFrom(phHost.Database, entry);

                if (!profile.IsValid)
                {
                    return;
                }
            }

            // All entries are supported, so add our stuff
            addToWindows = selectedItemsMenu.DropDown.Items.Add("In Windows einfügen", null, AddEntriesToWindows);
            exportToXML  = selectedItemsMenu.DropDown.Items.Add("In .xml Datei exportieren", null, AddEntriesToXML);
        }
Example #3
0
        /// <summary>Writes to a xml file</summary>
        /// <param name="pwExportInfo">The information to be exported</param>
        /// <param name="sOutput">A stream to the xml file/entry</param>
        /// <param name="slLogger">Logger to be used</param>
        public override bool Export(PwExportInfo pwExportInfo, Stream sOutput, IStatusLogger slLogger)
        {
            XmlSerializer xml        = new XmlSerializer(typeof(WlanProfile));
            WlanProfile   curProfile = new WlanProfile();

            if (slLogger != null)
            {
                slLogger.SetText("Schreibe XML", LogStatusType.Info);
                slLogger.SetProgress(0);
            }

            double progress = 0;
            String name;

            foreach (PwEntry entry in pwExportInfo.DataGroup.GetEntries(true))
            {
                if (slLogger != null)
                {
                    name = entry.Strings.Get(PwDefs.TitleField).ReadString();
                    if ((name == null) || (name.Length == 0))
                    {
                        name = entry.Strings.Get(FieldNames.SSID).ReadString();
                        if ((name == null) || (name.Length == 0))
                        {
                            continue;
                        }
                    }

                    slLogger.SetText(String.Format("Schreibe Wifi-Information {0}", name), LogStatusType.Info);
                    progress += 50 / pwExportInfo.DataGroup.GetEntriesCount(true);
                    slLogger.SetProgress((uint)progress);
                }

                curProfile.LoadFrom(pwExportInfo.ContextDatabase, entry);
                xml.Serialize(sOutput, curProfile);
                if (slLogger != null)
                {
                    progress += 50 / pwExportInfo.DataGroup.GetEntriesCount(true);
                    slLogger.SetProgress((uint)progress);
                }
            }

            return(true);
        }
Example #4
0
        /// <summary>
        /// Exports a wlan connection information from the database to a .xml profil.
        /// </summary>
        /// <param name="pwStorage">The database in which the key lies</param>
        /// <param name="entry">The entry which we want to export</param>
        /// <param name="soutput">Where to print to the xml structure (via serialization)</param>
        /// <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>
        /// <remarks>Note that minProcents + totalProcents has to be less than or equal to 100.
        /// <para>Note furthermore that nothing is written to soutput if an error occured</para></remarks>
        /// <returns>Whether the export was successfull.</returns>
        public bool Export(PwDatabase pwStorage, PwEntry entry, Stream sOutput,
                           IStatusLogger slLogger = null, double totalProcents = 60,
                           double minProcents     = 20)
        {
            WlanProfile profile = new WlanProfile();

            profile.LoadFrom(pwStorage, entry);

            if (!profile.IsValid)
            {
                return(false);
            }

            XmlSerializer xml = new XmlSerializer(typeof(WlanProfile));

            xml.Serialize(sOutput, profile);

            return(true);
        }
        /// <summary>Add all entries, we selected to the Windows system.</summary>
        /// <param name="sender">Ignored</param>
        /// <param name="e">Ignored</param>
        public void AddEntriesToXML(object sender, EventArgs e)
        {
            XmlSerializer xml     = new XmlSerializer(typeof(WlanProfile));
            WlanProfile   profile = new WlanProfile();
            StreamWriter  stream;

            // If we only export one entry, then we let the user choose the .xml file otherwise
            // only the folder.
            if (phHost.MainWindow.GetSelectedEntries().Length == 1)
            {
                profile.LoadFrom(phHost.Database, phHost.MainWindow.GetSelectedEntry(true));
                SaveFileDialog fileDialog = new SaveFileDialog();
                fileDialog.Filter = "XML files (*.xml)|*.xml";

                if (fileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                if ((stream = new StreamWriter(fileDialog.OpenFile())) == null)
                {
                    return;
                }
                xml.Serialize(stream, profile);
                stream.Close();
            }
            else
            {
                FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
                folderBrowser.ShowNewFolderButton = true;
                folderBrowser.Description         = "Verzeichnis für die .xml Dateien wählen";
                if (folderBrowser.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                String path;

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

                    if (!profile.IsValid)
                    {
                        continue;
                    }

                    path = String.Format("{0}\\{1}.xml", folderBrowser.SelectedPath, profile.NameOrSSID);
                    if (File.Exists(path))
                    {
                        KeePass.UI.VistaTaskDialog vtd = new KeePass.UI.VistaTaskDialog();
                        vtd.CommandLinks    = false;
                        vtd.MainInstruction = String.Format("Es ist bereits eine Datei namens {0} vorhanden.\n" +
                                                            "Soll die Datei ersetzt werden, ein neuer Dateiname erzeugt werden oder der" +
                                                            "Eintrag übersprungen werden?", path);
                        vtd.SetIcon(KeePass.UI.VtdCustomIcon.Question);
                        vtd.WindowTitle = String.Format("Zieldatei für {0}", profile.NameOrSSID);

                        vtd.AddButton((int)MSWifi.BehaviourForExEntry.REPLACE, "Ersetzen", null);
                        vtd.AddButton((int)MSWifi.BehaviourForExEntry.RENAME_NEW_ONE, "Neuer Dateiname", null);
                        vtd.AddButton((int)MSWifi.BehaviourForExEntry.CANCEL_WITHOUT_ERROR, "Überspringen", null);
                        vtd.ShowDialog();
                        switch (vtd.Result)
                        {
                        case (int)MSWifi.BehaviourForExEntry.REPLACE:
                            File.Delete(path);
                            break;

                        case (int)MSWifi.BehaviourForExEntry.RENAME_NEW_ONE:
                            for (int no = 2; File.Exists(path); ++no)
                            {
                                path = String.Format("{0}\\{1} ({2}).xml", folderBrowser.SelectedPath,
                                                     profile.NameOrSSID, no);
                            }
                            break;

                        default:
                        case (int)MSWifi.BehaviourForExEntry.CANCEL_WITHOUT_ERROR:
                            continue;
                        }
                    }

                    stream = new StreamWriter(path, false);
                    xml.Serialize(stream, profile);
                    stream.Close();
                }
            }
        }