Skip to content

Commit 87be59a

Browse files
committed
Fix crash when started with other arguments
1 parent 7803ba3 commit 87be59a

1 file changed

Lines changed: 6 additions & 20 deletions

File tree

CollapseLauncher/Program.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -698,42 +698,28 @@ private static string[] KillParentPidIfRestartRequested(params string[] args)
698698
return args;
699699
}
700700

701-
int indexOfArg = -1;
702-
string[] restArgs = args.Length == 1 ? [] : new string[args.Length - 1];
703-
704-
// Copy other args and find restart arg
705-
for (int i = 0; i < args.Length; i++)
706-
{
707-
string currentArg = args[i];
708-
if (currentArg.StartsWith(restartedFromPidArgKey, StringComparison.OrdinalIgnoreCase))
709-
{
710-
indexOfArg = i;
711-
continue;
712-
}
713-
restArgs[i < indexOfArg ? i : i - 1] = currentArg;
714-
}
715-
716-
if (indexOfArg < 0)
701+
string firstArg = args[0];
702+
if (!firstArg.StartsWith(restartedFromPidArgKey, StringComparison.OrdinalIgnoreCase))
717703
{
718704
return args;
719705
}
720706

721-
ReadOnlySpan<char> restartParentPidArg = args[indexOfArg];
722-
ReadOnlySpan<char> restartParentPid = ConverterTool.GetSplit(restartParentPidArg, 1, ":,#$;");
707+
string[] otherArgs = args.Length > 1 ? args[1..] : [];
708+
ReadOnlySpan<char> restartParentPid = ConverterTool.GetSplit(firstArg, 1, ":,#$;");
723709

724710
// Check for PID. If exist, then kill.
725711
if (!int.TryParse(restartParentPid, out int parentPid) ||
726712
!ProcessChecker.IsProcessExist(parentPid))
727713
{
728-
return restArgs;
714+
return otherArgs;
729715
}
730716

731717
Console.WriteLine($"Waiting to kill parent process: {parentPid}");
732718
using Process parentProcess = Process.GetProcessById(parentPid);
733719
parentProcess.Kill();
734720
parentProcess.WaitForExit();
735721

736-
return restArgs;
722+
return otherArgs;
737723
}
738724
}
739725
}

0 commit comments

Comments
 (0)