Ejemplo n.º 1
0
 private void WriteGPXFile(List <Geocache> cacheList, Dictionary <string, string> waypointmappings, ACacheStore store)
 {
     writer.Complete      += HandleWriterComplete;
     writer.WriteWaypoint += HandleWriterWriteWaypoint;
     writer.WriteGPXFile(m_file, cacheList, waypointmappings, store);
     this.Complete(this, new WriteEventArgs("Complete"));
     return;
 }
Ejemplo n.º 2
0
        public void WriteToGPS(List<Geocache> cacheList, Dictionary<string,string> waypointmappings, ACacheStore store)
        {
            writer = new GPXWriter ();
            writer.NameMode = m_nameMode;
            writer.DescriptionMode = m_descMode;
            writer.Limit = m_Limit;
            writer.LogLimit = m_LogLimit;
            writer.IncludeChildWaypoints = true;
            writer.WriteAttributes = m_incAttr;
            if (m_format == "OCM_GPX") {
                if (m_file == "%auto%")
                {
                    string dBShort = Utilities.GetShortFileName(store.StoreName);
                    dBShort = dBShort.Substring(0, dBShort.Length - 4);
                    dBShort+= ".gpx";
                    m_file = "/media/GARMIN/Garmin/GPX/" + dBShort;
                }
                writer.HTMLOutput = HTMLMode.GARMIN;
                writer.UseOCMPtTypes = true;
                WriteGPXFile (cacheList, waypointmappings, store);
                return;
            }
            else if (m_format == "delgpx")
            {
                writer.HTMLOutput = HTMLMode.PLAINTEXT;
                writer.UseOCMPtTypes = false;
                if (m_file == "%auto%")
                {
                    string dBShort = Utilities.GetShortFileName(store.StoreName);
                    dBShort = dBShort.Substring(0, dBShort.Length - 4);
                    dBShort+= ".gpx";
                    m_file = "/media/EM_USERMAPS/waypoints/" + dBShort;
                }
                WriteGPXFile (cacheList, waypointmappings, store);
                return;
            }

            if (m_format == "edge")
            {
                writer.UseOCMPtTypes = true;
                writer.IncludeGroundSpeakExtensions = false;
                WriteGPXFile (cacheList, waypointmappings, store);
                return;
            }

            writer.IncludeGroundSpeakExtensions = true;
            writer.UseOCMPtTypes = true;
            writer.IncludeChildWaypoints = m_includeChildren;
            if (m_format == "garmin_gpi")
            {
                writer.UseOCMPtTypes = false;
                writer.IncludeGroundSpeakExtensions = false;
                if (m_forcePlainText)
                    writer.HTMLOutput = HTMLMode.PLAINTEXT;
                else
                    writer.HTMLOutput = HTMLMode.GARMIN;
            }
            else if (m_format == "garmin")
            {
                writer.IncludeGroundSpeakExtensions = false;
            }
            writer.Complete += HandleWriterComplete;
            String tempFile = Path.GetTempFileName ();
            writer.WriteWaypoint += HandleWriterWriteWaypoint;
            writer.WriteGPXFile (tempFile, cacheList, waypointmappings, store);
            this.StartSend (this, new WriteEventArgs ("Sending Waypoints to GPS"));
            StringBuilder builder = new StringBuilder ();
            builder.Append ("-i gpx -f ");
            builder.Append (tempFile);
            builder.Append (" -o ");
            builder.Append (m_format);
            if (!String.IsNullOrEmpty(m_otherBabelParams))
            {
                builder.Append(",");
                builder.Append(m_otherBabelParams);
            }
            builder.Append (" -F ");
            builder.Append (m_file);

            if (writer.Cancel)
            {
                throw new Exception ("Aborted");
            }
            ProcessStartInfo sp = new ProcessStartInfo();
            sp.Arguments = builder.ToString();
            sp.FileName = "gpsbabel";
            Process babel = Process.Start (sp);
            babel.WaitForExit ();
            if (babel.ExitCode != 0)
                throw new Exception ("Failed to send caches to GPS");
            this.Complete (this, new WriteEventArgs ("Complete"));
        }
