コード例 #1
0
    static Rule ReadContextMenu(RuleFileReader reader)
    {
        var item        = reader.Read();
        var name        = reader.Read();
        var description = reader.Read();
        var directive   = reader.Read();

        IList <string> folders;

        if (directive == ":SEARCH")
        {
            var folder = reader.Read();
            var root   = Path.Combine("HKEY_CLASSES_ROOT", folder);

            folders = RegHelper.Search(root, item)
                      .Select(name => Path.Combine(folder, name))
                      .ToList();
        }
        else
        {
            folders = reader.Drain().ToList();
            folders.Add(directive);
        }

        return(new ContextMenuRule(item, folders, name, description));
    }
コード例 #2
0
 public IEnumerable <Optimizable> Scan()
 {
     return(RuleFileReader
            .Iter(Resources.TaskSchdulerRules)
            .Select(CheckOptimizable)
            .Where(item => item != null));
 }
コード例 #3
0
    public void EmptyContent()
    {
        var reader = new RuleFileReader(string.Empty);

        Assert.IsFalse(reader.MoveNext());
        Assert.AreEqual(string.Empty, reader.Read());
    }
コード例 #4
0
    public void SkipComment()
    {
        var text   = "#foo\n#bar\n\nFirst";
        var reader = new RuleFileReader(text);

        Assert.IsTrue(reader.MoveNext());
        Assert.AreEqual("First", reader.Read());
    }
コード例 #5
0
    public void RepeatReadEnpty()
    {
        var reader = new RuleFileReader("\n");

        Assert.AreEqual(string.Empty, reader.Read());
        Assert.AreEqual(string.Empty, reader.Read());
        Assert.AreEqual(string.Empty, reader.Read());
        Assert.AreEqual(string.Empty, reader.Read());
    }
コード例 #6
0
    public void Drain()
    {
        var text   = "我\n好\n他\n妈\n帅\n\n(误)";
        var reader = new RuleFileReader(text);

        var value = string.Join("", reader.Drain());

        Assert.AreEqual("我好他妈帅", value);
    }
コード例 #7
0
    public void ReadLines(string text)
    {
        var reader = new RuleFileReader(text);

        Assert.IsTrue(reader.MoveNext());
        Assert.AreEqual("First", reader.Read());
        Assert.AreEqual("Second", reader.Read());

        Assert.IsFalse(reader.MoveNext());
    }
コード例 #8
0
    Optimizable DeleteByRuleList(RuleFileReader reader)
    {
        var filename = reader.Read();
        var path     = Path.Combine(folder, filename);

        if (!File.Exists(path))
        {
            return(null);
        }
        var localName = LocalizedName(filename);

        return(new OptimizeAction(localName, reader.Read(), () => File.Delete(path)));
    }
コード例 #9
0
    public IEnumerable <Optimizable> Scan()
    {
        var cleanInList = RuleFileReader.Iter(Resources.SendToRules)
                          .Select(DeleteByRuleList)
                          .Where(item => item != null);

        var cleanInvalidLinks = Directory.GetFiles(folder)
                                .Where(path => Path.GetExtension(path) == ".lnk")
                                .Where(path => !File.Exists(Utils.GetShortcutTarget(path)))
                                .Select(DeleteInvalidLink);

        return(Enumerable.Concat(cleanInList, cleanInvalidLinks));
    }
コード例 #10
0
    static Rule ReadWmiLogger(RuleFileReader reader)
    {
        var name        = reader.Read();
        var description = reader.Read();
        var key         = reader.Read();

        var  cy    = reader.Read();
        bool?cycle = cy == "null" ? null : bool.Parse(cy);

        var fs       = reader.Read();
        int?fileSize = fs == "null" ? null : int.Parse(fs);

        return(new WMILoggerRule(name, description, key, cycle, fileSize));
    }
コード例 #11
0
    public void Iter()
    {
        var text       = "\n\n\n\nFirst\n\n";
        var enumerable = RuleFileReader.Iter(text);

        var enumerator = enumerable.GetEnumerator();

        Assert.IsTrue(enumerator.MoveNext());
        Assert.AreEqual("First", enumerator.Current.Read());
        Assert.IsFalse(enumerator.MoveNext());

        enumerator.Reset();
        Assert.IsTrue(enumerator.MoveNext());
        Assert.AreEqual("First", enumerator.Current.Read());
    }
コード例 #12
0
    Optimizable CheckOptimizable(RuleFileReader reader)
    {
        var path        = reader.Read();
        var description = reader.Read();
        var keep        = reader.Read() == ":DISABLE";

        try
        {
            var folder = TaskSchedulerManager.Root.GetFolder(path);
            if (folder.GetTasks((int)_TASK_ENUM_FLAGS.TASK_ENUM_HIDDEN).Count == 0)
            {
                return(null);
            }
            return(new FolderOptimizeItem(folder, description));
        }
        catch (IOException e)
            when(e is DirectoryNotFoundException || e is FileNotFoundException)
            {
                // Ignore, maybe the path is a task.
            }

        try
        {
            var task = TaskSchedulerManager.Root.GetTask(path);
            if (keep && !task.Enabled)
            {
                return(null);
            }
            return(new TaskOptimizeItem(task, keep, description));
        }
        catch (IOException e)
            when(e is DirectoryNotFoundException || e is FileNotFoundException)
            {
                return(null);        // Task not found, cannot optimize
            }
    }
コード例 #13
0
    // 下面是各种规则的加载逻辑,为了省点字把 Rule 后缀去掉了(ReadTaskRule -> ReadTask)

    static Rule ReadRegistry(RuleFileReader reader)
    {
        return(new RegFileRule(reader.Read(), reader.Read(), GetEmbeddedRegFile(reader.Read())));
    }
コード例 #14
0
 static Rule ReadGroupPolicy(RuleFileReader reader)
 {
     return(new GroupPolicyRule(reader.Read(), reader.Read(), reader.Read(), reader.Read(), reader.Read()));
 }
コード例 #15
0
    void LoadRuleFile(string name, string content, Func <RuleFileReader, Rule> func)
    {
        var rules = RuleFileReader.Iter(content).Select(func).ToList();

        RuleSets.Add(new RuleList(name, rules));
    }
コード例 #16
0
 static Rule ReadService(RuleFileReader reader)
 {
     return(new ServiceRule(reader.Read(), reader.Read(),
                            (ServiceState)Enum.Parse(typeof(ServiceState), reader.Read())));
 }
コード例 #17
0
 static Rule ReadStartupMenu(RuleFileReader reader)
 {
     return(new StartupMenuRule(true, reader.Read(), reader.Read()));
 }