private void removePackage(Package package, string path, bool isGlobal) { foreach (var action in package.PreUninstallActions) { if (isGlobal && action.Global != null) _dispatch(action.Global); else _dispatch(action.Action); } Directory.Delete( Path.Combine(path, package.Command + "-files"), true); Directory .GetFiles(path) .Where(x => Path.GetFileNameWithoutExtension(x) == package.Command) .ToList() .ForEach(x => File.Delete(x)); foreach (var action in package.PostUninstallActions) { if (isGlobal && action.Global != null) _dispatch(action.Global); else _dispatch(action.Action); } }
private void update(string source, Package existingPackage, ActionParameters args) { if (existingPackage == null) { _dispatch("error|the requested package is not installed. Try install instead."); return; } if (!runInstallVerify(args.TempPath, args.InstallPath)) { printUpdateFailed(args.Package.Signature); return; } if (!runUpgrade(args.TempPath, args.InstallPath, "before-update")) { printUpdateFailed(args.Package.Signature); return; } var backupLocation = backupScripts(args.Package.Command, args.InstallPath); removePackage(args.Package, args.InstallPath, _useGlobal); new PackageExtractor().Extract(source, args.InstallPath); restoreScripts(args.Package.Command, args.InstallPath, backupLocation); if (!runUpgrade(args.InstallPath, args.InstallPath, "after-update")) { printUpdateFailed(args.Package.Signature); return; } _dispatch( string.Format( "package updated from {0} to {1}", existingPackage.Signature, args.Package.Signature)); }
private void printConflictingPackage(string name, Package package, IEnumerable<string> matches) { var pkgInfo = ""; var existingPackage = getPackage(matches.First()); if (existingPackage != null) pkgInfo = string.Format(" ({0})", existingPackage.Signature); _dispatch( string.Format( "error|there is already an installed {2} package called {0}{1}", name, pkgInfo, package.Target)); if (existingPackage != null) { _dispatch(""); _dispatch(existingPackage.ToVerboseString()); } _dispatch(""); _dispatch( "warning|to replace/update the installed package use the update command"); }
private void printUnexistingUpdate(string name, Package package) { _dispatch(string.Format("error|there is no installed {1} package {0} to update", name, package.Target)); }
private string getLanguageInstallPath(Package package, bool forcelocal) { var language = _locator .Locate() .FirstOrDefault(x => x.GetLanguage() == package.Language); if (language == null) { Logger.Write("Failed to locate language " + package.Language); return null; } var basepath = Path.GetDirectoryName(language.FullPath); if (forcelocal) { var profiles = new ProfileLocator(_token); basepath = Path.Combine(profiles.GetLocalProfilePath(profiles.GetActiveLocalProfile()), "languages"); } return Path.Combine( Path.Combine( basepath, language.GetLanguage() + "-files"), package.Target.Replace("language-", "") + "s"); }
private void installPackage(string source, Package package, string tempPath, string installPath, string activeProfile) { if (!runInstallVerify(tempPath, installPath)) { _dispatch(""); _dispatch(string.Format("error|failed to install package {0}", package.Signature)); return; } foreach (var action in package.PreInstallActions) { if (_useGlobal && action.Global != null) _dispatch(action.Global); else _dispatch(action.Action); } if (!installDependencies(package.Dependencies)) return; new PackageExtractor().Extract(source, installPath); foreach (var action in package.PostInstallActions) { if (_useGlobal && action.Global != null) _dispatch(action.Global); else _dispatch(action.Action); } _dispatch(string.Format("installed {1} package {0} in profile {2}", package.Signature, package.Target, activeProfile)); }
private string getLanguageInstallPath(Package package) { return getLanguageInstallPath(package, false); }
private string getInstallPath(Package package, ProfileLocator profiles, string activeProfile) { string installPath; if (package.Target.StartsWith("language-")) { var path = getLanguageInstallPath(package, !_useGlobal); if (path == null) { _dispatch("error|could not find language to install language dependent package in"); return null; } if (_useGlobal && !profiles.IsGlobal(path)) { _dispatch("error|cannot install language dependent package globally as language is installed locally."); return null; } return path; } if (_useGlobal) installPath = profiles.GetGlobalProfilePath(activeProfile); else installPath = profiles.GetLocalProfilePath(activeProfile); if (installPath == null) { _dispatch("error|the current location does not have an initialized config point"); return null; } return Path.Combine(installPath, package.Target + "s"); }
private string getLanguageInstallPath(Package package) { var language = _locator .Locate() .FirstOrDefault(x => x.GetLanguage() == package.Language); return Path.Combine( Path.Combine( Path.GetDirectoryName(language.FullPath), language.GetLanguage() + "-files"), package.Target.Replace("language-", "") + "s"); }
private string getInstallPath(Package package, ProfileLocator profiles, string activeProfile) { string installPath; if (package.Target.StartsWith("language-")) return getLanguageInstallPath(package); if (_useGlobal) installPath = profiles.GetGlobalProfilePath(activeProfile); else installPath = profiles.GetLocalProfilePath(activeProfile); if (installPath == null) return null; return Path.Combine(installPath, package.Target + "s"); }
private static Package read(string file, string json) { try { var data = JObject.Parse(json); var os = new List<string>(); data["os"].Children().ToList() .ForEach(x => os.Add(x.ToString())); var package = new Package( os.ToArray(), data["target"].ToString(), data["id"].ToString(), data["version"].ToString(), data["command"].ToString(), data["name"].ToString(), data["description"].ToString()); var language = data["language"]; if (language != null) package.Language = language.ToString(); package.File = file; if (data["pre-install-actions"] != null) { data["pre-install-actions"].Children().ToList() .ForEach(x => package.AddPreInstallAction(x.ToString())); } if (data["dependencies"] != null) { data["dependencies"].Children().ToList() .ForEach(x => package.AddDependency( x["id"].ToString(), x["versions"].Children() .Select(y => y.ToString()))); } if (data["post-install-actions"] != null) { data["post-install-actions"].Children().ToList() .ForEach(x => package.AddPostInstallAction(x.ToString())); } if (package.IsValid()) return package; } catch (Exception ex) { Logger.Write(ex); } return null; }