Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions data/translations/Internationalization_vi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@
<message>
<location filename="../../src/widgets/capturelauncher.cpp" line="41"/>
<source>Full Screen</source>
<translation type="unfinished"></translation>
<translation>Toàn Màn Hình</translation>
</message>
<message>
<location filename="../../src/widgets/capturelauncher.cpp" line="46"/>
<source>Monitor %1: %2 (%3x%4)</source>
<translation type="unfinished"></translation>
<translation>Màn hình %1: %2 (%3x%4)</translation>
</message>
<message>
<source>Full Screen (All Monitors)</source>
Expand Down Expand Up @@ -193,7 +193,7 @@
<location filename="../../src/widgets/capturelauncher.ui" line="71"/>
<location filename="../../build/src/flameshot_autogen/include/ui_capturelauncher.h" line="184"/>
<source>Monitor:</source>
<translation type="unfinished"></translation>
<translation>Màn hình:</translation>
</message>
<message>
<location filename="../../src/widgets/capturelauncher.ui" line="87"/>
Expand Down Expand Up @@ -1356,7 +1356,7 @@ Vui lòng xử lí chúng thủ công trong tệp cấu hình.</translation>
<message>
<location filename="../../src/config/generalconf.cpp" line="929"/>
<source>Capture active monitor (skip monitor selection)</source>
<translation type="unfinished"></translation>
<translation>Chụp màn hình đang hoạt động (bỏ quả bước chọn màn hình)</translation>
</message>
<message>
<location filename="../../src/config/generalconf.cpp" line="931"/>
Expand Down
13 changes: 7 additions & 6 deletions src/config/buttonlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ void ButtonListView::updateActiveButtons(QListWidgetItem* item)
{
CaptureTool::Type bType = m_buttonTypeByName[item->text()];
if (item->checkState() == Qt::Checked) {
m_listButtons.append(bType);
// TODO refactor so we don't need external sorts
// Refactored to avoid external sort: insert into the correct position
using bt = CaptureTool::Type;
std::sort(m_listButtons.begin(), m_listButtons.end(), [](bt a, bt b) {
return CaptureToolButton::getPriorityByButton(a) <
CaptureToolButton::getPriorityByButton(b);
});
auto it = std::lower_bound(
m_listButtons.begin(), m_listButtons.end(), bType, [](bt a, bt b) {
return CaptureToolButton::getPriorityByButton(a) <
CaptureToolButton::getPriorityByButton(b);
});
m_listButtons.insert(it, bType);
} else {
m_listButtons.removeOne(bType);
}
Expand Down
72 changes: 52 additions & 20 deletions src/windows-cli.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors

#include <iostream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -38,12 +41,17 @@ static void appendQuotedArg(std::wstring& cmdline, const std::wstring& arg)
// forwarding each argument as literal data. flameshot.exe is passed via
// lpApplicationName so no command interpreter is involved and shell
// metacharacters have no effect. When wait is true, the child's stdout is
// captured and relayed.
void CallFlameshot(int argc, wchar_t* argv[], bool wait)
// captured and relayed. Returns child's process exit code. If wait==false,
// returns 0 (child running).
int CallFlameshot(int argc, wchar_t* argv[], bool wait)
{
// Full path to flameshot.exe, in the same directory as this executable.
wchar_t path[MAX_PATH];
GetModuleFileNameW(NULL, path, MAX_PATH);
DWORD len = GetModuleFileNameW(NULL, path, MAX_PATH);
if (len == 0 || len == MAX_PATH) {
return static_cast<int>(GetLastError());
}

std::wstring pathstring(path);
size_t lastBackslash = pathstring.find_last_of(L'\\');
std::wstring directory = (lastBackslash != std::wstring::npos)
Expand All @@ -70,7 +78,7 @@ void CallFlameshot(int argc, wchar_t* argv[], bool wait)
sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
if (!CreatePipe(&readEnd, &writeEnd, &sa, 0)) {
return;
return static_cast<int>(GetLastError());
}
SetHandleInformation(readEnd, HANDLE_FLAG_INHERIT, 0);

Expand All @@ -81,51 +89,75 @@ void CallFlameshot(int argc, wchar_t* argv[], bool wait)
}

PROCESS_INFORMATION pi{};
BOOL ok = CreateProcessW(exePath.c_str(),
mutableCmd.data(),
NULL,
NULL,
wait ? TRUE : FALSE,
0,
NULL,
NULL,
&si,
&pi);
BOOL ok = CreateProcessW(
exePath.c_str(),
mutableCmd.data(),
NULL,
NULL,
wait ? TRUE : FALSE, // only inherit handles when we created a pipe
0,
NULL,
NULL,
&si,
&pi);

if (writeEnd) {
CloseHandle(writeEnd);
writeEnd = NULL;
}

if (!ok) {
if (readEnd) {
CloseHandle(readEnd);
}
return;
return static_cast<int>(GetLastError());
}

int exitCode = 0;

if (wait) {
// Read child's stdout/stderr
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
char buffer[2048];
DWORD n = 0;
while (ReadFile(readEnd, buffer, sizeof(buffer), &n, NULL) && n > 0) {
std::cout.write(buffer, n);
}
CloseHandle(readEnd);
readEnd = NULL;

WaitForSingleObject(pi.hProcess, INFINITE);
DWORD code = 0;
if (GetExitCodeProcess(pi.hProcess, &code)) {
exitCode = static_cast<int>(code);
} else {
exitCode = static_cast<int>(GetLastError());
}
} else {
// Not waiting: Exit code can't be known
exitCode = 0;
}

CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

return exitCode;
}

// Console 'wrapper' for flameshot on windows
int wmain(int argc, wchar_t* argv[])
{
// if no args, do not wait for stdout
// if no args, do not wait for stdout => return 0.
// If args exist, wait and return flameshot's exit code.
if (argc == 1) {
std::cout << "Starting flameshot in daemon mode" << std::endl;
CallFlameshot(argc, argv, false);
int code = CallFlameshot(argc, argv, false);
std::cout.flush();
return code;
} else {
CallFlameshot(argc, argv, true);
int code = CallFlameshot(argc, argv, true);
std::cout.flush();
return code;
}
std::cout.flush();
return 0;
}
Loading