Ejemplo n.º 3
0
        public void WriteToGPS(List <Geocache> cacheList, Dictionary <string, string> waypointmappings, ACacheStore store)
        {
            writer                       = new GPXWriter();
            writer.NameMode              = m_nameMode;
            writer.DescriptionMode       = m_descMode;
            writer.Limit                 = m_Limit;
            writer.LogLimit              = m_LogLimit;
            writer.IncludeChildWaypoints = true;
            writer.WriteAttributes       = m_incAttr;
            if (m_format == "OCM_GPX")
            {
                if (m_file == "%auto%")
                {
                    string dBShort = Utilities.GetShortFileName(store.StoreName);
                    dBShort  = dBShort.Substring(0, dBShort.Length - 4);
                    dBShort += ".gpx";
                    m_file   = "/media/GARMIN/Garmin/GPX/" + dBShort;
                }
                writer.HTMLOutput    = HTMLMode.GARMIN;
                writer.UseOCMPtTypes = true;
                WriteGPXFile(cacheList, waypointmappings, store);
                return;
            }
            else if (m_format == "delgpx")
            {
                writer.HTMLOutput    = HTMLMode.PLAINTEXT;
                writer.UseOCMPtTypes = false;
                if (m_file == "%auto%")
                {
                    string dBShort = Utilities.GetShortFileName(store.StoreName);
                    dBShort  = dBShort.Substring(0, dBShort.Length - 4);
                    dBShort += ".gpx";
                    m_file   = "/media/EM_USERMAPS/waypoints/" + dBShort;
                }
                WriteGPXFile(cacheList, waypointmappings, store);
                return;
            }

            if (m_format == "edge")
            {
                writer.UseOCMPtTypes = true;
                writer.IncludeGroundSpeakExtensions = false;
                WriteGPXFile(cacheList, waypointmappings, store);
                return;
            }

            writer.IncludeGroundSpeakExtensions = true;
            writer.UseOCMPtTypes         = true;
            writer.IncludeChildWaypoints = m_includeChildren;
            if (m_format == "garmin_gpi")
            {
                writer.UseOCMPtTypes = false;
                writer.IncludeGroundSpeakExtensions = false;
                if (m_forcePlainText)
                {
                    writer.HTMLOutput = HTMLMode.PLAINTEXT;
                }
                else
                {
                    writer.HTMLOutput = HTMLMode.GARMIN;
                }
            }
            else if (m_format == "garmin")
            {
                writer.IncludeGroundSpeakExtensions = false;
            }
            writer.Complete += HandleWriterComplete;
            String tempFile = Path.GetTempFileName();

            writer.WriteWaypoint += HandleWriterWriteWaypoint;
            writer.WriteGPXFile(tempFile, cacheList, waypointmappings, store);
            this.StartSend(this, new WriteEventArgs("Sending Waypoints to GPS"));
            StringBuilder builder = new StringBuilder();

            builder.Append("-i gpx -f ");
            builder.Append(tempFile);
            builder.Append(" -o ");
            builder.Append(m_format);
            if (!String.IsNullOrEmpty(m_otherBabelParams))
            {
                builder.Append(",");
                builder.Append(m_otherBabelParams);
            }
            builder.Append(" -F \"");
            builder.Append(m_file.Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("$", "\\$").Replace("`", "\\`"));
            builder.Append("\"");

            if (writer.Cancel)
            {
                throw new Exception("Aborted");
            }
            ProcessStartInfo sp = new ProcessStartInfo();

            sp.Arguments = builder.ToString();
            sp.FileName  = "gpsbabel";
            Process babel = Process.Start(sp);

            babel.WaitForExit();
            if (babel.ExitCode != 0)
            {
                throw new Exception("Failed to send caches to GPS");
            }
            this.Complete(this, new WriteEventArgs("Complete"));
        }