Skip to content

Commit

Permalink
Update namespace name
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Jan 22, 2021
1 parent ca46db5 commit c9526fc
Show file tree
Hide file tree
Showing 55 changed files with 1,151 additions and 1,916 deletions.
14 changes: 7 additions & 7 deletions BatsWinApi/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int *bvePanel, *bveSound;

void l_printerr() {
const char * err = lua_tostring(L, -1);
if (MessageBoxA(NULL, err, "BlocklyATS Lua Script Error", MB_RETRYCANCEL | MB_ICONERROR) == IDCANCEL) {
if (MessageBoxA(NULL, err, "BlocklyAts Lua Script Error", MB_RETRYCANCEL | MB_ICONERROR) == IDCANCEL) {
lua_close(L);
L = NULL;
}
Expand Down Expand Up @@ -64,7 +64,7 @@ static int l_sound_getset(lua_State *L) {

static int l_msgbox(lua_State *L) {
const char* msg = luaL_checkstring(L, 1);
MessageBoxA(NULL, msg, "BlocklyATS Message", MB_ICONINFORMATION);
MessageBoxA(NULL, msg, "BlocklyAts Message", MB_ICONINFORMATION);
return 0;
}

Expand All @@ -77,25 +77,25 @@ ATS_API void WINAPI Load() {

if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPCSTR)&Dispose, &hm) == 0) {
MessageBoxA(NULL, "GetModuleHandle failed, ATS plugin cannot load", "BlocklyATS Error", MB_ICONERROR);
MessageBoxA(NULL, "GetModuleHandle failed, ATS plugin cannot load", "BlocklyAts Error", MB_ICONERROR);
return;
}
if (GetModuleFileNameA(hm, dllPath, sizeof(dllPath)) == 0) {
MessageBoxA(NULL, "GetModuleFileName failed, ATS plugin cannot load", "BlocklyATS Error", MB_ICONERROR);
MessageBoxA(NULL, "GetModuleFileName failed, ATS plugin cannot load", "BlocklyAts Error", MB_ICONERROR);
return;
}

HANDLE hFile = CreateFileA(dllPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE == hFile) {
MessageBoxA(NULL, "CreateFileA failed, ATS plugin cannot load", "BlocklyATS Error", MB_ICONERROR);
MessageBoxA(NULL, "CreateFileA failed, ATS plugin cannot load", "BlocklyAts Error", MB_ICONERROR);
return;
}
ReadFile(hFile, buffer, sizeof(buffer), &read, NULL);
IMAGE_DOS_HEADER* dosheader = (IMAGE_DOS_HEADER*)buffer;
IMAGE_NT_HEADERS32* header = (IMAGE_NT_HEADERS32*)(buffer + dosheader->e_lfanew);
if (dosheader->e_magic != IMAGE_DOS_SIGNATURE || header->Signature != IMAGE_NT_SIGNATURE) {
CloseHandle(hFile);
MessageBoxA(NULL, "PE header malformed, ATS plugin cannot load", "BlocklyATS Error", MB_ICONERROR);
MessageBoxA(NULL, "PE header malformed, ATS plugin cannot load", "BlocklyAts Error", MB_ICONERROR);
return;
}

Expand All @@ -112,7 +112,7 @@ ATS_API void WINAPI Load() {
DWORD filesize = GetFileSize(hFile, NULL);
if (filesize - exesize <= 0) {
CloseHandle(hFile);
MessageBoxA(NULL, "Cannot locate PE terminal offset, ATS plugin cannot load", "BlocklyATS Error", MB_ICONERROR);
MessageBoxA(NULL, "Cannot locate PE terminal offset, ATS plugin cannot load", "BlocklyAts Error", MB_ICONERROR);
return;
}
SetFilePointer(hFile, exesize, NULL, FILE_BEGIN);
Expand Down
9 changes: 5 additions & 4 deletions BlocklyAts.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ Global
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Debug|x64.ActiveCfg = Debug|x64
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Debug|x64.Build.0 = Debug|x64
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Debug|x86.ActiveCfg = Debug|Any CPU
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Debug|x86.Build.0 = Debug|Any CPU
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Debug|x86.ActiveCfg = Debug|x86
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Debug|x86.Build.0 = Debug|x86
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Release|Any CPU.Build.0 = Release|Any CPU
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Release|x64.ActiveCfg = Release|x64
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Release|x64.Build.0 = Release|x64
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Release|x86.ActiveCfg = Release|Any CPU
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Release|x86.Build.0 = Release|Any CPU
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Release|x86.ActiveCfg = Release|x86
{77703C7D-A2A3-4426-956D-D0B20F69D735}.Release|x86.Build.0 = Release|x86
{E88B7D02-F658-4EFD-B260-0568E53F816C}.Debug|Any CPU.ActiveCfg = Debug|Win32
{E88B7D02-F658-4EFD-B260-0568E53F816C}.Debug|x64.ActiveCfg = Debug|x64
{E88B7D02-F658-4EFD-B260-0568E53F816C}.Debug|x64.Build.0 = Debug|x64
{E88B7D02-F658-4EFD-B260-0568E53F816C}.Debug|x86.ActiveCfg = Debug|Win32
{E88B7D02-F658-4EFD-B260-0568E53F816C}.Debug|x86.Build.0 = Debug|Win32
{E88B7D02-F658-4EFD-B260-0568E53F816C}.Release|Any CPU.ActiveCfg = Release|Win32
{E88B7D02-F658-4EFD-B260-0568E53F816C}.Release|Any CPU.Build.0 = Release|Win32
{E88B7D02-F658-4EFD-B260-0568E53F816C}.Release|x64.ActiveCfg = Release|x64
{E88B7D02-F658-4EFD-B260-0568E53F816C}.Release|x64.Build.0 = Release|x64
{E88B7D02-F658-4EFD-B260-0568E53F816C}.Release|x86.ActiveCfg = Release|Win32
Expand Down
13 changes: 10 additions & 3 deletions BlocklyAtsGui/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
</configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="x86"/>
</assemblyBinding>
</runtime>
</configuration>
55 changes: 37 additions & 18 deletions BlocklyAtsGui/BaseBrowser.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using System.Xml.Linq;

namespace BlocklyATS {
namespace BlocklyAts {

public abstract class BaseBrowser : IDisposable {
public abstract Control GetControl();
public abstract void Reload();
public abstract void Navigate(string url);
public abstract event EventHandler PageFinished;
public abstract event PreviewKeyDownEventHandler KeyDown;
public abstract object InvokeScript(string script);
public abstract Task<object> InvokeScript(string script);
public abstract void ShowDevTools();
public abstract void Dispose();

public virtual void BindTo(Control parent) {
Expand All @@ -30,18 +34,29 @@ public static BaseBrowser AcquireInstance(string url = "about:blank") {
#if MONO
return new WinformBrowser(url);
#else
var CEFAvailable = File.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),
"x86", "CefSharp.dll"));
if (CEFAvailable) {
return new CefBrowser(url);
if (PlatformFunction.IsWindows()) {
var CEFAvailable = File.Exists(Path.Combine(CompilerFunction.appDir, @"x86\CefSharp.dll"));
const string EdgeKeyName = @"SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}";
var WebView2Available = Registry.LocalMachine.OpenSubKey(EdgeKeyName)?.GetValue("pv", null) != null;
if (CEFAvailable) {
return new CefBrowser(url);
} else if (WebView2Available) {
return new WebView2Browser(url);
} else {
return new WinformBrowser(url);
}
} else {
return new WinformBrowser(url);
}
#endif
}

private static JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

public static string EscapeJsString(string s) {
StringBuilder sb = new StringBuilder();
return jsSerializer.Serialize(s);

/* StringBuilder sb = new StringBuilder();
foreach (char c in s) {
switch (c) {
case '\"':
Expand Down Expand Up @@ -75,30 +90,34 @@ public static string EscapeJsString(string s) {
break;
}
}
return sb.ToString();
return "\"" + sb.ToString() + "\""; */
}

public static string UnescapeJsString(string s) {
return (string)jsSerializer.Deserialize(s, typeof(string));
}

public void BkyResetWorkspace() {
InvokeScript("batsWkspReset();");
public async Task BkyResetWorkspace() {
await InvokeScript("batsWkspReset();");
}

public XElement BkySaveWorkspace() {
var element = XElement.Parse(InvokeScript("batsWkspSave();").ToString());
public async Task<XElement> BkySaveWorkspace() {
var element = XElement.Parse((await InvokeScript("batsWkspSave();")).ToString());
element.RemoveAttributes();
return element;
}

public void BkyLoadWorkspace(XElement bkyxml) {
public async Task BkyLoadWorkspace(XElement bkyxml) {
var arg = EscapeJsString(bkyxml.ToString(SaveOptions.DisableFormatting));
InvokeScript(string.Format("batsWkspLoad('{0}');", arg));
await InvokeScript(string.Format("batsWkspLoad({0});", arg));
}

public string BkyExportLua() {
return InvokeScript("batsWkspExportLua();").ToString();
public async Task<string> BkyExportLua() {
return (await InvokeScript("batsWkspExportLua();")).ToString();
}

public string BkyExportCSharp() {
return InvokeScript("batsWkspExportCSharp();").ToString();
public async Task<string> BkyExportCSharp() {
return (await InvokeScript("batsWkspExportCSharp();")).ToString();
}
}
}
Loading

0 comments on commit c9526fc

Please sign in to comment.