Fix crash

This commit is contained in:
Stefan Markovic 2024-02-22 14:00:28 +01:00
parent a3be4cb6d6
commit 48811ecb4d
2 changed files with 29 additions and 30 deletions

View File

@ -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.");
}
}
}
}

View File

@ -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);