コード例 #1
0
        public string download(Uri uri)
        {
            "Downloading from Uri: {0}".info(uri);
            if (uri.isNull())
            {
                return(null);
            }
            VersionWebDownload = uri.str();

            //var localFilePath = PublicDI.config.O2TempDir.pathCombine(CurrentVersionZipFile);
            //"downloading file {0} from {1} to {2}".info(CurrentVersionZipFile, CurrentVersionWebDownload,localFilePath);
            "downloading file {0}".info(VersionWebDownload);

            //if (new Web().httpFileExists(VersionWebDownload))
            //{
            //  var downloadedFile =  new Web().downloadBinaryFile(VersionWebDownload);
            var downloadedFile = VersionWebDownload.download();

            if (downloadedFile.fileExists())
            {
                var targetFile = tempLocationOf_Install_File();        //localDownloadsDir.pathCombine(Install_File);
                "Copying file: {0}".info(targetFile);
                Files.Copy(downloadedFile, targetFile);
                "Deleting file: {0}".info(targetFile);
                Files.deleteFile(downloadedFile);
                if (targetFile.fileExists())
                {
                    return(targetFile);
                }
            }
            //}
            return(null);
        }
コード例 #2
0
        public string download(Uri uri)
        {
            var targetFile = tempLocationOf_Install_File();    //localDownloadsDir.pathCombine(Install_File);

            if (targetFile.fileExists())
            {
                "found previously downloaded copy: {0}".info(targetFile);
                return(targetFile);
            }
            "Downloading from Uri: {0}".info(uri);
            if (uri.isNull())
            {
                return(null);
            }
            VersionWebDownload = uri.str();

            var downloadedFile = VersionWebDownload.download();

            if (downloadedFile.fileExists())
            {
                for (int i = 0; i < 5; i++) // try to get the file 5 times since sometimes the file is still not available (due to AV)
                {
                    this.sleep(1000);
                    "Copying file: {0}".info(targetFile);
                    if (Files.copy(downloadedFile, targetFile).valid())
                    {
                        "Deleting file: {0}".info(downloadedFile);
                        Files.deleteFile(downloadedFile);
                    }
                    if (targetFile.fileExists())
                    {
                        return(targetFile);
                    }
                }
            }
            ;
            return(null);
        }