public void ReadScript() { if (FILE != null) { string[] lines = File.ReadAllLines(FILE); lines = FormatInput(lines); foreach (string line in lines) { Result.Add(line.ToString()); commands = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (commands[0].ToString() == DEPEND) { Depend(); } if (commands[0].ToString() == INSTALL) { if (!Installed.Contains(commands[1].ToString())) { ExplicitlyInstalled.Add(commands[1].ToString()); Install(commands[1].ToString()); } else { Result.Add(" " + commands[1].ToString() + " already installed"); } } if (commands[0].ToString() == REMOVE) { if (Installed.Contains(commands[1].ToString())) { dependantCount = 0; Remove(commands[1].ToString()); } else { Result.Add(" " + commands[1].ToString() + " not installed"); } } if (commands[0].ToString() == LIST) { List(); } } } else { Message = "Please select a file"; } }
public void Remove(string name) { int count = 0; foreach (string comp in Installed) { var temp = Dependencies.FirstOrDefault(x => x.Name == comp); if (temp != null) { foreach (var components in temp.Dependants) { if (components.Name == name) { count++; } } } } if (count == 0) { dependantCount = 1; Result.Add(" Removing " + name); Installed.Remove(name); var temp = Dependencies.FirstOrDefault(x => x.Name == name); if (temp != null) { foreach (var components in temp.Dependants) { if (!ExplicitlyInstalled.Contains(components.Name)) { Remove(components.Name); } } } } else if (count > 0 && dependantCount != 1) { Result.Add(" " + name + " is still needed"); } }