< Summary

Information
Class: SwitchBlade.Services.RestartLogic
Assembly: SwitchBlade
File(s): D:\a\switchblade\switchblade\Services\RestartLogic.cs
Tag: 203_23722840422
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 58
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
BuildRestartStartInfo(...)100%22100%

File(s)

D:\a\switchblade\switchblade\Services\RestartLogic.cs

#LineLine coverage
 1using System.Diagnostics;
 2
 3namespace SwitchBlade.Services
 4{
 5    public static class RestartLogic
 6    {
 7        public static ProcessStartInfo BuildRestartStartInfo(string processPath, string currentWorkingDirectory, int cur
 38        {
 9            // Determine if we're de-elevating (currently admin, turning it off)
 10            // If we are currently elevated (isElevated = true), we assume the intention of a generic restart
 11            // is to return to the logical "default" state or just restart.
 12            // However, the original logic specifically had a check: bool isDeElevating = Program.IsRunningAsAdmin();
 13            // And then it had two branches.
 14            // Branch 1 (isDeElevating == true): Uses mixed mode with explorer.exe to de-elevate?
 15            // Actually, let's look at the original code carefully:
 16            // "bool isDeElevating = Program.IsRunningAsAdmin();"
 17            // This variable name implies that if we ARE admin, we are treating this restart as a "de-elevation" attempt
 18            // or at least a restart that might need to handle the admin context carefully.
 19            //
 20            // Original Code:
 21            // if (isDeElevating) {
 22            //    command = Wait-Process... Start-Process explorer.exe -ArgumentList 'escapedPath'
 23            // } else {
 24            //    command = Wait-Process... Start-Process 'processPath'
 25            // }
 26            //
 27            // The logic seems to be: If we are admin, launch via explorer to essentially de-elevate (since explorer is 
 28
 329            if (isElevated)
 230            {
 231                var escapedPath = processPath.Replace("\"", "`\"");
 232                var command = $"Wait-Process -Id {currentPid} -ErrorAction SilentlyContinue; Start-Process explorer.exe 
 33
 234                return new ProcessStartInfo
 235                {
 236                    FileName = "powershell.exe",
 237                    Arguments = $"-NoProfile -WindowStyle Hidden -Command \"{command}\"",
 238                    UseShellExecute = false,
 239                    CreateNoWindow = true,
 240                    WorkingDirectory = currentWorkingDirectory
 241                };
 42            }
 43            else
 144            {
 145                var command = $"Wait-Process -Id {currentPid} -ErrorAction SilentlyContinue; Start-Process '{processPath
 46
 147                return new ProcessStartInfo
 148                {
 149                    FileName = "powershell.exe",
 150                    Arguments = $"-NoProfile -WindowStyle Hidden -Command \"{command}\"",
 151                    UseShellExecute = false,
 152                    CreateNoWindow = true,
 153                    WorkingDirectory = currentWorkingDirectory
 154                };
 55            }
 356        }
 57    }
 58}