Merge remote-tracking branch 'Blu3train/limitStringLength'

This commit is contained in:
Chenx221 2024-09-05 12:03:22 +08:00
commit e72789a21d
4 changed files with 8 additions and 1 deletions

View File

@ -65,6 +65,7 @@ extern const char* FLUSH_DELAY;
extern const char* FLUSH_DELAY_SPACING;
extern const char* MAX_BUFFER_SIZE;
extern const char* MAX_HISTORY_SIZE;
extern const char* LIMIT_STRING_LENGTH;
extern const char* CONFIG_JP_LOCALE;
extern const wchar_t* ABOUT;
extern const wchar_t* CL_OPTIONS;
@ -508,6 +509,7 @@ namespace
{ TextThread::maxBufferSize, MAX_BUFFER_SIZE },
{ TextThread::flushDelay, FLUSH_DELAY },
{ TextThread::maxHistorySize, MAX_HISTORY_SIZE },
{ TextThread::limitStringLength, LIMIT_STRING_LENGTH },
{ Host::defaultCodepage, DEFAULT_CODEPAGE },
})
{
@ -672,6 +674,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
TextThread::flushDelay = settings.value(FLUSH_DELAY, TextThread::flushDelay).toInt();
TextThread::maxBufferSize = settings.value(MAX_BUFFER_SIZE, TextThread::maxBufferSize).toInt();
TextThread::maxHistorySize = settings.value(MAX_HISTORY_SIZE, TextThread::maxHistorySize).toInt();
TextThread::limitStringLength = settings.value(LIMIT_STRING_LENGTH, TextThread::limitStringLength).toInt();
Host::defaultCodepage = settings.value(DEFAULT_CODEPAGE, Host::defaultCodepage).toInt();
Host::Start(ProcessConnected, ProcessDisconnected, ThreadAdded, ThreadRemoved, SentenceReceived);

View File

@ -113,7 +113,8 @@ void TextThread::Flush()
if (buffer.empty()) return;
if (buffer.size() > maxBufferSize || GetTickCount64() - lastPushTime > flushDelay)
{
AddSentence(std::move(buffer));
if (limitStringLength==0 || buffer.length()<limitStringLength) // Limit string length (0=disabled)
AddSentence(std::move(buffer));
buffer.clear();
}
}

View File

@ -12,6 +12,7 @@ public:
inline static bool flushDelaySpacing = false;
inline static int flushDelay = 500; // flush every 500ms by default
inline static int maxBufferSize = 3000;
inline static int limitStringLength = 1000; // Limit string length to 1000 chars by default
inline static int maxHistorySize = 10'000'000;
TextThread(ThreadParam tp, HookParam hp, std::optional<std::wstring> name = {});

View File

@ -95,6 +95,7 @@ const char* FLUSH_DELAY = u8"Flush delay";
const char* FLUSH_DELAY_SPACING = u8"Flush delay string spacing";
const char* MAX_BUFFER_SIZE = u8"Max buffer size";
const char* MAX_HISTORY_SIZE = u8"Max history size";
const char* LIMIT_STRING_LENGTH = u8"Limit string length (0=Off)";
const char* CONFIG_JP_LOCALE = u8"Launch with JP locale";
const wchar_t* CONSOLE = L"Console";
const wchar_t* CLIPBOARD = L"Clipboard";
@ -862,6 +863,7 @@ Per rimuovere un estenzione, selezionala e premi rimuovi)";
FLUSH_DELAY_SPACING = u8"Spazia ritardo flush string";
MAX_BUFFER_SIZE = u8"Massima dimensione buffer";
MAX_HISTORY_SIZE = u8"Massima dimensione cronologia";
LIMIT_STRING_LENGTH = u8"Limita lunghezza stringa (0=Off)";
CONFIG_JP_LOCALE = u8"Avvia con il JP locale";
CONSOLE = L"Console";
CLIPBOARD = L"Appunti";