mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Improve code quality
This commit is contained in:
parent
a088f91541
commit
a899ff83e5
1 changed files with 11 additions and 11 deletions
|
|
@ -38,11 +38,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
fixed (char* bufferChar = buffer)
|
||||
{
|
||||
((IShellLinkW)link).GetPath((PWSTR)bufferChar, MAX_PATH, &data, (uint)SLGP_FLAGS.SLGP_SHORTPATH);
|
||||
|
||||
// Truncate the buffer to the actual length of the string
|
||||
int validLength = Array.IndexOf(buffer, '\0');
|
||||
if (validLength < 0) validLength = MAX_PATH;
|
||||
target = new string(buffer, 0, validLength);
|
||||
target = GetStringFromBuffer(buffer, MAX_PATH);
|
||||
}
|
||||
|
||||
// To set the app description
|
||||
|
|
@ -54,9 +50,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
fixed (char* buffer1Char = buffer1)
|
||||
{
|
||||
((IShellLinkW)link).GetDescription((PWSTR)buffer1Char, MAX_PATH);
|
||||
int validLength = Array.IndexOf(buffer1, '\0');
|
||||
if (validLength < 0) validLength = MAX_PATH;
|
||||
description = new string(buffer1, 0, validLength);
|
||||
description = GetStringFromBuffer(buffer1, MAX_PATH);
|
||||
}
|
||||
}
|
||||
catch (COMException e)
|
||||
|
|
@ -71,9 +65,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
fixed (char* buffer2Char = buffer2)
|
||||
{
|
||||
((IShellLinkW)link).GetArguments((PWSTR)buffer2Char, MAX_PATH);
|
||||
int validLength = Array.IndexOf(buffer2, '\0');
|
||||
if (validLength < 0) validLength = MAX_PATH;
|
||||
arguments = new string(buffer2, 0, validLength);
|
||||
arguments = GetStringFromBuffer(buffer2, MAX_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,5 +74,13 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
|
||||
return target;
|
||||
}
|
||||
|
||||
private static unsafe string GetStringFromBuffer(char[] buffer, int maxLength)
|
||||
{
|
||||
// Truncate the buffer to the actual length of the string
|
||||
int validLength = Array.IndexOf(buffer, '\0');
|
||||
if (validLength < 0) validLength = maxLength;
|
||||
return new string(buffer, 0, validLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue