protected virtual bool AddGeocacheImage(Framework.Data.GeocacheImage l) { bool result = false; if (_geocacheImgsEmpty) { Core.GeocacheImages.Add(l); result = true; } else { Framework.Data.GeocacheImage oldwp = Utils.DataAccess.GetGeocacheImage(Core.GeocacheImages, l.ID); if (oldwp == null) { Core.GeocacheImages.Add(l); result = true; } else { if (l.DataFromDate >= l.DataFromDate) { Utils.DataAccess.UpdateGeocacheImageData(oldwp, l); } } } return(result); }
public void OnGeocacheImageRemoved(Framework.Data.GeocacheImage wp) { if (!_updating && GeocacheImageRemoved != null) { GeocacheImageRemoved(this, new Framework.EventArguments.GeocacheImageEventArgs(wp)); } OnListDataChanged(); }
public override void Remove(object value) { Framework.Data.GeocacheImage wp = value as Framework.Data.GeocacheImage; if (wp != null) { RemoveAt(IndexOf(wp)); } }
public void OnDataChanged(Framework.Data.GeocacheImage wp) { _dataChanged = true; if (!_updating && DataChanged != null) { DataChanged(this, new Framework.EventArguments.GeocacheImageEventArgs(wp)); _dataChanged = false; wp.IsDataChanged = false; } }
public static bool UpdateGeocacheImageData(Framework.Data.GeocacheImage l, Framework.Data.GeocacheImage newData) { bool result = false; if (l.ID == newData.ID) { l.UpdateFrom(newData); result = true; } return(result); }
public override void RemoveAt(int index) { if (index >= 0 && index < Count) { Framework.Data.GeocacheImage wp = this[index] as Framework.Data.GeocacheImage; //grouping (_geocacheImageGroups[wp.GeocacheCode ?? ""] as Hashtable).Remove(wp.ID); //end grouping _qaItems.Remove(wp.ID); wp.DataChanged -= new EventArguments.GeocacheImageEventHandler(gc_DataChanged); base.RemoveAt(index); OnGeocacheImageRemoved(wp); } }
public static bool AddGeocacheImage(Framework.Interfaces.ICore core, Framework.Data.GeocacheImage l) { bool result = false; Framework.Data.GeocacheImage oldwp = DataAccess.GetGeocacheImage(core.GeocacheImages, l.ID); if (oldwp == null) { core.GeocacheImages.Add(l); result = true; } else { if (l.DataFromDate >= oldwp.DataFromDate) { DataAccess.UpdateGeocacheImageData(oldwp, l); } } return(result); }
public static Framework.Data.GeocacheImage GeocacheImage(Framework.Interfaces.ICore core, OKAPIService.GeocacheImage img, string GeocacheCode) { Framework.Data.GeocacheImage result = null; if (img != null) { Framework.Data.GeocacheImage tmp = DataAccess.GetGeocacheImage(core.GeocacheImages, img.uuid); result = new Framework.Data.GeocacheImage(); if (tmp != null) { result.UpdateFrom(tmp); } result.ID = img.uuid; result.DataFromDate = DateTime.Now; result.GeocacheCode = GeocacheCode; result.Name = img.caption; result.Url = img.url; result.ThumbUrl = img.thumb_url; result.MobileUrl = img.thumb_url; result.Description = ""; } return(result); }
public static Framework.Data.GeocacheImage GeocacheImage(Framework.Interfaces.ICore core, LiveV6.ImageData img, string GeocacheCode) { Framework.Data.GeocacheImage result = null; if (img != null) { Framework.Data.GeocacheImage tmp = DataAccess.GetGeocacheImage(core.GeocacheImages, img.ImageGuid.ToString()); result = new Framework.Data.GeocacheImage(); if (tmp != null) { result.UpdateFrom(tmp); } result.ID = img.ImageGuid.ToString(); result.DataFromDate = DateTime.Now; result.GeocacheCode = GeocacheCode; result.Name = img.Name; result.Url = img.Url; result.ThumbUrl = img.ThumbUrl; result.MobileUrl = img.MobileUrl; result.Description = img.Description; } return(result); }
public override int Add(object value) { int result; Framework.Data.GeocacheImage wp = value as Framework.Data.GeocacheImage; if (wp != null) { _qaItems[wp.ID] = wp; //grouping if (_geocacheImageGroups[wp.GeocacheCode ?? ""] == null) { _geocacheImageGroups[wp.GeocacheCode ?? ""] = new Hashtable(); } (_geocacheImageGroups[wp.GeocacheCode ?? ""] as Hashtable)[wp.ID] = wp; //end grouping _sorted = false; result = base.Add(wp); wp.DataChanged += new EventArguments.GeocacheImageEventHandler(gc_DataChanged); OnGeocacheImageAdded(wp); } else { //for now, only supported between begin and end update List <GeocacheImage> lgs = value as List <GeocacheImage>; if (lgs != null) { _batchAddition = lgs; result = 0; } else { result = -1; } } return(result); }
private bool insertFromDatabase(bool overwrite) { bool result = false; try { int lsize = sizeof(long); byte[] memBuffer = new byte[10 * 1024 * 1024]; using (MemoryStream ms = new MemoryStream(memBuffer)) using (BinaryReader br = new BinaryReader(ms)) using (FileCollection fc = new FileCollection(_selectedInsertFromFilename)) { int gcCount = 0; int logCount = 0; int logimgCount = 0; int geocacheimgCount = 0; int wptCount = 0; int usrwptCount = 0; Hashtable htInsertedGeocaches = new Hashtable(); Hashtable htInsertedLogs = new Hashtable(); XmlDocument doc = new XmlDocument(); doc.Load(fc.DatabaseInfoFilename); XmlElement root = doc.DocumentElement; gcCount = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText); logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText); logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText); wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText); usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText); if (root.SelectSingleNode("GeocacheImagesCount") != null) { geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").InnerText); } DateTime nextUpdateTime = DateTime.MinValue; RecordInfo ri = new RecordInfo(); using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0)) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0)) { int index = 0; FileStream fs = fc._fsGeocaches; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free //ignore fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString().Substring(2); bool newGeocache; Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, ri.ID); if (gc == null) { gc = new Framework.Data.Geocache(); htInsertedGeocaches.Add(ri.ID, gc); newGeocache = true; } else { if (overwrite || htInsertedGeocaches[ri.ID] != null) { newGeocache = false; } else { continue; } } gc.BeginUpdate(); try { gc.Code = ri.ID; gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.LongDescription = br.ReadString(); gc.LongDescriptionInHtml = br.ReadBoolean(); } catch { } gc.EndUpdate(); if (newGeocache) { Core.Geocaches.Add(gc); } } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newGeocache; Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, ri.ID); if (gc == null) { gc = new Framework.Data.Geocache(); htInsertedGeocaches.Add(ri.ID, gc); newGeocache = true; } else { if (overwrite || htInsertedGeocaches[ri.ID] != null) { newGeocache = false; } else { continue; } } gc.BeginUpdate(); try { gc.Code = ri.ID; gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32()); gc.CustomCoords = br.ReadBoolean(); gc.Country = br.ReadString(); if (br.ReadBoolean()) { gc.CustomLat = br.ReadDouble(); gc.CustomLon = br.ReadDouble(); } gc.Difficulty = br.ReadDouble(); gc.EncodedHints = br.ReadString(); gc.Favorites = br.ReadInt32(); gc.Flagged = br.ReadBoolean(); gc.Found = br.ReadBoolean(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.MemberOnly = br.ReadBoolean(); gc.Municipality = br.ReadString(); gc.Name = br.ReadString(); gc.Notes = br.ReadString(); gc.Owner = br.ReadString(); gc.OwnerId = br.ReadString(); gc.PersonaleNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); gc.Locked = br.ReadBoolean(); Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); } catch { } gc.EndUpdate(); if (newGeocache) { Core.Geocaches.Add(gc); } index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; nextUpdateTime = DateTime.MinValue; FileStream fs = fc._fsLogs; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString().Substring(2); fs.Position = ri.Offset + ri.Length; bool newLog; bool logComplete = true; Framework.Data.Log log = Utils.DataAccess.GetLog(Core.Logs, ri.ID); if (log == null) { newLog = true; log = htInsertedLogs[ri.ID] as Framework.Data.Log; if (log == null) { log = new Framework.Data.Log(); htInsertedLogs.Add(ri.ID, log); logComplete = false; } else { logComplete = true; } } else { if (overwrite) { newLog = false; } else { continue; } } log.BeginUpdate(); try { log.ID = ri.ID; log.TBCode = br.ReadString(); log.FinderId = br.ReadString(); log.Text = br.ReadString(); log.Encoded = br.ReadBoolean(); } catch { } log.EndUpdate(); if (newLog && logComplete && htInsertedLogs[ri.ID] != null) { if (htInsertedGeocaches[log.GeocacheCode ?? ""] != null || Utils.DataAccess.GetGeocache(Core.Geocaches, log.GeocacheCode ?? "") != null) { Core.Logs.Add(log); } htInsertedLogs.Remove(ri.ID); } } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newLog; bool logComplete = true; Framework.Data.Log log = Utils.DataAccess.GetLog(Core.Logs, ri.ID); if (log == null) { newLog = true; log = htInsertedLogs[ri.ID] as Framework.Data.Log; if (log == null) { log = new Framework.Data.Log(); htInsertedLogs.Add(ri.ID, log); logComplete = false; } else { logComplete = true; } } else { if (overwrite) { newLog = false; } else { continue; } } log.BeginUpdate(); try { log.ID = ri.ID; log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Finder = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32()); } catch { } log.EndUpdate(); if (newLog && logComplete && htInsertedLogs[ri.ID] != null) { //check if geocache is present if (htInsertedGeocaches[log.GeocacheCode ?? ""] != null || Utils.DataAccess.GetGeocache(Core.Geocaches, log.GeocacheCode ?? "") != null) { Core.Logs.Add(log); } htInsertedLogs.Remove(ri.ID); } index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(fc.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.Waypoint wp = Utils.DataAccess.GetWaypoint(Core.Waypoints, ri.ID); if (wp == null) { newWp = true; wp = new Framework.Data.Waypoint(); } else { if (overwrite) { newWp = false; } else { continue; } } wp.BeginUpdate(); try { wp.Code = ri.ID; wp.Comment = br.ReadString(); wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.ID = br.ReadString(); if (br.ReadBoolean()) { wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); } wp.Name = br.ReadString(); wp.Time = DateTime.Parse(br.ReadString()); wp.Url = br.ReadString(); wp.UrlName = br.ReadString(); wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32()); } catch { } wp.EndUpdate(); if (newWp) { if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null) { Core.Waypoints.Add(wp); } } index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(fc.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.LogImage li = Utils.DataAccess.GetLogImage(Core.LogImages, ri.ID); if (li == null) { newWp = true; li = new Framework.Data.LogImage(); } else { if (overwrite) { newWp = false; } else { continue; } } li.BeginUpdate(); try { li.ID = ri.ID; li.DataFromDate = DateTime.Parse(br.ReadString()); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); } catch { } li.EndUpdate(); if (newWp) { if (Utils.DataAccess.GetLog(Core.Logs, li.LogID ?? "") != null) { Core.LogImages.Add(li); } } index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(fc.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.GeocacheImage wp = Utils.DataAccess.GetGeocacheImage(Core.GeocacheImages, ri.ID); if (wp == null) { newWp = true; wp = new Framework.Data.GeocacheImage(); } else { if (overwrite) { newWp = false; } else { continue; } } wp.BeginUpdate(); try { wp.ID = ri.ID; wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.GeocacheCode = br.ReadString(); wp.Description = br.ReadString(); wp.Name = br.ReadString(); wp.Url = br.ReadString(); wp.MobileUrl = br.ReadString(); wp.ThumbUrl = br.ReadString(); } catch { } wp.EndUpdate(); if (newWp) { if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null) { Core.GeocacheImages.Add(wp); } } index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, index); procStep = 0; } } } } } { using (FileStream fs = File.Open(fc.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.UserWaypoint wp = Utils.DataAccess.GetUserWaypoint(Core.UserWaypoints, int.Parse(ri.ID)); if (wp == null) { newWp = true; wp = new Framework.Data.UserWaypoint(); } else { if (overwrite) { newWp = false; } else { continue; } } wp.BeginUpdate(); try { wp.ID = int.Parse(ri.ID); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); } catch { } if (newWp) { if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null) { Core.UserWaypoints.Add(wp); } } wp.EndUpdate(); } } } } } } result = true; } catch { } return result; }
private void copyToFolderThreadMethod() { DateTime nextUpdate = DateTime.Now.AddSeconds(2); using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_CREATINGFOLDER, STR_CREATINGFOLDER, _gcList.Count, 0, true)) { try { if (!Directory.Exists(PluginSettings.Instance.CreateFolderPath)) { Directory.CreateDirectory(PluginSettings.Instance.CreateFolderPath); } string imgFolder = Path.Combine(PluginSettings.Instance.CreateFolderPath, "GeocachePhotos"); if (!Directory.Exists(imgFolder)) { Directory.CreateDirectory(imgFolder); } if (PluginSettings.Instance.ClearBeforeCopy) { string[] fls = Directory.GetFiles(imgFolder); if (fls != null) { foreach (string f in fls) { File.Delete(f); } } fls = Directory.GetDirectories(imgFolder); if (fls != null) { foreach (string f in fls) { Directory.Delete(f, true); } } } int index = 0; foreach (Framework.Data.Geocache gc in _gcList) { List <string> linkList = new List <string>(); bool folderCreated = false; List <Framework.Data.GeocacheImage> imgList = DataAccess.GetGeocacheImages(Core.GeocacheImages, gc.Code); if (imgList != null) { foreach (Framework.Data.GeocacheImage img in imgList) { linkList.Add(img.Url); } } List <string> linksInDescr; lock (_lockDBObject) { linksInDescr = Utils.ImageSupport.GetImageUrlsFromGeocache(gc); } foreach (string lnk in linksInDescr) { if (!linkList.Contains(lnk)) { if (!PluginSettings.Instance.CopyNotInDescription) { linkList.Add(lnk); } } else if (PluginSettings.Instance.CopyNotInDescription) { //remove the entries that are within the description linkList.Remove(lnk); } } if (linkList.Count > 0) { int imgIndex = 1; string cacheFolder = ""; foreach (string link in linkList) { string fn = Utils.ImageSupport.Instance.GetImagePath(link); if (link != fn) { if (!folderCreated) { cacheFolder = Path.Combine(imgFolder, gc.Code[gc.Code.Length - 1].ToString()); if (!Directory.Exists(cacheFolder)) { Directory.CreateDirectory(cacheFolder); } cacheFolder = Path.Combine(cacheFolder, gc.Code[gc.Code.Length - 2].ToString()); if (!Directory.Exists(cacheFolder)) { Directory.CreateDirectory(cacheFolder); } cacheFolder = Path.Combine(cacheFolder, gc.Code); if (!Directory.Exists(cacheFolder)) { Directory.CreateDirectory(cacheFolder); } folderCreated = true; } string imgname = imgIndex.ToString(); if (imgList != null) { Framework.Data.GeocacheImage img = (from a in imgList where a.Url == link select a).FirstOrDefault(); if (img != null) { imgname = string.Format("{1}{0}", imgIndex, getValidNameForFile(img.Name)); } } string dst = Path.Combine(cacheFolder, string.Format("{0}{1}", imgname, Path.GetExtension(fn))); if (!File.Exists(dst)) { File.Copy(fn, dst); } } imgIndex++; } } index++; if (DateTime.Now >= nextUpdate) { if (!progress.UpdateProgress(STR_CREATINGFOLDER, STR_CREATINGFOLDER, _gcList.Count, index)) { break; } nextUpdate = DateTime.Now.AddSeconds(2); } } } catch { } } }
private void readGeocacheImageData(RecordInfo ri, MemoryStream ms, BinaryReader br) { _geocacheimgsInDB.Add(ri.ID, ri); Framework.Data.GeocacheImage l = new Framework.Data.GeocacheImage(); l.ID = ri.ID; l.DataFromDate = DateTimeFromLong(br.ReadInt64()); l.GeocacheCode = br.ReadString(); ms.Position = 220; l.Url = br.ReadString(); ms.Position = 420; l.MobileUrl = br.ReadString(); ms.Position = 520; l.ThumbUrl = br.ReadString(); ms.Position = 620; l.Name = br.ReadString(); ms.Position = 800; l.Description = br.ReadString(); l.Saved = true; l.IsDataChanged = false; Core.GeocacheImages.Add(l); }
public override bool LoadGeocacheImages(List<Framework.Data.GeocacheImage> geocacheimgs) { bool result = true; int index = 0; int procStep = 0; if (File.Exists(_fileCollection.DatabaseInfoFilename)) { int lsize = sizeof(long); byte[] memBuffer = new byte[5 * 1024]; using (MemoryStream ms = new MemoryStream(memBuffer)) using (BinaryReader br = new BinaryReader(ms)) { int geocacheimgCount = 0; XmlDocument doc = new XmlDocument(); doc.Load(_fileCollection.DatabaseInfoFilename); XmlElement root = doc.DocumentElement; if (root.SelectSingleNode("GeocacheImagesCount") != null) { geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").InnerText); } using (FileStream fs = File.Open(_fileCollection.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.GeocacheImage li = new Framework.Data.GeocacheImage(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; li.ID = br.ReadString(); ri.ID = li.ID; li.DataFromDate = DateTime.Parse(br.ReadString()); li.GeocacheCode = br.ReadString(); li.Description = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); li.MobileUrl = br.ReadString(); li.ThumbUrl = br.ReadString(); li.Saved = true; li.IsDataChanged = false; geocacheimgs.Add(li); index++; procStep++; if (procStep >= 2000) { UpdateLoadingInBackgroundProgress(STR_LOADING_GEOCACHEIMAGES_BG, geocacheimgCount, index); procStep = 0; } } _fileCollection._geocacheimgsInDB.Add(ri.ID, ri); } } } } return result; }
public static Framework.Data.GeocacheImage GeocacheImage(Framework.Interfaces.ICore core, LiveV6.ImageData img, string GeocacheCode) { Framework.Data.GeocacheImage result = null; if (img != null) { Framework.Data.GeocacheImage tmp = DataAccess.GetGeocacheImage(core.GeocacheImages, img.ImageGuid.ToString()); result = new Framework.Data.GeocacheImage(); if (tmp != null) { result.UpdateFrom(tmp); } result.ID = img.ImageGuid.ToString(); result.DataFromDate = DateTime.Now; result.GeocacheCode = GeocacheCode; result.Name = img.Name; result.Url = img.Url; result.ThumbUrl = img.ThumbUrl; result.MobileUrl = img.MobileUrl; result.Description = img.Description; } return result; }
protected override void ImportMethod() { try { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, _gcList.Count, 0, true)) { int totalcount = _gcList.Count; using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken))) { int index = 0; while (_gcList.Count > 0) { if (PluginSettings.Instance.AdditionalDelayBetweenImageImport > 0) { Thread.Sleep(PluginSettings.Instance.AdditionalDelayBetweenImageImport); } var resp = client.Client.GetImagesForGeocache(client.Token, _gcList[0].Code); if (resp.Status.StatusCode == 0) { if (resp.Images != null) { List <string> ids = new List <string>(); foreach (var img in resp.Images) { if (img.Url.IndexOf("/cache/log/") < 0) { Framework.Data.GeocacheImage gcImg = Utils.API.Convert.GeocacheImage(Core, img, _gcList[0].Code); AddGeocacheImage(gcImg); ids.Add(gcImg.ID); } } List <Framework.Data.GeocacheImage> allImages = Utils.DataAccess.GetGeocacheImages(Core.GeocacheImages, _gcList[0].Code); foreach (Framework.Data.GeocacheImage gim in allImages) { if (!ids.Contains(gim.ID)) { Core.GeocacheImages.Remove(gim); } } } if (PluginSettings.Instance.DeselectGeocacheAfterUpdate) { _gcList[0].Selected = false; } index++; if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, totalcount, index)) { break; } _gcList.RemoveAt(0); if (_gcList.Count > 0) { Thread.Sleep(3000); } } else { _errormessage = resp.Status.StatusMessage; break; } } } } } catch (Exception e) { _errormessage = e.Message; } }
public static Framework.Data.GeocacheImage GeocacheImage(Framework.Interfaces.ICore core, OKAPIService.GeocacheImage img, string GeocacheCode) { Framework.Data.GeocacheImage result = null; if (img != null) { Framework.Data.GeocacheImage tmp = DataAccess.GetGeocacheImage(core.GeocacheImages, img.uuid); result = new Framework.Data.GeocacheImage(); if (tmp != null) { result.UpdateFrom(tmp); } result.ID = img.uuid; result.DataFromDate = DateTime.Now; result.GeocacheCode = GeocacheCode; result.Name = img.caption; result.Url = img.url; result.ThumbUrl = img.thumb_url; result.MobileUrl = img.thumb_url; result.Description = ""; } return result; }
public override bool Load(bool geocachesOnly) { bool result = true; if (File.Exists(_fileCollection.DatabaseInfoFilename)) { int lsize = sizeof(long); byte[] memBuffer = new byte[10 * 1024 * 1024]; using (MemoryStream ms = new MemoryStream(memBuffer)) using (BinaryReader br = new BinaryReader(ms)) { int gcCount = 0; int logCount = 0; int logimgCount = 0; int geocacheimgCount = 0; int wptCount = 0; int usrwptCount = 0; XmlDocument doc = new XmlDocument(); doc.Load(_fileCollection.DatabaseInfoFilename); XmlElement root = doc.DocumentElement; gcCount = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText); logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText); logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText); wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText); usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText); if (root.SelectSingleNode("GeocacheImagesCount") != null) { geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").InnerText); } DateTime nextUpdateTime = DateTime.MinValue; using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0)) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0)) { int index = 0; //int procStep = 0; List<Framework.Data.Geocache> gcList = new List<Framework.Data.Geocache>(); FileStream fs = _fileCollection._fsGeocaches; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { //lazy loading ri.FreeSlot = false; int readCount = Math.Min(32, (int)(ri.Length - lsize - 1)); fs.Read(memBuffer, 0, readCount); ms.Position = 0; ri.ID = br.ReadString(); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.Geocache gc = new Framework.Data.Geocache(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; gc.Code = br.ReadString(); ri.ID = gc.Code; gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32()); gc.CustomCoords = br.ReadBoolean(); gc.Country = br.ReadString(); if (br.ReadBoolean()) { gc.CustomLat = br.ReadDouble(); gc.CustomLon = br.ReadDouble(); } gc.Difficulty = br.ReadDouble(); gc.EncodedHints = br.ReadString(); gc.Favorites = br.ReadInt32(); gc.Flagged = br.ReadBoolean(); gc.Found = br.ReadBoolean(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.MemberOnly = br.ReadBoolean(); gc.Municipality = br.ReadString(); gc.Name = br.ReadString(); gc.Notes = br.ReadString(); gc.Owner = br.ReadString(); gc.OwnerId = br.ReadString(); gc.PersonaleNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); gc.Locked = br.ReadBoolean(); Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); gc.Saved = true; gc.IsDataChanged = false; //gcList.Add(gc); Core.Geocaches.Add(gc); index++; //procStep++; //if (procStep >= 1000) if (DateTime.Now>=nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); //procStep = 0; } } _fileCollection._geocachesInDB.Add(ri.ID, ri); } //Core.Geocaches.Add(gcList); } if (!geocachesOnly) { using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; nextUpdateTime = DateTime.MinValue; List<Framework.Data.Log> lgList = new List<Framework.Data.Log>(); FileStream fs = _fileCollection._fsLogs; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { //lazy loading ri.FreeSlot = false; int readCount = Math.Min(32, (int)(ri.Length - lsize - 1)); fs.Read(memBuffer, 0, readCount); ms.Position = 0; ri.ID = br.ReadString(); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.Log log = new Framework.Data.Log(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; log.ID = br.ReadString(); ri.ID = log.ID; log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Finder = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32()); log.Saved = true; log.IsDataChanged = false; lgList.Add(log); index++; //procStep++; //if (procStep >= 1000) if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); //procStep = 0; } } _fileCollection._logsInDB.Add(ri.ID, ri); } Core.Logs.Add(lgList); } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; List<Framework.Data.Waypoint> wptList = new List<Framework.Data.Waypoint>(); using (FileStream fs = File.Open(_fileCollection.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; wp.Code = br.ReadString(); ri.ID = wp.Code; wp.Comment = br.ReadString(); wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.ID = br.ReadString(); if (br.ReadBoolean()) { wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); } wp.Name = br.ReadString(); wp.Time = DateTime.Parse(br.ReadString()); wp.Url = br.ReadString(); wp.UrlName = br.ReadString(); wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32()); wp.Saved = true; wp.IsDataChanged = false; wptList.Add(wp); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } _fileCollection._wptsInDB.Add(ri.ID, ri); } } Core.Waypoints.Add(wptList); } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; List<Framework.Data.LogImage> lgiList = new List<Framework.Data.LogImage>(); using (FileStream fs = File.Open(_fileCollection.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.LogImage li = new Framework.Data.LogImage(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; li.ID = br.ReadString(); ri.ID = li.ID; li.DataFromDate = DateTime.Parse(br.ReadString()); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); li.Saved = true; li.IsDataChanged = false; lgiList.Add(li); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } _fileCollection._logimgsInDB.Add(ri.ID, ri); } } Core.LogImages.Add(lgiList); } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, 0)) { int index = 0; int procStep = 0; List<Framework.Data.GeocacheImage> lgiList = new List<Framework.Data.GeocacheImage>(); using (FileStream fs = File.Open(_fileCollection.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.GeocacheImage li = new Framework.Data.GeocacheImage(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; li.ID = br.ReadString(); ri.ID = li.ID; li.DataFromDate = DateTime.Parse(br.ReadString()); li.GeocacheCode = br.ReadString(); li.Description = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); li.MobileUrl = br.ReadString(); li.ThumbUrl = br.ReadString(); li.Saved = true; li.IsDataChanged = false; lgiList.Add(li); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, index); procStep = 0; } } _fileCollection._geocacheimgsInDB.Add(ri.ID, ri); } } Core.GeocacheImages.Add(lgiList); } //using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; List<Framework.Data.UserWaypoint> uwplList = new List<Framework.Data.UserWaypoint>(); using (FileStream fs = File.Open(_fileCollection.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); wp.ID = int.Parse(ri.ID); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); wp.Saved = true; wp.IsDataChanged = false; uwplList.Add(wp); index++; procStep++; if (procStep >= 1000) { //progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } _fileCollection._usrwptsInDB.Add(ri.ID, ri); } } Core.UserWaypoints.Add(uwplList); } } } } } return result; }
private bool insertFromDatabase(bool overwrite) { bool result = false; try { int lsize = sizeof(long); byte[] memBuffer = new byte[10 * 1024 * 1024]; using (MemoryStream ms = new MemoryStream(memBuffer)) using (BinaryReader br = new BinaryReader(ms)) using (FileCollection fc = new FileCollection(_selectedInsertFromFilename)) { int gcCount = 0; int logCount = 0; int logimgCount = 0; int geocacheimgCount = 0; int wptCount = 0; int usrwptCount = 0; Hashtable htInsertedGeocaches = new Hashtable(); Hashtable htInsertedLogs = new Hashtable(); XmlDocument doc = new XmlDocument(); doc.Load(fc.DatabaseInfoFilename); XmlElement root = doc.DocumentElement; gcCount = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText); logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText); logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText); wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText); usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText); if (root.SelectSingleNode("GeocacheImagesCount") != null) { geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").InnerText); } DateTime nextUpdateTime = DateTime.MinValue; RecordInfo ri = new RecordInfo(); using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0)) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0)) { int index = 0; FileStream fs = fc._fsGeocaches; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free //ignore fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString().Substring(2); bool newGeocache; Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, ri.ID); if (gc == null) { gc = new Framework.Data.Geocache(); htInsertedGeocaches.Add(ri.ID, gc); newGeocache = true; } else { if (overwrite || htInsertedGeocaches[ri.ID] != null) { newGeocache = false; } else { continue; } } gc.BeginUpdate(); try { gc.Code = ri.ID; gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.LongDescription = br.ReadString(); gc.LongDescriptionInHtml = br.ReadBoolean(); } catch { } gc.EndUpdate(); if (newGeocache) { Core.Geocaches.Add(gc); } } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newGeocache; Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, ri.ID); if (gc == null) { gc = new Framework.Data.Geocache(); htInsertedGeocaches.Add(ri.ID, gc); newGeocache = true; } else { if (overwrite || htInsertedGeocaches[ri.ID] != null) { newGeocache = false; } else { continue; } } gc.BeginUpdate(); try { gc.Code = ri.ID; gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32()); gc.CustomCoords = br.ReadBoolean(); gc.Country = br.ReadString(); if (br.ReadBoolean()) { gc.CustomLat = br.ReadDouble(); gc.CustomLon = br.ReadDouble(); } gc.Difficulty = br.ReadDouble(); gc.EncodedHints = br.ReadString(); gc.Favorites = br.ReadInt32(); gc.Flagged = br.ReadBoolean(); gc.Found = br.ReadBoolean(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.MemberOnly = br.ReadBoolean(); gc.Municipality = br.ReadString(); gc.Name = br.ReadString(); gc.Notes = br.ReadString(); gc.Owner = br.ReadString(); gc.OwnerId = br.ReadString(); gc.PersonaleNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); gc.Locked = br.ReadBoolean(); Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); } catch { } gc.EndUpdate(); if (newGeocache) { Core.Geocaches.Add(gc); } index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; nextUpdateTime = DateTime.MinValue; FileStream fs = fc._fsLogs; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString().Substring(2); fs.Position = ri.Offset + ri.Length; bool newLog; bool logComplete = true; Framework.Data.Log log = Utils.DataAccess.GetLog(Core.Logs, ri.ID); if (log == null) { newLog = true; log = htInsertedLogs[ri.ID] as Framework.Data.Log; if (log == null) { log = new Framework.Data.Log(); htInsertedLogs.Add(ri.ID, log); logComplete = false; } else { logComplete = true; } } else { if (overwrite) { newLog = false; } else { continue; } } log.BeginUpdate(); try { log.ID = ri.ID; log.TBCode = br.ReadString(); log.FinderId = br.ReadString(); log.Text = br.ReadString(); log.Encoded = br.ReadBoolean(); } catch { } log.EndUpdate(); if (newLog && logComplete && htInsertedLogs[ri.ID] != null) { if (htInsertedGeocaches[log.GeocacheCode ?? ""] != null || Utils.DataAccess.GetGeocache(Core.Geocaches, log.GeocacheCode ?? "") != null) { Core.Logs.Add(log); } htInsertedLogs.Remove(ri.ID); } } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newLog; bool logComplete = true; Framework.Data.Log log = Utils.DataAccess.GetLog(Core.Logs, ri.ID); if (log == null) { newLog = true; log = htInsertedLogs[ri.ID] as Framework.Data.Log; if (log == null) { log = new Framework.Data.Log(); htInsertedLogs.Add(ri.ID, log); logComplete = false; } else { logComplete = true; } } else { if (overwrite) { newLog = false; } else { continue; } } log.BeginUpdate(); try { log.ID = ri.ID; log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Finder = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32()); } catch { } log.EndUpdate(); if (newLog && logComplete && htInsertedLogs[ri.ID] != null) { //check if geocache is present if (htInsertedGeocaches[log.GeocacheCode ?? ""] != null || Utils.DataAccess.GetGeocache(Core.Geocaches, log.GeocacheCode ?? "") != null) { Core.Logs.Add(log); } htInsertedLogs.Remove(ri.ID); } index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(fc.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.Waypoint wp = Utils.DataAccess.GetWaypoint(Core.Waypoints, ri.ID); if (wp == null) { newWp = true; wp = new Framework.Data.Waypoint(); } else { if (overwrite) { newWp = false; } else { continue; } } wp.BeginUpdate(); try { wp.Code = ri.ID; wp.Comment = br.ReadString(); wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.ID = br.ReadString(); if (br.ReadBoolean()) { wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); } wp.Name = br.ReadString(); wp.Time = DateTime.Parse(br.ReadString()); wp.Url = br.ReadString(); wp.UrlName = br.ReadString(); wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32()); } catch { } wp.EndUpdate(); if (newWp) { if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null) { Core.Waypoints.Add(wp); } } index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(fc.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.LogImage li = Utils.DataAccess.GetLogImage(Core.LogImages, ri.ID); if (li == null) { newWp = true; li = new Framework.Data.LogImage(); } else { if (overwrite) { newWp = false; } else { continue; } } li.BeginUpdate(); try { li.ID = ri.ID; li.DataFromDate = DateTime.Parse(br.ReadString()); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); } catch { } li.EndUpdate(); if (newWp) { if (Utils.DataAccess.GetLog(Core.Logs, li.LogID ?? "") != null) { Core.LogImages.Add(li); } } index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(fc.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.GeocacheImage wp = Utils.DataAccess.GetGeocacheImage(Core.GeocacheImages, ri.ID); if (wp == null) { newWp = true; wp = new Framework.Data.GeocacheImage(); } else { if (overwrite) { newWp = false; } else { continue; } } wp.BeginUpdate(); try { wp.ID = ri.ID; wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.GeocacheCode = br.ReadString(); wp.Description = br.ReadString(); wp.Name = br.ReadString(); wp.Url = br.ReadString(); wp.MobileUrl = br.ReadString(); wp.ThumbUrl = br.ReadString(); } catch { } wp.EndUpdate(); if (newWp) { if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null) { Core.GeocacheImages.Add(wp); } } index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, index); procStep = 0; } } } } } { using (FileStream fs = File.Open(fc.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.UserWaypoint wp = Utils.DataAccess.GetUserWaypoint(Core.UserWaypoints, int.Parse(ri.ID)); if (wp == null) { newWp = true; wp = new Framework.Data.UserWaypoint(); } else { if (overwrite) { newWp = false; } else { continue; } } wp.BeginUpdate(); try { wp.ID = int.Parse(ri.ID); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); } catch { } if (newWp) { if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null) { Core.UserWaypoints.Add(wp); } } wp.EndUpdate(); } } } } } } result = true; } catch { } return(result); }