mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Add prefixes to process arguments in WinProcessListHelper
GitOrigin-RevId: f5f21c3fd0cef7f9d568b7d8a0c73e481841a19b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
771533c7cb
commit
c75a9b09f6
@@ -183,19 +183,19 @@ int main(int argc, char **argv)
|
||||
|
||||
VARIANT vtId;
|
||||
pclsObj->Get(L"ProcessId", 0, &vtId, nullptr, nullptr);
|
||||
wcout << vtId.intVal << "\n";
|
||||
wcout << "pid:" << vtId.intVal << "\n";
|
||||
VARIANT vtName;
|
||||
pclsObj->Get(L"Name", 0, &vtName, nullptr, nullptr);
|
||||
if (vtName.bstrVal != nullptr)
|
||||
wcout << escapeLineBreaks(vtName.bstrVal) << L"\n";
|
||||
wcout << L"name:" << escapeLineBreaks(vtName.bstrVal) << L"\n";
|
||||
else
|
||||
wcout << L"\n";
|
||||
wcout << L"name:\n";
|
||||
VARIANT vtCmd;
|
||||
pclsObj->Get(L"CommandLine", 0, &vtCmd, nullptr, nullptr);
|
||||
if (vtCmd.bstrVal != nullptr)
|
||||
wcout << L"\"" << escapeLineBreaks(vtCmd.bstrVal) << L"\"\n";
|
||||
wcout << L"cmd:" << escapeLineBreaks(vtCmd.bstrVal) << L"\n";
|
||||
else
|
||||
wcout << L"\"\"\n";
|
||||
wcout << L"cmd:\n";
|
||||
VariantClear(&vtId);
|
||||
VariantClear(&vtName);
|
||||
VariantClear(&vtCmd);
|
||||
|
||||
+18
-9
@@ -278,11 +278,9 @@ public final class ProcessListUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String unescapeString(String str, boolean quoted) {
|
||||
private static String unescapeString(@Nullable String str) {
|
||||
if (str == null) return null;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (quoted) {
|
||||
str = str.substring(1, str.length() - 1);
|
||||
}
|
||||
for (int index = 0; index < str.length(); index++) {
|
||||
if (str.charAt(index) == '\\') {
|
||||
if (index == str.length() - 1) {
|
||||
@@ -317,6 +315,16 @@ public final class ProcessListUtil {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String removePrefix(String str, String prefix) {
|
||||
if (str.startsWith(prefix)) {
|
||||
return str.substring(prefix.length());
|
||||
}
|
||||
logErrorTestSafe("Can't remove prefix \"" + prefix + "\"");
|
||||
LOG.debug(str);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static List<ProcessInfo> parseWinProcessListHelperOutput(@NotNull String output) {
|
||||
String[] lines = StringUtil.splitByLines(output, false);
|
||||
@@ -329,7 +337,8 @@ public final class ProcessListUtil {
|
||||
int processCount = lines.length / 3;
|
||||
for (int i = 0; i < processCount; i++) {
|
||||
int offset = i * 3;
|
||||
int id = StringUtil.parseInt(lines[offset], -1);
|
||||
String idString = removePrefix(lines[offset], "pid:");
|
||||
int id = StringUtil.parseInt(idString, -1);
|
||||
if (id == -1) {
|
||||
logErrorTestSafe("Broken output of " + WIN_PROCESS_LIST_HELPER_FILENAME + ": process ID is not a number: " + lines[offset]);
|
||||
LOG.debug(output);
|
||||
@@ -337,17 +346,17 @@ public final class ProcessListUtil {
|
||||
}
|
||||
if (id == 0) continue;
|
||||
|
||||
String name = unescapeString(lines[offset + 1], false);
|
||||
String name = unescapeString(removePrefix(lines[offset + 1], "name:"));
|
||||
if (name == null) {
|
||||
logErrorTestSafe("Failed to unescape a process name: " + lines[offset + 1]);
|
||||
logErrorTestSafe("Failed to read a process name: " + lines[offset + 1]);
|
||||
LOG.debug(output);
|
||||
return null;
|
||||
}
|
||||
if (name.isEmpty()) continue;
|
||||
|
||||
String commandLine = unescapeString(lines[offset + 2], true);
|
||||
String commandLine = unescapeString(removePrefix(lines[offset + 2], "cmd:"));
|
||||
if (commandLine == null) {
|
||||
logErrorTestSafe("Failed to unescape a process command line: " + lines[offset + 2]);
|
||||
logErrorTestSafe("Failed to read a process command line: " + lines[offset + 2]);
|
||||
LOG.debug(output);
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user