DownloadFilesAsync() private method

private DownloadFilesAsync ( string downloadDir ) : System.Threading.Tasks.Task
downloadDir string
return System.Threading.Tasks.Task
Esempio n. 1
0
        async Task <bool> CopyPackageContent(InstallablePackage entry, InstallSettings settings)
        {
            string cachePath  = Environment.ExpandEnvironmentVariables(Defaults.CachePath);
            string versionDir = Path.Combine(cachePath, Provider.Name, entry.Name, entry.Version);
            bool   hasCopied  = false;

            await entry.DownloadFilesAsync(versionDir);

            await Task.Run(() =>
            {
                try
                {
                    foreach (string file in entry.Files)
                    {
                        string cleanFile = file.Replace("/", "\\");
                        string src       = Path.Combine(versionDir, cleanFile);
                        string dest      = Path.Combine(settings.InstallDirectory, cleanFile);

                        if (File.Exists(dest))
                        {
                            var srcDate  = File.GetLastWriteTime(src);
                            var destDate = File.GetLastWriteTime(dest);

                            if (srcDate == destDate)
                            {
                                continue;
                            }
                        }

                        string dir = Path.GetDirectoryName(dest);
                        Directory.CreateDirectory(dir);

                        OnCopying(src, dest);
                        File.Copy(src, dest, true);
                        OnCopied(src, dest);
                        hasCopied = true;
                    }
                }
                catch (Exception)
                {
                    try
                    {
                        Directory.Delete(versionDir, true);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.Write(ex);
                    }
                }
            });

            return(hasCopied);
        }
Esempio n. 2
0
        async Task<bool> CopyPackageContent(InstallablePackage entry, InstallSettings settings)
        {
            string cachePath = Environment.ExpandEnvironmentVariables(Defaults.CachePath);
            string versionDir = Path.Combine(cachePath, Provider.Name, entry.Name, entry.Version);
            bool hasCopied = false;

            await entry.DownloadFilesAsync(versionDir);

            await Task.Run(() =>
            {
                try
                {
                    foreach (string file in entry.Files)
                    {
                        string cleanFile = file.Replace("/", "\\");
                        string src = Path.Combine(versionDir, cleanFile);
                        string dest = Path.Combine(settings.InstallDirectory, cleanFile);

                        if (File.Exists(dest))
                        {
                            var srcDate = File.GetLastWriteTime(src);
                            var destDate = File.GetLastWriteTime(dest);

                            if (srcDate == destDate)
                                continue;
                        }

                        string dir = Path.GetDirectoryName(dest);
                        Directory.CreateDirectory(dir);

                        OnCopying(src, dest);
                        File.Copy(src, dest, true);
                        OnCopied(src, dest);
                        hasCopied = true;
                    }
                }
                catch (Exception)
                {
                    try
                    {
                        Directory.Delete(versionDir, true);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.Write(ex);
                    }
                }
            });

            return hasCopied;
        }