//Design standard public static void RemovePackages(Validator val, PackageOverview overview) { if (val.removeAll) { foreach (Package i in overview.packages) { //It's redundant, but prevents spamming errors. if (PackageUtil.DoesPackageExist(i)) { Remove(i, val, overview); } } } else { foreach (string i in val.packageNames) { Package current = overview.GetPackageWithName(i); if (current != null) { Remove(current, val, overview); } else { Console.WriteLine(("WARNING: No package with name " + i + ".").Pastel("ffff00")); } } } }
//Design standard public static void UpdatePackages(Validator val, PackageOverview overview) { //If we update all with wildcard *. This method doesn't require a list of previous packages. if (val.updateAll) { foreach (Package i in overview.packages) { if (PackageUtil.DoesPackageExist(i)) { Update(i, val, overview).Wait(); } } } //If we list packages else { foreach (string i in val.packageNames) { if (overview.GetPackageWithName(i) != null) { Update(overview.GetPackageWithName(i), val, overview).Wait(); } else { Console.WriteLine(("WARNING: No package with name " + i + ".").Pastel("ffff00")); } } } }
public async static Task Update(Package package, Validator val, PackageOverview overview) { //Create tmp dir so files are gone after execution. using (TmpDir dir = new TmpDir(".")) using (WebClient client = new WebClient()) { //Check if it exists if (PackageUtil.DoesPackageExist(package)) { string filename = Path.GetFileName(package.downloadLocation); Console.WriteLine("Getting newest version of package " + package.name); //Setup loading bar client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(LoadingBar.DownloadProgressCallback); //Get latest version await client.DownloadFileTaskAsync(package.downloadLink, dir.dirName + filename); Console.Write("\n\r"); //Compare. The && ! will make it so that it will always go to 2nd case if val.forceUpdate is ture. if (FileCompare.CompareFiles(dir.dirName + filename, "../sm_plugins/" + package.downloadLocation) && !val.forceUpdate) { Console.WriteLine(package.name + " is up to date."); } else { File.Move(dir.dirName + filename, "../sm_plugins/" + package.downloadLocation, true); Console.WriteLine(package.name + " was updated."); } } else { Console.WriteLine(("WARNING: Package " + package.name + " is not installed. Skipping.").Pastel("ffff00")); } } }
private static void Remove(Package package, Validator val, PackageOverview overview) { //Check if it exists. if (PackageUtil.DoesPackageExist(package)) { Console.WriteLine("Removing package " + package.name); //Remove if (PackageUtil.DoesDirectoryExist(package)) { File.Delete("../sm_plugins/" + package.downloadLocation); } else { Console.WriteLine("ERROR: sm_plugins and/or dependencies could not be found. Did you unzip all the app files into a folder at the same level as sm_plugins?".Pastel("ff0000")); } } else { Console.WriteLine(("WARNING: You have not installed " + package.name + ", skipping.").Pastel("ffff00")); } }
private static async Task GetFile(Package package, PackageOverview overview, Validator val) { Console.WriteLine("Downloading " + package.name); //Download dependencies first foreach (string i in package.dependencies) { await GetFile(overview.GetPackageWithName(i), overview, val); } //Check if any incompatible package are installed bool incompat = false; foreach (string i in package.incompatibilities) { if (PackageUtil.DoesPackageExist(overview.GetPackageWithName(i))) { bool res = Dialog.YNDialog(("WARNING: " + package.name + " is incompatiable with " + i + ". Would you like to remove the other package (Yes/No)? ").Pastel("ffff00")); if (res) { Validator newVal = ClassCopy.DeepCopy(val); newVal.packageNames = new List <string> { i }; Remover.RemovePackages(newVal, overview); } else { incompat = true; } } } if (!incompat) { //Check if file already exists if (!PackageUtil.DoesPackageExist(package)) { using (WebClient client = new WebClient()) { //Setup loading bar client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(LoadingBar.DownloadProgressCallback); //Download file to directory after checking if the folders existba if (PackageUtil.DoesDirectoryExist(package)) { await client.DownloadFileTaskAsync(package.downloadLink, "../sm_plugins/" + package.downloadLocation); Console.Write("\n\r"); } else { if (val.createDir) { Directory.CreateDirectory(Path.GetDirectoryName("../sm_plugins/" + package.downloadLocation)); await client.DownloadFileTaskAsync(package.downloadLink, "../sm_plugins/" + package.downloadLocation); Console.Write("\n\r"); } else { Console.WriteLine("ERROR: The folder to install to does not exist. Did you unzip all the app files into a folder at the same level as sm_plugins?".Pastel("ff0000")); } } } } else { Console.WriteLine(("WARNING: Plugin " + package.name + " is already installed, skipping.").Pastel("ffff000")); } } }