mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
feat: progress AyuSync implementation
This commit is contained in:
parent
d37022c9f4
commit
acb335ea2b
6 changed files with 37 additions and 19 deletions
|
@ -138,7 +138,7 @@ public:
|
||||||
{
|
{
|
||||||
native_mode = mode & std::ios_base::in ? PIPE_ACCESS_INBOUND : PIPE_ACCESS_OUTBOUND;
|
native_mode = mode & std::ios_base::in ? PIPE_ACCESS_INBOUND : PIPE_ACCESS_OUTBOUND;
|
||||||
|
|
||||||
handle = CreateNamedPipeW(std::data(native_name), native_mode, PIPE_READMODE_BYTE | PIPE_WAIT, 1, buf_size, buf_size, 0, nullptr);
|
handle = CreateNamedPipeW(std::data(native_name), native_mode, PIPE_READMODE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, buf_size, buf_size, 0, nullptr);
|
||||||
if(handle == INVALID_HANDLE_VALUE)
|
if(handle == INVALID_HANDLE_VALUE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -43,19 +43,27 @@ namespace AyuSync {
|
||||||
|
|
||||||
if (!isAgentRunning()) {
|
if (!isAgentRunning()) {
|
||||||
auto configPath = std::filesystem::absolute("./tdata/sync_preferences.json");
|
auto configPath = std::filesystem::absolute("./tdata/sync_preferences.json");
|
||||||
auto process = nes::process{AgentPath, {configPath.string()}};
|
auto process = nes::process{AgentPath, {configPath.string(), ""}, nes::process_options::none};
|
||||||
process.detach();
|
process.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
pipe = std::make_unique<ayu_pipe_wrapper>();
|
|
||||||
|
|
||||||
std::thread receiverThread(&ayu_sync_controller::receiver, this);
|
std::thread receiverThread(&ayu_sync_controller::receiver, this);
|
||||||
|
receiverThread.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ayu_sync_controller::receiver() {
|
void ayu_sync_controller::receiver() {
|
||||||
|
pipe = std::make_unique<ayu_pipe_wrapper>();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
auto p = pipe->receive();
|
auto p = pipe->receive();
|
||||||
invokeHandler(p);
|
if (p == std::nullopt) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string s = p->dump();
|
||||||
|
LOG(("[AyuSync] Received message: %1").arg(QString::fromStdString(s)));
|
||||||
|
|
||||||
|
invokeHandler(p.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,9 @@ using json = nlohmann::json;
|
||||||
|
|
||||||
const std::string AgentFilename =
|
const std::string AgentFilename =
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
"AyuSyncAgent.exe";
|
"AyuSync.Agent.exe";
|
||||||
#else
|
#else
|
||||||
"AyuSyncAgent";
|
"AyuSync.Agent";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const std::string AgentPath = "./AyuSync/" + AgentFilename;
|
const std::string AgentPath = "./AyuSync/" + AgentFilename;
|
||||||
|
|
|
@ -11,22 +11,31 @@
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void ayu_pipe_wrapper::send(T obj) {
|
void ayu_pipe_wrapper::send(T obj) {
|
||||||
auto s = json(obj).dump();
|
// auto s = json(obj).dump();
|
||||||
auto length = s.length();
|
// auto length = s.length();
|
||||||
char lengthBuff[4];
|
// char lengthBuff[4];
|
||||||
bit_converter::i32_to_bytes(length, false, lengthBuff);
|
// bit_converter::i32_to_bytes(length, false, lengthBuff);
|
||||||
|
//
|
||||||
os.write(lengthBuff, 4);
|
// os.write(lengthBuff, 4);
|
||||||
os.write(s.c_str(), length);
|
// os.write(s.c_str(), length);
|
||||||
os.flush();
|
// os.flush();
|
||||||
|
throw std::logic_error("not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
json ayu_pipe_wrapper::receive() {
|
std::optional<json> ayu_pipe_wrapper::receive() {
|
||||||
|
if (!is.is_open()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
char lengthBuff[4];
|
char lengthBuff[4];
|
||||||
is.read(lengthBuff, 4);
|
is.read(lengthBuff, 4);
|
||||||
|
|
||||||
auto length = bit_converter::bytes_to_i32(lengthBuff, false);
|
auto length = bit_converter::bytes_to_i32(lengthBuff, false);
|
||||||
|
|
||||||
|
if (length <= 0) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
auto sb = std::stringbuf();
|
auto sb = std::stringbuf();
|
||||||
char buff[4096];
|
char buff[4096];
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,8 @@ public:
|
||||||
template<class T>
|
template<class T>
|
||||||
void send(T obj);
|
void send(T obj);
|
||||||
|
|
||||||
json receive();
|
std::optional<json> receive();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nes::basic_pipe_istream<char> is{"AyuSync"};
|
nes::pipe_istream is{"AyuSync"};
|
||||||
nes::basic_pipe_ostream<char> os{"AyuSync"};
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -414,6 +414,8 @@ namespace Settings {
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
SetupAyuSync(container);
|
SetupAyuSync(container);
|
||||||
|
|
||||||
|
AddDivider(container);
|
||||||
|
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
SetupBetaFunctions(container);
|
SetupBetaFunctions(container);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue