コード例 #1
0
 public void SaveSettings(Framework.Interfaces.ICore core)
 {
     GeocachingComAccount              = new Framework.Data.GeocachingComAccountInfo();
     GeocachingComAccount.AccountName  = core.GeocachingComAccount.AccountName;
     GeocachingComAccount.APIToken     = core.GeocachingComAccount.APIToken;
     GeocachingComAccount.MemberType   = core.GeocachingComAccount.MemberType;
     GeocachingComAccount.MemberTypeId = core.GeocachingComAccount.MemberTypeId;
     Framework.Interfaces.IPluginInternalStorage storage = (from Framework.Interfaces.IPluginInternalStorage a in core.GetPlugin(Framework.PluginType.InternalStorage) select a).FirstOrDefault();
     InternalStorageInfo = storage.ActiveStorageDestination;
 }
コード例 #2
0
 public async Task SwitchSettingsFolder(string newFolder)
 {
     if (Core.SettingsProvider.GetSettingsScope().ToLower() != newFolder.ToLower())
     {
         bool cancel = false;
         if (Core.AutoSaveOnClose)
         {
             Framework.Interfaces.IPluginInternalStorage p = (from Framework.Interfaces.IPluginInternalStorage ip in Core.GetPlugin(Framework.PluginType.InternalStorage) select ip).FirstOrDefault();
             if (p != null)
             {
                 cancel = !await p.SaveAllData();
             }
         }
         else
         {
             int cnt = 0;
             cnt += (from Framework.Data.Geocache c in Core.Geocaches where !c.Saved select c).Count();
             cnt += (from Framework.Data.Log c in Core.Logs where !c.Saved select c).Count();
             cnt += (from Framework.Data.LogImage c in Core.LogImages where !c.Saved select c).Count();
             cnt += (from Framework.Data.Waypoint c in Core.Waypoints where !c.Saved select c).Count();
             if (cnt > 0)
             {
                 System.Windows.Forms.DialogResult res = System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_ASKSAVEDATA), Utils.LanguageSupport.Instance.GetTranslation(STR_WARNING), System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Warning, System.Windows.Forms.MessageBoxDefaultButton.Button3);
                 if (res == System.Windows.Forms.DialogResult.Yes)
                 {
                     Framework.Interfaces.IPluginInternalStorage p = (from Framework.Interfaces.IPluginInternalStorage ip in Core.GetPlugin(Framework.PluginType.InternalStorage) select ip).FirstOrDefault();
                     if (p != null)
                     {
                         cancel = !await p.SaveAllData();
                     }
                 }
                 else if (res == System.Windows.Forms.DialogResult.No)
                 {
                 }
                 else
                 {
                     cancel = true;
                 }
             }
         }
         if (!cancel)
         {
             Core.SettingsProvider.SetSettingsScopeForNextStart(newFolder);
             Core.PrepareClosingApplication();
             Application.Restart();
         }
     }
 }
コード例 #3
0
 public void RestoreSettings(Framework.Interfaces.ICore core)
 {
     if (SwitchGeocachingComAccount && GeocachingComAccount != null)
     {
         core.GeocachingComAccount.AccountName  = GeocachingComAccount.AccountName;
         core.GeocachingComAccount.APIToken     = GeocachingComAccount.APIToken;
         core.GeocachingComAccount.MemberType   = GeocachingComAccount.MemberType;
         core.GeocachingComAccount.MemberTypeId = GeocachingComAccount.MemberTypeId;
     }
     if (SwitchDatabase && InternalStorageInfo != null)
     {
         Framework.Interfaces.IPluginInternalStorage storage = (from Framework.Interfaces.IPluginInternalStorage a in core.GetPlugin(Framework.PluginType.InternalStorage) select a).FirstOrDefault();
         if (!InternalStorageInfo.SameDestination(storage.ActiveStorageDestination))
         {
             storage.SetStorageDestination(InternalStorageInfo);
         }
     }
 }
