Skip to content

Commit

Permalink
Fix some nullable warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
marticliment committed Jul 20, 2024
1 parent ffc28ba commit 66f14fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
15 changes: 7 additions & 8 deletions src/UniGetUI.Core.Tools/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ public static long HashStringAsLong(string inputString)
/// <returns></returns>
public static async Task CreateSymbolicLinkDir(string linkPath, string targetPath)
{
var psi = new ProcessStartInfo
var startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c mklink /D \"{linkPath}\" \"{targetPath}\"",
Expand All @@ -450,14 +450,13 @@ public static async Task CreateSymbolicLinkDir(string linkPath, string targetPat
RedirectStandardError = true
};

using (var process = Process.Start(psi))
Process p = Process.Start(startInfo);

Check warning on line 453 in src/UniGetUI.Core.Tools/Tools.cs

View workflow job for this annotation

GitHub Actions / test

Converting null literal or possible null value to non-nullable type.
if (p is not null)
{await p.WaitForExitAsync();}
if (p is null || p.ExitCode != 0)
{
await process.WaitForExitAsync();
if (process.ExitCode != 0)
{
throw new Exception(
$"The operation did not complete successfully: \n{await process.StandardOutput.ReadToEndAsync()}\n{await process.StandardError.ReadToEndAsync()}\n");
}
throw new Exception(
$"The operation did not complete successfully: \n{await p.StandardOutput.ReadToEndAsync()}\n{await p.StandardError.ReadToEndAsync()}\n");

Check warning on line 459 in src/UniGetUI.Core.Tools/Tools.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static async Task<Package[]> FindPackages_UnSafe(WinGet Manager, string q
int VersionIndex = -1;
int SourceIndex = -1;
bool DashesPassed = false;
string line;
string? line;
while ((line = await p.StandardOutput.ReadLineAsync()) != null)
{
logger.AddToStdOut(line);
Expand All @@ -62,7 +62,7 @@ public static async Task<Package[]> FindPackages_UnSafe(WinGet Manager, string q
else
{
string sourceName = line[(SourceIndex - offset)..].Trim().Split(' ')[0];
source = Manager.SourceProvider.SourceFactory.GetSourceOrDefault(sourceName);
source = Manager.GetSourceOrDefault(sourceName);
}
Packages.Add(new Package(name, id, version, source, Manager));
}
Expand Down Expand Up @@ -105,7 +105,7 @@ public static async Task<Package[]> GetAvailableUpdates_UnSafe(WinGet Manager)
int NewVersionIndex = -1;
int SourceIndex = -1;
bool DashesPassed = false;
string line;
string? line;
while ((line = await p.StandardOutput.ReadLineAsync()) != null)
{
logger.AddToStdOut(line);
Expand Down Expand Up @@ -147,7 +147,7 @@ public static async Task<Package[]> GetAvailableUpdates_UnSafe(WinGet Manager)
else
{
string sourceName = line[(SourceIndex - offset)..].Trim().Split(' ')[0];
source = Manager.SourceProvider.SourceFactory.GetSourceOrDefault(sourceName);
source = Manager.GetSourceOrDefault(sourceName);
}

Packages.Add(new Package(name, id, version, newVersion, source, Manager));
Expand Down Expand Up @@ -189,7 +189,7 @@ public static async Task<Package[]> GetInstalledPackages_UnSafe(WinGet Manager)
int SourceIndex = -1;
int NewVersionIndex = -1;
bool DashesPassed = false;
string line;
string? line;
while ((line = await p.StandardOutput.ReadLineAsync()) != null)
{
try
Expand Down Expand Up @@ -224,7 +224,7 @@ public static async Task<Package[]> GetInstalledPackages_UnSafe(WinGet Manager)
else
{
string sourceName = line[(SourceIndex - offset)..].Trim().Split(' ')[0].Trim();
source = Manager.SourceProvider.SourceFactory.GetSourceOrDefault(sourceName);
source = Manager.GetSourceOrDefault(sourceName);
}
Packages.Add(new Package(name, id, version, source, Manager));
}
Expand Down

0 comments on commit 66f14fb

Please sign in to comment.