/// <summary> /// 从项目文件中加载一个符号(symbology),到指定的层 /// </summary> /// <param name="filename">包含项目文件名的完整路径</param> /// <param name="handle">要加载symbology的图层的handle</param> public bool LoadLayerSymbologyFromProjectFile(string filename, int handle) { XmlDocument projectFile = new XmlDocument(); projectFile.Load(filename); //确保该层的句柄存在 if (Program.frmMain.m_Layers[handle] == null) { return(false); } XmlProjectFile projectXml = new XmlProjectFile(); foreach (XmlNode layerNode in projectFile.GetElementsByTagName("Layer")) { //图层名和存储的图层名一致,文件名也要一致 if (layerNode.Attributes["Name"].InnerText == Program.frmMain.m_Layers[handle].Name && Path.GetFileName(layerNode.Attributes["Path"].InnerText).ToLower() == Path.GetFileName(Program.frmMain.m_Layers[handle].FileName).ToLower()) { projectXml.LoadLayerProperties(layerNode, handle, true); return(true); } } return(false); }
public static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //无法捕捉异常将送到CustomExceptionHandler类处理 Application.ThreadException += new ThreadExceptionEventHandler(CustomExceptionHandler.OnThreadException); messageBox = new Utility.CustomMessageBox(); // 检查ocx是否可用,没有就尝试注册 if (!CheckOCXRegistration()) { return; } projInfo = new XmlProjectFile(); //启动一个线程,确保projnad文件存在并设置为环境变量setenv.exe try { Thread projnadCheck = new Thread(new System.Threading.ThreadStart(CheckPROJNAD)); projnadCheck.SetApartmentState(ApartmentState.STA); projnadCheck.Start(); } catch { } appInfo = new AppInfo(); //在配置文件中读取使用语言种类 LoadCulture(); //设置了语言后,需要立即初始化脚本窗体,以便可以翻译成为相应的语言版本 scripts = new frmScript(); //如果双击的是配置文件(.mwcfg),则从配置文件启动 bool broadcastCmdLine = false; RunConfigCommandLine(ref broadcastCmdLine); // 初始化程序界面 frmLogo formLogo = new frmLogo(); formLogo.Show(); formLogo.lblVersion.Text = "Version: " + App.VersionString; Application.DoEvents(); // 创建一个MainWinForm实例 formLogo.lblStatus.Text = "初始化..."; formLogo.lblStatus.Refresh(); frmMain = new MapWinForm(); MapWinGIS.Utility.Logger.ProgressStatus = new MWGProgressStatus(); // 恢复到old symbology 默认不恢复 // frmMain.MapMain.ShapeDrawingMethod = MapWinGIS.tkShapeDrawingMethod.dmStandard; // 加载投影数据库 formLogo.lblStatus.Text = "读取投影数据库..."; formLogo.lblStatus.Refresh(); //ProjectionDB.ReadFromExecutablePath(Application.ExecutablePath); // MapWindow.Controls 中的 // 创建菜单 frmMain.CreateMenus(); // 加载应用程序插件(application plugins) formLogo.lblStatus.Text = "加载应用程序插件..."; formLogo.lblStatus.Refresh(); frmMain.m_PluginManager.LoadApplicationPlugins(appInfo.ApplicationPluginDir); // 外部插件加载(plugin-in) formLogo.lblStatus.Text = "加载外部插件..."; formLogo.lblStatus.Refresh(); formLogo.Refresh(); frmMain.m_PluginManager.LoadPlugins(); //确保在plugin目录中的所有插件都加载了 frmMain.SynchPluginMenu(); // 加载配置,窗体的位置和大小 LoadConfig(); // 关闭,释放frmLogo formLogo.Close(); formLogo.Dispose(); //显示主窗体(MainWinForm) frmMain.LoadToolStripSettings(frmMain.StripDocker); frmMain.mapPanel.Show(frmMain.dckPanel); frmMain.Show(); frmMain.Update(); frmMain.SetModified(false); frmMain.m_HasBeenSaved = true; frmMain.MapMain.Focus(); Application.DoEvents(); //决定是否显示欢迎界面 //如果程序是双击配置文件(.mwcfg)形式启动,则不显示 if (appInfo.ShowWelcomeScreen && !broadcastCmdLine) { ShowWelcomeScreen(); } //如果双击项目文件并且存在项目文件,则将其提取到projinfo对象中 bool broadcastCmdLine_2 = false; RunProjectCommandLine(Environment.CommandLine, ref broadcastCmdLine_2); if (broadcastCmdLine || broadcastCmdLine_2) //从.mwcfg或mwprj启动的话,就把该消息广播给插件 { frmMain.m_PluginManager.BroadcastMessage("COMMAND_LINE:" + Environment.CommandLine); } //一切就绪,如果一个script等待执行,则现在就处理 //if (Scripts.pFileName != "") //{ // Scripts.RunSavedScript(); //} try { Application.Run(frmMain); } catch (ObjectDisposedException) { //当应用程序退出时引发的异常,所以忽略 } catch (Exception) { } /**********************************************************************************************************************/ //下面的代码将在程序终止后执行 //移除自定义错误处理handler Application.ThreadException -= new ThreadExceptionEventHandler(CustomExceptionHandler.OnThreadException); foreach (string s in g_KillList) { try { System.IO.File.Delete(s); } catch (Exception e) { Debug.WriteLine("删除临时文件失败: " + s + " " + e.Message); } } g_KillList.Clear(); }
/// <summary> /// 将配置保存到配置文件(configuration file) /// </summary> /// <returns>保存配置成功与否</returns> public bool SaveConfig(bool isSaveDocker = true, bool isSaveCulture = false) { if (isSaveDocker) { //保存Dock的配置,到独立的文件 string dockConfigFile = System.IO.Path.Combine(XmlProjectFile.GetApplicationDataDir(), "MapWinGISDock.config"); try { MapWinGIS.Utility.Logger.Dbg("保存Dock Panel配置:" + dockConfigFile); Program.frmMain.dckPanel.SaveAsXml(dockConfigFile); } catch (IOException e) { MapWinGIS.Utility.Logger.Dbg("保存Dock Panel配置:异常:" + e.ToString()); } } if (isSaveCulture) { //保存语言 SaveCulture(); } //保存系统设置 XmlElement root; try { //从指定的字符串加载Xml文档 p_Doc.LoadXml("<Mapwin type='configurationfile' version='" + App.VersionString + "'></Mapwin>"); root = p_Doc.DocumentElement; //保存AppInfo的设置到用户配置文件 AddAppInfo(p_Doc, root); //保存最近项目到用户配置文件 AddRecentProjects(p_Doc, root); //保存程序视图样式到用户配置文件 AddViewElement(p_Doc, root); //保存已经加载的插件信息到用户配置文件 AddPluginsElement(p_Doc, root, true); //保存内部插件信息到用户配置文件 //注释掉,因为在加载时没有从xml加载内部插件 //AddApplicationPluginsElement(p_Doc, root, true); //保存调色板信息到用户配置文件 AddColorPalettes(p_Doc, root); // 保存喜爱的项目到用户配置文件 // 该主题没有工作,先注释掉 //List<int> list = Program.appInfo.FavoriteProjections; //if (list.Count > 0) //{ // string s = ""; // foreach (int proj in list) // { // s += proj.ToString() + ";"; // } // //移除最后一个分号(semicolon) // if (s.Length > 0) // { // s = s.Substring(0, s.Length - 1); // } // XmlElement el = p_Doc.CreateElement("FavoriteProjections"); // el.InnerText = s; // root.AppendChild(el); //} MapWinGIS.Utility.Logger.Dbg("保存配置: " + ConfigFileName); p_Doc.Save(ConfigFileName); return(true); } catch (System.Exception ex) { Program.ShowError(ex); return(false); } }