From fa2ae8c3b417732f8155e71df85c4e5bfeee3d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=85=E6=B0=B8?= Date: Fri, 2 Aug 2019 22:23:48 +0800 Subject: [PATCH] Added features to avoid repeated downloads of running data. Perhaps you can add more code to implement the hash check ingress of the file and intermittently pass on. --- src/TensorFlowHub/Utils.cs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/TensorFlowHub/Utils.cs b/src/TensorFlowHub/Utils.cs index 10aaf958..72ee9430 100644 --- a/src/TensorFlowHub/Utils.cs +++ b/src/TensorFlowHub/Utils.cs @@ -25,13 +25,25 @@ namespace Tensorflow.Hub if (!Path.IsPathRooted(dirSaveTo)) dirSaveTo = Path.Combine(AppContext.BaseDirectory, dirSaveTo); - if (!Directory.Exists(dirSaveTo)) - Directory.CreateDirectory(dirSaveTo); - - using (var wc = new WebClient()) + var fileSaveTo = Path.Combine(dirSaveTo, fileName); + + if (File.Exists(fileSaveTo)) { - await wc.DownloadFileTaskAsync(url, Path.Combine(dirSaveTo, fileName)); + //TODO:maybe you can check file's hashcode and "donglowad.info" to complete file ... + Console.WriteLine($"{fileSaveTo} already exists."); } + else + { + if (!Directory.Exists(dirSaveTo)) + Directory.CreateDirectory(dirSaveTo); + + using (var wc = new WebClient()) + { + await wc.DownloadFileTaskAsync(url, fileSaveTo); + } + + } + } public static async Task UnzipAsync(this IModelLoader modelLoader, string zipFile, string saveTo) @@ -42,7 +54,7 @@ namespace Tensorflow.Hub if (!Directory.Exists(saveTo)) Directory.CreateDirectory(saveTo); - + if (!Path.IsPathRooted(zipFile)) zipFile = Path.Combine(AppContext.BaseDirectory, zipFile); @@ -78,7 +90,7 @@ namespace Tensorflow.Hub var cts = new CancellationTokenSource(); var showProgressTask = ShowProgressInConsole(cts); - + try { await task; @@ -86,7 +98,7 @@ namespace Tensorflow.Hub finally { cts.Cancel(); - } + } } private static async Task ShowProgressInConsole(CancellationTokenSource cts)