private static bool DownloadFileFromServer(ISonarConfiguration authentication, VersionData versionToUse, string tmpFile, string tmpDir)
{
try
{
var urldownload = authentication.Hostname + versionToUse.DownloadPath;
using (var client = new WebClient())
{
client.DownloadFile(urldownload, tmpFile);
ZipFile.ExtractToDirectory(tmpFile, tmpDir);
var files = Directory.GetFiles(tmpDir);
var versionDir = "";
foreach (var file in files)
{
if (string.IsNullOrEmpty(versionDir))
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(file);
string ver = fvi.FileVersion;
versionDir = Path.Combine(versionToUse.InstallPath, ver);
versionToUse.InstallPath = Path.Combine(versionToUse.InstallPath, ver);
if (!Directory.Exists(versionToUse.InstallPath))
{
Directory.CreateDirectory(versionToUse.InstallPath);
}
}
var endPath = Path.Combine(versionToUse.InstallPath, Path.GetFileName(file));
if (!File.Exists(endPath))
{
File.Copy(file, endPath, true);
}
}
}
return true;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
return false;
}
}