Skip to content

Commit b690f7f

Browse files
committed
Removed references to KillCalculatorProcess() and StartCalculatorProcess().
1 parent f49dda1 commit b690f7f

File tree

2 files changed

+3
-159
lines changed

2 files changed

+3
-159
lines changed

src/tests/TestActionExecute.cpp

Lines changed: 1 addition & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -59,162 +59,6 @@ namespace shellanything
5959
{
6060
namespace test
6161
{
62-
ra::strings::StringVector RunProcesAndCaptureOutput(const std::string& base_command)
63-
{
64-
static const ra::strings::StringVector EMPTY_LIST;
65-
66-
std::string random_value = ra::strings::ToString(ra::random::GetRandomInt(0, 32767) + 10000);
67-
std::string temp_file = ra::filesystem::GetTemporaryDirectory() + "\\" + __FUNCTION__ + "." + random_value + ".tmp";
68-
ra::strings::Replace(temp_file, "::", ".");
69-
70-
// Execute
71-
std::string full_command = base_command + ">" + temp_file;
72-
int exit_code = system(full_command.c_str());
73-
74-
if (exit_code != 0)
75-
return EMPTY_LIST; // error
76-
77-
ra::strings::StringVector output;
78-
bool success_read = ra::filesystem::ReadTextFile(temp_file, output);
79-
if (!success_read)
80-
return EMPTY_LIST;
81-
82-
return output;
83-
}
84-
85-
size_t FindValue(const ra::strings::StringVector& list_values, const std::string& query_value)
86-
{
87-
for (size_t i = 0; i < list_values.size(); i++)
88-
{
89-
const std::string& list_value = list_values[i];
90-
if (query_value == list_value)
91-
return i;
92-
}
93-
return std::string::npos;
94-
}
95-
96-
ra::strings::StringVector FindNewValues(const ra::strings::StringVector& baseline_values, const ra::strings::StringVector& current_values)
97-
{
98-
ra::strings::StringVector new_values;
99-
100-
for (size_t i = 0; i < current_values.size(); i++)
101-
{
102-
const std::string& current_value = current_values[i];
103-
size_t find_pos = FindValue(baseline_values, current_value);
104-
if (find_pos == std::string::npos)
105-
{
106-
// This is a new value
107-
new_values.push_back(current_value);
108-
}
109-
}
110-
111-
return new_values;
112-
}
113-
114-
void KillCalculatorProcess()
115-
{
116-
printf("Killing all calculator processes...\n");
117-
118-
system("cmd.exe /c taskkill /IM calc.exe >NUL 2>NUL");
119-
120-
// On Windows 10, calc.exe launches Calculator which is an application in the Microsoft App Store.
121-
//The executable path is something similar to C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_10.2103.8.0_x64__8wbfmf6g6wwcr\Calculator.exe
122-
system("cmd.exe /c WMIC PROCESS WHERE \"ExecutablePath like '%%Microsoft.WindowsCalculator%%Calculator.exe'\" DELETE >NUL 2>NUL");
123-
system("cmd.exe /c WMIC PROCESS WHERE \"ExecutablePath like '%%Microsoft.WindowsCalculator%%CalculatorApp.exe'\" DELETE >NUL 2>NUL");
124-
125-
ra::timing::Millisleep(1000);
126-
127-
printf("killed.\n");
128-
}
129-
130-
bool StartCalculatorProcess(ra::process::processid_t & pId)
131-
{
132-
// https://stackoverflow.com/questions/63990787/the-process-id-returned-by-the-createprocess-function-is-different-from-the-task
133-
// calc.exe is a stub/proxy which will launch the actual CalculatorApp.exe.
134-
// For my system, thats is "C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_11.2405.2.0_x64__8wekyb3d8bbwe\CalculatorApp.exe"
135-
// However, a normal user cannot launch this process:
136-
// Windows cannot access the specified device, path, or file.You may not have the appropriate permissions to access the item.
137-
// So we hack our way and try our best to detect it...
138-
//
139-
140-
141-
/*
142-
PropertyManager& pmgr = PropertyManager::GetInstance();
143-
printf("Starting calc.exe...\n");
144-
145-
SelectionContext c;
146-
{
147-
StringList elements;
148-
elements.push_back("C:\\Windows\\System32\\cmd.exe");
149-
c.SetElements(elements);
150-
}
151-
152-
ActionExecute ae;
153-
ae.SetPath("C:\\Windows\\System32\\calc.exe");
154-
ae.SetPid("tmp.pid");
155-
156-
bool executed = ae.Execute(c);
157-
if (!executed)
158-
{
159-
printf("error: not started.\n");
160-
return false;
161-
}
162-
163-
ra::timing::Millisleep(2000);
164-
165-
bool parsed = ra::strings::Parse(pmgr.GetProperty("tmp.pid"), pId);
166-
if (!parsed)
167-
{
168-
printf("error: unknown pid.\n");
169-
return false;
170-
}
171-
172-
printf("started.\n");
173-
return true;
174-
*/
175-
176-
printf("Starting calc.exe...\n");
177-
178-
static const std::string base_command = "powershell -ExecutionPolicy bypass -Command \"Get-Process | Where{ $_.ProcessName -eq 'CalculatorApp' } | Select -ExpandProperty 'Id'\"";
179-
ra::strings::StringVector baseline_processes = RunProcesAndCaptureOutput(base_command);
180-
181-
system("start \"\" calc.exe >NUL 2>NUL");
182-
183-
double start = ra::timing::GetMillisecondsTimer();
184-
double elapsed_ms = ra::timing::GetMillisecondsTimer() - start;
185-
while (pId == 0 && elapsed_ms < 2500)
186-
{
187-
ra::timing::Millisleep(250);
188-
189-
// Search for a new process
190-
ra::strings::StringVector new_processes = RunProcesAndCaptureOutput(base_command);
191-
192-
// Check for new values
193-
ra::strings::StringVector new_values = FindNewValues(baseline_processes, new_processes);
194-
if (new_values.size() >= 1)
195-
{
196-
// This is the one
197-
std::string pid_str = new_values[0];
198-
199-
bool parsed = ra::strings::Parse(pid_str, pId);
200-
if (parsed)
201-
{
202-
printf("started.\n");
203-
return true;
204-
}
205-
206-
// We failed parsing, ignore this value for the next pass.
207-
baseline_processes.push_back(pid_str);
208-
}
209-
210-
// refresh timers
211-
elapsed_ms = ra::timing::GetMillisecondsTimer() - start;
212-
}
213-
214-
printf("error: not running.\n");
215-
return false;
216-
}
217-
21862
void KillShellAnythingArgumentsDebuggerProcess()
21963
{
22064
printf("Killing all arguments.debugger.window.exe processes...\n");
@@ -434,7 +278,7 @@ namespace shellanything
434278

435279
//Cleanup
436280
ra::timing::Millisleep(500);
437-
KillCalculatorProcess();
281+
KillMsPaintProcess();
438282
}
439283
//--------------------------------------------------------------------------------------------------
440284
TEST_F(TestActionExecute, testArguments)

src/tests/TestPlugins.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ namespace shellanything
4040
{
4141
namespace test
4242
{
43-
extern void KillCalculatorProcess();
44-
extern bool StartCalculatorProcess(ra::process::processid_t& pId);
43+
extern void KillArgumentsDebuggerProcess();
44+
extern bool StartArgumentsDebuggerProcess(ra::process::processid_t& pId);
4545
extern void KillMsPaintProcess();
4646
extern bool StartMsPaintProcess(ra::process::processid_t& pId);
4747

0 commit comments

Comments
 (0)