From b2fd88592485a6e8861547b0d4e8479d2c055545 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Thu, 6 Mar 2025 13:28:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AE=9E=E9=AA=8C=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Tools/AsposeHelper.cs | 37 ++++++----- Assets/Scripts/Tools/ChinarFileController.cs | 65 +++++++++++++++++++ .../Tools/ChinarFileController.cs.meta | 11 ++++ Assets/Scripts/Tools/ChinarFileDlog.cs | 57 ++++++++++++++++ Assets/Scripts/Tools/ChinarFileDlog.cs.meta | 11 ++++ Assets/Scripts/UI/UIScore.cs | 2 +- 6 files changed, 166 insertions(+), 17 deletions(-) create mode 100644 Assets/Scripts/Tools/ChinarFileController.cs create mode 100644 Assets/Scripts/Tools/ChinarFileController.cs.meta create mode 100644 Assets/Scripts/Tools/ChinarFileDlog.cs create mode 100644 Assets/Scripts/Tools/ChinarFileDlog.cs.meta diff --git a/Assets/Scripts/Tools/AsposeHelper.cs b/Assets/Scripts/Tools/AsposeHelper.cs index f0bafae1..2fdf7b4a 100644 --- a/Assets/Scripts/Tools/AsposeHelper.cs +++ b/Assets/Scripts/Tools/AsposeHelper.cs @@ -1,17 +1,15 @@ using Aspose.Words; using Aspose.Words.Replacing; -using QFramework; -using System.IO; using UnityEngine; -using System.Windows.Forms; using Newtonsoft.Json.Linq; using System; +using System.IO; public class AsposeHelper : MonoBehaviour { - public static void Writer(string json, Action callback = null) + public static void Writer(string json, Action callback = null) { // Wordĵ Document doc = new Document(Global.reportDemoPath); @@ -24,25 +22,32 @@ public class AsposeHelper : MonoBehaviour string value = property.Value.ToString(); doc.Range.Replace($"{{{key}}}", $"{value}", new FindReplaceOptions()); } + + string filePath = ChinarFileController.SaveProject(Path.GetFileName(Global.reportDemoPath).Split('.')[1]); + if (string.IsNullOrEmpty(filePath) == false) + { + doc.Save(filePath); + } + callback?.Invoke(); // 滻ı - SaveWithDialog(doc, callback); + //SaveWithDialog(doc, callback); //Debug.Log("ĵɣĵѱ浽: " + outputFilePath); } - private static void SaveWithDialog(Document doc, Action callback) - { - SaveFileDialog dialog = new SaveFileDialog(); - dialog.Filter = "Wordĵ|*.docx"; - var result = dialog.ShowDialog(); - if (result == DialogResult.OK) - { - doc.Save(dialog.FileName); - } - callback?.Invoke(result); - } + //private static void SaveWithDialog(Document doc, Action callback) + //{ + // SaveFileDialog dialog = new SaveFileDialog(); + // dialog.Filter = "Wordĵ|*.docx"; + // var result = dialog.ShowDialog(); + // if (result == DialogResult.OK) + // { + // doc.Save(dialog.FileName); + // } + // callback?.Invoke(result); + //} } diff --git a/Assets/Scripts/Tools/ChinarFileController.cs b/Assets/Scripts/Tools/ChinarFileController.cs new file mode 100644 index 00000000..1e6c7dc0 --- /dev/null +++ b/Assets/Scripts/Tools/ChinarFileController.cs @@ -0,0 +1,65 @@ +using UnityEngine; +using System.Runtime.InteropServices; +using System; + + +/// +/// ļƽű +/// +public class ChinarFileController : MonoBehaviour +{ + /// + /// Ŀ + /// + public static string OpenProject() + { + string originalDir = Environment.CurrentDirectory; + string filepath = string.Empty; + OpenFileDlg pth = new OpenFileDlg(); + pth.structSize = Marshal.SizeOf(pth); + // ʽƳĩβߣ + //pth.filter = @"All Files (*.*)|*.jpg"; + pth.file = new string(new char[256]); + pth.maxFile = pth.file.Length; + pth.fileTitle = new string(new char[64]); + pth.maxFileTitle = pth.fileTitle.Length; + pth.initialDir = Application.dataPath.Replace("/", "\\") + "\\Resources"; + pth.title = "Ŀ"; + pth.defExt = "dat"; + // Flagsãؼѡ + pth.flags = 0x00080000 | 0x00001000 | 0x00000800; // OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST + + if (OpenFileDialog.GetOpenFileName(pth)) + { + filepath = pth.file; + } + Environment.CurrentDirectory = originalDir; + return filepath; + } + + + /// + /// ļĿ + /// + public static string SaveProject(string ext) + { + string filepath = string.Empty; + SaveFileDlg pth = new SaveFileDlg(); + pth.structSize = Marshal.SizeOf(pth); + pth.filter = "All files (*.*)|*.*"; + pth.file = new string(new char[256]); + pth.maxFile = pth.file.Length; + pth.fileTitle = new string(new char[64]); + pth.maxFileTitle = pth.fileTitle.Length; + pth.initialDir = Application.dataPath; //Ĭ· + pth.title = "Ŀ"; + pth.defExt = ext; + pth.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; + if (SaveFileDialog.GetSaveFileName(pth)) + { + filepath = pth.file; //ѡļ·; + } + return filepath; + } +} + diff --git a/Assets/Scripts/Tools/ChinarFileController.cs.meta b/Assets/Scripts/Tools/ChinarFileController.cs.meta new file mode 100644 index 00000000..bf809f53 --- /dev/null +++ b/Assets/Scripts/Tools/ChinarFileController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6ff1bbdf3a991ec45bbf4e8be1ca5b91 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/ChinarFileDlog.cs b/Assets/Scripts/Tools/ChinarFileDlog.cs new file mode 100644 index 00000000..607f0996 --- /dev/null +++ b/Assets/Scripts/Tools/ChinarFileDlog.cs @@ -0,0 +1,57 @@ +using System.Runtime.InteropServices; +using System; + + +/// +/// ļ־ +/// +// [(.,ַ=ַ.Զ)] +[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] +public class ChinarFileDlog +{ + public int structSize = 0; + public IntPtr dlgOwner = IntPtr.Zero; + public IntPtr instance = IntPtr.Zero; + public String filter = null; + public String customFilter = null; + public int maxCustFilter = 0; + public int filterIndex = 0; + public String file = null; + public int maxFile = 0; + public String fileTitle = null; + public int maxFileTitle = 0; + public String initialDir = null; + public String title = null; + public int flags = 0; + public short fileOffset = 0; + public short fileExtension = 0; + public String defExt = null; + public IntPtr custData = IntPtr.Zero; + public IntPtr hook = IntPtr.Zero; + public String templateName = null; + public IntPtr reservedPtr = IntPtr.Zero; + public int reservedInt = 0; + public int flagsEx = 0; +} + +[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] +public class OpenFileDlg : ChinarFileDlog +{ +} + +public class OpenFileDialog +{ + [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)] + public static extern bool GetOpenFileName([In, Out] OpenFileDlg ofd); +} + +public class SaveFileDialog +{ + [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)] + public static extern bool GetSaveFileName([In, Out] SaveFileDlg ofd); +} + +[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] +public class SaveFileDlg : ChinarFileDlog +{ +} \ No newline at end of file diff --git a/Assets/Scripts/Tools/ChinarFileDlog.cs.meta b/Assets/Scripts/Tools/ChinarFileDlog.cs.meta new file mode 100644 index 00000000..8b41be2c --- /dev/null +++ b/Assets/Scripts/Tools/ChinarFileDlog.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9824f58b2cf6cc64ab2ef5d8ec6153b3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/UIScore.cs b/Assets/Scripts/UI/UIScore.cs index f6f3bbb5..30dfd68d 100644 --- a/Assets/Scripts/UI/UIScore.cs +++ b/Assets/Scripts/UI/UIScore.cs @@ -40,7 +40,7 @@ namespace QFramework.Example loader.LoadAsync(); #elif UNITY_STANDALONE_WIN DownLoad.interactable = false; - AsposeHelper.Writer(GetScoreDataJson(), result => + AsposeHelper.Writer(GetScoreDataJson(), () => { DownLoad.interactable = true; });