Selaa lähdekoodia

update 8/19 15

XKSYU2021 2 kuukautta sitten
vanhempi
sitoutus
da0722d4f4

+ 1 - 1
Ui for BDS/Function.h

@@ -13,7 +13,7 @@ void StopBDS();
 void ForceStopBDS();
 
 bool SendCommand(LPCSTR command);
-bool SendCommand_WhenStop(LPCSTR command);
+bool SendCommand_NoErr(LPCSTR command);
 bool SendCommand_WithID(const std::string& front, const std::string& id, const std::string& behind);
 
 

+ 4 - 1
Ui for BDS/ID.h

@@ -41,4 +41,7 @@
 #define ID_FS_LIST 4002
 
 #define ID_LOG 50101
-#define ID_LOG_CLEAR 50102
+#define ID_LOG_CLEAR 50102
+
+#define ID_FILE_Config 5100
+#define ID_FILE_Backup 5200

+ 24 - 2
Ui for BDS/MAIN.cpp

@@ -56,7 +56,7 @@ int WINAPI WinMain(
         szWindowClass, szTitle,
         WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
         CW_USEDEFAULT, CW_USEDEFAULT,
-        610, 600, NULL, NULL,
+        610, 800, NULL, NULL,
         hInstance, NULL
     );
     Err(hWnd,
@@ -93,7 +93,7 @@ int WINAPI WinMain(
     );
     HWND hUWP = CreateWindow(
         L"BUTTON", L"解除回环",
-        WS_VISIBLE | WS_CHILD,
+        /*WS_VISIBLE | */WS_CHILD,
         340, 100, 110, 40,
         hWnd, (HMENU)ID_DUWP,
         (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
@@ -182,6 +182,28 @@ int WINAPI WinMain(
         (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
     );
 
+    HWND hLabel_5 = CreateWindow(
+        L"STATIC", L"文件与配置操作",
+        WS_VISIBLE | WS_CHILD,
+        30, 470, 150, 30,
+        hWnd, NULL,
+        (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+    );
+    HWND hFIconf = CreateWindow(
+        L"BUTTON", L"编辑配置文件",
+        WS_VISIBLE | WS_CHILD,
+        30, 510, 150, 40,
+        hWnd, (HMENU)ID_FILE_Config,
+        (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+    );
+    HWND hFIbk = CreateWindow(
+        L"BUTTON", L"备份存档",
+        WS_VISIBLE | WS_CHILD,
+        210, 510, 110, 40,
+        hWnd, (HMENU)ID_FILE_Backup,
+        (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL
+    );
+
     //Font
     HFONT hFont = CreateFont(
         -40,

+ 1 - 1
Ui for BDS/SharedValue.h

@@ -6,7 +6,7 @@
 #define C(x) (x "\n")
 
 extern HANDLE UIw_key, BDSr_key, UIr_log, BDSw_log;
-extern HWND hWnd, hLog, hTime, hWeather, hPlayer;
+extern HWND hWnd, hLog, hTime, hWeather, hPlayer, hConfig;
 
 #define TITLE _T("UI for BDS")
 

+ 1 - 0
Ui for BDS/Ui for BDS.vcxproj

@@ -139,6 +139,7 @@
     <ClCompile Include="childProc.cpp" />
     <ClCompile Include="childProcSet.cpp" />
     <ClCompile Include="cmdSend.cpp" />
+    <ClCompile Include="configEdit.cpp" />
     <ClCompile Include="errCheck.cpp" />
     <ClCompile Include="log.cpp" />
     <ClCompile Include="mainProc.cpp" />

+ 3 - 0
Ui for BDS/Ui for BDS.vcxproj.filters

@@ -56,6 +56,9 @@
     <ClCompile Include="mainProc.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
+    <ClCompile Include="configEdit.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="Ui for BDS.rc">

+ 2 - 1
Ui for BDS/childProc.cpp

@@ -499,4 +499,5 @@ LRESULT CALLBACK PlayerProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam)
     }
     return 0;
     return 0;
-}
+}
+

+ 1 - 1
Ui for BDS/cmdSend.cpp

@@ -19,7 +19,7 @@ bool SendCommand(LPCSTR command)
 	}
 }
 
-bool SendCommand_WhenStop(LPCSTR command)
+bool SendCommand_NoErr(LPCSTR command)
 {
 	DWORD size = strlen(command);
 	if (WriteFile(UIw_key, command, size, NULL, NULL) != 0)

+ 103 - 0
Ui for BDS/configEdit.cpp

@@ -0,0 +1,103 @@
+#include "Win32.h"
+#include "ID.h"
+#include "Function.h"
+#include "SharedValue.h"
+
+HFONT Font();
+
+LRESULT CALLBACK ConfProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+	switch (msg)
+	{
+    case WM_CREATE:
+    {
+        HFONT hFont = Font();
+
+         HWND hLabel_1 = CreateWindow(
+            L"STATIC", L"服务器名称",
+            WS_VISIBLE | WS_CHILD,
+            20, 20, 100, 30,
+            hWnd1, NULL,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
+        );
+        HWND hServerName = CreateWindow(
+            L"EDIT", L"不修改",
+            WS_VISIBLE | WS_CHILD | WS_BORDER |  ES_MULTILINE,
+            150, 20, 300, 40,
+            hWnd1, (HMENU)NULL,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
+        );
+
+        HWND hLabel_2 = CreateWindow(
+            L"STATIC", L"游戏模式",
+            WS_VISIBLE | WS_CHILD,
+            20, 85, 100, 30,
+            hWnd1, NULL,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
+        );
+        HWND hGamemode = CreateWindow(
+            L"COMBOBOX", NULL,
+            WS_VISIBLE | WS_CHILD | CBS_DROPDOWNLIST,
+            150, 85, 150, 100,
+            hWnd1, (HMENU)NULL,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
+        );
+        SendMessage(hGamemode, CB_ADDSTRING, 0, (LPARAM)L"不修改");
+        SendMessage(hGamemode, CB_ADDSTRING, 0, (LPARAM)L"冒险");
+        SendMessage(hGamemode, CB_ADDSTRING, 0, (LPARAM)L"生存");
+        SendMessage(hGamemode, CB_ADDSTRING, 0, (LPARAM)L"创造");
+        HWND hForceGM = CreateWindow(
+            L"BUTTON", L"强制游戏模式",
+            WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
+            320, 80, 150, 40,
+            hWnd1, (HMENU)NULL,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
+        );
+        HWND hLabel_3 = CreateWindow(
+            L"STATIC", L"游戏难度",
+            WS_VISIBLE | WS_CHILD,
+            20, 150, 100, 30,
+            hWnd1, NULL,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
+        );
+        HWND hDifficulty = CreateWindow(
+            L"COMBOBOX", NULL,
+            WS_VISIBLE | WS_CHILD | CBS_DROPDOWNLIST,
+            150, 150, 150, 100,
+            hWnd1, (HMENU)NULL,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
+        );
+        SendMessage(hDifficulty, CB_ADDSTRING, 0, (LPARAM)L"不修改");
+        SendMessage(hDifficulty, CB_ADDSTRING, 0, (LPARAM)L"和平");
+        SendMessage(hDifficulty, CB_ADDSTRING, 0, (LPARAM)L"简单");
+        SendMessage(hDifficulty, CB_ADDSTRING, 0, (LPARAM)L"普通");
+        SendMessage(hDifficulty, CB_ADDSTRING, 0, (LPARAM)L"困难");
+
+        HWND hCheat = CreateWindow(
+            L"BUTTON", L"作弊模式",
+            WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
+            20, 210, 110, 40,
+            hWnd1, NULL,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
+        );
+        HWND hCheat_1 = CreateWindow(
+            L"BUTTON", L"不修改此项",
+            WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
+            150, 210, 150, 40,
+            hWnd1, NULL,
+            (HINSTANCE)GetWindowLongPtr(hWnd1, GWLP_HINSTANCE), NULL
+        );
+        SendMessage(hCheat_1, BM_SETCHECK, BST_CHECKED, 0);
+
+        break;
+    }
+    case WM_CLOSE:
+        DestroyWindow(hWnd1);
+        break;
+    case WM_DESTROY:
+        hConfig = NULL;
+        break;
+    default:
+        return DefWindowProc(hWnd1, msg, wParam, lParam);
+	}
+}

+ 17 - 5
Ui for BDS/errCheck.cpp

@@ -1,5 +1,7 @@
 #include "Win32.h"
 
+static bool errShow = FALSE;
+
 static LPWSTR GetError()
 {
     DWORD error = GetLastError();
@@ -12,27 +14,33 @@ static LPWSTR GetError()
 
 int Err(HWND hwnd, LPCTSTR message)
 {
-    if (!hwnd)
+    if ((!hwnd) && !errShow)
     {
+        errShow = TRUE;
         MessageBox(NULL, message, GetError(), MB_ICONERROR);
+        errShow = FALSE;
         return 1;
     }
     return 0;
 }
 int Err(ATOM atom, LPCTSTR message)
 {
-    if (!atom)
+    if ((!atom) && !errShow)
     {
+        errShow = TRUE;
         MessageBox(NULL, message, GetError(), MB_ICONERROR);
+        errShow = FALSE;
         return 1;
     }
     return 0;
 }
 int Err(LPCTSTR message)
 {
-    if (GetLastError() != 0)
+    if ((GetLastError() != 0) && !errShow)
     {
+        errShow = TRUE;
         MessageBox(NULL, message, GetError(), MB_ICONERROR);
+        errShow = FALSE;
         return 1;
     }
     return 0;
@@ -44,18 +52,22 @@ void ForceErrCheck(LPCTSTR title)
 
 int Err(std::ifstream* file, LPCTSTR message)
 {
-    if (!file)
+    if ((!file) && !errShow)
     {
+        errShow = TRUE;
         MessageBox(NULL, message, GetError(), MB_ICONERROR);
+        errShow = FALSE;
         return 1;
     }
     return 0;
 }
 int Err(std::ofstream* file, LPCTSTR message)
 {
-    if (!file)
+    if ((!file) && !errShow)
     {
+        errShow = TRUE;
         MessageBox(NULL, message, GetError(), MB_ICONERROR);
+        errShow = FALSE;
         return 1;
     }
     return 0;

+ 22 - 6
Ui for BDS/mainProc.cpp

@@ -3,12 +3,15 @@
 #include "Function.h"
 #include "SharedValue.h"
 
-InitHW(hTime);   InitHW(hWeather);   InitHW(hLog);   InitHW(hPlayer);
+InitHW(hTime);   InitHW(hWeather);   InitHW(hLog);   InitHW(hPlayer); InitHW(hConfig);
 
 LRESULT CALLBACK TimeProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
 LRESULT CALLBACK WeatherProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
 LRESULT CALLBACK LogProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
 LRESULT CALLBACK PlayerProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
+LRESULT CALLBACK ConfProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam);
+
+
 
 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
@@ -63,9 +66,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 
         case ID_DUWP:
             ShellExecute(
-                NULL, L"open",
-                L"C:\\windows\\system32\\cmd.exe",
-                L"/c start powershell.exe -Command \"Get-ChildItem -Path Registry::'HKCU\\Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppContainer\\Mappings\\' -name | ForEach-Object {CheckNetIsolation.exe LoopbackExempt -a -p=$_}\"" ,               
+                NULL, L"runas",
+                L"C:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe",
+                L"-NoProfile -ExecutionPolicy Bypass -Command \"Get-ChildItem -Path Registry::'HKCU\\Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppContainer\\Mappings\\' -name | ForEach-Object {CheckNetIsolation.exe LoopbackExempt -a -p=$_}\"" ,               
                 NULL, SW_SHOWNORMAL
             );
             break;
@@ -106,8 +109,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
             }
             break;
         case ID_FS_WT:
-            SendCommand(C("time query daytime"));
-            SendCommand(C("weather query"));
+            if (SendCommand_NoErr(C("time query daytime")) == FALSE  || 
+                SendCommand_NoErr(C("weather query")) == FALSE)
+            {
+                Err(_T("发送命令失败\n可能是因为服务器已被关闭"));
+            }
             break;
 
         case ID_FC_PLAYER:
@@ -123,6 +129,16 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
         case ID_FS_LIST:
             SendCommand(C("list"));
             break;
+        case ID_FILE_Config:
+            if (!hConfig)
+            {
+                HINSTANCE HI_FI_config = NULL;
+                hConfig = CreateChildWindow(hWnd,
+                    _T("配置文件编辑"),
+                    700, 1000,
+                    ConfProc, _T("fc_player"), HI_FI_config);
+            }
+            break;
         }
         break;
     }

+ 1 - 1
Ui for BDS/o&c.cpp

@@ -66,7 +66,7 @@ void StopBDS()
 {
     if (pi.hProcess)
     {
-        SendCommand_WhenStop(C("stop"));
+        SendCommand_NoErr(C("stop"));
     }
 }