예제 #1
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);
        }
예제 #2
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;
        }