public static Core.Data.UserWaypoint ImportUserWaypoint(Core.Storage.Database db, LiveV6.UserWaypoint wp) { Core.Data.UserWaypoint result = null; if (wp != null) { result = db.UserWaypointCollection.GetUserWaypoint(wp.ID.ToString()); Core.Data.IUserWaypointData wpd; if (result == null) { wpd = new Core.Data.UserWaypointData(); wpd.ID = wp.ID.ToString(); } else { wpd = result; } wpd.Description = wp.Description; wpd.GeocacheCode = wp.CacheCode; wpd.Lat = wp.Latitude; wpd.Lon = wp.Longitude; wpd.Date = wp.UTCDate.ToLocalTime(); if (wpd is Core.Data.UserWaypointData) { if (Utils.DataAccess.AddUserWaypoint(db, wpd as Core.Data.UserWaypointData)) { result = db.UserWaypointCollection.GetUserWaypoint(wp.ID.ToString()); if (wp.IsCorrectedCoordinate) { Core.Data.Geocache thisGC = db.GeocacheCollection.GetGeocache(wp.CacheCode); if (thisGC != null) { thisGC.CustomLat = wp.Latitude; thisGC.CustomLon = wp.Longitude; } } } } } return(result); }
public async Task ImportFile(Core.Storage.Database db, string filename) { using (Utils.DataUpdater upd = new DataUpdater(db)) { await Task.Run(() => { try { DateTime nextUpdate = DateTime.Now.AddSeconds(1); 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("ImportGAPPDataExchangeFile", "ImportGeocaches", count, 0)) { for (int index = 0; index < count; index++) { Core.Data.GeocacheData gc = new Core.Data.GeocacheData(); 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(br.ReadInt32()); bool dummyb = 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(br.ReadInt32()); string dummystr = 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.PersonalNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); dummyb = br.ReadBoolean(); gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); dummystr = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); if (version > 1) { gc.Locked = br.ReadBoolean(); } bool gcAdded = Utils.DataAccess.AddGeocache(db, gc); int logcount = br.ReadInt32(); for (int lc = 0; lc < logcount; lc++) { Core.Data.LogData log = new Core.Data.LogData(); 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(br.ReadInt32()); log.TBCode = br.ReadString(); log.Text = br.ReadString(); if (gcAdded) { Utils.DataAccess.AddLog(db, log); } int logimgcount = br.ReadInt32(); for (int lic = 0; lic < logimgcount; lic++) { Core.Data.LogImageData li = new Core.Data.LogImageData(); li.DataFromDate = DateTime.Parse(br.ReadString()); li.ID = br.ReadString(); li.LogId = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); if (gcAdded) { Utils.DataAccess.AddLogImage(db, li); } } } int wpcount = br.ReadInt32(); for (int wpc = 0; wpc < wpcount; wpc++) { Core.Data.WaypointData wp = new Core.Data.WaypointData(); 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(br.ReadInt32()); if (gcAdded) { Utils.DataAccess.AddWaypoint(db, wp); } } if (version > 2) { int usrwpcount = br.ReadInt32(); for (int wpc = 0; wpc < usrwpcount; wpc++) { Core.Data.UserWaypointData wp = new Core.Data.UserWaypointData(); wp.ID = br.ReadInt32().ToString(); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); if (gcAdded) { Utils.DataAccess.AddUserWaypoint(db, wp); } } } index++; if (DateTime.Now >= nextUpdate) { prog.Update("ImportGeocaches", count, index); nextUpdate = DateTime.Now.AddSeconds(1); } } } } else { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, "Version not supported"); } } else { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, "Wrong file signature"); } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); } }
private static bool Import(Database database, string filename) { bool result = false; try { byte[] memBuffer = new byte[10 * 1024 * 1024]; int gcCount = 0; int logCount = 0; int logimgCount = 0; int geocacheimgCount = 0; int wptCount = 0; int usrwptCount = 0; int index = 0; XmlDocument doc = new XmlDocument(); doc.Load(filename); 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.Now.AddSeconds(1); using (Utils.ProgressBlock prog = new ProgressBlock("Importing database", "Importing...", 6, 0)) { List<RecordInfo> records = new List<RecordInfo>(); Hashtable f_records = new Hashtable(); using (Utils.ProgressBlock subProg = new ProgressBlock("Importing geocaches...", gcCount, 0)) { //GEOCACHES //first all record using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.cch", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; ri.Length = br.ReadInt64(); byte slotType = br.ReadByte(); if (slotType == 0) { //free } else { //read ri.ID = br.ReadString(); if (slotType == 1) { records.Add(ri); } else { f_records.Add(ri.ID, ri); } } fs.Position = ri.Offset + ri.Length; } foreach (RecordInfo ri in records) { GeocacheData gc = new GeocacheData(); gc.Code = ri.ID; fs.Position = ri.Offset + 9; string dummyString = br.ReadString(); //id gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(br.ReadInt32()); bool dummyBool = 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(br.ReadInt32()); dummyString = 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.PersonalNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Name = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); gc.Locked = br.ReadBoolean(); RecordInfo rf = f_records[string.Format("F_{0}", ri.ID)] as RecordInfo; if (rf != null) { fs.Position = rf.Offset + 9; br.ReadString(); //id gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.LongDescription = br.ReadString(); gc.LongDescriptionInHtml = br.ReadBoolean(); } DataAccess.AddGeocache(database, gc); index++; if (DateTime.Now >= nextUpdateTime) { subProg.Update("Importing geocaches...", gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } } } prog.Update("Importing...", 6, 1); records.Clear(); f_records.Clear(); using (Utils.ProgressBlock subProg = new ProgressBlock("Importing logs...", logCount, 0)) { index = 0; //LOGS //first all record using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.lgs", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; ri.Length = br.ReadInt64(); byte slotType = br.ReadByte(); if (slotType == 0) { //free } else { //read ri.ID = br.ReadString(); if (slotType == 1) { records.Add(ri); } else { f_records.Add(ri.ID, ri); } } fs.Position = ri.Offset + ri.Length; } foreach (RecordInfo ri in records) { LogData gc = new LogData(); gc.ID = ri.ID; fs.Position = ri.Offset + 9; string dummyString = br.ReadString(); //id gc.DataFromDate = DateTime.Parse(br.ReadString()); gc.Date = DateTime.Parse(br.ReadString()); gc.Finder = br.ReadString(); gc.GeocacheCode = br.ReadString(); gc.ID = br.ReadString(); gc.LogType = Utils.DataAccess.GetLogType(br.ReadInt32()); RecordInfo rf = f_records[string.Format("F_{0}", ri.ID)] as RecordInfo; if (rf != null) { fs.Position = rf.Offset + 9; br.ReadString(); //id gc.TBCode = br.ReadString(); gc.FinderId = br.ReadString(); gc.Text = br.ReadString(); gc.Encoded = br.ReadBoolean(); } DataAccess.AddLog(database, gc); index++; if (DateTime.Now >= nextUpdateTime) { subProg.Update("Importing geocaches...", gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } } } prog.Update("Importing...", 6, 2); records.Clear(); f_records.Clear(); using (Utils.ProgressBlock subProg = new ProgressBlock("Importing waypoints...", logCount, 0)) { index = 0; //Waypoints using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.wpt", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { fs.Position = 0; long eof = fs.Length; RecordInfo ri = new RecordInfo(); while (fs.Position < eof) { ri.Offset = fs.Position; ri.Length = br.ReadInt64(); byte slotType = br.ReadByte(); if (slotType == 0) { //free } else { //read Core.Data.WaypointData wp = new Core.Data.WaypointData(); 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(br.ReadInt32()); DataAccess.AddWaypoint(database, wp); index++; if (DateTime.Now >= nextUpdateTime) { subProg.Update("Importing waypoints...", gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } fs.Position = ri.Offset + ri.Length; } } } prog.Update("Importing...", 6, 3); records.Clear(); f_records.Clear(); using (Utils.ProgressBlock subProg = new ProgressBlock("Importing log images...", logimgCount, 0)) { index = 0; using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.lmg", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { fs.Position = 0; long eof = fs.Length; RecordInfo ri = new RecordInfo(); while (fs.Position < eof) { ri.Offset = fs.Position; ri.Length = br.ReadInt64(); byte slotType = br.ReadByte(); if (slotType == 0) { //free } else { //read Core.Data.LogImageData li = new Core.Data.LogImageData(); li.ID = br.ReadString(); li.DataFromDate = DateTime.Parse(br.ReadString()); li.LogId = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); DataAccess.AddLogImage(database, li); index++; if (DateTime.Now >= nextUpdateTime) { subProg.Update("Importing log images...", logimgCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } fs.Position = ri.Offset + ri.Length; } } } prog.Update("Importing...", 6, 4); records.Clear(); f_records.Clear(); using (Utils.ProgressBlock subProg = new ProgressBlock("Importing geocache images...", geocacheimgCount, 0)) { index = 0; using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.gmg", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { fs.Position = 0; long eof = fs.Length; RecordInfo ri = new RecordInfo(); while (fs.Position < eof) { ri.Offset = fs.Position; ri.Length = br.ReadInt64(); byte slotType = br.ReadByte(); if (slotType == 0) { //free } else { //read Core.Data.GeocacheImageData li = new Core.Data.GeocacheImageData(); li.ID = br.ReadString(); 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(); DataAccess.AddGeocacheImage(database, li); index++; if (DateTime.Now >= nextUpdateTime) { subProg.Update("Importing geocache images...", geocacheimgCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } fs.Position = ri.Offset + ri.Length; } } } prog.Update("Importing...", 6, 5); records.Clear(); f_records.Clear(); using (Utils.ProgressBlock subProg = new ProgressBlock("Importing user waypoints...", usrwptCount, 0)) { index = 0; using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.uwp", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { fs.Position = 0; long eof = fs.Length; RecordInfo ri = new RecordInfo(); while (fs.Position < eof) { ri.Offset = fs.Position; ri.Length = br.ReadInt64(); byte slotType = br.ReadByte(); if (slotType == 0) { //free } else { //read Core.Data.UserWaypointData wp = new Core.Data.UserWaypointData(); wp.ID = br.ReadString(); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); DataAccess.AddUserWaypoint(database, wp); index++; if (DateTime.Now >= nextUpdateTime) { subProg.Update("Importing user waypoints...", usrwptCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } fs.Position = ri.Offset + ri.Length; } } } prog.Update("Importing...", 6, 6); result = true; } } catch { } return result; }
public static Core.Data.UserWaypoint ImportUserWaypoint(Core.Storage.Database db, LiveV6.UserWaypoint wp) { Core.Data.UserWaypoint result = null; if (wp != null) { result = db.UserWaypointCollection.GetUserWaypoint(wp.ID.ToString()); Core.Data.IUserWaypointData wpd; if (result == null) { wpd = new Core.Data.UserWaypointData(); wpd.ID = wp.ID.ToString(); } else { wpd = result; } wpd.Description = wp.Description; wpd.GeocacheCode = wp.CacheCode; wpd.Lat = wp.Latitude; wpd.Lon = wp.Longitude; wpd.Date = wp.UTCDate.ToLocalTime(); if (wpd is Core.Data.UserWaypointData) { if (Utils.DataAccess.AddUserWaypoint(db, wpd as Core.Data.UserWaypointData)) { result = db.UserWaypointCollection.GetUserWaypoint(wp.ID.ToString()); if (wp.IsCorrectedCoordinate) { Core.Data.Geocache thisGC = db.GeocacheCollection.GetGeocache(wp.CacheCode); if (thisGC != null) { thisGC.CustomLat = wp.Latitude; thisGC.CustomLon = wp.Longitude; } } } } } return result; }
async public Task PasteGeocaches() { if (Core.ApplicationData.Instance.ActiveDatabase != null && !string.IsNullOrEmpty(_sourceDatabaseFilename) && Core.ApplicationData.Instance.ActiveDatabase.FileName != _sourceDatabaseFilename && _gcCodes != null && _gcCodes.Count > 0) { Core.Storage.Database srcDb = (from a in Core.ApplicationData.Instance.Databases where a.FileName == _sourceDatabaseFilename select a).FirstOrDefault(); if (srcDb != null) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { DateTime nextUpdate = DateTime.Now.AddSeconds(1); using (Utils.ProgressBlock prog = new Utils.ProgressBlock("CopyingGeocaches", "CopyingGeocaches", _gcCodes.Count, 0, true)) { int index = 0; Core.Data.GeocacheData gcData = new Core.Data.GeocacheData(); Core.Data.LogData lgData = new Core.Data.LogData(); Core.Data.WaypointData wpData = new Core.Data.WaypointData(); Core.Data.UserWaypointData uwpData = new Core.Data.UserWaypointData(); Core.Data.LogImageData lgiData = new Core.Data.LogImageData(); Core.Data.GeocacheImageData gciData = new Core.Data.GeocacheImageData(); foreach (string gcCode in _gcCodes) { Core.Data.Geocache gc = srcDb.GeocacheCollection.GetGeocache(gcCode); if (gc != null) { Core.Data.GeocacheData.Copy(gc, gcData); Utils.DataAccess.AddGeocache(Core.ApplicationData.Instance.ActiveDatabase, gcData); List <Core.Data.Log> lgs = Utils.DataAccess.GetLogs(srcDb, gc.Code); foreach (var l in lgs) { Core.Data.LogData.Copy(l, lgData); Utils.DataAccess.AddLog(Core.ApplicationData.Instance.ActiveDatabase, lgData); List <Core.Data.LogImage> lgis = Utils.DataAccess.GetLogImages(srcDb, l.ID); foreach (var li in lgis) { Core.Data.LogImageData.Copy(li, lgiData); Utils.DataAccess.AddLogImage(Core.ApplicationData.Instance.ActiveDatabase, lgiData); } } List <Core.Data.Waypoint> wps = Utils.DataAccess.GetWaypointsFromGeocache(srcDb, gc.Code); foreach (var wp in wps) { Core.Data.WaypointData.Copy(wp, wpData); Utils.DataAccess.AddWaypoint(Core.ApplicationData.Instance.ActiveDatabase, wpData); } List <Core.Data.UserWaypoint> uwps = Utils.DataAccess.GetUserWaypointsFromGeocache(srcDb, gc.Code); foreach (var wp in uwps) { Core.Data.UserWaypointData.Copy(wp, uwpData); Utils.DataAccess.AddUserWaypoint(Core.ApplicationData.Instance.ActiveDatabase, uwpData); } List <Core.Data.GeocacheImage> gcis = Utils.DataAccess.GetGeocacheImages(srcDb, gc.Code); foreach (var wp in gcis) { Core.Data.GeocacheImageData.Copy(wp, gciData); Utils.DataAccess.AddGeocacheImage(Core.ApplicationData.Instance.ActiveDatabase, gciData); } index++; if (DateTime.Now >= nextUpdate) { if (!prog.Update("CopyingGeocaches", _gcCodes.Count, index)) { break; } } } } } }); } } } }
private static bool Import(Database database, string filename) { bool result = false; try { byte[] memBuffer = new byte[10 * 1024 * 1024]; int gcCount = 0; int logCount = 0; int logimgCount = 0; int geocacheimgCount = 0; int wptCount = 0; int usrwptCount = 0; int index = 0; XmlDocument doc = new XmlDocument(); doc.Load(filename); 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.Now.AddSeconds(1); using (Utils.ProgressBlock prog = new ProgressBlock("ImportingDatabase", "Importing", 6, 0)) { List <RecordInfo> records = new List <RecordInfo>(); Hashtable f_records = new Hashtable(); using (Utils.ProgressBlock subProg = new ProgressBlock("ImportingGeocaches", gcCount, 0)) { //GEOCACHES //first all record using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.cch", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; ri.Length = br.ReadInt64(); byte slotType = br.ReadByte(); if (slotType == 0) { //free } else { //read ri.ID = br.ReadString(); if (slotType == 1) { records.Add(ri); } else { f_records.Add(ri.ID, ri); } } fs.Position = ri.Offset + ri.Length; } foreach (RecordInfo ri in records) { GeocacheData gc = new GeocacheData(); gc.Code = ri.ID; fs.Position = ri.Offset + 9; string dummyString = br.ReadString(); //id gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(br.ReadInt32()); bool dummyBool = 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(br.ReadInt32()); dummyString = 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.PersonalNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Name = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); gc.Locked = br.ReadBoolean(); RecordInfo rf = f_records[string.Format("F_{0}", ri.ID)] as RecordInfo; if (rf != null) { fs.Position = rf.Offset + 9; br.ReadString(); //id gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.LongDescription = br.ReadString(); gc.LongDescriptionInHtml = br.ReadBoolean(); } DataAccess.AddGeocache(database, gc); index++; if (DateTime.Now >= nextUpdateTime) { subProg.Update("ImportingGeocaches", gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } } } prog.Update("Importing...", 6, 1); records.Clear(); f_records.Clear(); using (Utils.ProgressBlock subProg = new ProgressBlock("ImportingLogs", logCount, 0)) { index = 0; //LOGS //first all record using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.lgs", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; ri.Length = br.ReadInt64(); byte slotType = br.ReadByte(); if (slotType == 0) { //free } else { //read ri.ID = br.ReadString(); if (slotType == 1) { records.Add(ri); } else { f_records.Add(ri.ID, ri); } } fs.Position = ri.Offset + ri.Length; } foreach (RecordInfo ri in records) { LogData gc = new LogData(); gc.ID = ri.ID; fs.Position = ri.Offset + 9; string dummyString = br.ReadString(); //id gc.DataFromDate = DateTime.Parse(br.ReadString()); gc.Date = DateTime.Parse(br.ReadString()); gc.Finder = br.ReadString(); gc.GeocacheCode = br.ReadString(); gc.ID = br.ReadString(); gc.LogType = Utils.DataAccess.GetLogType(br.ReadInt32()); RecordInfo rf = f_records[string.Format("F_{0}", ri.ID)] as RecordInfo; if (rf != null) { fs.Position = rf.Offset + 9; br.ReadString(); //id gc.TBCode = br.ReadString(); gc.FinderId = br.ReadString(); gc.Text = br.ReadString(); gc.Encoded = br.ReadBoolean(); } DataAccess.AddLog(database, gc); index++; if (DateTime.Now >= nextUpdateTime) { subProg.Update("ImportingLogs", logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } } } prog.Update("Importing", 6, 2); records.Clear(); f_records.Clear(); using (Utils.ProgressBlock subProg = new ProgressBlock("ImportingWaypoints", wptCount, 0)) { index = 0; //Waypoints using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.wpt", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { fs.Position = 0; long eof = fs.Length; RecordInfo ri = new RecordInfo(); while (fs.Position < eof) { ri.Offset = fs.Position; ri.Length = br.ReadInt64(); byte slotType = br.ReadByte(); if (slotType == 0) { //free } else { //read Core.Data.WaypointData wp = new Core.Data.WaypointData(); 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(br.ReadInt32()); DataAccess.AddWaypoint(database, wp); index++; if (DateTime.Now >= nextUpdateTime) { subProg.Update("ImportingWaypoints", wptCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } fs.Position = ri.Offset + ri.Length; } } } prog.Update("Importing", 6, 3); records.Clear(); f_records.Clear(); using (Utils.ProgressBlock subProg = new ProgressBlock("ImportingLogImages", logimgCount, 0)) { index = 0; using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.lmg", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { fs.Position = 0; long eof = fs.Length; RecordInfo ri = new RecordInfo(); while (fs.Position < eof) { ri.Offset = fs.Position; ri.Length = br.ReadInt64(); byte slotType = br.ReadByte(); if (slotType == 0) { //free } else { //read Core.Data.LogImageData li = new Core.Data.LogImageData(); li.ID = br.ReadString(); li.DataFromDate = DateTime.Parse(br.ReadString()); li.LogId = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); DataAccess.AddLogImage(database, li); index++; if (DateTime.Now >= nextUpdateTime) { subProg.Update("ImportingLogImages", logimgCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } fs.Position = ri.Offset + ri.Length; } } } prog.Update("Importing...", 6, 4); records.Clear(); f_records.Clear(); using (Utils.ProgressBlock subProg = new ProgressBlock("ImportingGeocacheImages", geocacheimgCount, 0)) { index = 0; using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.gmg", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { fs.Position = 0; long eof = fs.Length; RecordInfo ri = new RecordInfo(); while (fs.Position < eof) { ri.Offset = fs.Position; ri.Length = br.ReadInt64(); byte slotType = br.ReadByte(); if (slotType == 0) { //free } else { //read Core.Data.GeocacheImageData li = new Core.Data.GeocacheImageData(); li.ID = br.ReadString(); 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(); DataAccess.AddGeocacheImage(database, li); index++; if (DateTime.Now >= nextUpdateTime) { subProg.Update("ImportingGeocacheImages", geocacheimgCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } fs.Position = ri.Offset + ri.Length; } } } prog.Update("Importing", 6, 5); records.Clear(); f_records.Clear(); using (Utils.ProgressBlock subProg = new ProgressBlock("ImportingUserWaypoints", usrwptCount, 0)) { index = 0; using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.uwp", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { fs.Position = 0; long eof = fs.Length; RecordInfo ri = new RecordInfo(); while (fs.Position < eof) { ri.Offset = fs.Position; ri.Length = br.ReadInt64(); byte slotType = br.ReadByte(); if (slotType == 0) { //free } else { //read Core.Data.UserWaypointData wp = new Core.Data.UserWaypointData(); wp.ID = br.ReadString(); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); DataAccess.AddUserWaypoint(database, wp); index++; if (DateTime.Now >= nextUpdateTime) { subProg.Update("ImportingUserWaypoints", usrwptCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } fs.Position = ri.Offset + ri.Length; } } } prog.Update("Importing", 6, 6); result = true; } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(new Importer(), e); } return(result); }