-
Notifications
You must be signed in to change notification settings - Fork 23
/
fileDownload.cake
74 lines (66 loc) · 2.33 KB
/
fileDownload.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.IO;
using Polly;
using NuGet;
public static class Utils
{
public static bool MoveFolderContents(string SourcePath, string DestinationPath)
{
SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";
try
{
if (System.IO.Directory.Exists(SourcePath))
{
if (System.IO.Directory.Exists(DestinationPath) == false)
{
System.IO.Directory.CreateDirectory(DestinationPath);
}
foreach (string files in System.IO.Directory.GetFiles(SourcePath))
{
FileInfo fileInfo = new FileInfo(files);
fileInfo.MoveTo(string.Format(@"{0}\{1}", DestinationPath, fileInfo.Name));
}
foreach (string drs in System.IO.Directory.GetDirectories(SourcePath))
{
System.IO.DirectoryInfo directoryInfo = new DirectoryInfo(drs);
if (MoveFolderContents(drs, DestinationPath + directoryInfo.Name) == false)
{
return false;
}
}
}
return true;
}
catch (Exception ex)
{
return false;
}
}
}
public class ArchiveDownloadInfo
{
public string URL {get;set;}
public string Name {get;set;}
public FilePath DestinationFile {get; set;}
public string Format {get; set;}
public Action<DirectoryPath, ArchiveDownloadInfo> PostExtract {get; set;}
}
public class ToolchainDownloadInfo
{
private DirectoryPath _artifactsDir;
public ToolchainDownloadInfo(DirectoryPath artifactsDir)
{
_artifactsDir = artifactsDir;
Downloads = new List<ArchiveDownloadInfo>();
}
public DirectoryPath BaseDir {get { return _artifactsDir.Combine(RID); } }
public DirectoryPath ZipDir {get { return _artifactsDir.Combine("zip").Combine(RID); } }
public string RID {get; set;}
public List<ArchiveDownloadInfo> Downloads {get; set;}
}