diff --git a/BlocklyAtsGui/BlocklyAtsGui.csproj b/BlocklyAtsGui/BlocklyAtsGui.csproj index 957908d..d559ce4 100644 --- a/BlocklyAtsGui/BlocklyAtsGui.csproj +++ b/BlocklyAtsGui/BlocklyAtsGui.csproj @@ -99,7 +99,6 @@ FormBugReport.cs - @@ -196,19 +195,13 @@ XCOPY "$(SolutionDir)www" "$(TargetDir)\www\" /E /Y XCOPY "$(SolutionDir)assets" "$(TargetDir)\" /E /Y -COPY /Y "$(TargetDir)\x86\WebView2Loader.dll" "$(TargetDir)\WebView2Loader.x86.dll" -RMDIR /S /Q "$(TargetDir)\x86" -COPY /Y "$(TargetDir)\x64\WebView2Loader.dll" "$(TargetDir)\WebView2Loader.x64.dll" -RMDIR /S /Q "$(TargetDir)\x64" -COPY /Y "$(TargetDir)\arm64\WebView2Loader.dll" "$(TargetDir)\WebView2Loader.arm64.dll" -RMDIR /S /Q "$(TargetDir)\arm64" IF $(ConfigurationName)==Release ( COPY /Y "$(SolutionDir)BatsWinApi\Release\batswinapi_x86.dll" "$(TargetDir)\lib" COPY /Y "$(SolutionDir)BatsWinApi\Release\batswinapi_x64.dll" "$(TargetDir)\lib" ERASE "$(TargetDir)\WebView2Loader.dll" RMDIR /S /Q "${TargetDir)\BlocklyATS.exe.WebView2" -DEL "$(TargetDir)\*.xml" -DEL "$(TargetDir)\*.zip" +ERASE "$(TargetDir)\*.xml" +ERASE "$(TargetDir)\*.zip" "C:\Program Files\7-zip\7z.exe" a BlocklyAts.zip . ) diff --git a/BlocklyAtsGui/Program.cs b/BlocklyAtsGui/Program.cs index 3bd9ce1..0fd9449 100644 --- a/BlocklyAtsGui/Program.cs +++ b/BlocklyAtsGui/Program.cs @@ -18,7 +18,12 @@ static void Main() { Application.SetCompatibleTextRenderingDefault(false); Application.Run(new FormMain()); - PreferenceManager.SavePreference(); + if (!PreferenceManager.SavePreference()) { + MessageBox.Show( + I18n.TranslateAllLang("Msg.PreferenceWriteFail"), "Cannot Write Preference", + MessageBoxButtons.OK, MessageBoxIcon.Error + ); + } } } } diff --git a/BlocklyAtsGui/Properties/AssemblyInfo.cs b/BlocklyAtsGui/Properties/AssemblyInfo.cs index 27ed92c..73da3bd 100644 --- a/BlocklyAtsGui/Properties/AssemblyInfo.cs +++ b/BlocklyAtsGui/Properties/AssemblyInfo.cs @@ -32,4 +32,4 @@ // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.5.101")] +[assembly: AssemblyVersion("1.0.5.102")] diff --git a/BlocklyAtsGui/System/PreferenceManager.cs b/BlocklyAtsGui/System/PreferenceManager.cs index e1eafb4..cbb813c 100644 --- a/BlocklyAtsGui/System/PreferenceManager.cs +++ b/BlocklyAtsGui/System/PreferenceManager.cs @@ -11,6 +11,13 @@ static class PreferenceManager { public static Preference CurrentPreference; + public static string DataDirectory = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), + "zbx1425", "BlocklyAts" + ); + public static string PreferencePath = Path.Combine(DataDirectory, "Preference.xml"); + public static string WebView2UserDataPath = Path.Combine(DataDirectory, "WebView2UserData"); + public static bool FirstStartup = true; public static void ResetPreference() { @@ -20,10 +27,15 @@ public static void ResetPreference() { }; } - public static bool LoadPreference(string path = "Preference.xml") { - if (File.Exists(path)) { + public static bool LoadPreference() { + try { + if (!Directory.Exists(DataDirectory)) Directory.CreateDirectory(DataDirectory); + } catch { + return false; + } + if (File.Exists(PreferencePath)) { try { - CurrentPreference = Preference.LoadFromFile(path); + CurrentPreference = Preference.LoadFromFile(PreferencePath); FirstStartup = false; } catch { ResetPreference(); @@ -37,9 +49,10 @@ public static bool LoadPreference(string path = "Preference.xml") { } } - public static bool SavePreference(string path = "Preference.xml") { + public static bool SavePreference() { try { - CurrentPreference.SaveToFile(path); + if (!Directory.Exists(DataDirectory)) Directory.CreateDirectory(DataDirectory); + CurrentPreference.SaveToFile(PreferencePath); } catch { return false; } diff --git a/BlocklyAtsGui/UserInterface/FormAbout.Designer.cs b/BlocklyAtsGui/UserInterface/FormAbout.Designer.cs index eef662e..7f00cd0 100644 --- a/BlocklyAtsGui/UserInterface/FormAbout.Designer.cs +++ b/BlocklyAtsGui/UserInterface/FormAbout.Designer.cs @@ -136,14 +136,14 @@ private void InitializeComponent() { // this.linkLabel1.AutoSize = true; this.linkLabel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.linkLabel1.LinkArea = new System.Windows.Forms.LinkArea(21, 14); + this.linkLabel1.LinkArea = new System.Windows.Forms.LinkArea(20, 14); this.linkLabel1.Location = new System.Drawing.Point(106, 58); this.linkLabel1.Margin = new System.Windows.Forms.Padding(6, 0, 3, 5); this.linkLabel1.Name = "linkLabel1"; this.linkLabel1.Size = new System.Drawing.Size(357, 19); this.linkLabel1.TabIndex = 25; this.linkLabel1.TabStop = true; - this.linkLabel1.Text = "feedback@zbx1425.cn; www.zbx1425.cn"; + this.linkLabel1.Text = "support@zbx1425.cn; www.zbx1425.cn"; this.linkLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; this.linkLabel1.UseCompatibleTextRendering = true; this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); diff --git a/BlocklyAtsGui/UserInterface/FormBugReport.Designer.cs b/BlocklyAtsGui/UserInterface/FormBugReport.Designer.cs index ea039d9..216182f 100644 --- a/BlocklyAtsGui/UserInterface/FormBugReport.Designer.cs +++ b/BlocklyAtsGui/UserInterface/FormBugReport.Designer.cs @@ -78,14 +78,14 @@ private void InitializeComponent() { // llbEmail // this.llbEmail.AutoSize = true; - this.llbEmail.LinkArea = new System.Windows.Forms.LinkArea(0, 19); + this.llbEmail.LinkArea = new System.Windows.Forms.LinkArea(0, 18); this.llbEmail.Location = new System.Drawing.Point(94, 158); this.llbEmail.Margin = new System.Windows.Forms.Padding(10); this.llbEmail.Name = "llbEmail"; - this.llbEmail.Size = new System.Drawing.Size(270, 24); + this.llbEmail.Size = new System.Drawing.Size(261, 24); this.llbEmail.TabIndex = 7; this.llbEmail.TabStop = true; - this.llbEmail.Text = "feedback@zbx1425.cn (As of 2021)"; + this.llbEmail.Text = "support@zbx1425.cn (As of 2021)"; this.llbEmail.UseCompatibleTextRendering = true; this.llbEmail.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llbEmail_LinkClicked); // diff --git a/BlocklyAtsGui/UserInterface/FormBugReport.cs b/BlocklyAtsGui/UserInterface/FormBugReport.cs index e5a5624..78eeefc 100644 --- a/BlocklyAtsGui/UserInterface/FormBugReport.cs +++ b/BlocklyAtsGui/UserInterface/FormBugReport.cs @@ -27,7 +27,7 @@ private void llbTwitter_LinkClicked(object sender, LinkLabelLinkClickedEventArgs } private void llbEmail_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { - PlatformFunction.CallBrowser("mailto:feedback@zbx1425.cn?subject=BlocklyAts%20Bug%20Report"); + PlatformFunction.CallBrowser("mailto:support@zbx1425.cn?subject=BlocklyAts%20Bug%20Report"); } private void FormBugReport_Load(object sender, EventArgs e) { diff --git a/BlocklyAtsGui/UserInterface/FormMain.cs b/BlocklyAtsGui/UserInterface/FormMain.cs index c78bc8b..5d7da2a 100644 --- a/BlocklyAtsGui/UserInterface/FormMain.cs +++ b/BlocklyAtsGui/UserInterface/FormMain.cs @@ -168,12 +168,8 @@ private async void tsbtnSaveAs_Click(object sender, EventArgs e) { Title = "Save Workspace" }; if (sfd.ShowDialog() != DialogResult.OK) return; - - var workspaceState = await mainWebBrowser.BkySaveWorkspace(); - if (workspaceState == null) return; - currentWorkspace.BlocklyXml = new FPXElement(workspaceState); - currentWorkspace.SaveToFile(sfd.FileName); - updateSaveFileState(); + + await saveWorkspace(sfd.FileName); } private async void tsbtnOpen_Click(object sender, EventArgs e) { @@ -192,7 +188,18 @@ private async void tsbtnOpen_Click(object sender, EventArgs e) { } } + private async Task saveWorkspace(string path = null) { + if (path == null && string.IsNullOrEmpty(currentWorkspace.SaveFilePath)) return; + var workspaceState = await mainWebBrowser.BkySaveWorkspace(); + if (workspaceState == null) return; + currentWorkspace.BlocklyXml = new FPXElement(workspaceState); + currentWorkspace.SaveToFile(path); + updateSaveFileState(); + } + private async Task buildAllPlatforms() { + await saveWorkspace(); // Autosave + var luaCode = await mainWebBrowser.BkyExportLua(); var outputList = new List>(); if (currentWorkspace.Config.ShouldCompilex86) { @@ -241,11 +248,7 @@ private async void tsbtnCompile_Click(object sender, EventArgs e) { } private async void tsbtnSave_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(currentWorkspace.SaveFilePath)) return; - var workspaceState = await mainWebBrowser.BkySaveWorkspace(); - if (workspaceState == null) return; - currentWorkspace.BlocklyXml = new FPXElement(workspaceState); - currentWorkspace.SaveToFile(); + await saveWorkspace(); } private async void tsbtnCompileRun_Click(object sender, EventArgs e) { diff --git a/BlocklyAtsGui/WebView/HttpServer.cs b/BlocklyAtsGui/WebView/HttpServer.cs index c83e975..3f3d068 100644 --- a/BlocklyAtsGui/WebView/HttpServer.cs +++ b/BlocklyAtsGui/WebView/HttpServer.cs @@ -117,7 +117,7 @@ private async Task HandleIncomingConnections(CancellationToken cancelToken) { resp.StatusCode = 404; string errorMessageTemplate = @"

Error: 404 Not Found

-

Please inform developer with these information: zbx1425@outlook.com

+

Please inform developer with these information.


diff --git a/BlocklyAtsGui/WebView/WebView2Browser.Reflection.cs b/BlocklyAtsGui/WebView/WebView2Browser.Reflection.cs deleted file mode 100644 index 19e7ac6..0000000 --- a/BlocklyAtsGui/WebView/WebView2Browser.Reflection.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Microsoft.Web.WebView2.Core; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; - -namespace BlocklyAts { - partial class WebView2Browser { - - [DllImport("kernel32.dll", SetLastError = true)] - private static extern IntPtr LoadLibrary(string dllToLoad); - - private static void TryLoadWebview2Loader() { - var FLoaderLoaded = typeof(CoreWebView2Environment) - .GetField("webView2LoaderLoaded", BindingFlags.Static | BindingFlags.NonPublic); - if (!(bool)FLoaderLoaded.GetValue(null)) { - string frameworkDescription = RuntimeInformation.FrameworkDescription; - if (frameworkDescription.StartsWith(".NET Framework")) { - string localPath = new Uri(typeof(CoreWebView2Environment).Assembly.CodeBase).LocalPath; - string directoryName = Path.GetDirectoryName(localPath); - string arch; - switch (RuntimeInformation.ProcessArchitecture) { - case Architecture.X86: - arch = "x86"; - break; - case Architecture.X64: - arch = "x64"; - break; - case Architecture.Arm64: - arch = "arm64"; - break; - default: - throw new NotSupportedException( - string.Format("{0} bit WebView2Loader.dll is not supported", RuntimeInformation.ProcessArchitecture) - ); - } - string dllName = "WebView2Loader." + arch + ".dll"; - if (File.Exists(dllName)) { - File.Copy(dllName, "WebView2Loader.dll", true); - if (LoadLibrary("WebView2Loader.dll") == IntPtr.Zero) { - int hrforLastWin32Error = Marshal.GetHRForLastWin32Error(); - Marshal.ThrowExceptionForHR(hrforLastWin32Error); - } else { - FLoaderLoaded.SetValue(null, true); - } - } - } - } - } - } -} diff --git a/BlocklyAtsGui/WebView/WebView2Browser.cs b/BlocklyAtsGui/WebView/WebView2Browser.cs index 5341003..4803dc7 100644 --- a/BlocklyAtsGui/WebView/WebView2Browser.cs +++ b/BlocklyAtsGui/WebView/WebView2Browser.cs @@ -18,14 +18,10 @@ partial class WebView2Browser : BaseBrowser { private WebView2 browser; public WebView2Browser(string url = "about:blank") { - // Use an alternative path for WebView2 Loader, for a better appearance - // Might remove it if it causes troubles - TryLoadWebview2Loader(); - browser = new WebView2(); browser.NavigationCompleted += Browser_DocumentCompleted; - var createTask = CoreWebView2Environment.CreateAsync(); + var createTask = CoreWebView2Environment.CreateAsync(null, PreferenceManager.WebView2UserDataPath, null); createTask.Wait(); environment = createTask.Result; browser.CoreWebView2Ready += (sender, e) => { @@ -86,7 +82,7 @@ private void CoreWebView2_WebResourceRequested(object sender, CoreWebView2WebRes } else { string errorMessageTemplate = @"

Error: 404 Not Found

-

Please inform developer with these information: zbx1425@outlook.com

+

Please inform developer with these information.


Missing Path{0}
Missing Path{0}