Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
update loader
Browse files Browse the repository at this point in the history
  • Loading branch information
huoji120 committed Oct 8, 2023
1 parent 4bfd7fb commit 04b99a1
Show file tree
Hide file tree
Showing 40 changed files with 18,529 additions and 12 deletions.
58 changes: 46 additions & 12 deletions loader/loader/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,46 @@
#include <iostream>
#include <string.h>
#include <filesystem>
#include <fstream>
#include "../../raidjson/rapidjson/rapidjson.h"
#include <istreamwrapper.h>
#include <document.h>
struct _Config
{
std::string path;
std::string command;
};
namespace Config {
std::vector<_Config> configs;
auto ReadConfig() -> bool {
bool result = false;
std::ifstream ifs("config.json");
if (!ifs.is_open()) {
std::cerr << "Could not open file for reading!\n";
return result;
}

// 读取INI文件
std::pair<std::string, std::string> readConfig() {
char path[255], command[255];
rapidjson::IStreamWrapper isw(ifs);
rapidjson::Document d;
d.ParseStream(isw);

GetPrivateProfileStringA("server", "path", "", path, 255, ".\\config.ini");
GetPrivateProfileStringA("server", "command", "", command, 255, ".\\config.ini");

return { std::string(path), std::string(command) };
}
const rapidjson::Value& servers = d["servers"]; // Using a reference for consecutive access is handy and faster.
assert(servers.IsArray());
for (rapidjson::SizeType i = 0; i < servers.Size(); i++) { // Uses SizeType instead of size_t
const rapidjson::Value& server = servers[i];
assert(server.IsObject()); // Each server should be an object.
if (server.HasMember("path") && server["path"].IsString() && server.HasMember("command") && server["command"].IsString())
{
configs.push_back(_Config{
.path = server["path"].GetString(),
.command = server["command"].GetString()
});
}
}
result = true;
return result;
}
};

// 创建进程
PROCESS_INFORMATION createProcess(const std::string& path, const std::string& command) {
Expand Down Expand Up @@ -48,9 +78,13 @@ void loadDll(PROCESS_INFORMATION pi) {
}

int main() {
auto [path, command] = readConfig();
PROCESS_INFORMATION pi = createProcess(path, command);
loadDll(pi);

Config::ReadConfig();
if (Config::configs.size() > 0) {
for (auto& config : Config::configs)
{
PROCESS_INFORMATION pi = createProcess(config.path, config.command);
loadDll(pi);
}
}
return 0;
}
2 changes: 2 additions & 0 deletions loader/loader/loader.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(ProjectDir)..\..\raidjson\rapidjson;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(ProjectDir)..\..\raidjson\rapidjson;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down
Loading

0 comments on commit 04b99a1

Please sign in to comment.