public void Geotag8352Image() { var cache = new GeoCacheLoader(8352).Load(); var client = new Client(); var imageData = client.DownloadData("http://www.geocaching.su/photos/caches/8352.jpg"); File.WriteAllBytes("D:\\8352.jpg", imageData); GpsInfoSaver.WriteLongLat(File.ReadAllBytes("D:\\8352.jpg"), cache.Latitude, cache.Longitude); }
private void savingWorker_DoWork(object sender, DoWorkEventArgs e) { var argument = e.Argument as SavingWorkerArgument; var cachesLoaded = 0; savingWorker.ReportProgress(0, "Загрузка кэшей..."); var cachesList = new List<GeoCache>(); foreach (var cacheId in caches) { if (savingWorker.CancellationPending) { e.Cancel = true; break; } var cacheEntity = new GeoCacheLoader(cacheId).Load(); if (string.IsNullOrEmpty(cacheEntity.Country)) { cacheEntity.Country = argument.CountryText; } if (string.IsNullOrEmpty(cacheEntity.State)) { cacheEntity.State = argument.RegionText; } cachesList.Add(cacheEntity); savingWorker.ReportProgress(cachesLoaded * 100 / caches.Count); cachesLoaded++; } savingWorker.ReportProgress(100, "Сохранение кэшей..."); var gpxFolderPath = argument.PoiStyle ? argument.SelectedPath : Path.Combine(argument.SelectedPath, "GPX"); if (!Directory.Exists(gpxFolderPath)) Directory.CreateDirectory(gpxFolderPath); var gpxFilePath = Path.Combine(gpxFolderPath, GetRegionFileName(argument.SelectedRegion)); var fs = File.Create(gpxFilePath); new GeoCacheListSaver(cachesList, argument.PoiStyle).Save(fs); fs.Flush(); fs.Close(); if (Settings.Default.SaveCachePhotos && !Settings.Default.SaveMinimalInfo) { savingWorker.ReportProgress(0, "Сохранение картинок..."); var imagesFolderPath = argument.PoiStyle ? argument.SelectedPath : Path.Combine(argument.SelectedPath, "GeocachePhotos"); if (!Directory.Exists(imagesFolderPath)) Directory.CreateDirectory(imagesFolderPath); var imagesSaved = 0; foreach (var cache in cachesList) { if (savingWorker.CancellationPending) { e.Cancel = true; break; } var client = new Client(); try { if (!string.IsNullOrEmpty(cache.CacheImage)) { var imageData = client.DownloadData(cache.CacheImage); var imagePath = argument.PoiStyle ? imagesFolderPath + "\\" + cache.Id + ".jpg" : GetRelateiveImagePath(imagesFolderPath, cache.FullId, 0); File.WriteAllBytes(imagePath, imageData); } if (Settings.Default.SaveTerritoryPhotos && !argument.PoiStyle) { var territoryImageIndex = 1; foreach (var territoryImage in cache.TerritoryImages) { var imageData = client.DownloadData(territoryImage); var imagePath = GetRelateiveImagePath(imagesFolderPath, cache.FullId, territoryImageIndex); File.WriteAllBytes(imagePath, imageData); territoryImageIndex++; } } savingWorker.ReportProgress(imagesSaved * 100 / cachesList.Count); } catch (WebException) { savingWorker.ReportProgress(imagesSaved * 100 / cachesList.Count, "Пропущена " + cache.Id); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка"); } imagesSaved++; } } if (argument.PoiStyle) { savingWorker.ReportProgress(99, "Сохранение POI..."); var poiPath = Path.Combine(argument.SelectedPath, "POI"); Registry.SetValue("HKEY_CURRENT_USER\\SOFTWARE\\Garmin\\POI Loader\\Settings", "Directory", argument.SelectedPath); var psi = new System.Diagnostics.ProcessStartInfo(poiLoaderPath) { Arguments = "/s /d \"" + poiPath + "\"" }; var result = System.Diagnostics.Process.Start(psi); result.WaitForExit(); var regionFile = GetRegionFileName(argument.SelectedRegion); var regionPath = Path.Combine(poiPath, regionFile); regionPath = Path.ChangeExtension(regionPath, "gpi"); if (File.Exists(regionPath)) { File.Delete(regionPath); } File.Move(Path.Combine(poiPath, "Poi.gpi"), regionPath); string[] sourceFiles = Directory.GetFiles(argument.SelectedPath, "*.*"); foreach (var sourceFile in sourceFiles) { File.Delete(sourceFile); } } }