mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-12 02:09:24 +08:00
Fix crash
This commit is contained in:
parent
a3be4cb6d6
commit
48811ecb4d
@ -96,36 +96,40 @@ namespace FileLocksmith::Interop
|
||||
|
||||
static array<System::String ^>^ ReadPathsFromPipe(System::String^ pipeName)
|
||||
{
|
||||
std::wstring pipe = from_system_string(pipeName);
|
||||
HANDLE hStdin;
|
||||
HANDLE hStdin = INVALID_HANDLE_VALUE;
|
||||
|
||||
if (pipe.size() > 0)
|
||||
if (!pipeName->Empty)
|
||||
{
|
||||
while (1)
|
||||
std::wstring pipe = from_system_string(pipeName);
|
||||
|
||||
if (pipe.size() > 0)
|
||||
{
|
||||
hStdin = CreateFile(
|
||||
pipe.c_str(), // pipe name
|
||||
GENERIC_READ | GENERIC_WRITE, // read and write
|
||||
0, // no sharing
|
||||
NULL, // default security attributes
|
||||
OPEN_EXISTING, // opens existing pipe
|
||||
0, // default attributes
|
||||
NULL); // no template file
|
||||
|
||||
// Break if the pipe handle is valid.
|
||||
if (hStdin != INVALID_HANDLE_VALUE)
|
||||
break;
|
||||
|
||||
// Exit if an error other than ERROR_PIPE_BUSY occurs.
|
||||
auto error = GetLastError();
|
||||
if (error != ERROR_PIPE_BUSY)
|
||||
while (1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
hStdin = CreateFile(
|
||||
pipe.c_str(), // pipe name
|
||||
GENERIC_READ | GENERIC_WRITE, // read and write
|
||||
0, // no sharing
|
||||
NULL, // default security attributes
|
||||
OPEN_EXISTING, // opens existing pipe
|
||||
0, // default attributes
|
||||
NULL); // no template file
|
||||
|
||||
if (!WaitNamedPipe(pipe.c_str(), 3))
|
||||
{
|
||||
printf("Could not open pipe: 20 second wait timed out.");
|
||||
// Break if the pipe handle is valid.
|
||||
if (hStdin != INVALID_HANDLE_VALUE)
|
||||
break;
|
||||
|
||||
// Exit if an error other than ERROR_PIPE_BUSY occurs.
|
||||
auto error = GetLastError();
|
||||
if (error != ERROR_PIPE_BUSY)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (!WaitNamedPipe(pipe.c_str(), 3))
|
||||
{
|
||||
printf("Could not open pipe: 20 second wait timed out.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,11 +82,6 @@ namespace PowerToys.FileLocksmithUI.ViewModels
|
||||
var args = Environment.GetCommandLineArgs();
|
||||
var pipeName = args.Where(s => s.Contains("\\\\.\\pipe\\")).FirstOrDefault();
|
||||
|
||||
foreach (var s in args)
|
||||
{
|
||||
MessageBox.Show(s);
|
||||
}
|
||||
|
||||
paths = NativeMethods.ReadPathsFromPipe(pipeName);
|
||||
Logger.LogInfo($"Starting FileLocksmith with {paths.Length} files selected.");
|
||||
LoadProcessesCommand = new AsyncRelayCommand(LoadProcessesAsync);
|
||||
|
Loading…
Reference in New Issue
Block a user