Esempio n. 1
0
 public async Task<string> DownloadAsync(string destinationFolder, string unsanitizedFileName, FileOverwriteMode mode, CancellationToken ct, IProgress<DataTransferProgress> progress)
 {
     Directory.CreateDirectory(destinationFolder);
     string path;
     if (mode == FileOverwriteMode.Rename)
     {
         path = FileSystem.GetUniqueFileName(destinationFolder, unsanitizedFileName);
     }
     else
     {
         path = FileSystem.SanitizeFileName(destinationFolder, unsanitizedFileName);
         if (File.Exists(path))
         {
             if (mode == FileOverwriteMode.Error) throw new ArgumentException("File " + path + " already exists.");
             else if (mode == FileOverwriteMode.Skip) return path;
         }
         if (mode == FileOverwriteMode.GenerateNameOnly) return path;
     }
     await DownloadAsync(path, ct, progress);
     return path;
 }
Esempio n. 2
0
        public async Task <string> DownloadAsync(string destinationFolder, string unsanitizedFileName, FileOverwriteMode mode, CancellationToken ct, IProgress <DataTransferProgress> progress)
        {
#if !STANDALONE
            if (Utils.PreventLocalFileAccess)
            {
                if (Path.IsPathRooted(destinationFolder))
                {
                    throw new NotSupportedException("Downloading to absolute locations is not supported in this configuration.");
                }

                var verifier = Runtime.Compiler.Verifier.Instance;
                if (verifier == null || verifier.DatabasePath == null)
                {
                    throw new NotSupportedException("Downloading files requires a deployed connector.");
                }

                var downloads = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(verifier.DatabasePath), "Downloads"));
                destinationFolder = Path.GetFullPath(Path.Combine(downloads, destinationFolder));
                if (!destinationFolder.StartsWith(downloads))
                {
                    throw new NotSupportedException("Downloading to absolute locations is not supported in this configuration.");
                }
            }
#endif
            Directory.CreateDirectory(destinationFolder);
            string path;
            if (mode == FileOverwriteMode.Rename)
            {
                path = FileSystem.GetUniqueFileName(destinationFolder, unsanitizedFileName);
            }
            else
            {
                path = FileSystem.SanitizeFileName(destinationFolder, unsanitizedFileName);
                if (File.Exists(path))
                {
                    if (mode == FileOverwriteMode.Error)
                    {
                        throw new ArgumentException("File " + path + " already exists.");
                    }
                    else if (mode == FileOverwriteMode.Skip)
                    {
                        return(path);
                    }
                }
                if (mode == FileOverwriteMode.GenerateNameOnly)
                {
                    return(path);
                }
            }
            await DownloadAsync(path, ct, progress);

            return(path);
        }
Esempio n. 3
0
 public Task<string> DownloadAsync(string destinationFolder, string unsanitizedFileName, FileOverwriteMode mode)
 {
     return DownloadAsync(destinationFolder, unsanitizedFileName, mode, CancellationToken.None, null);
 }
Esempio n. 4
0
 public Task <string> DownloadAsync(string destinationFolder, string unsanitizedFileName, FileOverwriteMode mode)
 {
     return(DownloadAsync(destinationFolder, unsanitizedFileName, mode, CancellationToken.None, null));
 }