-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #4102 Skip temp files for repo updates
- Loading branch information
Showing
14 changed files
with
227 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,99 @@ | ||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
|
||
using ChinhDo.Transactions.FileManager; | ||
|
||
namespace CKAN | ||
{ | ||
public partial class NetAsyncDownloader | ||
{ | ||
public class DownloadTarget | ||
public abstract class DownloadTarget | ||
{ | ||
public List<Uri> urls { get; private set; } | ||
public string filename { get; private set; } | ||
public long size { get; set; } | ||
public string mimeType { get; private set; } | ||
public List<Uri> urls { get; protected set; } | ||
public long size { get; protected set; } | ||
public string mimeType { get; protected set; } | ||
|
||
public DownloadTarget(List<Uri> urls, | ||
string filename = null, | ||
long size = 0, | ||
string mimeType = "") | ||
protected DownloadTarget(List<Uri> urls, | ||
long size = 0, | ||
string mimeType = "") | ||
{ | ||
var FileTransaction = new TxFileManager(); | ||
|
||
this.urls = urls; | ||
this.filename = string.IsNullOrEmpty(filename) | ||
? FileTransaction.GetTempFileName() | ||
: filename; | ||
this.size = size; | ||
this.mimeType = mimeType; | ||
} | ||
|
||
public DownloadTarget(Uri url, | ||
string filename = null, | ||
long size = 0, | ||
string mimeType = "") | ||
: this(new List<Uri> { url }, | ||
filename, size, mimeType) | ||
public abstract long CalculateSize(); | ||
public abstract void DownloadWith(ResumingWebClient wc, Uri url); | ||
} | ||
|
||
public sealed class DownloadTargetFile : DownloadTarget | ||
{ | ||
public string filename { get; private set; } | ||
|
||
public DownloadTargetFile(List<Uri> urls, | ||
string filename = null, | ||
long size = 0, | ||
string mimeType = "") | ||
: base(urls, size, mimeType) | ||
{ | ||
this.filename = filename ?? Path.GetTempFileName(); | ||
} | ||
|
||
public DownloadTargetFile(Uri url, | ||
string filename = null, | ||
long size = 0, | ||
string mimeType = "") | ||
: this(new List<Uri> { url }, filename, size, mimeType) | ||
{ | ||
} | ||
|
||
public override long CalculateSize() | ||
{ | ||
size = new FileInfo(filename).Length; | ||
return size; | ||
} | ||
|
||
public override void DownloadWith(ResumingWebClient wc, Uri url) | ||
{ | ||
wc.DownloadFileAsyncWithResume(url, filename); | ||
} | ||
} | ||
|
||
public sealed class DownloadTargetStream : DownloadTarget, IDisposable | ||
{ | ||
public Stream contents { get; private set; } | ||
|
||
public DownloadTargetStream(List<Uri> urls, | ||
long size = 0, | ||
string mimeType = "") | ||
: base(urls, size, mimeType) | ||
{ | ||
contents = new MemoryStream(); | ||
} | ||
|
||
public DownloadTargetStream(Uri url, | ||
long size = 0, | ||
string mimeType = "") | ||
: this(new List<Uri> { url }, size, mimeType) | ||
{ | ||
} | ||
|
||
public override long CalculateSize() | ||
{ | ||
size = contents.Length; | ||
return size; | ||
} | ||
|
||
public override void DownloadWith(ResumingWebClient wc, Uri url) | ||
{ | ||
wc.DownloadFileAsyncWithResume(url, contents); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// Close the stream | ||
contents.Dispose(); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.