Complete file browser operations when command posting fails

This commit is contained in:
evgeny committed 2026-10-28 00:58:59 +01:00
1 parent 7d789f68d4
commit bc90e88e72
2 files changed
+25 -45

No files matched your search

+12 -21
View File
@@ -12,7 +12,6 @@
#include <cstring>
extern "C" {
#include "member_files/member_files.h"
#include "mem.h"
#include "debug_config.h"
}
@@ -35,10 +34,7 @@ MemberFileBatch::~MemberFileBatch() {
}
void MemberFileBatch::cancelRequest(quint64 id) {
if (!id || !gui_bridge_is_uasync_ready()) return;
auto* q = (mf_cancel_request*)u_calloc(1, sizeof(mf_cancel_request));
if (!q) { DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "file batch: cancel allocation failed id=%llu", (unsigned long long)id); return; }
q->inst = gui_bridge_get_inst(); q->id = id; gui_bridge_post_uasync_fn(member_files_gui_cancel, q);
if (id) gui_bridge_member_files_cancel(id);
}
// Сначала проверяем всё локальное дерево; до успешного обхода сервер не изменяется.
@@ -118,20 +114,16 @@ void MemberFileBatch::start(const QList<MemberFileEntry>& entries, const QString
}
void MemberFileBatch::request(uint8_t command) {
auto* q = (mf_gui_request*)u_calloc(1, sizeof(mf_gui_request));
if (!q || !gui_bridge_is_uasync_ready()) {
u_free(q); finish(text("Unable to request directory")); return;
}
const auto& entry = m_queue.first();
q->inst = gui_bridge_get_inst(); q->group = m_group; q->server = m_server;
auto& r = q->message; r.kind = MF_REQUEST; r.command = command; r.owner = m_owner; r.request_id = nextId();
mf_message r{}; r.kind = MF_REQUEST; r.command = command; r.owner = m_owner; r.request_id = nextId();
memcpy(r.path, entry.remote.toUtf8().constData(), entry.remote.toUtf8().size());
if ((m_mode == Download || command == MF_REMOVE_PATH || command == MF_LIST) && entry.version.size() == 16)
memcpy(r.version, entry.version.constData(), 16);
r.cursor = command == MF_LIST ? entry.cursor : 0; m_command = command; m_request = r.request_id;
r.cursor = command == MF_LIST ? entry.cursor : 0;
if (gui_bridge_member_files_request(m_group, m_server, &r) < 0) { finish(text("Unable to request directory")); return; }
m_command = command; m_request = r.request_id;
DEBUG_TRACE(DEBUG_CATEGORY_MEDIA, "file batch: request id=%llu command=%s path=%s cursor=%llu",
(unsigned long long)m_request, mf_command_text(command), r.path, (unsigned long long)r.cursor);
gui_bridge_post_uasync_fn(member_files_gui_request, q);
}
void MemberFileBatch::next() {
@@ -241,15 +233,14 @@ bool MemberFileBatch::response(const mf_message& r) {
}
void MemberFileBatch::copyFile(const QByteArray& version) {
auto* q = (mf_transfer_request*)u_calloc(1, sizeof(mf_transfer_request));
if (!q || !gui_bridge_is_uasync_ready()) { u_free(q); finish(text("Unable to start transfer")); return; }
const auto& e = m_queue.first();
q->inst = gui_bridge_get_inst(); q->id = nextId(); q->group = m_group; q->server = m_server; q->owner = m_owner;
q->upload = m_mode == Upload;
memcpy(q->remote, e.remote.toUtf8().constData(), e.remote.toUtf8().size());
memcpy(q->local, e.local.toUtf8().constData(), e.local.toUtf8().size());
if (version.size() == 16) memcpy(q->version, version.constData(), 16);
m_transfer = q->id; gui_bridge_post_uasync_fn(member_files_gui_transfer, q);
mf_transfer_request q{}; q.id = nextId(); q.group = m_group; q.server = m_server; q.owner = m_owner;
q.upload = m_mode == Upload;
memcpy(q.remote, e.remote.toUtf8().constData(), e.remote.toUtf8().size());
memcpy(q.local, e.local.toUtf8().constData(), e.local.toUtf8().size());
if (version.size() == 16) memcpy(q.version, version.constData(), 16);
if (gui_bridge_member_files_transfer(&q) < 0) { finish(text("Unable to start transfer")); return; }
m_transfer = q.id;
}
bool MemberFileBatch::transfer(const uint8_t* data, int length) {
+13 -24
View File
@@ -42,7 +42,6 @@
#include <cstring>
extern "C" {
#include "member_files/member_files.h"
#include "mem.h"
#include "debug_config.h"
#include "json_flat.h"
}
@@ -284,26 +283,18 @@ void MemberFileBrowser::updateActions() {
}
bool MemberFileBrowser::post(mf_message& message) {
if (!m_group || !server() || !gui_bridge_is_uasync_ready()) {
DEBUG_DEBUG(DEBUG_CATEGORY_MEDIA, "member_files: GUI post rejected cmd=%s group=%llx server=%llx ready=%d",
mf_command_text(message.command), (unsigned long long)m_group, (unsigned long long)server(), gui_bridge_is_uasync_ready());
return false;
}
auto* q = (mf_gui_request*)u_calloc(1, sizeof(mf_gui_request));
if (!q) { DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "file browser: request allocation failed"); return false; }
message.request_id = requestId(); message.kind = MF_REQUEST;
q->inst = gui_bridge_get_inst(); q->group = m_group; q->server = server(); q->message = message;
if (gui_bridge_member_files_request(m_group, server(), &message) < 0) {
m_status->setText(text("Unable to request directory")); return false;
}
DEBUG_DEBUG(DEBUG_CATEGORY_MEDIA, "member_files: GUI post id=%llu cmd=%s group=%llx server=%llx owner=%llx path=%s",
(unsigned long long)message.request_id, mf_command_text(message.command), (unsigned long long)m_group,
(unsigned long long)server(), (unsigned long long)message.owner, message.path);
gui_bridge_post_uasync_fn(member_files_gui_request, q); return true;
return true;
}
void MemberFileBrowser::cancelRequest(quint64 id) {
if (!id || !gui_bridge_is_uasync_ready()) return;
auto* q = (mf_cancel_request*)u_calloc(1, sizeof(mf_cancel_request));
if (!q) { DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "file browser: cancel allocation failed"); return; }
q->inst = gui_bridge_get_inst(); q->id = id; gui_bridge_post_uasync_fn(member_files_gui_cancel, q);
if (id) gui_bridge_member_files_cancel(id);
}
void MemberFileBrowser::requestQuota() {
@@ -596,19 +587,17 @@ void MemberFileBrowser::exportFile(bool clipboard, const QString& destination) {
}
bool MemberFileBrowser::startTransfer(const QString& remote, const QString& local, bool uploading, const QByteArray& version) {
auto* q = (mf_transfer_request*)u_calloc(1, sizeof(mf_transfer_request));
if (!q) { DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "file browser: transfer allocation failed"); return false; }
if (!copyPath(q->remote, remote) || !copyPath(q->local, local) || !mf_path_valid(q->remote, 0) || !gui_bridge_is_uasync_ready()) {
DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "file browser: transfer rejected remote=%s local=%s ready=%d",
qPrintable(remote), qPrintable(local), gui_bridge_is_uasync_ready());
u_free(q); m_status->setText(text("Invalid path or chat is stopped")); return false;
mf_transfer_request q{};
if (!copyPath(q.remote, remote) || !copyPath(q.local, local) || !mf_path_valid(q.remote, 0)) {
DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "file browser: transfer rejected remote=%s local=%s", qPrintable(remote), qPrintable(local));
m_status->setText(text("Invalid path or chat is stopped")); return false;
}
q->inst = gui_bridge_get_inst(); q->id = requestId(); q->group = m_group; q->server = server(); q->owner = owner(); q->upload = uploading;
if (version.size() == 16) memcpy(q->version, version.constData(), 16);
m_transferId = q->id; m_transferGroup = q->group; m_transferServer = q->server; m_local = local;
q.id = requestId(); q.group = m_group; q.server = server(); q.owner = owner(); q.upload = uploading;
if (version.size() == 16) memcpy(q.version, version.constData(), 16);
if (gui_bridge_member_files_transfer(&q) < 0) { m_status->setText(text("Unable to start transfer")); return false; }
m_transferId = q.id; m_transferGroup = q.group; m_transferServer = q.server; m_local = local;
if (uploading) m_openAfter = false;
m_progress->setRange(0, 0); m_progress->show(); m_status->setText(text("Preparing transfer…")); updateActions();
gui_bridge_post_uasync_fn(member_files_gui_transfer, q);
return true;
}