From 8d7a67ab1d635cb954337d8a767878ae526dd3dc Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期六, 07 九月 2024 10:27:24 +0800
Subject: [PATCH] 修改打开、保存、另存为功能

---
 TEWin/FrmWin.cs  |  119 ++++++++++++++++++++++-----------------
 TEWin/FrmTool.cs |    2 
 2 files changed, 69 insertions(+), 52 deletions(-)

diff --git a/TEWin/FrmTool.cs b/TEWin/FrmTool.cs
index 5440f67..35f60ec 100644
--- a/TEWin/FrmTool.cs
+++ b/TEWin/FrmTool.cs
@@ -17,7 +17,7 @@
             "褰卞儚鏁版嵁", "鍦板舰鏁版嵁", "妯″瀷鏁版嵁(osgb)", "妯″瀷鏁版嵁(obj)", "缂栬緫鏁版嵁", "鐐归噺绠�", 
             "鍧″悜鍒嗘瀽", "绾块噺绠�", "闈㈤噺绠�", "浣撻噺绠�", "瑙掗噺绠�", "绌洪棿缁熻", "绌洪棿鍒嗘瀽", 
             "鍓栭潰鍒嗘瀽", "鍧″害鍒嗘瀽", "绛夊�肩嚎", "鍓栧垏鍒嗘瀽", "鍦扮悊鍦烘櫙浜у搧缁勮", "浼犵粺4D浜у搧娲剧敓", 
-            "鎵撳紑fly", "鍔犺浇shp", "璇诲彇shp", "鎸夌収灞炴�ф樉绀�", "鎸夌収灞炴�ц缃鑹�", "鎵撳紑鏁版嵁鏂规", "淇濆瓨椤圭洰" };
+            "鎵撳紑fly", "鍔犺浇shp", "璇诲彇shp", "鎸夌収灞炴�ф樉绀�", "鎸夌収灞炴�ц缃鑹�", "鎵撳紑鏁版嵁鏂规", "鍙﹀瓨涓�" };
 
         public FrmTool(FrmWin win)
         {
diff --git a/TEWin/FrmWin.cs b/TEWin/FrmWin.cs
index 7b6c236..96d9d3b 100644
--- a/TEWin/FrmWin.cs
+++ b/TEWin/FrmWin.cs
@@ -101,7 +101,7 @@
                     tool = new FrmTool(this);
                     tool.Show();
 
-                    SG.Open(this.fly);
+                    //SG.Open(this.fly);
                 }
                 //else
                 //{
@@ -232,9 +232,9 @@
                 case 0xdb: // 鎸夌収灞炴�ц缃鑹�
                     DisplayByAttribute(1, "鎸夌収灞炴�ц缃鑹�"); break;
                 case 0xdc: // 鎵撳紑鏁版嵁鏂规
-                    OpenPrj(); break;
-                case 0xdd: // 淇濆瓨椤圭洰
-                    SavePrj(); break;
+                    Open(); break;
+                case 0xdd: // 鍙﹀瓨涓�
+                    SaveAs(); break;
             }
         }
         #endregion
@@ -792,50 +792,7 @@
         {
             SaveLocation();
             this.SG.Command.Execute(1019, 0); // Capture Tree State
-            SG.Command.Execute(1003, 0); // this.SG.Project.Save();
-        }
-
-        private void SaveAs(string flyPath)
-        {
-            SaveLocation();
-            this.SG.Command.Execute(1019, 0); // Capture Tree State
-            this.SG.Project.SaveAs(flyPath);
-        }
-
-        private void OpenPrj()
-        {
-            string flyPath = ReadPrjPath();
-            if (String.IsNullOrEmpty(flyPath)) flyPath = this.fly; // 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 = this.fly; // 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 });
-                CreateShortcut(flyPath, this.fly);
-            }
-            catch (Exception ex)
-            {
-                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
-            }
+            SG.Command.Execute(1003, 0); // this.SG.Project.Save(); // 
         }
 
         private void SaveLocation()
@@ -854,13 +811,28 @@
             }
         }
 
+        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();
@@ -873,6 +845,51 @@
             }
         }
 
+        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);

--
Gitblit v1.9.3