private bool addGeocaches(Utils.ProgressBlock progress, List<Framework.Data.Geocache> gcList, List<Framework.Data.GeocacheType> typeList, XmlDocument doc, XmlElement rootDoc, string folderName, string tempFolder, List<string> fileList) { bool result = true; // //folder XmlElement folder = doc.CreateElement("Folder"); rootDoc.AppendChild(folder); XmlElement el = doc.CreateElement("name"); XmlText txt = doc.CreateTextNode(Utils.LanguageSupport.Instance.GetTranslation(folderName)); el.AppendChild(txt); folder.AppendChild(el); foreach (Framework.Data.Geocache g in gcList) { //check if style exists Framework.Data.GeocacheType gt = g.GeocacheType; string imgIcon = Utils.ImageSupport.Instance.GetImagePath(Core, Framework.Data.ImageSize.Default, gt); string destImg = Path.Combine(tempFolder, Path.GetFileName(imgIcon)); if (!typeList.Contains(gt)) { typeList.Add(gt); string mapIcon = Utils.ImageSupport.Instance.GetImagePath(Core, Framework.Data.ImageSize.Map, gt); string destFile = Path.Combine(tempFolder, Path.GetFileName(mapIcon)); string mapIconC = Utils.ImageSupport.Instance.GetImagePath(Core, Framework.Data.ImageSize.Map, gt, true); string destFileC = Path.Combine(tempFolder, Path.GetFileName(mapIconC)); if (!File.Exists(destFile)) { File.Copy(mapIcon, destFile); } if (!File.Exists(destFileC)) { File.Copy(mapIconC, destFileC); } if (!File.Exists(destImg)) { File.Copy(imgIcon, destImg); } if (!fileList.Contains(destFile)) { fileList.Add(destFile); } if (!fileList.Contains(destFileC)) { fileList.Add(destFileC); } if (!fileList.Contains(destImg)) { fileList.Add(destImg); } //adding style /* * <Style id="TNA"> * <IconStyle id="iconTNA"> * <scale>1</scale> * <Icon> * <href>http://hulmgulm.de/gc/myGoogleEarth/mrk_traditional.png</href> * </Icon> * </IconStyle> * <LabelStyle id="labelTNA"> * <scale>1</scale> * </LabelStyle> * </Style> */ XmlElement style = doc.CreateElement("Style"); rootDoc.AppendChild(style); XmlAttribute attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(string.Format("id{0}", gt.ID)); attr.AppendChild(txt); style.Attributes.Append(attr); XmlElement iconstyle = doc.CreateElement("IconStyle"); style.AppendChild(iconstyle); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(string.Format("iconid{0}", gt.ID)); attr.AppendChild(txt); iconstyle.Attributes.Append(attr); el = doc.CreateElement("scale"); txt = doc.CreateTextNode("1"); el.AppendChild(txt); iconstyle.AppendChild(el); XmlElement icon = doc.CreateElement("Icon"); iconstyle.AppendChild(icon); el = doc.CreateElement("href"); txt = doc.CreateTextNode(string.Format("Images/{0}",Path.GetFileName(mapIcon))); el.AppendChild(txt); icon.AppendChild(el); XmlElement labelstyle = doc.CreateElement("LabelStyle"); style.AppendChild(labelstyle); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(string.Format("labelid{0}", gt.ID)); attr.AppendChild(txt); labelstyle.Attributes.Append(attr); el = doc.CreateElement("scale"); txt = doc.CreateTextNode("1"); el.AppendChild(txt); labelstyle.AppendChild(el); // //corrected // style = doc.CreateElement("Style"); rootDoc.AppendChild(style); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(string.Format("idC{0}", gt.ID)); attr.AppendChild(txt); style.Attributes.Append(attr); iconstyle = doc.CreateElement("IconStyle"); style.AppendChild(iconstyle); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(string.Format("iconidC{0}", gt.ID)); attr.AppendChild(txt); iconstyle.Attributes.Append(attr); el = doc.CreateElement("scale"); txt = doc.CreateTextNode("1"); el.AppendChild(txt); iconstyle.AppendChild(el); icon = doc.CreateElement("Icon"); iconstyle.AppendChild(icon); el = doc.CreateElement("href"); txt = doc.CreateTextNode(string.Format("Images/{0}",Path.GetFileName(mapIconC))); el.AppendChild(txt); icon.AppendChild(el); labelstyle = doc.CreateElement("LabelStyle"); style.AppendChild(labelstyle); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(string.Format("labelidC{0}", gt.ID)); attr.AppendChild(txt); labelstyle.Attributes.Append(attr); el = doc.CreateElement("scale"); txt = doc.CreateTextNode("1"); el.AppendChild(txt); labelstyle.AppendChild(el); } XmlElement placemark = doc.CreateElement("Placemark"); folder.AppendChild(placemark); el = doc.CreateElement("name"); txt = doc.CreateTextNode(g.Name ?? ""); el.AppendChild(txt); placemark.AppendChild(el); el = doc.CreateElement("styleUrl"); if (g.ContainsCustomLatLon) { txt = doc.CreateTextNode(string.Format("#idC{0}", gt.ID)); } else { txt = doc.CreateTextNode(string.Format("#id{0}", gt.ID)); } el.AppendChild(txt); placemark.AppendChild(el); el = doc.CreateElement("description"); string descr = string.Format("<table width='250'><tr><td align='center'><a href='{0}'>{1}</a><br><font size='4'><b>{2}</b></font><br /><i>{3} {4}</i><br /><br /><img src='Images/{5}' /> <br /><br />{6}: {7}<br />{8}: {9}<br />{10}: {11}<br /><br />({12})<br><br></td></tr></table>", g.Url, g.Code, g.Name ?? "", HttpUtility.HtmlEncode(Utils.LanguageSupport.Instance.GetTranslation(STR_BY)), g.Owner ?? "", Path.GetFileName(destImg), HttpUtility.HtmlEncode(Utils.LanguageSupport.Instance.GetTranslation(STR_DIFFICULTY)), g.Difficulty.ToString("0.#"), HttpUtility.HtmlEncode(Utils.LanguageSupport.Instance.GetTranslation(STR_TERRAIN)), g.Terrain.ToString("0.#"), HttpUtility.HtmlEncode(Utils.LanguageSupport.Instance.GetTranslation(STR_CONTAINER)), HttpUtility.HtmlEncode(Utils.LanguageSupport.Instance.GetTranslation(g.Container.Name)), Utils.Conversion.GetCoordinatesPresentation(g.Lat, g.Lon)); txt = doc.CreateTextNode(descr); el.AppendChild(txt); placemark.AppendChild(el); el = doc.CreateElement("Snippet"); txt = doc.CreateTextNode(string.Format("<a href='{0}'>{1}</a> {2}<br>{3} {4}", g.Url, g.Code, g.Name ?? "", Utils.LanguageSupport.Instance.GetTranslation(STR_BY), g.Owner ?? "")); el.AppendChild(txt); placemark.AppendChild(el); XmlElement point = doc.CreateElement("Point"); placemark.AppendChild(point); el = doc.CreateElement("coordinates"); if (g.ContainsCustomLatLon) { txt = doc.CreateTextNode(string.Format("{0},{1}", g.CustomLon.ToString().Replace(',', '.'), g.CustomLat.ToString().Replace(',', '.'))); } else { txt = doc.CreateTextNode(string.Format("{0},{1}", g.Lon.ToString().Replace(',', '.'), g.Lat.ToString().Replace(',', '.'))); } el.AppendChild(txt); point.AppendChild(el); _indexDone++; if (_indexDone % 100 == 0) { if (!progress.UpdateProgress(STR_EXPORTINGGPX, STR_CREATINGFILE, _gcList.Count, _indexDone)) { result = false; break; } } } return result; }