Ejemplo n.º 1
0
        public void RestoreDefaultSettings()
        {
            if (System.Windows.Forms.MessageBox.Show("Failed to initialize the application. Some settings files or data files might have been corrupted.\r\nDo you want to restore the default settings?", "Failed to start GAPP", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Error, System.Windows.Forms.MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
            {
                string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName         = Path.Combine(exePath, "RestoreDefaultSettings.exe");
                psi.UseShellExecute  = true;
                psi.WorkingDirectory = exePath;
                Process.Start(psi);

                try
                {
                    _settingsProvider.Dispose();
                    _settingsProvider = null;
                    Process.GetCurrentProcess().Kill();
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 2
0
 public void Dispose()
 {
     if (_settingsProvider != null)
     {
         _settingsProvider.Dispose();
         _settingsProvider = null;
     }
 }
Ejemplo n.º 3
0
        public Engine()
        {
            try
            {
                _settingsProvider = new SettingsProvider(null);

                string[] args = Environment.GetCommandLineArgs();
                if (EnablePluginDataPathAtStartup || (args != null && args.Contains("/f")))
                {
                    using (SelectSettingsForm dlg = new SelectSettingsForm(this))
                    {
                        _pluginDataFolderSelected = dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK;
                    }
                }
                else
                {
                    _pluginDataFolderSelected = true;
                }

                if (_pluginDataFolderSelected)
                {
                    _geocachingAccountNames = new Framework.Data.GeocachingAccountNames();
                    var p = _settingsProvider.GetSettingsValueStringCollection("Core.GeocachingAccountNames", null);
                    if (p != null)
                    {
                        foreach (string s in p)
                        {
                            string[] parts = s.Split("|".ToArray(), 2);
                            if (parts.Length == 2)
                            {
                                _geocachingAccountNames.SetAccountName(parts[0], parts[1]);
                            }
                        }
                    }
                    _geocachingAccountNames.Changed += new Framework.EventArguments.GeocachingAccountNamesEventHandler(_geocachingAccountNames_Changed);

                    _geocachingComAccount = new Framework.Data.GeocachingComAccountInfo();
                    _geocachingComAccount.AccountName = _settingsProvider.GetSettingsValue("Core.GCComAccountName", null);
                    _geocachingComAccount.APIToken = _settingsProvider.GetSettingsValue("Core.GCComAccountToken", null);
                    _geocachingComAccount.APITokenStaging = _settingsProvider.GetSettingsValue("Core.GCComAccountTokenStaging", null);
                    _geocachingComAccount.MemberType = _settingsProvider.GetSettingsValue("Core.GCComAccountMemberType", null);
                    _geocachingComAccount.MemberTypeId = _settingsProvider.GetSettingsValueInt("Core.GCComAccountMemberTypeId", 0);
                    _geocachingComAccount.Changed += new Framework.EventArguments.GeocacheComAccountEventHandler(_geocachingComAccount_Changed);
                    GeocachingAccountNames.SetAccountName("GC", _settingsProvider.GetSettingsValue("Core.GCComAccountName", null) ?? "");

                    _logs = new Framework.Data.LogCollection();
                    _userWaypoints = new Framework.Data.UserWaypointCollection();
                    _waypoints = new Framework.Data.WaypointCollection();
                    _geocaches = new Framework.Data.GeocacheCollection(this);
                    _logImages = new Framework.Data.LogImageCollection();
                    _geocacheImages = new Framework.Data.GeocacheImageCollection();
                    _geocacheAttributes = new Framework.Data.GeocacheAttributeCollection();
                    _geocacheTypes = new Framework.Data.GeocacheTypeCollection();
                    _geocacheContainers = new Framework.Data.GeocacheContainerCollection();
                    _logTypes = new Framework.Data.LogTypeCollection();
                    _waypointTypes = new Framework.Data.WaypointTypeCollection();
                    _homeLocation = new Framework.Data.Location();
                    _centerLocation = new Framework.Data.Location();
                    _gpsLocation = new Framework.Data.GPSLocation();
                    _languageItems = new Framework.Data.LanguageItemCollection();

                    _detectedPlugins = new List<string>();
                    _internalStoragePlugins = new List<string>();
                    _selectedLanguage = System.Globalization.CultureInfo.CurrentCulture;
                    _plugins = new List<Framework.Interfaces.IPlugin>();
                    _currentDomain = AppDomain.CurrentDomain;
                    _currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromSameFolder);

                    //set initial data
                    //default location settings
                    _centerLocation.SetLocation(_settingsProvider.GetSettingsValueDouble("Core.CenterLat", 51.5), _settingsProvider.GetSettingsValueDouble("Core.CenterLon", 5.5));
                    _centerLocation.Changed += new Framework.EventArguments.LocationEventHandler(_centerLocation_Changed);
                    _homeLocation.SetLocation(_settingsProvider.GetSettingsValueDouble("Core.HomeLat", 51.5), _settingsProvider.GetSettingsValueDouble("Core.HomeLon", 5.5));
                    _homeLocation.Changed += new Framework.EventArguments.LocationEventHandler(_homeLocation_Changed);

                    //default (unknown) cache- ,container etc. types. Position 0 means unknown
                    Framework.Data.GeocacheType ct = new Framework.Data.GeocacheType();
                    ct.ID = 0;
                    ct.Name = "Not present";
                    _geocacheTypes.Add(ct);
                    Framework.Data.GeocacheAttribute attr = new Framework.Data.GeocacheAttribute();
                    attr.ID = 0;
                    attr.Name = "Unknown";
                    _geocacheAttributes.Add(attr);
                    Framework.Data.GeocacheContainer cont = new Framework.Data.GeocacheContainer();
                    cont.ID = 0;
                    cont.Name = "Unknown";
                    _geocacheContainers.Add(cont);
                    Framework.Data.LogType lt = new Framework.Data.LogType();
                    lt.ID = 0;
                    lt.Name = "Unknown";
                    lt.AsFound = false;
                    _logTypes.Add(lt);
                    Framework.Data.WaypointType wpt = new Framework.Data.WaypointType();
                    wpt.ID = 0;
                    wpt.Name = "Unknown";
                    _waypointTypes.Add(wpt);

                    _shortcuts = new List<Framework.Data.ShortcutInfo>();
                }
            }
            catch
            {
                RestoreDefaultSettings();
            }
        }
Ejemplo n.º 4
0
        public void InitiateUpdaterAndExit()
        {
            //check the type of update
            string updatePath = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GAPP", "Update");
            string[] files = Directory.GetFiles(updatePath);
            if (files != null && files.Length>0)
            {
                if (files[0].ToLower().EndsWith(".zip"))
                {
                    PrepareClosingApplication();

                    string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                    ProcessStartInfo psi = new ProcessStartInfo();
                    psi.FileName = Path.Combine(exePath, "GlobalcachingApplication.Updater.exe");
                    psi.UseShellExecute = true;
                    psi.WorkingDirectory = exePath;
                    try
                    {
                        if (Environment.OSVersion.Version.Major > 5)
                        {
                            psi.Verb = "runas";
                        }
                    }
                    catch
                    {
                        psi.Verb = "runas";
                    }
                    Process.Start(psi);

                    try
                    {
                        _settingsProvider.Dispose();
                        _settingsProvider = null;
                        Process.GetCurrentProcess().Kill();
                    }
                    catch
                    {
                    }
                    //System.Windows.Forms.Application.Exit();
                }
                else if (files[0].ToLower().EndsWith(".msi"))
                {
                    PrepareClosingApplication();

                    ProcessStartInfo psi = new ProcessStartInfo();
                    psi.FileName = "msiexec";
                    //psi.UseShellExecute = true;
                    psi.WorkingDirectory = updatePath;
                    psi.Arguments = string.Format("/i \"{0}\"", files[0]);
                    try
                    {
                        if (Environment.OSVersion.Version.Major > 5)
                        {
                            psi.Verb = "runas";
                        }
                    }
                    catch
                    {
                        psi.Verb = "runas";
                    }
                    Process.Start(psi);

                    try
                    {
                        _settingsProvider.Dispose();
                        _settingsProvider = null;
                        Process.GetCurrentProcess().Kill();
                    }
                    catch
                    {
                    }
                    //System.Windows.Forms.Application.Exit();
                }
            }
        }
Ejemplo n.º 5
0
        public void RestoreDefaultSettings()
        {
            if (System.Windows.Forms.MessageBox.Show("Failed to initialize the application. Some settings files or data files might have been corrupted.\r\nDo you want to restore the default settings?", "Failed to start GAPP", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Error, System.Windows.Forms.MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
            {
                string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName = Path.Combine(exePath, "RestoreDefaultSettings.exe");
                psi.UseShellExecute = true;
                psi.WorkingDirectory = exePath;
                Process.Start(psi);

                try
                {
                    _settingsProvider.Dispose();
                    _settingsProvider = null;
                    Process.GetCurrentProcess().Kill();
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 6
0
        public Engine()
        {
            try
            {
                _settingsProvider = new SettingsProvider(null);

                string[] args = Environment.GetCommandLineArgs();
                if (EnablePluginDataPathAtStartup || (args != null && args.Contains("/f")))
                {
                    using (SelectSettingsForm dlg = new SelectSettingsForm(this))
                    {
                        _pluginDataFolderSelected = dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK;
                    }
                }
                else
                {
                    _pluginDataFolderSelected = true;
                }

                if (_pluginDataFolderSelected)
                {
                    _geocachingAccountNames = new Framework.Data.GeocachingAccountNames();
                    var p = _settingsProvider.GetSettingsValueStringCollection("Core.GeocachingAccountNames", null);
                    if (p != null)
                    {
                        foreach (string s in p)
                        {
                            string[] parts = s.Split("|".ToArray(), 2);
                            if (parts.Length == 2)
                            {
                                _geocachingAccountNames.SetAccountName(parts[0], parts[1]);
                            }
                        }
                    }
                    _geocachingAccountNames.Changed += new Framework.EventArguments.GeocachingAccountNamesEventHandler(_geocachingAccountNames_Changed);

                    _geocachingComAccount                 = new Framework.Data.GeocachingComAccountInfo();
                    _geocachingComAccount.AccountName     = _settingsProvider.GetSettingsValue("Core.GCComAccountName", null);
                    _geocachingComAccount.APIToken        = _settingsProvider.GetSettingsValue("Core.GCComAccountToken", null);
                    _geocachingComAccount.APITokenStaging = _settingsProvider.GetSettingsValue("Core.GCComAccountTokenStaging", null);
                    _geocachingComAccount.MemberType      = _settingsProvider.GetSettingsValue("Core.GCComAccountMemberType", null);
                    _geocachingComAccount.MemberTypeId    = _settingsProvider.GetSettingsValueInt("Core.GCComAccountMemberTypeId", 0);
                    _geocachingComAccount.Changed        += new Framework.EventArguments.GeocacheComAccountEventHandler(_geocachingComAccount_Changed);
                    GeocachingAccountNames.SetAccountName("GC", _settingsProvider.GetSettingsValue("Core.GCComAccountName", null) ?? "");

                    _logs               = new Framework.Data.LogCollection();
                    _userWaypoints      = new Framework.Data.UserWaypointCollection();
                    _waypoints          = new Framework.Data.WaypointCollection();
                    _geocaches          = new Framework.Data.GeocacheCollection(this);
                    _logImages          = new Framework.Data.LogImageCollection();
                    _geocacheImages     = new Framework.Data.GeocacheImageCollection();
                    _geocacheAttributes = new Framework.Data.GeocacheAttributeCollection();
                    _geocacheTypes      = new Framework.Data.GeocacheTypeCollection();
                    _geocacheContainers = new Framework.Data.GeocacheContainerCollection();
                    _logTypes           = new Framework.Data.LogTypeCollection();
                    _waypointTypes      = new Framework.Data.WaypointTypeCollection();
                    _homeLocation       = new Framework.Data.Location();
                    _centerLocation     = new Framework.Data.Location();
                    _gpsLocation        = new Framework.Data.GPSLocation();
                    _languageItems      = new Framework.Data.LanguageItemCollection();

                    _detectedPlugins        = new List <string>();
                    _internalStoragePlugins = new List <string>();
                    _selectedLanguage       = System.Globalization.CultureInfo.CurrentCulture;
                    _plugins       = new List <Framework.Interfaces.IPlugin>();
                    _currentDomain = AppDomain.CurrentDomain;
                    _currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromSameFolder);

                    //set initial data
                    //default location settings
                    _centerLocation.SetLocation(_settingsProvider.GetSettingsValueDouble("Core.CenterLat", 51.5), _settingsProvider.GetSettingsValueDouble("Core.CenterLon", 5.5));
                    _centerLocation.Changed += new Framework.EventArguments.LocationEventHandler(_centerLocation_Changed);
                    _homeLocation.SetLocation(_settingsProvider.GetSettingsValueDouble("Core.HomeLat", 51.5), _settingsProvider.GetSettingsValueDouble("Core.HomeLon", 5.5));
                    _homeLocation.Changed += new Framework.EventArguments.LocationEventHandler(_homeLocation_Changed);

                    //default (unknown) cache- ,container etc. types. Position 0 means unknown
                    Framework.Data.GeocacheType ct = new Framework.Data.GeocacheType();
                    ct.ID   = 0;
                    ct.Name = "Not present";
                    _geocacheTypes.Add(ct);
                    Framework.Data.GeocacheAttribute attr = new Framework.Data.GeocacheAttribute();
                    attr.ID   = 0;
                    attr.Name = "Unknown";
                    _geocacheAttributes.Add(attr);
                    Framework.Data.GeocacheContainer cont = new Framework.Data.GeocacheContainer();
                    cont.ID   = 0;
                    cont.Name = "Unknown";
                    _geocacheContainers.Add(cont);
                    Framework.Data.LogType lt = new Framework.Data.LogType();
                    lt.ID      = 0;
                    lt.Name    = "Unknown";
                    lt.AsFound = false;
                    _logTypes.Add(lt);
                    Framework.Data.WaypointType wpt = new Framework.Data.WaypointType();
                    wpt.ID   = 0;
                    wpt.Name = "Unknown";
                    _waypointTypes.Add(wpt);

                    _shortcuts = new List <Framework.Data.ShortcutInfo>();
                }
            }
            catch
            {
                RestoreDefaultSettings();
            }
        }
Ejemplo n.º 7
0
        public void InitiateUpdaterAndExit()
        {
            //check the type of update
            string updatePath = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GAPP", "Update");

            string[] files = Directory.GetFiles(updatePath);
            if (files != null && files.Length > 0)
            {
                if (files[0].ToLower().EndsWith(".zip"))
                {
                    PrepareClosingApplication();

                    string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                    ProcessStartInfo psi = new ProcessStartInfo();
                    psi.FileName         = Path.Combine(exePath, "GlobalcachingApplication.Updater.exe");
                    psi.UseShellExecute  = true;
                    psi.WorkingDirectory = exePath;
                    try
                    {
                        if (Environment.OSVersion.Version.Major > 5)
                        {
                            psi.Verb = "runas";
                        }
                    }
                    catch
                    {
                        psi.Verb = "runas";
                    }
                    Process.Start(psi);

                    try
                    {
                        _settingsProvider.Dispose();
                        _settingsProvider = null;
                        Process.GetCurrentProcess().Kill();
                    }
                    catch
                    {
                    }
                    //System.Windows.Forms.Application.Exit();
                }
                else if (files[0].ToLower().EndsWith(".msi"))
                {
                    PrepareClosingApplication();

                    ProcessStartInfo psi = new ProcessStartInfo();
                    psi.FileName = "msiexec";
                    //psi.UseShellExecute = true;
                    psi.WorkingDirectory = updatePath;
                    psi.Arguments        = string.Format("/i \"{0}\"", files[0]);
                    try
                    {
                        if (Environment.OSVersion.Version.Major > 5)
                        {
                            psi.Verb = "runas";
                        }
                    }
                    catch
                    {
                        psi.Verb = "runas";
                    }
                    Process.Start(psi);

                    try
                    {
                        _settingsProvider.Dispose();
                        _settingsProvider = null;
                        Process.GetCurrentProcess().Kill();
                    }
                    catch
                    {
                    }
                    //System.Windows.Forms.Application.Exit();
                }
            }
        }