Example #1
0
        /// Download package
        public void Download(Updater updater)
        {
            var context = ScriptContextScope.Current;

            DirectoryInfo download = updater.GetDownloadDirectory();

            download.Create();

            DirectoryInfo dsum = updater.GetWorkingDirectory(Name);

            if (updater.Cleanup)
            {
                Cleanup(updater);
            }
            dsum.Create();

            PackageInfo pi = updater.GetPackage(Name);

            if (pi.DownloadUri == null)
            {
                context.Info.WriteLine("[{0}] No download location provided...", Name);
                return;
            }

            var    edition  = context.TransformStr(updater.Edition, Transform);
            string fileName = edition + "." + Name + "." + pi.Version + ".zip";

            _packageDownloadName = Path.Combine(download.FullName, fileName);
            // If there is hash, we don't necessarily have to download
            if (pi.Hash == null || !isValidHash(_packageDownloadName, pi.Hash))
            {
                context.Info.WriteLine("[{0}] Downloading package from {1}...", Name, Utils.SecureUri(pi.DownloadUri));

                Download dn = new Download
                {
                    From       = pi.DownloadUri.ToString(),
                    To         = _packageDownloadName,
                    CacheLevel = updater.CacheLevel,
                    Transform  = TransformRules.None
                };
                context.InitializeAndExecute(dn);

                // Validate hash
                if (pi.Hash != null && !isValidHash(_packageDownloadName, pi.Hash))
                {
                    throw new ScriptRuntimeException("Hash of data downloaded from " + Utils.SecureUri(pi.DownloadUri) + " is invalid");
                }
            }

            // Extract the file
            context.Info.WriteLine("[{0}] Extracting {1}...", Name, _packageDownloadName);
            Unzip ex = new Unzip
            {
                To        = dsum.FullName,
                From      = _packageDownloadName,
                Clean     = false,
                ZipTime   = updater.ZipTime,
                Password  = updater.Password,
                Transform = TransformRules.None
            };

            context.InitializeAndExecute(ex);
        }
Example #2
0
        private static Script genUnzip(ScriptContext context, List<string> filteredArgs)
        {
            Script script;
            string[] s = context.GetStringArray(xs.unzip);
            if (s.Length < 1)
                throw new ArgumentException("Invalid arguments to " + xs.unzip + " command");

            script = createEmptyScript(context, "xsharper //unzip");
            script.Id = "unzip";
            filteredArgs.AddRange(s);

            script.Usage.Options = UsageOptions.IfHelp | UsageOptions.IfNoArguments | UsageOptions.UsageLine | UsageOptions.AutoSuffix;
            script.Parameters.Add(new CommandLineParameter("zip", CommandLineValueCount.Single, null, null) { Required = true, Description = "archive.zip", Value = "Zip archive to extract" });
            script.Parameters.Add(new CommandLineParameter("destination", CommandLineValueCount.Single, ".", null) { Description = "directory", Value = "Directory where to decompress files" });
            script.Parameters.Add(new CommandLineParameter("filter", CommandLineValueCount.Single, "*.*", null) { Description = "filter", Value = "File wildcard" });
            script.Parameters.Add(new CommandLineParameter("dirfilter", CommandLineValueCount.Single, "*", null) { Description = "directory-filter", Value = "Directory wildcard" });
            script.Parameters.Add(new CommandLineParameter(null, "zipTime", CommandLineValueCount.Single, "fileTime", null) { Synonyms = "zt", Value = "How to process time for files created in zip entries ( fileTime/utcFileTime = set to entry time, now/utcNow =ignore)" });
            script.Parameters.Add(new CommandLineParameter(null, "overwrite", CommandLineValueCount.Single, OverwriteMode.Always.ToString(), null) { Synonyms="o",Value = "Overwrite mode" });
            script.Parameters.Add(new CommandLineParameter(null, "password", CommandLineValueCount.Single, null, null) { Synonyms = "p", Value = "Archive password" });
            script.Parameters.Add(new CommandLineParameter(null, "ignore", CommandLineValueCount.None, "0", "1") { Synonyms = "i", Value = "Ignore errors" });
            script.Parameters.Add(new CommandLineParameter(null, "hidden", CommandLineValueCount.None, "0", "1") { Synonyms = "i", Value = "Extract hidden files" });

            script.Add(new PathOperation { Value = "${zip}", Operation = PathOperationType.GetFullPath, OutTo = "zip", Existence = Existence.FileExists});
            script.Add(new If(new Set("zip", "${=Path.ChangeExtension(${zip},'.zip')}"))
            {
                IsEmpty = "${=Path.GetExtension(${zip})}"
            });
            script.Add(new PathOperation { Value= "${destination}", Operation = PathOperationType.ToDirectoryInfo, Backslash = BackslashOption.Add, OutTo = "destination" });
            script.Add(new SetAttr("z", "zipTime", "${zipTime}"));
            script.Add(new SetAttr("z", "overwrite", "${overwrite}"));
            script.Add(new SetAttr("z", "hidden", "${hidden}"));

            script.Add(new Print { Value = "Extracting ${zip} => ${destination} ... " });

            Unzip z = new Unzip()
                          {
                              Id="z",
                              From = "${zip}",
                              To = "${destination}",
                              Transform = TransformRules.Expand,
                              Syntax = FilterSyntax.Auto,
                              Filter = "${filter}",
                              DirectoryFilter = "${dirfilter}",
                              Password = "******"
                          };
            z.Add(new Print { Value = "  ${to}", OutTo = "^info" });

            If f=new If(new[] { new Print("Failed: '${}' : ${=c.CurrentException.Message}") { OutTo = "^error"}});
            f.IsTrue = "${ignore}";
            f.AddElse(new Throw());
            z.AddCatch(f);

            script.Add(z);
            script.Add(new Print { Value = "Completed" });
            return script;
        }
Example #3
0
        /// Download package
        public void Download(Updater updater)
        {
            var context = ScriptContextScope.Current;

            DirectoryInfo download = updater.GetDownloadDirectory();
            download.Create();

            DirectoryInfo dsum = updater.GetWorkingDirectory(Name);
            if (updater.Cleanup)
                Cleanup(updater);
            dsum.Create();

            PackageInfo pi = updater.GetPackage(Name);
            if (pi.DownloadUri == null)
            {
                context.Info.WriteLine("[{0}] No download location provided...", Name);
                return;
            }

            var edition = context.TransformStr(updater.Edition, Transform);
            string fileName = edition + "." +Name + "." +  pi.Version + ".zip";

            _packageDownloadName = Path.Combine(download.FullName, fileName);
            // If there is hash, we don't necessarily have to download
            if (pi.Hash==null || !isValidHash(_packageDownloadName, pi.Hash))
            {
                context.Info.WriteLine("[{0}] Downloading package from {1}...", Name, Utils.SecureUri(pi.DownloadUri));

                Download dn = new Download
                    {
                        From = pi.DownloadUri.ToString(),
                        To = _packageDownloadName,
                        CacheLevel = updater.CacheLevel,
                        Transform = TransformRules.None

                    };
                context.InitializeAndExecute(dn);

                // Validate hash
                if (pi.Hash!=null && !isValidHash(_packageDownloadName, pi.Hash))
                    throw new ScriptRuntimeException("Hash of data downloaded from " + Utils.SecureUri(pi.DownloadUri) + " is invalid");
            }

            // Extract the file
            context.Info.WriteLine("[{0}] Extracting {1}...", Name, _packageDownloadName);
            Unzip ex = new Unzip
                                {
                                    To = dsum.FullName,
                                    From = _packageDownloadName,
                                    Clean = false,
                                    ZipTime = updater.ZipTime,
                                    Password = updater.Password,
                                    Transform = TransformRules.None
                                };
            context.InitializeAndExecute(ex);
        }