Ejemplo n.º 1
0
 protected override void OnStartup(StartupEventArgs e)
 {
     ProcessArg = delegate(string arg)
     {
         ResetApplication(arg);
     };
     WpfSingleInstance.Make("PunchInApplication", this);
     base.OnStartup(e);
 }
        public Window1()
        {
            ProcessArg = delegate(String arg)
            {
                ArgsRun.Text = arg;
            };

            this.Initialized += delegate(object sender, EventArgs e) {
                ArgsRun.Text = (String)Application.Current.Resources[WpfSingleInstance.StartArgKey];
                Application.Current.Resources.Remove(WpfSingleInstance.StartArgKey);
            };


            InitializeComponent();
        }
Ejemplo n.º 3
0
        public MainWindow()
        {
            ProcessArg = delegate(string[] args)
            {
                //process arguments
                System.Windows.MessageBox.Show("Please close GSAKWrapper before using the GSAK macro to execute GSAKWrapper.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            };

            this.Initialized += delegate(object sender, EventArgs e)
            {
                //process arguments
                //ArgsRun.Text = (String)Application.Current.Resources[WpfSingleInstance.StartArgKey];
                try
                {
                    Application.Current.Resources.Remove(WpfSingleInstance.StartArgKey);
                }
                catch
                {
                }
            };

            if (Settings.Settings.ApplicationRunning)
            {
                var settings = new CefSettings();
                settings.LogSeverity = LogSeverity.Disable;
                settings.RegisterScheme(new CefCustomScheme
                {
                    SchemeName           = CefSupport.CefSharpSchemeHandlerFactory.SchemeName,
                    SchemeHandlerFactory = new CefSupport.CefSharpSchemeHandlerFactory()
                });
                if (!Cef.Initialize(settings))
                {
                    throw new Exception("Unable to Initialize Cef");
                }

                Dialogs.ProgessWindow prog = Dialogs.ProgessWindow.Instance;
                ApplicationData.Instance.MainWindow = this;

                string p = System.IO.Path.Combine(new string[] { System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GSAKWrapper" });
                if (!Directory.Exists(p))
                {
                    Directory.CreateDirectory(p);
                }
                string fn = System.IO.Path.Combine(p, "settings.db3");

                //create backup first
                List <string> availableBackups = new List <string>();
                if (File.Exists(fn))
                {
                    File.Copy(fn, string.Format("{0}.{1}.bak", fn, DateTime.Now.ToString("yyyyMMddHHmmss")));

                    //keep maximum of X backups
                    availableBackups = Directory.GetFiles(p, "settings.db3.*.bak").OrderBy(x => x).ToList();
                    while (availableBackups.Count > 10)
                    {
                        File.Delete(availableBackups[0]);
                        availableBackups.RemoveAt(0);
                    }
                }

                bool dbOK;
                bool backupUsed = false;
                do
                {
                    try
                    {
                        dbOK = Settings.Settings.Default.IsStorageOK;
                        //if (availableBackups.Count > 2) dbOK = false; //test
                    }
                    catch
                    {
                        dbOK = false;
                    }
                    if (!dbOK)
                    {
                        backupUsed = true;
                        Settings.Settings.Default.PrepareReloadSettings();
                        //delete settings and move to latest
                        File.Delete(fn);
                        if (availableBackups.Count > 0)
                        {
                            File.Move(availableBackups[availableBackups.Count - 1], fn);
                            availableBackups.RemoveAt(availableBackups.Count - 1);
                        }
                        Settings.Settings.Default.ReloadSettings();
                    }
                } while (!dbOK);

                if (backupUsed)
                {
                    System.Windows.MessageBox.Show("The settings file was corrupt and a backup file is restored.", "Settings");
                }

#if DEBUG
                Localization.TranslationManager.Instance.CreateOrUpdateXmlFiles();
#endif
                Settings.Settings.Default.ApplicationVersion     = Assembly.GetExecutingAssembly().GetName().Version;
                Settings.Settings.Default.ApplicationPath        = Assembly.GetExecutingAssembly().Location;
                Settings.Settings.Default.ActiveGeocacheCode     = null;
                Settings.Settings.Default.ExecutedWithParameters = false;

                AvailableDatabases = new ObservableCollection <string>();

                if (string.IsNullOrEmpty(Settings.Settings.Default.GSAKExecutablePath))
                {
                    Settings.Settings.Default.GSAKExecutablePath = Utils.GSAK.ExecutablePath;
                }

                if (string.IsNullOrEmpty(Settings.Settings.Default.GSAKSettingsPath))
                {
                    Settings.Settings.Default.GSAKSettingsPath = Utils.GSAK.SettingsFolderPath;
                }

                if (string.IsNullOrEmpty(Settings.Settings.Default.DatabaseFolderPath))
                {
                    Settings.Settings.Default.DatabaseFolderPath = Utils.GSAK.DatabaseFolderPath;
                }

                try
                {
                    if (!string.IsNullOrEmpty(Settings.Settings.Default.DatabaseFolderPath))
                    {
                        if (!System.IO.Directory.Exists(Settings.Settings.Default.DatabaseFolderPath))
                        {
                            Settings.Settings.Default.DatabaseFolderPath = null;
                        }
                    }
                }
                catch
                {
                    Settings.Settings.Default.DatabaseFolderPath = null;
                }

                checkSelectedDatabaseExists();

                ApplicationData.Instance.GSAKCustomGlobals = Utils.GSAK.GlobalCustomFields;
                ApplicationData.Instance.GSAKLocations     = Utils.GSAK.Locations;

                InitializeComponent();
                DataContext = this;

                Settings.Settings.Default.NewVersionChecked = false;
                Settings.Settings.Default.PropertyChanged  += Default_PropertyChanged;

                if (Settings.Settings.Default.ReleaseVersion > Settings.Settings.Default.ApplicationVersion)
                {
                    newVersionUrl.Visibility = System.Windows.Visibility.Visible;
                }
            }
        }