Exemplo n.º 1
0
 // Search windows don't die, they simply hide from view :-)
 protected override void OnClosing(CancelEventArgs e)
 {
     e.Cancel     = true;
     this.Visible = false;
     worldWindow.Focus();
     base.OnClosing(e);
 }
Exemplo n.º 2
0
        public MainApplication()
        {
            try
            {
                //配置
                if (Global.Settings.ConfigurationWizardAtStartup)
                {
                    if (!File.Exists(Global.Settings.FileName))
                    {
                        Global.Settings.ConfigurationWizardAtStartup = false;
                    }
                    ConfigurationWizard.Wizard wizard = new ConfigurationWizard.Wizard(Global.Settings);
                    wizard.TopMost       = true;
                    wizard.ShowInTaskbar = true;
                    wizard.ShowDialog();
                }

                using (this.splashScreen = new Splash())
                {
                    this.splashScreen.Owner = this;
                    this.splashScreen.Show();
                    this.splashScreen.SetText("Initializing...");

                    Application.DoEvents();
                    InitializeComponent();
                    //设置global
                    Global.worldWindow = worldWindow;
                    long CacheUpperLimit = (long)Global.Settings.CacheSizeMegaBytes * 1024L * 1024L;
                    long CacheLowerLimit = (long)Global.Settings.CacheSizeMegaBytes * 768L * 1024L;    //75% of upper limit
                                                                                                       //Set up the cache
                    worldWindow.Cache = new Cache(
                        Global.Settings.CachePath,
                        CacheLowerLimit,
                        CacheUpperLimit,
                        Global.Settings.CacheCleanupInterval,
                        Global.Settings.TotalRunTime);

                    WorldWind.Net.WebDownload.Log404Errors = World.Settings.Log404Errors;

                    DirectoryInfo worldsXmlDir = new DirectoryInfo(Global.Settings.ConfigPath);
                    if (!worldsXmlDir.Exists)
                    {
                        throw new ApplicationException(
                                  string.Format(CultureInfo.CurrentCulture,
                                                "World Wind configuration directory '{0}' could not be found.", worldsXmlDir.FullName));
                    }

                    FileInfo[] worldXmlDescriptorFiles = worldsXmlDir.GetFiles("*.xml");
                    int        worldIndex = 0;
                    foreach (FileInfo worldXmlDescriptorFile in worldXmlDescriptorFiles)
                    {
                        try
                        {
                            Log.Write(Log.Levels.Debug + 1, "CONF", "checking world " + worldXmlDescriptorFile.FullName + " ...");
                            string worldXmlSchema = null;
                            string layerSetSchema = null;
                            if (Global.Settings.ValidateXML)
                            {
                                worldXmlSchema = Global.Settings.ConfigPath + "\\WorldXmlDescriptor.xsd";
                                layerSetSchema = Global.Settings.ConfigPath + "\\Earth\\LayerSet.xsd";
                            }
                            World w = WorldWind.ConfigurationLoader.Load(
                                worldXmlDescriptorFile.FullName, worldWindow.Cache, worldXmlSchema, layerSetSchema);
                            if (!availableWorldList.Contains(w.Name))
                            {
                                this.availableWorldList.Add(w.Name, worldXmlDescriptorFile.FullName);
                            }

                            w.Dispose();
                            System.Windows.Forms.MenuItem mi = new System.Windows.Forms.MenuItem(w.Name, new System.EventHandler(OnWorldChange));
                            worldIndex++;
                        }
                        catch (Exception caught)
                        {
                            splashScreen.SetError(worldXmlDescriptorFile + ": " + caught.Message);
                            Log.Write(caught);
                        }
                    }

                    Log.Write(Log.Levels.Debug, "CONF", "loading startup world...");
                    OpenStartupWorld();

                    while (!this.splashScreen.IsDone)
                    {
                        System.Threading.Thread.Sleep(50);
                    }
                    // Force initial render to avoid showing random contents of frame buffer to user.
                    worldWindow.Render();
                    WorldWindow.Focus();
                }

                // Center the main window
                Rectangle screenBounds = Screen.GetBounds(this);
                this.Location = new Point(screenBounds.Width / 2 - this.Size.Width / 2, screenBounds.Height / 2 - this.Size.Height / 2);
            }
            catch
            {
            }
        }