• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Tatsh / winprefs / 17572772707

09 Sep 2025 05:29AM UTC coverage: 94.975% (-5.0%) from 100.0%
17572772707

push

github

Tatsh
tests: add managed test code to build system

51 of 115 new or added lines in 8 files covered. (44.35%)

3194 of 3363 relevant lines covered (94.97%)

196.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

10.64
/src/UnregisterSavePreferencesScheduledTask.cs
1
using Microsoft.Win32.TaskScheduler;
2
using System.Management.Automation;
3
using System.Runtime.CompilerServices;
4
using System.Runtime.Versioning;
5
using System.Security.Cryptography;
6
using System.Text;
7
using IOPath = System.IO.Path;
8

9
[assembly: InternalsVisibleTo("PSWinPrefsTests")]
10
namespace WinPrefs {
11
    [Alias("winprefs-uninstall-job")]
12
    [Cmdlet("Unregister", "SavePreferencesScheduledTask")]
13
    [SupportedOSPlatform("windows")]
14
    public class UnregisterSavePreferencesScheduledTask : PSCmdlet {
15
        [Alias("c")]
16
        [Parameter(HelpMessage = "Commit the changes with Git.")]
17
        public SwitchParameter Commit { get; set; } = false;
1✔
18

19
        [Alias("K")]
20
        [Parameter(HelpMessage = "Deploy key file path.")]
21
        public string? DeployKey;
22

23
        [Parameter(HelpMessage = "Output format.")]
24
        [ValidatePattern("^(reg|ps1?|cs|c#|c)$")]
25
        public string Format = "reg";
1✔
26

27
        [Alias("m")]
28
        [Parameter(HelpMessage = "Depth limit.")]
29
        public int MaxDepth = 20;
1✔
30

31
        [Alias("o")]
32
        [Parameter(HelpMessage = "Output directory.")]
33
        public string? OutputDirectory;
34

35
        [Alias("f")]
36
        [Parameter(HelpMessage = "Output filename.")]
37
        public string OutputFile = "exec-reg.bat";
1✔
38

39
        [Parameter(HelpMessage = "Full registry path.")]
40
        public string Path = "HKCU:\\";
1✔
41

42
        private string GetSuffix() {
×
43
            using var sha1 = SHA1.Create();
×
44
            return Convert.ToHexString(sha1.ComputeHash(
×
45
                Encoding.UTF8.GetBytes(
×
46
               $"c={Commit},K={DeployKey},o={OutputDirectory},f={OutputFile},p={Path}," +
×
47
               $"f={Format},m={MaxDepth}")));
×
48
        }
×
49

50
        protected override void ProcessRecord() {
×
51
            using TaskService ts = new();
×
52
            TaskFolderCollection rootColl = ts.RootFolder.SubFolders;
×
53
            if (!rootColl.Exists("tat.sh")) {
×
54
                return;
×
55
            }
56
            TaskFolder tatshFolder = ts.RootFolder.SubFolders["tat.sh"];
×
57
            if (!tatshFolder.SubFolders.Exists("WinPrefs")) {
×
58
                return;
×
59
            }
60
            TaskFolder winprefsFolder = tatshFolder.SubFolders["WinPrefs"];
×
61
            string taskName = $"tat.sh\\WinPrefs\\WinPrefs-{GetSuffix()}";
×
62
            Microsoft.Win32.TaskScheduler.Task task = ts.GetTask(taskName);
×
63
            if (task == null) {
×
64
                return;
×
65
            }
66
            winprefsFolder.DeleteTask(task.Name);
×
67
            // If everything is empty under tat.sh\WinPrefs delete the directories.
68
            if (winprefsFolder.Tasks.Count == 0) {
×
69
                tatshFolder.DeleteFolder("WinPrefs");
×
70
                string appDataDir = IOPath.Combine(Environment.GetFolderPath(
×
71
                  Environment.SpecialFolder.LocalApplicationData), "WinPrefs");
×
72
                string winprefswPath = IOPath.Combine(appDataDir, "winprefsw.exe");
×
73
                if (File.Exists(winprefswPath)) {
×
74
                    File.Delete(winprefswPath);
×
75
                }
×
76
                if (Directory.GetFiles(appDataDir).Length == 0) {
×
77
                    Directory.Delete(appDataDir);
×
78
                }
×
79
            }
×
80
            // Again for tat.sh
81
            if (tatshFolder.SubFolders.Count == 0 && tatshFolder.Tasks.Count == 0) {
×
82
                ts.RootFolder.DeleteFolder("tat.sh");
×
83
            }
×
84
        }
×
NEW
85
        internal void ProcessInternal() {
×
NEW
86
            BeginProcessing();
×
NEW
87
            ProcessRecord();
×
NEW
88
            EndProcessing();
×
NEW
89
        }
×
90
    }
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc