XKSYU2021 2 mesiacov pred
rodič
commit
6dd845b071

+ 3 - 2
Ui for BDS/Function.h

@@ -3,12 +3,13 @@
 
 int Err(HWND hwnd, LPCTSTR message);
 int Err(ATOM atom, LPCTSTR message);
-int Err(LPCTSTR title, LPCTSTR message);
+int Err(LPCTSTR message);
+void ForceErrCheck(LPCTSTR title);
 
 void StartBDS();
 void StopBDS();
 void ForceStopBDS();
 
-bool SendCommand(LPWSTR command);
+bool SendCommand(LPCSTR command);
 
 HWND CreateChildWindow(HWND hFather, LPCWCHAR childTitle, int x, int y, WNDPROC procFunc, LPCWCHAR className, HINSTANCE hInstance);

+ 1 - 1
Ui for BDS/ID.h

@@ -3,7 +3,7 @@
 #define InitH(x) HANDLE x = NULL
 #define InitHWND(x) HWND x = NULL
 
-#define CWORD(x) (LPWSTR)_T(x "\n")
+#define C(x) (x "\n")
 
 extern HANDLE UIw_key, BDSr_key, UIr_log, BDSw_log;
 extern HWND hWnd;

+ 9 - 4
Ui for BDS/cmdSend.cpp

@@ -3,12 +3,17 @@
 #include "Function.h"
 
 //Send
-bool SendCommand(LPWSTR command)
+bool SendCommand(LPCSTR command)
 {
-	if (WriteFile(UIw_key, command, sizeof(command), NULL, NULL) != 0)
+	DWORD size = strlen(command);
+	if (WriteFile(UIw_key, command, size, NULL, NULL) != 0)
+	{
+		FlushFileBuffers(UIw_key);
 		return true;
-	else {
-		Err(TITLE, _T("Failed to send command!"));
+	}
+	else
+	{
+		Err(_T("Failed to send command!"));
 		return false;
 	}
 }

+ 5 - 1
Ui for BDS/errCheck.cpp

@@ -32,7 +32,7 @@ int Err(ATOM atom, LPCTSTR message)
     }
     return 0;
 }
-int Err(LPCTSTR title, LPCTSTR message)
+int Err(LPCTSTR message)
 {
     if (GetLastError() != 0)
     {
@@ -40,4 +40,8 @@ int Err(LPCTSTR title, LPCTSTR message)
         return 1;
     }
     return 0;
+}
+void ForceErrCheck(LPCTSTR title)
+{
+       MessageBox(NULL, GetError(), title, MB_ICONWARNING);
 }

+ 17 - 11
Ui for BDS/o&c.cpp

@@ -17,48 +17,54 @@ static void AutoClose(DWORD time, LPCWSTR title)
 PROCESS_INFORMATION pi;
 HWND hBDS;
 
-static void CloseHandle()
+static void CloseHandleA()
 {
     CloseHandle(BDSr_key);
     CloseHandle(UIw_key);
     CloseHandle(UIr_log);
     CloseHandle(BDSw_log);
 }
+static void CloseHandleS()
+{
+    CloseHandle(BDSr_key);
+    CloseHandle(BDSw_log);
+}
+
 InitH(BDSr_key); InitH(UIw_key); InitH(BDSw_log); InitH(UIr_log);
 void StartBDS()
 {
     SECURITY_ATTRIBUTES sa = { sizeof(sa), NULL, TRUE };
     if(!CreatePipe(&BDSr_key, &UIw_key, &sa, 0))
-        Err(TITLE, _T("Failed to create pipe_key"));
+        Err(_T("Failed to create pipe_key"));
     if (!CreatePipe(&UIr_log, &BDSw_log, &sa, 0))
-        Err(TITLE, _T("Failed to create pipe_log"));
+        Err(_T("Failed to create pipe_log"));
     STARTUPINFO si = { sizeof(si) };
-    si.dwFlags = STARTF_USESTDHANDLES;
-    si.hStdInput = UIw_key;
+    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+    si.hStdInput = BDSr_key;
     si.wShowWindow = SW_SHOWMINIMIZED;
 
     if (CreateProcess(
         L"bedrock_server.exe",
         NULL, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))
     {
-        
+        CloseHandleS();
     }
     else {
-        Err(TITLE, _T("Failed to send command to BDS!"));
-        CloseHandle();
+        Err(_T("Failed to send command to BDS!"));
+        CloseHandleA();
     }
 }
 
 void StopBDS()
 {
-    SendCommand(CWORD("stop"));
-    //CloseHandle();
+    SendCommand(C("stop"));
+    CloseHandleA();
 }
 
 void ForceStopBDS()
 {
     TerminateProcess(pi.hProcess,0);
-    CloseHandle();
+    CloseHandleA();
     MessageBox(hWnd,
         _T("Òѳ¢ÊÔÇ¿ÐÐÍ£Ö¹·þÎñÆ÷"), TITLE,
         MB_OK);