• 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

8.33
/src/RegisterSavePreferencesScheduledTask.cs
1
using Microsoft.Win32.TaskScheduler;
2
using System.Management.Automation;
3
using System.Reflection;
4
using System.Runtime.CompilerServices;
5
using System.Runtime.Versioning;
6
using System.Security.Cryptography;
7
using System.Text;
8
using System.Text.RegularExpressions;
9
using IOPath = System.IO.Path;
10

11
[assembly: InternalsVisibleTo("PSWinPrefsTests")]
12
namespace WinPrefs {
13
    [Alias("winprefs-install-job")]
14
    [Cmdlet("Register", "SavePreferencesScheduledTask")]
15
    [SupportedOSPlatform("windows")]
16
    public class RegisterSavePreferencesScheduledTask : PSCmdlet {
17
        [Alias("m")]
18
        [Parameter(HelpMessage = "Depth limit.")]
19
        public int MaxDepth = 20;
1✔
20

21
        [Alias("c")]
22
        [Parameter(HelpMessage = "Commit the changes with Git.")]
23
        public SwitchParameter Commit { get; set; } = false;
1✔
24

25
        [Alias("K")]
26
        [Parameter(HelpMessage = "Deploy key file path.")]
27
        public string? DeployKey;
28

29
        [Parameter(HelpMessage = "Output format.")]
30
        [ValidatePattern("^(reg|ps1?|cs|c#|c)$")]
31
        public string Format = "reg";
1✔
32

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

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

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

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

52
        protected override void ProcessRecord() {
×
53
            using TaskService ts = new();
×
54
            TaskFolder folder = ts.RootFolder.CreateFolder(@"tat.sh\WinPrefs", null, false);
×
55
            TaskDefinition td = ts.NewTask();
×
56
            td.RegistrationInfo.Description = $"Runs WinPrefs every 12 hours (path {Path}).";
×
57
            DailyTrigger trigger = new() {
×
58
                StartBoundary = DateTime.Today.AddDays(1)
×
59
            };
×
60
            trigger.Repetition.Interval = TimeSpan.FromHours(12);
×
61
            td.Triggers.Add(trigger);
×
62
            string[] args = {
×
63
                    Commit ? "-c" : "",
×
64
                    $"-m {MaxDepth}",
×
65
                    DeployKey != null ? $"-K \"{DeployKey}\"" : "",
×
66
                    OutputDirectory != null ? $"-o \"{OutputDirectory}\"" : "",
×
67
                    $"-f \"{OutputFile}\"",
×
68
                    $"-F {Format}",
×
69
                    Path
×
70
                };
×
71
            td.Settings.ExecutionTimeLimit = TimeSpan.FromHours(2);
×
72
            td.Settings.StartWhenAvailable = true;
×
73
            string appDataDir = IOPath.Combine(Environment.GetFolderPath(
×
74
                  Environment.SpecialFolder.LocalApplicationData), "WinPrefs");
×
75
            string winprefswPath = IOPath.Combine(appDataDir, "winprefsw.exe");
×
76
            Directory.CreateDirectory(appDataDir);
×
77
            if (File.Exists(winprefswPath)) {
×
78
                File.Delete(winprefswPath);
×
79
            }
×
80
            string? assemblyLoc = IOPath.GetDirectoryName(
×
81
                Assembly.GetExecutingAssembly().Location);
×
82
            if (assemblyLoc == null) {
×
83
                ThrowTerminatingError(new ErrorRecord(
×
84
                    new Exception("Failed to get assembly location."),
×
85
                    "WinPrefs_RegisterTaskError", ErrorCategory.InvalidResult, null));
×
86
            }
×
87
            File.Copy(IOPath.Combine(assemblyLoc, "winprefsw.exe"), winprefswPath);
×
88
            td.Actions.Add(new ExecAction(
×
89
                winprefswPath,
×
90
                Regex.Replace(String.Join(" ", args), @"\s+", " "),
×
91
                Environment.GetFolderPath(Environment.SpecialFolder.UserProfile
×
92
            )));
×
93
            folder.RegisterTaskDefinition($"WinPrefs-{GetSuffix()}", td);
×
94
        }
×
NEW
95
        internal void ProcessInternal() {
×
NEW
96
            BeginProcessing();
×
NEW
97
            ProcessRecord();
×
NEW
98
            EndProcessing();
×
NEW
99
        }
×
100
    }
101
}
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