| | |
| | | LogOut.Info("开始运行.."); |
| | | bool isTest = "1" == ConfigurationManager.AppSettings["isTest"]; |
| | | |
| | | this.fly = ConfigurationManager.AppSettings["fly"] ?? ConfigurationManager.AppSettings["testFly"]; |
| | | this.fly = getFly(); |
| | | /*this.fly = ConfigurationManager.AppSettings["fly"] ?? ConfigurationManager.AppSettings["testFly"]; |
| | | if (!this.fly.Contains(":\\")) this.fly = Path.Combine(Application.StartupPath, this.fly); |
| | | if (!File.Exists(this.fly)) |
| | | { |
| | | LogOut.Error("Fly文件不存在:" + this.fly); |
| | | return; |
| | | } |
| | | }*/ |
| | | |
| | | SG = new SGWorld71(); |
| | | SG.OnLoadFinished += SG_OnLoadFinished; |
| | |
| | | tool = new FrmTool(this); |
| | | tool.Show(); |
| | | |
| | | SG.Open(this.fly); |
| | | //SG.Open(this.fly); |
| | | } |
| | | //else |
| | | //{ |
| | |
| | | { |
| | | try |
| | | { |
| | | this.SG.OnLoadFinished -= SG_OnLoadFinished; |
| | | //this.SG.OnLoadFinished -= SG_OnLoadFinished; |
| | | |
| | | string id = this.SG.ProjectTree.FindItem(startName); |
| | | if (string.IsNullOrEmpty(id)) return; |
| | |
| | | |
| | | public void InvokeByCode(int code) |
| | | { |
| | | LogOut.Info("InvokeByCode > 0x" + code.ToString("x")); |
| | | switch (code) |
| | | { |
| | | case 0xc0: // 重置鼠标模式 |
| | |
| | | case 0xdb: // 按照属性设置颜色 |
| | | DisplayByAttribute(1, "按照属性设置颜色"); break; |
| | | case 0xdc: // 打开数据方案 |
| | | OpenPrj(); break; |
| | | case 0xdd: // 保存项目 |
| | | SavePrj(); break; |
| | | Open(); break; |
| | | case 0xdd: // 另存为 |
| | | SaveAs(); break; |
| | | } |
| | | } |
| | | #endregion |
| | |
| | | #region 方案管理 |
| | | private void Save() |
| | | { |
| | | //SG.Command.Execute(1003, null); |
| | | SaveLocation(); |
| | | this.SG.Project.Save(); |
| | | } |
| | | |
| | | private void OpenPrj() |
| | | { |
| | | string flyPath = ReadPrjPath(); |
| | | if (String.IsNullOrEmpty(flyPath)) flyPath = Path.Combine(mainUrl, "see.fly"); |
| | | |
| | | if (!File.Exists(flyPath)) |
| | | { |
| | | flyPath = ConfigurationManager.AppSettings["fly"] ?? ConfigurationManager.AppSettings["testFly"]; |
| | | if (!flyPath.Contains(":\\")) flyPath = Path.Combine(mainUrl, flyPath); |
| | | } |
| | | |
| | | this.SG.Open(flyPath); |
| | | } |
| | | |
| | | private void SavePrj() |
| | | { |
| | | try |
| | | { |
| | | string flyPath = ReadPrjPath(); |
| | | if (String.IsNullOrEmpty(flyPath)) flyPath = Path.Combine(mainUrl, "see.fly"); |
| | | |
| | | this.Save(); |
| | | //this.SG.Project.SaveAs(flyPath); |
| | | if (this.fly.Equals(flyPath)) return; |
| | | if (File.Exists(flyPath)) File.Delete(flyPath); |
| | | |
| | | string cmd = string.Format("mklink \"{0}\" \"{1}\"", flyPath, this.fly); |
| | | ExecCmd(new List<string> { cmd }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); |
| | | } |
| | | this.SG.Command.Execute(1019, 0); // Capture Tree State |
| | | SG.Command.Execute(1003, 0); // this.SG.Project.Save(); // |
| | | } |
| | | |
| | | private void SaveLocation() |
| | |
| | | } |
| | | } |
| | | |
| | | private void Open() |
| | | { |
| | | this.fly = getFly(); |
| | | this.SG.Open(this.fly); |
| | | } |
| | | |
| | | private String getFly() |
| | | { |
| | | string flyPath = ReadPrjPath(); |
| | | if (String.IsNullOrEmpty(flyPath)) flyPath = "empty.fly"; |
| | | if (!flyPath.Contains(":\\")) flyPath = Path.Combine(Application.StartupPath, "Resources", flyPath); |
| | | |
| | | return flyPath; |
| | | } |
| | | |
| | | private String ReadPrjPath() |
| | | { |
| | | String txt = Path.Combine(mainUrl, "fly.txt"); |
| | | if (!File.Exists(txt)) return null; |
| | | |
| | | try |
| | | { |
| | | String txt = Path.Combine(mainUrl, "Resources", "fly.txt"); |
| | | if (!File.Exists(txt)) return null; |
| | | |
| | | using (StreamReader sr = new StreamReader(txt)) |
| | | { |
| | | return sr.ReadLine(); |
| | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private void SaveAs() |
| | | { |
| | | string flyPath = ReadPrjPath(); |
| | | string fileName = String.IsNullOrEmpty(flyPath) ? null : Path.GetFileName(flyPath); |
| | | |
| | | string dest = SaveAs(fileName); |
| | | if (string.IsNullOrEmpty(dest)) return; |
| | | |
| | | this.fly = dest; |
| | | string sourcePath = Path.Combine(mainUrl, "Resources"); |
| | | if (string.IsNullOrEmpty(flyPath) || (dest.Contains(sourcePath) && dest.IndexOf("\\", sourcePath.Length + 1) == -1)) return; |
| | | |
| | | CreateShortcut(flyPath, this.fly); |
| | | //ExecCmd(new List<string> { string.Format("mklink \"{0}\" \"{1}\"", flyPath, this.fly) }); |
| | | } |
| | | |
| | | private String SaveAs(String fileName) |
| | | { |
| | | try |
| | | { |
| | | if (String.IsNullOrEmpty(fileName)) fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".fly"; |
| | | |
| | | SaveLocation(); |
| | | this.SG.Command.Execute(1019, 0); // Capture Tree State |
| | | this.SG.Project.SaveAs(fileName); |
| | | |
| | | string source = Path.Combine(GetSavePath(), fileName); |
| | | if (!File.Exists(source)) |
| | | { |
| | | LogOut.Error(fileName + ",找不到"); |
| | | } |
| | | |
| | | string dest = Path.Combine(Application.StartupPath, "Resources", fileName); |
| | | if (File.Exists(dest)) File.Delete(dest); |
| | | File.Move(source, dest); |
| | | |
| | | return dest; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private String GetSavePath() |
| | | { |
| | | string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); |
| | | string tePathName = ConfigurationManager.AppSettings["tePath"].Contains("SmartEarth") ? "SmartEarth" : "Skyline"; |
| | | |
| | | return Path.Combine(appData, tePathName, "TerraExplorer"); |
| | | } |
| | | |
| | | public static void CreateShortcut(string shortcutPath, string targetPath, string description = null, string iconLocation = null) |
| | | { |
| | | var shell = new IWshRuntimeLibrary.WshShell(); |
| | | var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath + ".lnk"); // 创建快捷方式对象 |
| | | shortcut.TargetPath = targetPath; // 指定目标路径 |
| | | shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath); // 设置起始位置 |
| | | shortcut.WindowStyle = 1; // 设置运行方式,默认为常规窗口 |
| | | shortcut.Description = description; // 设置备注 |
| | | shortcut.IconLocation = string.IsNullOrWhiteSpace(iconLocation) ? targetPath : iconLocation; // 设置图标路径 |
| | | shortcut.Save(); // 保存快捷方式 |
| | | } |
| | | #endregion |
| | | } |
| | | } |