public ExportProgressDialog(GPXWriter writer)
 {
     this.Build ();
     writer.WriteWaypoint += HandleWriterWriteWaypoint;
     writer.Complete += HandleWriterComplete;
     m_writer = writer;
 }
Пример #2
0
        public void WriteToGPX(XmlWriter writer, GPXWriter gpx)
        {
            writer.WriteStartElement("wpt", GPXWriter.NS_GPX);
            WriteWPTDetails(writer, gpx);
            writer.WriteEndElement();
            if (!gpx.IncludeChildWaypoints)
            {
                return;
            }

            if ((this is Geocache) && ((this as Geocache).HasCorrected))
            {
                Geocache cache = this as Geocache;
                Waypoint orig  = new Waypoint();
                orig.Name   = cache.Name + "-ORIG";
                orig.Lat    = cache.OrigLat;
                orig.Lon    = cache.OrigLon;
                orig.Symbol = "Reference Point";
                orig.Type   = "Waypoint|Reference Point";
                orig.Desc   = Catalog.GetString("Original Location") + " - " + cache.CacheName;
                orig.WriteToGPX(writer, gpx);
            }
        }
Пример #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);

            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"));
        }
Пример #4
0
 internal override void WriteWPTDetails(XmlWriter writer, GPXWriter gpx)
 {
     base.WriteWPTDetails (writer,gpx);
     if (!gpx.IncludeGroundSpeakExtensions)
         return;
     writer.WriteStartElement(CACHE_PREFIX, "cache", GPXWriter.NS_CACHE);
     if (Symbol == "TerraCache" || Symbol == "Default")
         writer.WriteAttributeString("id", gpx.GetNextGUID().ToString());
     else
         writer.WriteAttributeString("id", CacheID);
     writer.WriteAttributeString("available", Available.ToString());
     writer.WriteAttributeString("archived", Archived.ToString());
     // Temp until smart-tag like support
     if (HasCorrected)
         writer.WriteElementString(CACHE_PREFIX,"name", GPXWriter.NS_CACHE, "(*) " + CacheName);
     else
         writer.WriteElementString(CACHE_PREFIX,"name", GPXWriter.NS_CACHE, CacheName);
     writer.WriteElementString(CACHE_PREFIX,"placed_by", GPXWriter.NS_CACHE,  PlacedBy);
     writer.WriteStartElement(CACHE_PREFIX,"owner", GPXWriter.NS_CACHE);
     writer.WriteAttributeString("id", OwnerID);
     writer.WriteString(CacheOwner);
     writer.WriteEndElement();
     writer.WriteElementString(CACHE_PREFIX,"type", GPXWriter.NS_CACHE, GetCTypeString(TypeOfCache));
     writer.WriteElementString(CACHE_PREFIX,"container", GPXWriter.NS_CACHE, Container);
     List<CacheAttribute> attrs = gpx.GetAttributes(this.Name);
     writer.WriteStartElement(CACHE_PREFIX, "attributes", GPXWriter.NS_CACHE);
     foreach(CacheAttribute curr in attrs)
     {
         writer.WriteStartElement(CACHE_PREFIX, "attribute", GPXWriter.NS_CACHE);
         if (!String.IsNullOrEmpty(curr.ID))
             writer.WriteAttributeString("id", curr.ID);
         if (curr.Include)
             writer.WriteAttributeString("inc", "1");
         else
             writer.WriteAttributeString("inc", "0");
         writer.WriteString(curr.AttrValue);
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
     writer.WriteElementString(CACHE_PREFIX,"difficulty", GPXWriter.NS_CACHE, Difficulty.ToString("0.#", CultureInfo.InvariantCulture));
     writer.WriteElementString(CACHE_PREFIX,"terrain", GPXWriter.NS_CACHE, Terrain.ToString("0.#", CultureInfo.InvariantCulture));
     writer.WriteElementString(CACHE_PREFIX,"country", GPXWriter.NS_CACHE,  Country);
     writer.WriteElementString(CACHE_PREFIX,"state", GPXWriter.NS_CACHE,  State);
     StringBuilder shortDescription = new StringBuilder();
     if (HasCorrected)
     {
         shortDescription.Append(Catalog.GetString("Original Coordinate:"));
         shortDescription.Append(Utilities.getCoordString(OrigLat, OrigLon));
         shortDescription.Append("<br/>");
     }
     if (gpx.WriteAttributes)
     {
         attrs = gpx.GetAttributes(this.Name);
         foreach(CacheAttribute curr in attrs)
         {
             if (curr.Include)
             {
                 shortDescription.Append(Catalog.GetString("Y:"));
             }
             else
             {
                 shortDescription.Append(Catalog.GetString("N:"));
             }
             shortDescription.Append(curr.AttrValue);
             shortDescription.Append("<br/>");
         }
         if (attrs.Count > 0)
             shortDescription.Append("<hr noshade/>");
     }
     if (!String.IsNullOrEmpty(Notes))
     {
         shortDescription.Append(Notes);
         shortDescription.Append("<hr noshade/>");
     }
     shortDescription.Append(ShortDesc);
     writer.WriteStartElement(CACHE_PREFIX,"short_description", GPXWriter.NS_CACHE);
     writer.WriteAttributeString("html", "True");
     if (gpx.HTMLOutput == HTMLMode.GARMIN)
         writer.WriteCData(Utilities.HTMLtoGarmin(shortDescription.ToString()));
     else if (gpx.HTMLOutput == HTMLMode.PLAINTEXT)
         writer.WriteCData(Utilities.HTMLtoText(shortDescription.ToString()));
     else
         writer.WriteCData(shortDescription.ToString());
     writer.WriteEndElement();
     writer.WriteStartElement(CACHE_PREFIX,"long_description", GPXWriter.NS_CACHE);
     writer.WriteAttributeString("html", "True");
     if (gpx.HTMLOutput == HTMLMode.GARMIN)
         writer.WriteCData(Utilities.HTMLtoGarmin(LongDesc));
     else if (gpx.HTMLOutput == HTMLMode.PLAINTEXT)
         writer.WriteCData(Utilities.HTMLtoText(LongDesc));
     else
         writer.WriteCData(LongDesc);
     writer.WriteEndElement();
     writer.WriteStartElement(CACHE_PREFIX,"encoded_hints", GPXWriter.NS_CACHE);
     writer.WriteAttributeString("html", "True");
     if (gpx.HTMLOutput == HTMLMode.GARMIN || gpx.HTMLOutput == HTMLMode.PLAINTEXT)
         writer.WriteCData(Utilities.HTMLtoText(Hint));
     else
         writer.WriteCData(Hint);
     writer.WriteEndElement();
     writer.WriteStartElement(CACHE_PREFIX,"logs", GPXWriter.NS_CACHE);
     if (gpx.IsMyFinds)
     {
         CacheLog log = gpx.CacheStore.GetLastFindLogBy(this.Name, gpx.MyFindsOwner);
         if (log.LogStatus == "find")
             log.LogStatus = "Found it";
         log.WriteToGPX(writer);
     }
     else
     {
         List<CacheLog> logs = gpx.GetCacheLogs(this.Name);
         int iCount = 0;
         foreach(CacheLog log in logs)
         {
             if ((iCount >= gpx.LogLimit) && (gpx.LogLimit != -1))
                 break;
             else
                 log.WriteToGPX(writer);
             iCount++;
     }
     }
     writer.WriteEndElement();
     writer.WriteStartElement(CACHE_PREFIX,"travelbugs", GPXWriter.NS_CACHE);
     List<TravelBug> bugs = gpx.GetTravelBugs(this.Name);
     foreach (TravelBug bug in bugs)
     {
         bug.WriteToGPX(writer);
     }
     writer.WriteEndElement();
     writer.WriteEndElement();
 }
Пример #5
0
        internal virtual void WriteWPTDetails(XmlWriter writer, GPXWriter gpx)
        {
            Geocache cache = null;
            if (this is Geocache)
            {
                cache = this as Geocache;
            }

            writer.WriteAttributeString("lat", this.Lat.ToString(CultureInfo.InvariantCulture));
            writer.WriteAttributeString("lon", this.Lon.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("time", this.Time.ToString("o"));
            if (cache != null && gpx.NameMode == WaypointNameMode.NAME)
                writer.WriteElementString("name", cache.CacheName);
            else if (cache != null && gpx.NameMode == WaypointNameMode.SHORTCODE)
                writer.WriteElementString("name", this.Name.Substring(2));
            else
                writer.WriteElementString("name", this.Name);
            if (cache != null && gpx.DescriptionMode == WaypointDescMode.CODESIZEANDHINT)
            {
                if (!String.IsNullOrEmpty(cache.Container))
                    writer.WriteElementString("desc", cache.Name + "/" + cache.Container.Substring(0, 3) + "/" + cache.Hint);
                else
                    writer.WriteElementString("desc", cache.Name);
            }
            else if (cache != null && gpx.DescriptionMode == WaypointDescMode.CODESIZETYPE)
            {
                if (!String.IsNullOrEmpty(cache.Container))
                    writer.WriteElementString("desc", cache.Name + "/" + cache.Container.Substring(0, 3) + "/" + cache.TypeOfCache.ToString());
                else
                    writer.WriteElementString("desc", cache.Name + "/" + cache.TypeOfCache.ToString());
            }
            else if (cache != null && gpx.DescriptionMode == WaypointDescMode.FULL)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append("<br/><br/>" + cache.ShortDesc);
                builder.Append("<br/>" + cache.LongDesc);
                if (!String.IsNullOrEmpty(cache.Hint))
                    builder.Append("<br/><br/>Hint: " + cache.Hint);
                builder.Append("<br/><br/>Logs:<br/>");
                List<CacheLog> logs = Engine.getInstance().Store.GetCacheLogs(cache.Name);
                foreach(CacheLog log in logs)
                {
                    builder.Append(log.toHTML());
                }

                writer.WriteStartElement("desc");
                if (gpx.HTMLOutput == HTMLMode.GARMIN)
                    writer.WriteCData(Utilities.HTMLtoGarmin(builder.ToString()));
                else if (gpx.HTMLOutput == HTMLMode.PLAINTEXT)
                    writer.WriteCData(Utilities.HTMLtoText(builder.ToString()));
                else
                    writer.WriteCData(builder.ToString());

                writer.WriteEndElement();
            }
            else
            {
                writer.WriteElementString("desc", this.Desc);
                writer.WriteElementString("cmt", this.Desc);
            }
            if (this.URL != null)
                writer.WriteElementString("url", this.URL.ToString());
            if (!String.IsNullOrEmpty(this.URLName))
                writer.WriteElementString("urlname", this.URLName);
            if (gpx.DescriptionMode == WaypointDescMode.FULL)
                writer.WriteElementString("sym", "Information");
            else if (!gpx.UseOCMPtTypes)
                writer.WriteElementString("sym", this.Symbol);
            else
            {
                    System.Console.WriteLine(this.Name);
                    if (cache != null && cache.Symbol == "Geocache Found")
                        writer.WriteElementString("sym", gpx.Mappings[this.Symbol]);
                    else if (cache != null && cache.TypeOfCache != Geocache.CacheType.GENERIC)
                    {
                        string key = "Geocache|" + Geocache.GetCTypeString(cache.TypeOfCache);
                        writer.WriteElementString("sym", gpx.Mappings[key]);
                    }
                    else if (gpx.Mappings.ContainsKey(this.Type))
                        writer.WriteElementString("sym", gpx.Mappings[this.Type]);
                    else
                        writer.WriteElementString("sym", this.Symbol);
            }
            writer.WriteElementString("type", this.Type);
            if (this.Parent != null)
                writer.WriteElementString("parent", "http://opencachemanage.sourceforge.net/schema1", this.Parent);
            if (cache != null && gpx.DescriptionMode == WaypointDescMode.FULL)
            {
                writer.WriteStartElement("extensions");
                writer.WriteStartElement("gpxx", "WaypointExtension", "http://www.garmin.com/xmlschemas/GpxExtensions/v3");
                writer.WriteElementString("gpxx:DisplayMode","SymbolAndName");
                writer.WriteStartElement("gpxx:Address");
                StringBuilder builder = new StringBuilder();
                builder.Append(Geocache.GetCTypeString(cache.TypeOfCache) + "\nBy: " + cache.PlacedBy);
                builder.Append("\n" + cache.Name + ":" + cache.CacheName);
                builder.Append("\n" + Utilities.getCoordString(cache.Lat, cache.Lon));
                builder.Append("\nT:" + cache.Terrain.ToString() + " D:" + cache.Difficulty.ToString() + " S:" + cache.Container);
                writer.WriteElementString("gpxx:PostalCode",builder.ToString());
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            else if (gpx.DescriptionMode == WaypointDescMode.FULL)
            {
                writer.WriteStartElement("extensions");
                writer.WriteStartElement("gpxx", "WaypointExtension", "http://www.garmin.com/xmlschemas/GpxExtensions/v3");
                writer.WriteElementString("gpxx:DisplayMode","SymbolAndName");
                writer.WriteStartElement("gpxx:Address");
                StringBuilder builder = new StringBuilder();
                builder.Append(this.Symbol + " for " + this.Parent);
                builder.Append("\n" + Utilities.getCoordString(this.Lat, this.Lon));
                writer.WriteElementString("gpxx:PostalCode",builder.ToString());
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
        }
Пример #6
0
        public void WriteToGPX(XmlWriter writer, GPXWriter gpx)
        {
            writer.WriteStartElement("wpt", GPXWriter.NS_GPX);
            WriteWPTDetails(writer, gpx);
            writer.WriteEndElement();
            if (!gpx.IncludeChildWaypoints)
                return;
            IEnumerator<Waypoint> itr = Engine.getInstance().GetChildWaypoints(this.Name);
            while (itr.MoveNext())
            {
                itr.Current.WriteToGPX(writer, gpx);
            }

            if ((this is Geocache) && ((this as Geocache).HasCorrected))
            {
                Geocache cache = this as Geocache;
                Waypoint orig = new Waypoint();
                orig.Name = cache.Name + "-ORIG";
                orig.Lat = cache.OrigLat;
                orig.Lon = cache.OrigLon;
                orig.Symbol = "Reference Point";
                orig.Type = "Waypoint|Reference Point";
                orig.Desc = Catalog.GetString("Original Location") + " - " + cache.CacheName;
                orig.WriteToGPX(writer, gpx);
            }
        }
Пример #7
0
        internal virtual void WriteWPTDetails(XmlWriter writer, GPXWriter gpx)
        {
            Geocache cache = null;

            if (this is Geocache)
            {
                cache = this as Geocache;
            }

            writer.WriteAttributeString("lat", this.Lat.ToString(CultureInfo.InvariantCulture));
            writer.WriteAttributeString("lon", this.Lon.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("time", this.Time.ToString("o"));
            if (cache != null && gpx.NameMode == WaypointNameMode.NAME)
            {
                writer.WriteElementString("name", cache.CacheName);
            }
            else if (cache != null && gpx.NameMode == WaypointNameMode.SHORTCODE)
            {
                writer.WriteElementString("name", this.Name.Substring(2));
            }
            else
            {
                writer.WriteElementString("name", this.Name);
            }
            if (cache != null && gpx.DescriptionMode == WaypointDescMode.CODESIZEANDHINT)
            {
                if (!String.IsNullOrEmpty(cache.Container))
                {
                    writer.WriteElementString("desc", cache.Name + "/" + cache.Container.Substring(0, 3) + "/" + cache.Hint);
                }
                else
                {
                    writer.WriteElementString("desc", cache.Name);
                }
            }
            else if (cache != null && gpx.DescriptionMode == WaypointDescMode.CODESIZETYPE)
            {
                if (!String.IsNullOrEmpty(cache.Container))
                {
                    writer.WriteElementString("desc", cache.Name + "/" + cache.Container.Substring(0, 3) + "/" + cache.TypeOfCache.ToString());
                }
                else
                {
                    writer.WriteElementString("desc", cache.Name + "/" + cache.TypeOfCache.ToString());
                }
            }
            else if (cache != null && gpx.DescriptionMode == WaypointDescMode.FULL)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append("<br/><br/>" + cache.ShortDesc);
                builder.Append("<br/>" + cache.LongDesc);
                if (!String.IsNullOrEmpty(cache.Hint))
                {
                    builder.Append("<br/><br/>Hint: " + cache.Hint);
                }
                builder.Append("<br/><br/>Logs:<br/>");
                List <CacheLog> logs   = gpx.GetCacheLogs(cache.Name);
                int             iCount = 0;
                foreach (CacheLog log in logs)
                {
                    if (iCount >= gpx.LogLimit && gpx.LogLimit >= 0)
                    {
                        break;
                    }
                    builder.Append(log.toHTML());
                    iCount++;
                }

                writer.WriteStartElement("desc");
                if (gpx.HTMLOutput == HTMLMode.GARMIN)
                {
                    writer.WriteCData(Utilities.HTMLtoGarmin(builder.ToString()));
                }
                else if (gpx.HTMLOutput == HTMLMode.PLAINTEXT)
                {
                    writer.WriteCData(Utilities.HTMLtoText(builder.ToString()));
                }
                else
                {
                    writer.WriteCData(builder.ToString());
                }

                writer.WriteEndElement();
            }
            else
            {
                writer.WriteElementString("desc", this.Desc);
                writer.WriteElementString("cmt", this.Desc);
            }
            if (this.URL != null)
            {
                writer.WriteElementString("url", this.URL.ToString());
            }
            if (!String.IsNullOrEmpty(this.URLName))
            {
                writer.WriteElementString("urlname", this.URLName);
            }
            if (gpx.DescriptionMode == WaypointDescMode.FULL)
            {
                writer.WriteElementString("sym", "Information");
            }
            else if (!gpx.UseOCMPtTypes)
            {
                writer.WriteElementString("sym", this.Symbol);
            }
            else
            {
                System.Console.WriteLine(this.Name);
                if (cache != null && cache.Symbol == "Geocache Found")
                {
                    writer.WriteElementString("sym", gpx.Mappings[this.Symbol]);
                }
                else if (cache != null && cache.TypeOfCache != Geocache.CacheType.GENERIC)
                {
                    string key = "Geocache|" + Geocache.GetCTypeString(cache.TypeOfCache);
                    writer.WriteElementString("sym", gpx.Mappings[key]);
                }
                else if (gpx.Mappings.ContainsKey(this.Type))
                {
                    writer.WriteElementString("sym", gpx.Mappings[this.Type]);
                }
                else
                {
                    writer.WriteElementString("sym", this.Symbol);
                }
            }
            writer.WriteElementString("type", this.Type);
            if (this.Parent != null)
            {
                writer.WriteElementString("parent", "http://opencachemanage.sourceforge.net/schema1", this.Parent);
            }
            if (cache != null && gpx.DescriptionMode == WaypointDescMode.FULL)
            {
                writer.WriteStartElement("extensions");
                writer.WriteStartElement("gpxx", "WaypointExtension", "http://www.garmin.com/xmlschemas/GpxExtensions/v3");
                writer.WriteElementString("gpxx:DisplayMode", "SymbolAndName");
                writer.WriteStartElement("gpxx:Address");
                StringBuilder builder = new StringBuilder();
                builder.Append(Geocache.GetCTypeString(cache.TypeOfCache) + "\nBy: " + cache.PlacedBy);
                builder.Append("\n" + cache.Name + ":" + cache.CacheName);
                builder.Append("\n" + Utilities.getCoordString(cache.Lat, cache.Lon));
                builder.Append("\nT:" + cache.Terrain.ToString() + " D:" + cache.Difficulty.ToString() + " S:" + cache.Container);
                writer.WriteElementString("gpxx:PostalCode", builder.ToString());
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            else if (gpx.DescriptionMode == WaypointDescMode.FULL)
            {
                writer.WriteStartElement("extensions");
                writer.WriteStartElement("gpxx", "WaypointExtension", "http://www.garmin.com/xmlschemas/GpxExtensions/v3");
                writer.WriteElementString("gpxx:DisplayMode", "SymbolAndName");
                writer.WriteStartElement("gpxx:Address");
                StringBuilder builder = new StringBuilder();
                builder.Append(this.Symbol + " for " + this.Parent);
                builder.Append("\n" + Utilities.getCoordString(this.Lat, this.Lon));
                writer.WriteElementString("gpxx:PostalCode", builder.ToString());
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
        }
Пример #8
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"));
        }
Пример #9
0
 public void OpenSelectedCacheInQLandKarte()
 {
     GPXWriter writer = new GPXWriter ();
     String tempPath = System.IO.Path.GetTempPath ();
     String tempFile = tempPath + "ocm_export.gpx";
     List<Geocache> cache = new List<Geocache> ();
     cache.Add (CacheList.SelectedCache);
     ExportProgressDialog dlg = new ExportProgressDialog (writer);
     dlg.AutoClose = true;
     dlg.Title = Catalog.GetString ("Preparing to send to QLandKarte GT");
     dlg.CompleteCommand = "qlandkartegt " + tempFile;
     dlg.Icon = this.Icon;
     dlg.Start (tempFile, cache, GPSProfileList.GetDefaultMappings (), m_app.CacheStore);
 }
Пример #10
0
        public void OpenInQLandKarte()
        {
            GPXWriter writer = new GPXWriter ();
            String tempPath = System.IO.Path.GetTempPath ();
            String tempFile = tempPath + "ocm_export.gpx";
            ExportProgressDialog dlg = new ExportProgressDialog (writer);

                        /*Connection DbusConnection = Bus.Session;
            IQLandkarteGT ql = DbusConnection.GetObject<IQLandkarteGT> ("org.qlandkarte.dbus", new ObjectPath ("QLandkarteGT"));
            System.Console.WriteLine("Connected");
            ql.loadGeoData("/home/campbelk/Desktop/export.gpx");*/

            dlg.AutoClose = true;
            dlg.Title = Catalog.GetString ("Preparing to send to QLandKarte GT");
            dlg.CompleteCommand = "qlandkartegt " + tempFile;
            dlg.Icon = this.Icon;
            dlg.Start (tempFile, CacheList.UnfilteredCaches, GPSProfileList.GetDefaultMappings (), m_app.CacheStore);
        }
Пример #11
0
        public void ExportGPX()
        {
            GPXWriter writer = new GPXWriter ();
            ExportProgressDialog edlg = new ExportProgressDialog (writer);
            edlg.AutoClose = Config.AutoCloseWindows;

            try {
                ExportGPXDialog dlg = new ExportGPXDialog ();
                dlg.SetCurrentFolder (System.Environment.GetFolderPath (System.Environment.SpecialFolder.MyDocuments));
                dlg.CurrentName = "export.gpx";
                dlg.WaypointMappings = GetExportMappings ();
                FileFilter filter = new FileFilter ();
                filter.Name = "GPX Files";
                filter.AddPattern ("*.gpx");
                dlg.AddFilter (filter);
                dlg.UsePlainText = Config.ExportAsPlainText;
                dlg.UseMappings = Config.ExportCustomSymbols;
                dlg.IsPaperless = Config.ExportPaperlessOptions;
                dlg.IncludeChildren = Config.ExportChildren;
                dlg.NameMode = Config.ExportWaypointNameMode;
                dlg.DescMode = Config.ExportWaypointDescMode;
                dlg.IncludeAttributes = Config.ExportIncludeAttributes;
                dlg.LogLimit = Config.ExportLimitLogs;
                dlg.CacheLimit = Config.ExportLimitCaches;
                if (dlg.Run () == (int)ResponseType.Ok) {
                    dlg.Hide ();
                    writer.Limit = dlg.CacheLimit;
                    writer.IncludeGroundSpeakExtensions = dlg.IsPaperless;
                    writer.IncludeChildWaypoints = dlg.IncludeChildren;
                    writer.UseOCMPtTypes = dlg.UseMappings;
                    writer.NameMode = dlg.NameMode;
                    writer.DescriptionMode = dlg.DescMode;
                    if (dlg.UsePlainText)
                        writer.HTMLOutput = HTMLMode.PLAINTEXT;
                    writer.WriteAttributes = dlg.IncludeAttributes;
                    writer.LogLimit = dlg.LogLimit;
                    edlg.Icon = this.Icon;

                    Config.ExportAsPlainText = dlg.UsePlainText;
                    Config.ExportChildren = dlg.IncludeChildren;
                    Config.ExportCustomSymbols = dlg.UseMappings;
                    Config.ExportIncludeAttributes = dlg.IncludeAttributes;
                    Config.ExportLimitCaches = dlg.CacheLimit;
                    Config.ExportLimitLogs = dlg.LogLimit;
                    Config.ExportPaperlessOptions = dlg.IsPaperless;
                    Config.ExportWaypointDescMode = dlg.DescMode;
                    Config.ExportWaypointNameMode = dlg.NameMode;
                    SaveWaypointMappings (dlg.WaypointMappings);
                    edlg.Start (dlg.Filename, CacheList.UnfilteredCaches, dlg.WaypointMappings, m_app.CacheStore);
                    RecentManager manager = RecentManager.Default;
                    manager.AddItem ("file://" + dlg.Filename);
                } else {
                    edlg.Destroy ();
                }
                dlg.Destroy ();
            } catch (Exception e) {
                //ShowException (e);
                System.Console.WriteLine(e.Message);
                System.Console.WriteLine(e.StackTrace);
                edlg.Destroy ();
            }
        }
Пример #12
0
        public void ExportFindsGPX()
        {
            GPXWriter writer = new GPXWriter ();
            writer.IsMyFinds = true;
            writer.MyFindsOwner = m_app.OwnerIDs[0];
            ExportProgressDialog edlg = new ExportProgressDialog (writer);
            edlg.AutoClose = Config.AutoCloseWindows;

            try {
                FileChooserDialog dlg = new FileChooserDialog (Catalog.GetString (" Export Finds GPX File"), this, FileChooserAction.Save, Catalog.GetString ("Cancel"), ResponseType.Cancel, Catalog.GetString ("Export"), ResponseType.Accept);
                dlg.SetCurrentFolder (System.Environment.GetFolderPath (System.Environment.SpecialFolder.MyDocuments));
                dlg.CurrentName = "finds.gpx";
                FileFilter filter = new FileFilter ();
                filter.Name = "GPX Files";
                filter.AddPattern ("*.gpx");

                dlg.AddFilter (filter);

                if (dlg.Run () == (int)ResponseType.Accept) {
                    dlg.Hide ();
                    edlg.Icon = this.Icon;
                    edlg.Start (dlg.Filename, m_app.CacheStore.GetFinds(), GPSProfileList.GetDefaultMappings(), m_app.CacheStore);
                    RecentManager manager = RecentManager.Default;
                    manager.AddItem ("file://" + dlg.Filename);
                } else {
                    edlg.Destroy ();
                }
                dlg.Destroy ();
            } catch (Exception e) {
                OCMApp.ShowException(e);
                edlg.Hide ();
            }
        }
Пример #13
0
        internal override void WriteWPTDetails(XmlWriter writer, GPXWriter gpx)
        {
            base.WriteWPTDetails(writer, gpx);
            if (!gpx.IncludeGroundSpeakExtensions)
            {
                return;
            }
            writer.WriteStartElement(CACHE_PREFIX, "cache", GPXWriter.NS_CACHE);
            if (String.IsNullOrEmpty(CacheID))
            {
                writer.WriteAttributeString("id", gpx.GetNextGUID().ToString());
            }
            else
            {
                writer.WriteAttributeString("id", CacheID);
            }
            writer.WriteAttributeString("available", Available.ToString());
            writer.WriteAttributeString("archived", Archived.ToString());
            // Temp until smart-tag like support
            if (HasCorrected)
            {
                writer.WriteElementString(CACHE_PREFIX, "name", GPXWriter.NS_CACHE, "(*) " + CacheName);
            }
            else
            {
                writer.WriteElementString(CACHE_PREFIX, "name", GPXWriter.NS_CACHE, CacheName);
            }
            writer.WriteElementString(CACHE_PREFIX, "placed_by", GPXWriter.NS_CACHE, PlacedBy);
            writer.WriteStartElement(CACHE_PREFIX, "owner", GPXWriter.NS_CACHE);
            writer.WriteAttributeString("id", OwnerID);
            writer.WriteString(CacheOwner);
            writer.WriteEndElement();
            writer.WriteElementString(CACHE_PREFIX, "type", GPXWriter.NS_CACHE, GetCTypeString(TypeOfCache));
            writer.WriteElementString(CACHE_PREFIX, "container", GPXWriter.NS_CACHE, Container);
            List <CacheAttribute> attrs = gpx.GetAttributes(this.Name);

            writer.WriteStartElement(CACHE_PREFIX, "attributes", GPXWriter.NS_CACHE);
            foreach (CacheAttribute curr in attrs)
            {
                writer.WriteStartElement(CACHE_PREFIX, "attribute", GPXWriter.NS_CACHE);
                if (!String.IsNullOrEmpty(curr.ID))
                {
                    writer.WriteAttributeString("id", curr.ID);
                }
                if (curr.Include)
                {
                    writer.WriteAttributeString("inc", "1");
                }
                else
                {
                    writer.WriteAttributeString("inc", "0");
                }
                writer.WriteString(curr.AttrValue);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            writer.WriteElementString(CACHE_PREFIX, "difficulty", GPXWriter.NS_CACHE, Difficulty.ToString("0.#", CultureInfo.InvariantCulture));
            writer.WriteElementString(CACHE_PREFIX, "terrain", GPXWriter.NS_CACHE, Terrain.ToString("0.#", CultureInfo.InvariantCulture));
            writer.WriteElementString(CACHE_PREFIX, "country", GPXWriter.NS_CACHE, Country);
            writer.WriteElementString(CACHE_PREFIX, "state", GPXWriter.NS_CACHE, State);
            StringBuilder shortDescription = new StringBuilder();

            if (HasCorrected)
            {
                shortDescription.Append(Catalog.GetString("Original Coordinate:"));
                shortDescription.Append(Utilities.getCoordString(OrigLat, OrigLon));
                shortDescription.Append("<br/>");
            }
            if (gpx.WriteAttributes)
            {
                attrs = gpx.GetAttributes(this.Name);
                foreach (CacheAttribute curr in attrs)
                {
                    if (curr.Include)
                    {
                        shortDescription.Append(Catalog.GetString("Y:"));
                    }
                    else
                    {
                        shortDescription.Append(Catalog.GetString("N:"));
                    }
                    shortDescription.Append(curr.AttrValue);
                    shortDescription.Append("<br/>");
                }
                if (attrs.Count > 0)
                {
                    shortDescription.Append("<hr noshade/>");
                }
            }
            if (!String.IsNullOrEmpty(Notes))
            {
                shortDescription.Append(Notes);
                shortDescription.Append("<hr noshade/>");
            }
            shortDescription.Append(ShortDesc);
            writer.WriteStartElement(CACHE_PREFIX, "short_description", GPXWriter.NS_CACHE);
            writer.WriteAttributeString("html", "True");
            if (gpx.HTMLOutput == HTMLMode.GARMIN)
            {
                writer.WriteCData(Utilities.HTMLtoGarmin(shortDescription.ToString()));
            }
            else if (gpx.HTMLOutput == HTMLMode.PLAINTEXT)
            {
                writer.WriteCData(Utilities.HTMLtoText(shortDescription.ToString()));
            }
            else
            {
                writer.WriteCData(shortDescription.ToString());
            }
            writer.WriteEndElement();
            writer.WriteStartElement(CACHE_PREFIX, "long_description", GPXWriter.NS_CACHE);
            writer.WriteAttributeString("html", "True");
            if (gpx.HTMLOutput == HTMLMode.GARMIN)
            {
                writer.WriteCData(Utilities.HTMLtoGarmin(LongDesc));
            }
            else if (gpx.HTMLOutput == HTMLMode.PLAINTEXT)
            {
                writer.WriteCData(Utilities.HTMLtoText(LongDesc));
            }
            else
            {
                writer.WriteCData(LongDesc);
            }
            writer.WriteEndElement();
            writer.WriteStartElement(CACHE_PREFIX, "encoded_hints", GPXWriter.NS_CACHE);
            writer.WriteAttributeString("html", "True");
            if (gpx.HTMLOutput == HTMLMode.GARMIN || gpx.HTMLOutput == HTMLMode.PLAINTEXT)
            {
                writer.WriteCData(Utilities.HTMLtoText(Hint));
            }
            else
            {
                writer.WriteCData(Hint);
            }
            writer.WriteEndElement();
            writer.WriteStartElement(CACHE_PREFIX, "logs", GPXWriter.NS_CACHE);
            if (gpx.IsMyFinds)
            {
                CacheLog log = gpx.CacheStore.GetLastFindLogBy(this.Name, gpx.MyFindsOwner);
                if (log.LogStatus == "find")
                {
                    log.LogStatus = "Found it";
                }
                log.WriteToGPX(writer);
            }
            else
            {
                List <CacheLog> logs   = gpx.GetCacheLogs(this.Name);
                int             iCount = 0;
                foreach (CacheLog log in logs)
                {
                    if ((iCount >= gpx.LogLimit) && (gpx.LogLimit != -1))
                    {
                        break;
                    }
                    else
                    {
                        log.WriteToGPX(writer);
                    }
                    iCount++;
                }
            }
            writer.WriteEndElement();
            writer.WriteStartElement(CACHE_PREFIX, "travelbugs", GPXWriter.NS_CACHE);
            List <TravelBug> bugs = gpx.GetTravelBugs(this.Name);

            foreach (TravelBug bug in bugs)
            {
                bug.WriteToGPX(writer);
            }
            writer.WriteEndElement();
            writer.WriteEndElement();
        }
Пример #14
0
 public void RunCommand()
 {
     string cmd = m_command;
     if (cmd.Contains("%gpx%"))
     {
         UIMonitor mon = UIMonitor.getInstance();
         GPXWriter writer = new GPXWriter();
         String tempPath = System.IO.Path.GetTempPath();
         String tempFile = tempPath + "ocm_export.gpx";
         ExportProgressDialog dlg = new ExportProgressDialog(writer);
         dlg.AutoClose = true;
         dlg.Title = Catalog.GetString("Preparing GPX File");
         dlg.WaypointsOnly = true;
         dlg.CompleteCommand = m_command.Replace("%gpx%", tempFile);
         dlg.Start(tempFile, mon.GetVisibleCacheList(), GPSProfileList.GetDefaultMappings());
     }
     if (cmd.Contains("%selected%"))
     {
         UIMonitor mon = UIMonitor.getInstance();
         if (mon.SelectedCache == null)
         {
             MessageDialog edlg = new MessageDialog(null, DialogFlags.Modal,
                                                   MessageType.Error, ButtonsType.Ok,
                                                   Catalog.GetString("No cache selected."));
             edlg.Run();
             edlg.Hide();
             edlg.Dispose();
             return;
         }
         GPXWriter writer = new GPXWriter();
         String tempPath = System.IO.Path.GetTempPath();
         String tempFile = tempPath + "ocm_export.gpx";
         ExportProgressDialog dlg = new ExportProgressDialog(writer);
         dlg.AutoClose = true;
         dlg.Title = Catalog.GetString("Preparing GPX File");
         dlg.WaypointsOnly = true;
         dlg.CompleteCommand = m_command.Replace("%selected%", tempFile);
         List<Geocache> cache = new List<Geocache>();
         cache.Add(mon.SelectedCache);
         dlg.Start(tempFile, cache, GPSProfileList.GetDefaultMappings());
     }
     else if (cmd.Contains("%finds%"))
     {
         UIMonitor mon = UIMonitor.getInstance();
         GPXWriter writer = new GPXWriter();
         writer.IsMyFinds = true;
         writer.MyFindsOwner = mon.OwnerID;
         String tempPath = System.IO.Path.GetTempPath();
         String tempFile = tempPath + "ocm_finds.gpx";
         ExportProgressDialog dlg = new ExportProgressDialog(writer);
         dlg.AutoClose = true;
         dlg.Title = Catalog.GetString("Preparing GPX File");
         dlg.WaypointsOnly = true;
         dlg.CompleteCommand = m_command.Replace("%finds%", tempFile);
         dlg.Start(tempFile, Engine.getInstance().Store.GetFinds(), GPSProfileList.GetDefaultMappings());
     }
     else
     {
         Process.Start(Utilities.StringToStartInfo(m_command));
     }
 }