Пример #1
0
 private void sourceCommands(string[] args)
 {
     var locator = new SourceLocator(_token, _sourcePrioritization);
     if (args.Length == 1) {
         locator
             .GetSources().ToList()
             .ForEach(x =>
                 Console.WriteLine(x.Name + " - " + x.Origin));
         return;
     }
     var useGlobal = globalSpecified(ref args);
     var path = locator.GetLocalDir();
     if (useGlobal)
         path = locator.GetGlobalDir();
     if (args.Length == 4 && args[1] == "add") {
         if (path == null) {
             printError("Config point is not initialized");
             return;
         }
         var name = args[2];
         var sources = locator.GetSourcesFrom(path);
         if (sources.Any(x => x.Name == name)) {
             printError("There is already a source named " + name);
             return;
         }
         if (!Directory.Exists(path))
             Directory.CreateDirectory(path);
         var destination = Path.Combine(path, name + ".source");
         download(args[3], destination);
         if (!File.Exists(destination))
             printError("Failed while downloading source file " + args[3]);
         _dispatch(string.Format("event|builtin package src added \"{0}\" \"{1}\"", name, destination));
         return;
     }
     if (args.Length == 3 && args[1] == "rm") {
         var name = args[2];
         var source =
             locator
                 .GetSources()
                 .FirstOrDefault(x => x.Name == name);
         if (source == null) {
             printError("There is no package source named " + name);
             return;
         }
         File.Delete(source.Path);
         _dispatch(string.Format("event|builtin package src removed \"{0}\" \"{1}\"", name, source.Path));
         return;
     }
     if (args.Length > 1 && args[1] == "update") {
         string name = null;
         if (args.Length > 2)
             name = args[2];
         var sources =
             locator
                 .GetSources()
                 .Where(x => name == null || x.Name == name);
         if (sources.Count() == 0) {
             printError("There are no package sources to update");
             return;
         }
         foreach (var source in sources) {
             _dispatch("downloading "+source.Origin);
             if (!download(source.Origin, source.Path))
                 printError("Failed to download source file " + source.Origin);
             else
                 _dispatch(string.Format("event|builtin package src updated \"{0}\" \"{1}\"", source.Name, source.Path));
         }
         return;
     }
     if (args.Length > 1 && args[1] == "list") {
         var os = getOS();
         string name = null;
         if (args.Length > 2)
             name = args[2];
         var sources =
             locator
                 .GetSources()
                 .Where(x => name == null || x.Name == name);
         foreach (var source in sources) {
             _dispatch("Packages in " +  source.Name);
             var sourcePackages = source.Packages.Where(x => x.OS.Contains(os)).OrderBy(x => x.Name);
             foreach (var package in sourcePackages)
                 _dispatch("    " + package.ToString());
         }
     }
 }
Пример #2
0
 public FetchedPackage Fetch(string source)
 {
     try {
         if (File.Exists(Path.GetFullPath(source)))
             return new FetchedPackage(Path.GetFullPath(source), false);
         var package = new SourceLocator(_token, _sourcePrioritization).GetPackage(source);
         if (package != null) {
             source = Path.Combine(Path.GetTempPath(), DateTime.Now.Ticks.ToString() + Path.GetFileName(package.Package));
             if (download(package.Package, source))
                 return new FetchedPackage(source, true);
         }
     } catch (Exception ex) {
         Logger.Write(ex);
     }
     return null;
 }