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)); }
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()); }
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()); }
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))); }
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)); }
public void EmptyContent() { var reader = new RuleFileReader(string.Empty); Assert.IsFalse(reader.MoveNext()); Assert.AreEqual(string.Empty, reader.Read()); }
public void SkipComment() { var text = "#foo\n#bar\n\nFirst"; var reader = new RuleFileReader(text); Assert.IsTrue(reader.MoveNext()); Assert.AreEqual("First", reader.Read()); }
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 } }
static Rule ReadService(RuleFileReader reader) { return(new ServiceRule(reader.Read(), reader.Read(), (ServiceState)Enum.Parse(typeof(ServiceState), reader.Read()))); }
static Rule ReadStartupMenu(RuleFileReader reader) { return(new StartupMenuRule(true, reader.Read(), reader.Read())); }
// 下面是各种规则的加载逻辑,为了省点字把 Rule 后缀去掉了(ReadTaskRule -> ReadTask) static Rule ReadRegistry(RuleFileReader reader) { return(new RegFileRule(reader.Read(), reader.Read(), GetEmbeddedRegFile(reader.Read()))); }
static Rule ReadGroupPolicy(RuleFileReader reader) { return(new GroupPolicyRule(reader.Read(), reader.Read(), reader.Read(), reader.Read(), reader.Read())); }