XKSYU2021 2 hónapja
szülő
commit
8aceb50c0b

+ 2 - 0
Ui for BDS/ConfigID.h → Ui for BDS/Config.h

@@ -1,5 +1,7 @@
 #pragma once
 
+void Submit(HWND hWnd1);
+
 #define CONF_ServerName 51010
 #define CONF_GameMode 51020
 #define CONF_ForeceGameMode 51021

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

@@ -129,7 +129,7 @@
     </Manifest>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClInclude Include="ConfigID.h" />
+    <ClInclude Include="Config.h" />
     <ClInclude Include="Function.h" />
     <ClInclude Include="Resource.h" />
     <ClInclude Include="ID.h" />

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

@@ -30,7 +30,7 @@
     <ClInclude Include="SharedValue.h">
       <Filter>头文件</Filter>
     </ClInclude>
-    <ClInclude Include="ConfigID.h">
+    <ClInclude Include="Config.h">
       <Filter>头文件</Filter>
     </ClInclude>
   </ItemGroup>

+ 1 - 1
Ui for BDS/Win32.h

@@ -3,7 +3,7 @@
 #include <windows.h>
 
 #include <stdlib.h>
-#include <string.h>
+#include <string>
 #include <tchar.h>
 #include <iostream>
 #include <fstream>

+ 98 - 1
Ui for BDS/config.cpp

@@ -1,5 +1,102 @@
 #include "Win32.h"
-#include "ConfigID.h"
+#include "Config.h"
 #include "Function.h"
 #include "SharedValue.h"
 
+#include <vector>
+
+
+//basic
+static std::vector<std::string> ConfigRead()
+{
+	std::ifstream read("server.properties");
+	Err(&read, _T("打开配置文件失败"));
+	std::vector<std::string> configs;
+	std::string config;
+	while (getline(read, config)) 
+	{
+		configs.push_back(config);
+	}
+	read.close();
+	return configs;
+}
+
+static void ConfigWrite(std::vector<std::string> &configText)
+{
+	std::ofstream write("server.properties", std::ios::out);
+	Err(&write, _T("写入配置文件失败"));
+	for (const auto& in : configText)
+	{
+		write << in << "\n";
+	}
+	write.close();
+}
+
+
+//normal
+static void ConfigSet_EDIT(std::vector<std::string> &configText, HWND hWnd1, std::string target, int id)
+{
+	char newText[1024] = { 0 };
+	GetWindowTextA(GetDlgItem(hWnd1, id), newText, 1024);
+	if (newText != "不修改")
+	{
+		for (auto& l : configText)
+		{
+			if (l.find(target) != std::string::npos)
+			{
+				l = target + '=' + newText;
+			}
+			return;
+		}
+	}
+}
+static void ConfigSet_CHECK_1(std::vector<std::string>& configText, HWND hWnd1, std::string target, int id, int no_id)
+{
+	if (IsDlgButtonChecked(hWnd1, no_id) != BST_CHECKED)
+	{
+		for (auto& l : configText)
+		{
+			if (l.find(target) != std::string::npos)
+			{
+				if(IsDlgButtonChecked(hWnd1, id) != BST_CHECKED)
+					l = target + "=true";
+				else l = target + "=false";
+				return;
+			}
+		}
+	}
+}
+static void ConfigSet_CHECK_1(std::vector<std::string>& configText, HWND hWnd1, std::string target, int id, int no_id)
+{
+	if (IsDlgButtonChecked(hWnd1, no_id) != BST_CHECKED)
+	{
+		for (auto& l : configText)
+		{
+			if (l.find(target) != std::string::npos)
+			{
+				if (IsDlgButtonChecked(hWnd1, id) != BST_CHECKED)
+					l = target + "=false";
+				else l = target + "=true";
+				return;
+			}
+		}
+	}
+}
+
+
+//special
+
+
+
+//whole
+void Submit(HWND hWnd1)
+{
+	std::vector<std::string> configText = ConfigRead();
+	ConfigSet_EDIT(configText, hWnd1, 
+		"server-name",  CONF_ServerName);
+
+	ConfigWrite(configText);
+	MessageBox(hWnd,
+		L"已尝试提交", TITLE,
+		MB_OK);
+}

+ 20 - 2
Ui for BDS/configEditProc.cpp

@@ -1,7 +1,9 @@
 #include "Win32.h"
 #include "Function.h"
 #include "SharedValue.h"
-#include "ConfigID.h"
+#include "Config.h"
+
+#include <vector>
 
 HFONT Font();
 
@@ -323,6 +325,22 @@ LRESULT CALLBACK ConfProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam)
 
         break;
     }
+
+    case WM_COMMAND:
+    {
+        WORD wmId = LOWORD(wParam);
+        switch (wmId)
+        {
+        case CONF_OK:
+            Submit(hWnd1);
+            DestroyWindow(hWnd1);
+            break;
+        default:
+            break;
+        }
+        break;
+    }
+
     case WM_CLOSE:
     {
         INT result = MessageBox(hWnd1,
@@ -330,7 +348,7 @@ LRESULT CALLBACK ConfProc(HWND hWnd1, UINT msg, WPARAM wParam, LPARAM lParam)
             MB_YESNOCANCEL | MB_ICONWARNING);
         if (result == IDYES)
         {
-
+            Submit(hWnd1);
             DestroyWindow(hWnd1);
         }
         else if (result == IDNO)

+ 7 - 3
Ui for BDS/mainProc.cpp

@@ -24,16 +24,20 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
     case WM_CREATE:
     {
         ClearLog();
+
+        //MessageBox(hWnd,
+        //    L"测试版程序\n数据无价,谨慎操作!", TITLE,
+        //    MB_OK | MB_ICONWARNING);
+
         //StartBDS();
+
         HINSTANCE HI_Log = NULL;
         hLog = CreateLogWindow(
             _T("日志"),
             1000, 690,
             LogProc, _T("log"), HI_Log);
         Log(GetDlgItem(hLog, ID_LOG));
-        //MessageBox(hWnd,
-        //    L"这是测试版程序\n数据无价,谨慎操作!", TITLE,
-        //    MB_OK | MB_ICONWARNING);
+
         break;
     }