Jelajahi Sumber

update 8/16 14

XKSYU2021 2 bulan lalu
induk
melakukan
42a2b358dd
6 mengubah file dengan 47 tambahan dan 16 penghapusan
  1. 1 0
      Ui for BDS/Function.h
  2. 11 3
      Ui for BDS/MAIN.cpp
  3. 15 1
      Ui for BDS/cmdSend.cpp
  4. 12 8
      Ui for BDS/log.cpp
  5. 8 4
      Ui for BDS/o&c.cpp
  6. 0 0
      Ui for BDS/result.txt

+ 1 - 0
Ui for BDS/Function.h

@@ -13,6 +13,7 @@ void StopBDS();
 void ForceStopBDS();
 
 bool SendCommand(LPCSTR command);
+bool SendCommand_WhenStop(LPCSTR command);
 
 void ClearLog();
 void Log(HWND hwnd);

+ 11 - 3
Ui for BDS/MAIN.cpp

@@ -188,6 +188,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
     case WM_CREATE:
     {
         ClearLog();
+        StartBDS();
         HINSTANCE HI_Log = NULL;
         hLog = CreateLogWindow(
             _T("日志"),
@@ -413,7 +414,7 @@ LRESULT CALLBACK LogProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam)
             (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
         );
         HWND hLogClear = CreateWindow(
-            L"BUTTON", L"清",
+            L"BUTTON", L"清除日志",
             WS_VISIBLE | WS_CHILD,
             790, 570, 110, 40,
             hWnd1, (HMENU)ID_LOG_CLEAR,
@@ -427,8 +428,15 @@ LRESULT CALLBACK LogProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam)
         switch (wmId)
         {
         case ID_LOG_CLEAR:
-            SetWindowText(GetDlgItem(hWnd1, ID_LOG), _T(" "));
-            break;
+            if (MessageBox(hWnd,
+                L"是否要清除所有日志?", TITLE,
+                MB_OKCANCEL | MB_APPLMODAL | MB_ICONWARNING)
+                == 1)
+            {
+                ClearLog();
+                SetWindowText(GetDlgItem(hWnd1, ID_LOG), _T("Null"));
+                break;
+            }
         }
     }
     case WM_TIMER:

+ 15 - 1
Ui for BDS/cmdSend.cpp

@@ -13,7 +13,21 @@ bool SendCommand(LPCSTR command)
 	}
 	else
 	{
-		Err(_T("Failed to send command!"));
+		Err(_T("发送命令失败\n可能是因为服务器已被关闭"));
+		return false;
+	}
+}
+
+bool SendCommand_WhenStop(LPCSTR command)
+{
+	DWORD size = strlen(command);
+	if (WriteFile(UIw_key, command, size, NULL, NULL) != 0)
+	{
+		FlushFileBuffers(UIw_key);
+		return true;
+	}
+	else
+	{
 		return false;
 	}
 }

+ 12 - 8
Ui for BDS/log.cpp

@@ -2,7 +2,6 @@
 #include "ID.h"
 #include "Function.h"
 
-static  DWORD size = 0;
 static bool statu = TRUE;
 
 static void Reflesh(HWND hwnd)
@@ -10,7 +9,7 @@ static void Reflesh(HWND hwnd)
     if (!statu) return;
     std::ifstream read;
     read.open("log.txt", std::ios::in);
-    Err(&read, _T("Failed to open log.txt"));
+    Err(&read, _T("打开日志文件失败"));
     std::string text(
         (std::istreambuf_iterator<char>(read)),
         std::istreambuf_iterator<char>()
@@ -20,19 +19,24 @@ static void Reflesh(HWND hwnd)
     std::wstring wtext(len, 0);
     MultiByteToWideChar(CP_ACP, 0, text.c_str(), -1, &wtext[0], len);
     SetWindowText(hwnd, wtext.c_str());
+    SendMessage(hwnd, WM_VSCROLL, SB_BOTTOM, 0);
 }
 
 static void GetLog()
 {
-    char log[4096] = { 0 };
-    statu = ReadFile(UIr_log, log, sizeof(log), &size, NULL);
-    if (!statu || size < 4) 
+    static DWORD size = 0;
+    char log[10240] = { 0 };
+
+    PeekNamedPipe(UIr_log, NULL , NULL, NULL,&size,NULL);
+    if(size < 1)
     {
         statu = FALSE;
         return;
     }
+     statu = ReadFile(UIr_log, log, sizeof(log), NULL, NULL);
+
     std::ofstream write("log.txt", std::ios::app);
-    Err(&write, _T("Failed to open log.txt"));
+    Err(&write, _T("打开日志文件失败"));
     write << log;
     write.close();
 }
@@ -40,7 +44,7 @@ static void GetLog()
 void ClearLog()
 {
     std::ofstream clear;
-    Err(&clear, _T("Failed to open log.txt"));
+    Err(&clear, _T("打开日志文件失败"));
     clear.open("log.txt", std::ios::out);
     clear.close();
 }
@@ -49,5 +53,5 @@ void Log(HWND hwnd)
 {
     GetLog();
     Reflesh(hwnd);
-    size = 0;
+    statu = TRUE;
 }

+ 8 - 4
Ui for BDS/o&c.cpp

@@ -23,6 +23,10 @@ static void CloseHandleA()
     CloseHandle(UIw_key);
     CloseHandle(UIr_log);
     CloseHandle(BDSw_log);
+    CloseHandle(pi.hProcess);
+    CloseHandle(pi.hThread);
+    BDSr_key = UIw_key = UIr_log = BDSw_log = NULL;
+    pi.hProcess = pi.hThread = NULL;
 }
 static void CloseHandleS()
 {
@@ -33,7 +37,8 @@ static void CloseHandleS()
 InitH(BDSr_key); InitH(UIw_key); InitH(BDSw_log); InitH(UIr_log);
 void StartBDS()
 {
-    SECURITY_ATTRIBUTES sa = { sizeof(sa), NULL, TRUE };
+    SECURITY_ATTRIBUTES sa = { sizeof(sa),NULL , TRUE };
+
     if(!CreatePipe(&BDSr_key, &UIw_key, &sa, 0))
         Err(_T("Failed to create pipe_key"));
     if (!CreatePipe(&UIr_log, &BDSw_log, &sa, 0))
@@ -42,7 +47,7 @@ void StartBDS()
     si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
     si.hStdInput = BDSr_key;
     si.hStdOutput = BDSw_log;
-    si.wShowWindow = SW_SHOWMINIMIZED;
+    //si.wShowWindow = SW_SHOWMINIMIZED;
 
     if (CreateProcess(
         L"bedrock_server.exe",
@@ -60,8 +65,7 @@ void StopBDS()
 {
     if (pi.hProcess)
     {
-        SendCommand(C("stop"));
-        CloseHandleA();
+        SendCommand_WhenStop(C("stop"));
     }
 }
 

+ 0 - 0
Ui for BDS/result.txt