public override int Add(object value) { int result; Framework.Data.UserWaypoint wp = value as Framework.Data.UserWaypoint; if (wp != null) { _qaItems[wp.ID] = wp; result = base.Add(wp); wp.DataChanged += new EventArguments.UserWaypointEventHandler(gc_DataChanged); OnUserWaypointAdded(wp); } else { //for now, only supported between begin and end update List <UserWaypoint> lgs = value as List <UserWaypoint>; if (lgs != null) { _batchAddition = lgs; result = 0; } else { result = -1; } } return(result); }
public void OnUserWaypointRemoved(Framework.Data.UserWaypoint wp) { if (!_updating && UserWaypointRemoved != null) { UserWaypointRemoved(this, new Framework.EventArguments.UserWaypointEventArgs(wp)); } OnListDataChanged(); }
private void button4_Click(object sender, EventArgs e) { WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem; Framework.Data.Location ll = Utils.Conversion.StringToLocation(textBox8.Text); if (Core.ActiveGeocache != null && wpi != null && wpi.WP.ID <= 0) { if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true)) { try { Utils.API.LiveV6.SaveUserWaypointResponse resp = null; Cursor = Cursors.WaitCursor; try { using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(Core)) { var req = new Utils.API.LiveV6.SaveUserWaypointRequest(); req.AccessToken = api.Token; req.CacheCode = Core.ActiveGeocache.Code; req.Description = textBox2.Text; req.Latitude = ll.Lat; req.Longitude = ll.Lon; resp = api.Client.SaveUserWaypoint(req); } } finally { Cursor = Cursors.Default; } if (resp != null) { if (resp.Status.StatusCode == 0) { Framework.Data.UserWaypoint wp = Utils.API.Convert.UserWaypoint(Core, resp.NewWaypoint); wp.Saved = false; wpi.WP = wp; Core.UserWaypoints.Add(wp); } else { MessageBox.Show(resp.Status.StatusMessage ?? "", Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)); } } else { MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)); } } catch { MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)); } } } }
public void OnDataChanged(Framework.Data.UserWaypoint wp) { _dataChanged = true; if (!_updating && DataChanged != null) { DataChanged(this, new Framework.EventArguments.UserWaypointEventArgs(wp)); _dataChanged = false; wp.IsDataChanged = false; } }
public override void RemoveAt(int index) { if (index >= 0 && index < Count) { Framework.Data.UserWaypoint wp = this[index] as Framework.Data.UserWaypoint; _qaItems.Remove(wp.ID); wp.DataChanged -= new EventArguments.UserWaypointEventHandler(gc_DataChanged); base.RemoveAt(index); OnUserWaypointRemoved(wp); } }
public static bool UpdateUserWaypointData(Framework.Data.UserWaypoint wp, Framework.Data.UserWaypoint newData) { bool result = false; if (wp.ID == newData.ID) { wp.UpdateFrom(newData); result = true; } return(result); }
public override void Remove(object value) { Framework.Data.UserWaypoint wp = value as Framework.Data.UserWaypoint; if (wp != null) { _qaItems.Remove(wp.ID); wp.DataChanged -= new EventArguments.UserWaypointEventHandler(gc_DataChanged); base.Remove(wp); OnUserWaypointRemoved(wp); } }
protected virtual bool AddUserWaypoint(Framework.Data.UserWaypoint wp) { bool result = false; Framework.Data.UserWaypoint oldwp = Utils.DataAccess.GetUserWaypoint(Core.UserWaypoints, wp.ID); if (oldwp == null) { Core.UserWaypoints.Add(wp); result = true; } else { Utils.DataAccess.UpdateUserWaypointData(oldwp, wp); } return(result); }
public static bool AddUserWaypoint(Framework.Interfaces.ICore core, Framework.Data.UserWaypoint wp) { bool result = false; Framework.Data.UserWaypoint oldwp = DataAccess.GetUserWaypoint(core.UserWaypoints, wp.ID); if (oldwp == null) { core.UserWaypoints.Add(wp); result = true; } else { DataAccess.UpdateUserWaypointData(oldwp, wp); } return(result); }
private void button5_Click(object sender, EventArgs e) { WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem; if (wpi != null) { Framework.Data.UserWaypoint wp = wpi.WP; Framework.Data.Location l = new Framework.Data.Location(wp.Lat, wp.Lon); using (Utils.Dialogs.GetLocationForm dlg = new Utils.Dialogs.GetLocationForm(Core, l)) { if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { textBox8.Text = Utils.Conversion.GetCoordinatesPresentation(dlg.Result); } } } }
public static Framework.Data.UserWaypoint UserWaypoint(Framework.Interfaces.ICore core, LiveV6.UserWaypoint wp) { Framework.Data.UserWaypoint result = null; if (wp != null) { Framework.Data.UserWaypoint tmp = DataAccess.GetUserWaypoint(core.UserWaypoints, (int)wp.ID); result = new Framework.Data.UserWaypoint(); if (tmp != null) { result.UpdateFrom(tmp); } result.Description = wp.Description; result.GeocacheCode = wp.CacheCode; result.ID = (int)wp.ID; result.Lat = wp.Latitude; result.Lon = wp.Longitude; result.Date = wp.UTCDate.ToLocalTime(); } 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; }
public static Framework.Data.UserWaypoint UserWaypoint(Framework.Interfaces.ICore core, LiveV6.UserWaypoint wp) { Framework.Data.UserWaypoint result = null; if (wp != null) { Framework.Data.UserWaypoint tmp = DataAccess.GetUserWaypoint(core.UserWaypoints, (int)wp.ID); result = new Framework.Data.UserWaypoint(); if (tmp != null) { result.UpdateFrom(tmp); } result.Description = wp.Description; result.GeocacheCode = wp.CacheCode; result.ID = (int)wp.ID; result.Lat = wp.Latitude; result.Lon = wp.Longitude; result.Date = wp.UTCDate.ToLocalTime(); } return result; }
public void Import(Framework.Interfaces.ICore core, Utils.BasePlugin.Plugin owner, string fileName) { using (Utils.ProgressBlock upd = new Utils.ProgressBlock(owner, STR_IMPORT, STR_IMPORT, 1, 0)) { using (FileStream fs = File.OpenRead(fileName)) using (BinaryReader br = new BinaryReader(fs)) { string tag = br.ReadString(); if (tag == "GAPP") { bool IsLittleEndian = br.ReadBoolean(); int version = br.ReadInt32(); if (IsLittleEndian == BitConverter.IsLittleEndian && version <= 3) { int count = br.ReadInt32(); using (Utils.ProgressBlock prog = new Utils.ProgressBlock(owner, STR_IMPORT, STR_IMPORT_CACHES, count, 0)) { for (int index = 0; index < count; index++) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Code = 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(); string s = br.ReadString(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.LongDescription = br.ReadString(); gc.LongDescriptionInHtml = br.ReadBoolean(); 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.Selected = br.ReadBoolean(); gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); if (version > 1) { gc.Locked = br.ReadBoolean(); } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, core.CenterLocation); (owner as Import).AddImportedGeocache(gc); int logcount = br.ReadInt32(); for (int lc = 0; lc < logcount; lc++) { Framework.Data.Log log = new Framework.Data.Log(); log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Encoded = br.ReadBoolean(); log.Finder = br.ReadString(); log.FinderId = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(core.LogTypes, br.ReadInt32()); log.TBCode = br.ReadString(); log.Text = br.ReadString(); (owner as Import).AddImportedLog(log); int logimgcount = br.ReadInt32(); for (int lic = 0; lic < logimgcount; lic++) { Framework.Data.LogImage li = new Framework.Data.LogImage(); li.DataFromDate = DateTime.Parse(br.ReadString()); li.ID = br.ReadString(); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); (owner as Import).AddImportedLogImage(li); } } int wpcount = br.ReadInt32(); for (int wpc = 0; wpc < wpcount; wpc++) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); wp.Code = br.ReadString(); 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()); (owner as Import).AddImportedWaypoint(wp); } if (version > 2) { int usrwpcount = br.ReadInt32(); for (int wpc = 0; wpc < usrwpcount; wpc++) { Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); wp.ID = br.ReadInt32(); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); (owner as Import).AddImportedUserWaypoint(wp); } } if (index % 200 == 0) { prog.UpdateProgress(STR_IMPORT, STR_IMPORT_CACHES, count, index); } } } } else { //message } } else { //message } } } }
public void Import(Framework.Interfaces.ICore core, Utils.BasePlugin.Plugin owner, string fileName) { using (Utils.ProgressBlock upd = new Utils.ProgressBlock(owner, STR_IMPORT, STR_IMPORT, 1, 0)) { using (FileStream fs = File.OpenRead(fileName)) using (BinaryReader br = new BinaryReader(fs)) { string tag = br.ReadString(); if (tag == "GAPP") { bool IsLittleEndian = br.ReadBoolean(); int version = br.ReadInt32(); if (IsLittleEndian == BitConverter.IsLittleEndian && version<=3) { int count = br.ReadInt32(); using (Utils.ProgressBlock prog = new Utils.ProgressBlock(owner, STR_IMPORT, STR_IMPORT_CACHES, count, 0)) { for (int index = 0; index < count; index++) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Code = 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(); string s = br.ReadString(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.LongDescription = br.ReadString(); gc.LongDescriptionInHtml = br.ReadBoolean(); 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.Selected = br.ReadBoolean(); gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); if (version > 1) { gc.Locked = br.ReadBoolean(); } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, core.CenterLocation); (owner as Import).AddImportedGeocache(gc); int logcount = br.ReadInt32(); for (int lc = 0; lc < logcount; lc++) { Framework.Data.Log log = new Framework.Data.Log(); log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Encoded = br.ReadBoolean(); log.Finder = br.ReadString(); log.FinderId = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(core.LogTypes, br.ReadInt32()); log.TBCode = br.ReadString(); log.Text = br.ReadString(); (owner as Import).AddImportedLog(log); int logimgcount = br.ReadInt32(); for (int lic = 0; lic < logimgcount; lic++) { Framework.Data.LogImage li = new Framework.Data.LogImage(); li.DataFromDate = DateTime.Parse(br.ReadString()); li.ID = br.ReadString(); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); (owner as Import).AddImportedLogImage(li); } } int wpcount = br.ReadInt32(); for (int wpc = 0; wpc < wpcount; wpc++) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); wp.Code = br.ReadString(); 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()); (owner as Import).AddImportedWaypoint(wp); } if (version > 2) { int usrwpcount = br.ReadInt32(); for (int wpc = 0; wpc < usrwpcount; wpc++) { Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); wp.ID = br.ReadInt32(); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); (owner as Import).AddImportedUserWaypoint(wp); } } if (index % 200 == 0) { prog.UpdateProgress(STR_IMPORT, STR_IMPORT_CACHES, count, index); } } } } else { //message } } else { //message } } } }
private void readUserWaypointData(RecordInfo ri, MemoryStream ms, BinaryReader br) { _usrwptsInDB.Add(ri.ID, ri); Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); wp.ID = int.Parse(ri.ID); //wp.GeocacheCode = ri.SubID; wp.Date = DateTimeFromLong(br.ReadInt64()); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); ms.Position = 200; wp.GeocacheCode = br.ReadString(); ms.Position = 220; wp.Description = br.ReadString(); wp.Saved = true; wp.IsDataChanged = false; Core.UserWaypoints.Add(wp); }
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; }
public override bool LoadWaypoints(List<Framework.Data.Waypoint> wps, List<Framework.Data.UserWaypoint> usrwps) { bool result = false; MySqlConnection dbcon = GetMySqlConnection(Properties.Settings.Default.SqlServer, Properties.Settings.Default.Database, Properties.Settings.Default.SqlServerPwd, Properties.Settings.Default.SqlServerUsername, Properties.Settings.Default.SqlServerUseIS, Properties.Settings.Default.SqlServerPort); if (dbcon != null && InitDatabase(dbcon, Properties.Settings.Default.Database)) { int wptCount = 0; using (MySqlCommand cmd = new MySqlCommand("select waypoint from counter", dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) if (dr.Read()) { wptCount = (int)dr["waypoint"]; } int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select * from waypoint", dbcon)) { cmd.CommandTimeout = 0; using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); wp.ID = (string)dr["id"]; wp.Code = (string)dr["code"]; wp.Url = (string)dr["url"]; wp.UrlName = (string)dr["urlname"]; wp.Name = (string)dr["name"]; wp.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); wp.Comment = (string)dr["comment"]; wp.GeocacheCode = (string)dr["geocachecode"]; wp.Description = (string)dr["description"]; wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, (int)dr["wptype"]); object o = dr["lat"]; if (o == null || o.GetType() == typeof(DBNull)) { wp.Lat = null; } else { wp.Lat = (double?)(float)o; } o = dr["lon"]; if (o == null || o.GetType() == typeof(DBNull)) { wp.Lon = null; } else { wp.Lon = (double?)(float)o; } wp.Time = DateTime.Parse((string)dr["time"]).ToLocalTime(); wp.Saved = true; wp.IsDataChanged = false; _wptsInDB[wp.Code] = wp.Code; wps.Add(wp); index++; procStep++; if (procStep >= 20000) { UpdateLoadingInBackgroundProgress(STR_LOADING_WAYPOINTS_BG, wptCount, index); procStep = 0; } } } using (MySqlCommand cmd = new MySqlCommand("select * from userwaypoint", dbcon)) { cmd.CommandTimeout = 0; using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); wp.ID = (int)dr["id"]; wp.GeocacheCode = (string)dr["geocachecode"]; wp.Description = (string)dr["description"]; wp.Lat = (double)(float)dr["lat"]; wp.Lon = (double)(float)dr["lon"]; wp.Date = DateTime.Parse((string)dr["time"]).ToLocalTime(); wp.Saved = true; wp.IsDataChanged = false; _usrwptsInDB[wp.ID] = wp.ID; usrwps.Add(wp); } } dbcon.Dispose(); dbcon = null; } return result; }
public override bool Load(bool geocachesOnly) { bool result = true; if (_dbcon != null) { List<string> activeAttr = new List<string>(); using (MySqlCommand cmd = new MySqlCommand("select field_name from geocache_cfields", _dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { string s = string.Format("{0}", dr["field_name"]); activeAttr.Add(s); Core.Geocaches.AddCustomAttribute(s); } int gcCount = 0; int logCount = 0; int logimgCount = 0; int wptCount = 0; using (MySqlCommand cmd = new MySqlCommand("select geocache, log, waypoint, logimage from counter", _dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) if (dr.Read()) { gcCount = (int)dr["geocache"]; logCount = (int)dr["log"]; logimgCount = (int)dr["waypoint"]; wptCount = (int)dr["logimage"]; } using (Utils.ProgressBlock fixscr = new ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0)) { using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0)) { int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select id, code, name, datafromdate, lat, lon, disttocent, angletocent, available, archived, country, state, cachetype, placedby, owner, ownerid, container, terrain, difficulty, encodedhints, url, memberonly, customcoords, attrids, favorites, selected, municipality, city, customlat, customlon, notes, publiceddate, personalnote, flagged, found, locked from geocache", _dbcon)) { cmd.CommandTimeout = 0; using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.ID = (string)dr["id"]; gc.Code = (string)dr["code"]; if (string.IsNullOrEmpty(gc.ID) && !string.IsNullOrEmpty(gc.Code) && gc.Code.ToUpper().StartsWith("GC")) { gc.ID = Utils.Conversion.GetCacheIDFromCacheCode(gc.Code).ToString(); } gc.Name = (string)dr["name"]; gc.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); gc.Lat = (double)(float)dr["lat"]; gc.Lon = (double)(float)dr["lon"]; //gc.DistanceToCenter = (int)dr["disttocent"]; //gc.AngleToCenter = (int)dr["angletocent"]; gc.Available = (int)dr["available"] != 0; gc.Archived = (int)dr["archived"] != 0; gc.Country = (string)dr["country"]; gc.State = (string)dr["state"]; gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, (int)dr["cachetype"]); gc.PlacedBy = (string)dr["placedby"]; gc.Owner = (string)dr["owner"]; gc.OwnerId = (string)dr["ownerid"]; gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, (int)dr["container"]); gc.Terrain = (double)(float)dr["terrain"]; gc.Difficulty = (double)(float)dr["difficulty"]; gc.EncodedHints = (string)dr["encodedhints"]; gc.Url = (string)dr["url"]; gc.MemberOnly = (int)dr["memberonly"] != 0; gc.CustomCoords = (int)dr["customcoords"] != 0; string s = (string)dr["attrids"]; string[] parts = s.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); List<int> attrList = new List<int>(); if (parts != null) { foreach (string si in parts) { attrList.Add(int.Parse(si)); } } gc.AttributeIds = attrList; gc.Municipality = (string)dr["municipality"]; gc.City = (string)dr["city"]; object o = dr["customlat"]; if (o == null || o.GetType() == typeof(DBNull)) { gc.CustomLat = null; } else { gc.CustomLat = (double?)(float)o; } o = dr["customlon"]; if (o == null || o.GetType() == typeof(DBNull)) { gc.CustomLon = null; } else { gc.CustomLon = (double?)(float)o; } gc.Notes = (string)dr["notes"]; gc.PublishedTime = DateTime.Parse((string)dr["publiceddate"]).ToLocalTime(); gc.PersonaleNote = (string)dr["personalnote"]; gc.Flagged = (int)dr["flagged"] != 0; gc.Locked = (int)dr["locked"] != 0; gc.Found = (int)dr["found"] != 0; gc.Favorites = (int)dr["favorites"]; gc.Selected = (int)dr["selected"] != 0; foreach (string attrField in activeAttr) { object objValue = null; try { objValue = dr[string.Format("_{0}", attrField)]; } catch { } gc.SetCustomAttribute(attrField, objValue); } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); gc.Saved = true; gc.IsDataChanged = false; _geocachesInDB[gc.Code] = gc.Code; Core.Geocaches.Add(gc); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); procStep = 0; } } } } if (!geocachesOnly) { using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select ID, gccode, Finder, DataFromDate, LogType, Date from log", _dbcon)) { cmd.CommandTimeout = 0; using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.Log lg = new Framework.Data.Log(); //id text, gccode text, tbcode text, date text, finder text, finderid text, logtext text, encoded integer, datafromdate text, logtype integer lg.ID = (string)dr["id"]; lg.GeocacheCode = (string)dr["gccode"]; lg.Date = DateTime.Parse((string)dr["date"]).ToLocalTime(); lg.Finder = (string)dr["finder"]; lg.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); lg.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, (int)dr["logtype"]); lg.Saved = true; lg.IsDataChanged = false; _logsInDB[lg.ID] = lg.ID; Core.Logs.Add(lg); index++; procStep++; if (procStep >= 20000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); procStep = 0; } } } } //(id text, logid text, url text, name text, datafromdate text) using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select * from logimage", _dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.LogImage lg = new Framework.Data.LogImage(); lg.ID = (string)dr["id"]; lg.LogID = (string)dr["logid"]; lg.Url = (string)dr["url"]; lg.Name = (string)dr["name"]; lg.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); lg.Saved = true; lg.IsDataChanged = false; _logimgsInDB[lg.ID] = lg.ID; Core.LogImages.Add(lg); index++; procStep++; if (procStep >= 2000) { progress.UpdateProgress("Loading...", "Loading log images...", logimgCount, index); procStep = 0; } } } //id text, code text, geocachecode text, name text, datafromdate text, comment text, description text, url text, urlname text, wptype integer, lat real, lon real, time text using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select * from waypoint", _dbcon)) { cmd.CommandTimeout = 0; using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); wp.ID = (string)dr["id"]; wp.Code = (string)dr["code"]; wp.Url = (string)dr["url"]; wp.UrlName = (string)dr["urlname"]; wp.Name = (string)dr["name"]; wp.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); wp.Comment = (string)dr["comment"]; wp.GeocacheCode = (string)dr["geocachecode"]; wp.Description = (string)dr["description"]; wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, (int)dr["wptype"]); object o = dr["lat"]; if (o == null || o.GetType() == typeof(DBNull)) { wp.Lat = null; } else { wp.Lat = (double?)(float)o; } o = dr["lon"]; if (o == null || o.GetType() == typeof(DBNull)) { wp.Lon = null; } else { wp.Lon = (double?)(float)o; } wp.Time = DateTime.Parse((string)dr["time"]).ToLocalTime(); wp.Saved = true; wp.IsDataChanged = false; _wptsInDB[wp.Code] = wp.Code; Core.Waypoints.Add(wp); index++; procStep++; if (procStep >= 20000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } } } using (MySqlCommand cmd = new MySqlCommand("select * from userwaypoint", _dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); wp.ID = (int)dr["id"]; wp.GeocacheCode = (string)dr["geocachecode"]; wp.Description = (string)dr["description"]; wp.Lat = (double)(float)dr["lat"]; wp.Lon = (double)(float)dr["lon"]; wp.Date = DateTime.Parse((string)dr["time"]).ToLocalTime(); wp.Saved = true; wp.IsDataChanged = false; _usrwptsInDB[wp.ID] = wp.ID; Core.UserWaypoints.Add(wp); } } } } return result; }
public bool RepairV1() { 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 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); 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; FileStream fs = _fileCollection._fsGeocaches; fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; 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) { ri.FreeSlot = false; fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); br.ReadString(); br.ReadBoolean(); br.ReadString(); br.ReadBoolean(); } 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(); gc.Saved = true; gc.IsDataChanged = false; index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } _uniqueCheckList.Clear(); using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; nextUpdateTime = DateTime.MinValue; FileStream fs = _fileCollection._fsLogs; fs.Position = 0; long lastOKPosition = 0; long eof = fs.Length; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; 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) { ri.FreeSlot = false; fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); br.ReadString(); br.ReadString(); br.ReadString(); br.ReadBoolean(); } 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; index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } _uniqueCheckList.Clear(); using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(_fileCollection.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; 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; index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } } _uniqueCheckList.Clear(); using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(_fileCollection.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; 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; index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } } { int index = 0; _uniqueCheckList.Clear(); using (FileStream fs = File.Open(_fileCollection.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; 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; index++; } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } } } } } return result; }
public override bool LoadWaypoints(List<Framework.Data.Waypoint> wps, List<Framework.Data.UserWaypoint> usrwps) { 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 wptCount = 0; XmlDocument doc = new XmlDocument(); doc.Load(_fileCollection.DatabaseInfoFilename); XmlElement root = doc.DocumentElement; wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText); 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; wps.Add(wp); index++; procStep++; if (procStep >= 20000) { UpdateLoadingInBackgroundProgress(STR_LOADING_WAYPOINTS_BG, wptCount, index); procStep = 0; } } _fileCollection._wptsInDB.Add(ri.ID, ri); } } 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; usrwps.Add(wp); } _fileCollection._usrwptsInDB.Add(ri.ID, ri); } } } } return result; }
public bool AddImportedUserWaypoint(Framework.Data.UserWaypoint wp) { return(base.AddUserWaypoint(wp)); }
public bool RepairV1() { 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 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); 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; FileStream fs = _fileCollection._fsGeocaches; fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; 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) { ri.FreeSlot = false; fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); br.ReadString(); br.ReadBoolean(); br.ReadString(); br.ReadBoolean(); } 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(); gc.Saved = true; gc.IsDataChanged = false; index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } _uniqueCheckList.Clear(); using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; nextUpdateTime = DateTime.MinValue; FileStream fs = _fileCollection._fsLogs; fs.Position = 0; long lastOKPosition = 0; long eof = fs.Length; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; 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) { ri.FreeSlot = false; fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); br.ReadString(); br.ReadString(); br.ReadString(); br.ReadBoolean(); } 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; index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } _uniqueCheckList.Clear(); using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(_fileCollection.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; 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; index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } } _uniqueCheckList.Clear(); using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(_fileCollection.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; 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; index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } } { int index = 0; _uniqueCheckList.Clear(); using (FileStream fs = File.Open(_fileCollection.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; 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; index++; } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } } } } } 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); }