コード例 #4
0
        protected override void ExportMethod()
        {
            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_EXPORTINGGPX, STR_CREATINGFILE, _gcList.Count, 0))
            {
                if (_oneGeocachePerFile)
                {
                    Utils.GPXGenerator gpxGenerator = new Utils.GPXGenerator(Core, _gcList, string.IsNullOrEmpty(PluginSettings.Instance.GPXVersionStr) ? Utils.GPXGenerator.V101 : Version.Parse(PluginSettings.Instance.GPXVersionStr));
                    gpxGenerator.UseNameForGCCode = _useName;
                    gpxGenerator.AddAdditionWaypointsToDescription = PluginSettings.Instance.AddWaypointsToDescription;
                    gpxGenerator.UseHintsForDescription            = PluginSettings.Instance.UseHintsForDescription;
                    gpxGenerator.AddFieldnotesToDescription        = PluginSettings.Instance.AddFieldNotesToDescription;
                    gpxGenerator.MaxNameLength             = PluginSettings.Instance.MaxGeocacheNameLength;
                    gpxGenerator.MinStartOfname            = PluginSettings.Instance.MinStartOfGeocacheName;
                    gpxGenerator.ExtraCoordPrefix          = PluginSettings.Instance.CorrectedNamePrefix;
                    gpxGenerator.AddExtraInfoToDescription = PluginSettings.Instance.AddExtraInfoToDescription;
                    gpxGenerator.MaxLogCount = PluginSettings.Instance.MaximumNumberOfLogs;
                    using (System.IO.TemporaryFile gpxFile = new System.IO.TemporaryFile(false))
                    {
                        using (System.IO.StreamWriter sw = new System.IO.StreamWriter(gpxFile.Path, false, Encoding.UTF8))
                        {
                            int block = 0;
                            //generate header
                            sw.Write(gpxGenerator.Start());
                            //preserve mem and do for each cache the export
                            for (int i = 0; i < gpxGenerator.Count; i++)
                            {
                                sw.WriteLine(gpxGenerator.Next());
                                if (_addChildWaypoints)
                                {
                                    string s = gpxGenerator.WaypointData();
                                    if (!string.IsNullOrEmpty(s))
                                    {
                                        sw.WriteLine(s);
                                    }
                                }
                                block++;
                                if (block > 10)
                                {
                                    block = 0;
                                    progress.UpdateProgress(STR_EXPORTINGGPX, STR_CREATINGFILE, gpxGenerator.Count, i + 1);
                                }
                            }
                            //finalize
                            sw.Write(gpxGenerator.Finish());
                        }

                        progress.UpdateProgress(STR_EXPORTINGGPX, STR_COPYINGFILE, 1, 0);
                        string filename = "geocaches.gpx";
                        if (PluginSettings.Instance.UseDatabaseNameForFileName)
                        {
                            Framework.Interfaces.IPluginInternalStorage storage = (from Framework.Interfaces.IPluginInternalStorage a in Core.GetPlugin(Framework.PluginType.InternalStorage) select a).FirstOrDefault();
                            if (storage != null)
                            {
                                var si = storage.ActiveStorageDestination;
                                if (si != null)
                                {
                                    string s   = storage.ActiveStorageDestination.Name;
                                    int    pos = s.LastIndexOf('.');
                                    if (pos < 0)
                                    {
                                        filename = string.Format("{0}.gpx", s);
                                    }
                                    else
                                    {
                                        filename = string.Format("{0}.gpx", s.Substring(0, pos));
                                    }
                                }
                            }
                        }
                        System.IO.File.Copy(gpxFile.Path, System.IO.Path.Combine(new string[] { _drive, "garmin", "gpx", filename }), true);
                    }
                }
                else
                {
                    List <Framework.Data.Geocache> gcl = new List <Framework.Data.Geocache>();
                    for (int i = 0; i < _gcList.Count; i++)
                    {
                        gcl.Clear();
                        gcl.Add(_gcList[i]);
                        Utils.GPXGenerator gpxGenerator = new Utils.GPXGenerator(Core, gcl, string.IsNullOrEmpty(PluginSettings.Instance.GPXVersionStr) ? Utils.GPXGenerator.V101 : Version.Parse(PluginSettings.Instance.GPXVersionStr));
                        gpxGenerator.UseNameForGCCode = _useName;
                        gpxGenerator.AddAdditionWaypointsToDescription = PluginSettings.Instance.AddWaypointsToDescription;
                        gpxGenerator.UseHintsForDescription            = PluginSettings.Instance.UseHintsForDescription;
                        gpxGenerator.AddFieldnotesToDescription        = PluginSettings.Instance.AddFieldNotesToDescription;
                        gpxGenerator.MaxNameLength             = PluginSettings.Instance.MaxGeocacheNameLength;
                        gpxGenerator.MinStartOfname            = PluginSettings.Instance.MinStartOfGeocacheName;
                        gpxGenerator.ExtraCoordPrefix          = PluginSettings.Instance.CorrectedNamePrefix;
                        gpxGenerator.AddExtraInfoToDescription = PluginSettings.Instance.AddExtraInfoToDescription;
                        gpxGenerator.MaxLogCount = PluginSettings.Instance.MaximumNumberOfLogs;
                        using (System.IO.TemporaryFile gpxFile = new System.IO.TemporaryFile(true))
                        {
                            int block = 0;

                            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(gpxFile.Path, false, Encoding.ASCII))
                            {
                                //generate header
                                sw.Write(gpxGenerator.Start());
                                //preserve mem and do for each cache the export
                                sw.WriteLine(gpxGenerator.Next());
                                if (_addChildWaypoints)
                                {
                                    string s = gpxGenerator.WaypointData();
                                    if (!string.IsNullOrEmpty(s))
                                    {
                                        sw.WriteLine(s);
                                    }
                                }
                                //finalize
                                sw.Write(gpxGenerator.Finish());
                            }
                            System.IO.File.Copy(gpxFile.Path, System.IO.Path.Combine(new string[] { _drive, "garmin", "gpx", string.Format("{0}.gpx", gcl[0].Code) }), true);

                            block++;
                            if (block > 10)
                            {
                                block = 0;
                                progress.UpdateProgress(STR_EXPORTINGGPX, STR_CREATINGFILE, _gcList.Count, i + 1);
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
        public async override Task <bool> ActionAsync(string action)
        {
            bool result = base.Action(action);

            if (result)
            {
                if (action == ACTION_EXPORT_ALL || action == ACTION_EXPORT_SELECTED || action == ACTION_EXPORT_ACTIVE)
                {
                    if (action == ACTION_EXPORT_ALL)
                    {
                        _gcList = (from Framework.Data.Geocache a in Core.Geocaches select a).ToList();
                    }
                    else if (action == ACTION_EXPORT_SELECTED)
                    {
                        _gcList = Utils.DataAccess.GetSelectedGeocaches(Core.Geocaches);
                    }
                    else
                    {
                        if (Core.ActiveGeocache != null)
                        {
                            _gcList = new List <Framework.Data.Geocache>();
                            _gcList.Add(Core.ActiveGeocache);
                        }
                    }
                    if (_gcList == null || _gcList.Count == 0)
                    {
                        System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_NOGEOCACHESELECTED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    }
                    else
                    {
                        using (SelectDeviceForm dlg = new SelectDeviceForm())
                        {
                            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                if (PluginSettings.Instance.CreateGGZFile)
                                {
                                    Utils.BasePlugin.Plugin p = Utils.PluginSupport.PluginByName(Core, "GlobalcachingApplication.Plugins.ExportGPX.GgzExport") as Utils.BasePlugin.Plugin;
                                    if (p != null)
                                    {
                                        var m = p.GetType().GetMethod("ExportToGGZ");
                                        if (m != null)
                                        {
                                            Utils.GPXGenerator gpxGenerator = new Utils.GPXGenerator(Core, _gcList, string.IsNullOrEmpty(PluginSettings.Instance.GPXVersionStr) ? Utils.GPXGenerator.V101 : Version.Parse(PluginSettings.Instance.GPXVersionStr));
                                            gpxGenerator.UseNameForGCCode = _useName;
                                            gpxGenerator.AddAdditionWaypointsToDescription = PluginSettings.Instance.AddWaypointsToDescription;
                                            gpxGenerator.UseHintsForDescription            = PluginSettings.Instance.UseHintsForDescription;
                                            gpxGenerator.AddFieldnotesToDescription        = PluginSettings.Instance.AddFieldNotesToDescription;
                                            gpxGenerator.MaxNameLength             = PluginSettings.Instance.MaxGeocacheNameLength;
                                            gpxGenerator.MinStartOfname            = PluginSettings.Instance.MinStartOfGeocacheName;
                                            gpxGenerator.ExtraCoordPrefix          = PluginSettings.Instance.CorrectedNamePrefix;
                                            gpxGenerator.AddExtraInfoToDescription = PluginSettings.Instance.AddExtraInfoToDescription;
                                            gpxGenerator.MaxLogCount = PluginSettings.Instance.MaximumNumberOfLogs;

                                            string filename = "geocaches.ggz";
                                            if (PluginSettings.Instance.UseDatabaseNameForFileName)
                                            {
                                                Framework.Interfaces.IPluginInternalStorage storage = (from Framework.Interfaces.IPluginInternalStorage a in Core.GetPlugin(Framework.PluginType.InternalStorage) select a).FirstOrDefault();
                                                if (storage != null)
                                                {
                                                    var si = storage.ActiveStorageDestination;
                                                    if (si != null)
                                                    {
                                                        string s   = storage.ActiveStorageDestination.Name;
                                                        int    pos = s.LastIndexOf('.');
                                                        if (pos < 0)
                                                        {
                                                            filename = string.Format("{0}.ggz", s);
                                                        }
                                                        else
                                                        {
                                                            filename = string.Format("{0}.ggz", s.Substring(0, pos));
                                                        }
                                                    }
                                                }
                                            }
                                            try
                                            {
                                                if (!System.IO.Directory.Exists(System.IO.Path.Combine(new string[] { dlg.SelectedDrive, "garmin", "ggz" })))
                                                {
                                                    System.IO.Directory.CreateDirectory(System.IO.Path.Combine(new string[] { dlg.SelectedDrive, "garmin", "ggz" }));
                                                }
                                            }
                                            catch
                                            {
                                            }
                                            m.Invoke(p, new object[] { System.IO.Path.Combine(new string[] { dlg.SelectedDrive, "garmin", "ggz", filename }), _gcList, gpxGenerator });
                                        }
                                    }
                                }
                                else
                                {
                                    _oneGeocachePerFile = !dlg.SeperateFilePerGeocache;
                                    _drive             = dlg.SelectedDrive;
                                    _addChildWaypoints = dlg.AddChildWaypoints;
                                    _useName           = dlg.UseName;
                                    if (!string.IsNullOrEmpty(_drive))
                                    {
                                        await PerformExport();
                                    }
                                }

                                if (PluginSettings.Instance.AddImages)
                                {
                                    Utils.BasePlugin.Plugin p = Utils.PluginSupport.PluginByName(Core, "GlobalcachingApplication.Plugins.ImgGrab.ImageGrabber") as Utils.BasePlugin.Plugin;
                                    if (p != null)
                                    {
                                        var m = p.GetType().GetMethod("CreateImageFolderForGeocaches");
                                        if (m != null)
                                        {
                                            m.Invoke(p, new object[] { _gcList, System.IO.Path.Combine(new string[] { dlg.SelectedDrive, "garmin" }) });
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }