Example #1
0
        /// Execute update
        public void DoUpdate(Updater updater )
        {
            var context = ScriptContextScope.Current;

            // Create a directory in download catalog
            DirectoryInfo dsum = updater.GetWorkingDirectory(Name);

            string dir = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(dsum.FullName);
            string oldPath = context.ScriptPath;
            try
            {
                context.ScriptPath = dsum.FullName + ";" + oldPath;
                context.Info.WriteLine("[{0}] Updating...", Name);
                context.Execute(Update);
                var cv=ReturnValue.Unwrap(CheckVersion());
                context.Out.WriteLine("[{0}] Update completed. New version is {1}", Name, cv);
            }
            finally
            {
                context.ScriptPath = oldPath;
                Directory.SetCurrentDirectory(dir);
            }
        }
Example #2
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 #3
0
 /// Cleanup
 public void Cleanup(Updater updater)
 {
     var context = ScriptContextScope.Current;
     Delete d = new Delete
         {
             ReadOnly = true,
             Root = true,
             Catch = new Block(),
             Recursive = true,
             From = updater.GetWorkingDirectory(Name).FullName,
             Transform = TransformRules.None
         };
     context.InitializeAndExecute(d);
 }