Example #1
0
        private object downloadSingleFile(IStringFilter nf, Uri single, FileInfo toFile)
        {
            var from = new UriFileInfo(single);
            var ff   = from.Name;

            if (string.IsNullOrEmpty(ff))
            {
                ff = toFile.Name;
            }
            if (nf != null && (!nf.IsMatch(ff)))
            {
                VerboseMessage("{0} did not pass filter", single);
                return(null);
            }

            var    to   = new FileOrDirectoryInfo(toFile);
            bool   skip = false;
            object ret  = ProcessPrepare(from, to,
                                         delegate
            {
                if (toFile.Directory != null && !toFile.Directory.Exists)
                {
                    bool created;
                    object r = createDir(new DirectoryInfo(Path.GetTempPath()), toFile.Directory, out created);
                    if (!created || r != null)
                    {
                        return(r);
                    }
                }


                bool overwrite = (Overwrite == OverwriteMode.Always);
                if (Overwrite == OverwriteMode.IfNewer)
                {
                    if (toFile.Exists && toFile.LastWriteTimeUtc >= from.LastWriteTimeUtc)
                    {
                        VerboseMessage("Ignoring never file {0} ", toFile.FullName);
                        return(null);
                    }
                    overwrite = true;
                }

                skip = (toFile.Exists && !overwrite);
                return(null);
            });

            if (ret != null)
            {
                return(ret);
            }
            if (skip && Overwrite != OverwriteMode.Confirm)
            {
                VerboseMessage("Ignoring existing file {0} ", toFile.FullName);
                return(null);
            }
            ret = ProcessComplete(from, to, skip, delegate(bool skip1)
            {
                if (!skip1)
                {
                    // Continue with copy
                    if (toFile.Directory != null && !toFile.Directory.Exists)
                    {
                        toFile.Directory.Create();
                    }
                    VerboseMessage("Downloading {0} => {1}", from.FullName, toFile.FullName);
                    Download dn = new Download
                    {
                        From      = single.OriginalString,
                        To        = toFile.FullName,
                        Transform = TransformRules.None
                    };
                    return(Context.Execute(dn));
                }
                return(null);
            });
            return(ret);
        }
Example #2
0
        private object downloadSingleFile(IStringFilter nf, Uri single, FileInfo toFile)
        {
            var from = new UriFileInfo(single);
            var ff = from.Name;
            if (string.IsNullOrEmpty(ff))
                ff = toFile.Name;
            if (nf != null && (!nf.IsMatch(ff)))
            {
                VerboseMessage("{0} did not pass filter", single);
                return null;
            }

            var to = new FileOrDirectoryInfo(toFile);
            bool skip = false;
            object ret = ProcessPrepare(from, to,
                delegate
                {
                    if (toFile.Directory != null && !toFile.Directory.Exists)
                    {
                        bool created;
                        object r = createDir(new DirectoryInfo(Path.GetTempPath()), toFile.Directory, out created);
                        if (!created || r != null)
                            return r;
                    }

                    bool overwrite = (Overwrite == OverwriteMode.Always);
                    if (Overwrite == OverwriteMode.IfNewer)
                    {
                        if (toFile.Exists && toFile.LastWriteTimeUtc >= from.LastWriteTimeUtc)
                        {
                            VerboseMessage("Ignoring never file {0} ", toFile.FullName);
                            return null;
                        }
                        overwrite = true;
                    }

                    skip = (toFile.Exists && !overwrite);
                    return null;
                });
            if (ret != null)
                return ret;
            if (skip && Overwrite != OverwriteMode.Confirm)
            {
                VerboseMessage("Ignoring existing file {0} ", toFile.FullName);
                return null;
            }
            ret = ProcessComplete(from, to, skip, delegate(bool skip1)
            {
                if (!skip1)
                {
                    // Continue with copy
                    if (toFile.Directory != null && !toFile.Directory.Exists)
                        toFile.Directory.Create();
                    VerboseMessage("Downloading {0} => {1}", from.FullName, toFile.FullName);
                    Download dn = new Download
                    {
                        From = single.OriginalString,
                        To = toFile.FullName,
                        Transform = TransformRules.None
                    };
                    return Context.Execute(dn);
                }
                return null;
            });
            return ret;
        }