diff --git a/SteamWareLib/UpdateMan.cs b/SteamWareLib/UpdateMan.cs index ed8ae19..a977dfa 100644 --- a/SteamWareLib/UpdateMan.cs +++ b/SteamWareLib/UpdateMan.cs @@ -111,27 +111,54 @@ namespace SteamWare } string localFile = ""; string localLast = ""; + string DownloadURL = ""; try { // in primis scarico update info... UpdateInfoEventArgs updateData = getUpdateInfo(remoteUrl); if (updateData.IsUpdateAvailable) { - string DownloadURL = updateData.DownloadURL; + DownloadURL = updateData.DownloadURL; localFile = string.Format(@"{0}\{1}_Build_{2}.zip", localRepo, packName, updateData.CurrentVersion); localLast = string.Format(@"{0}\{1}.zip", localRepo, packName); // scarica file e salva in directory locale... - var client = new WebClient(); - bool doAuth = !string.IsNullOrEmpty($"{userName}{passwd}"); - if (doAuth) + using (var http = new HttpClient()) { - client.Credentials = new System.Net.NetworkCredential(userName, passwd); + //var client = new WebClient(); + bool doAuth = !string.IsNullOrEmpty($"{userName}{passwd}"); + if (doAuth) + { + //client.Credentials = new System.Net.NetworkCredential(userName, passwd); + http.DefaultRequestHeaders.Accept.Clear(); + var byteArray = System.Text.ASCIIEncoding.UTF8.GetBytes($"{userName}:{passwd}"); + http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); + } + //client.DownloadFile(updateData.DownloadURL, localFile); + + // url da chiamare + http.BaseAddress = new Uri(DownloadURL); + // lettura + var data = http.GetAsync(DownloadURL).Result; + using (var myReader = data.Content.ReadAsStreamAsync()) + { + //var myReader = data.Content.ReadAsStreamAsync(); + if (data.StatusCode != HttpStatusCode.OK) + { + logger.lg.scriviLog($"Errore in chiamata getUpdateInfo per URL {remoteUrl}: status code: {data.StatusCode}", tipoLog.INFO); + } + else + { + using (Stream outStream = File.OpenWrite(localFile)) + { + myReader.Result.CopyTo(outStream); + } + // ora lo copio come latest... + File.Copy(localFile, localLast, true); + // indico come fatto! + done = 1; + } + } } - client.DownloadFile(updateData.DownloadURL, localFile); - // ora lo copio come latest... - File.Copy(localFile, localLast, true); - // indico come fatto! - done = 1; } else { @@ -139,7 +166,7 @@ namespace SteamWare // scrivo file in area target... using (StreamWriter sw = File.AppendText(localFile)) { - sw.WriteLine(string.Format("{0:yyyy-MM-dd HH:mm:ss} ATTENZIONE! Installer NON disponibile | {1}", DateTime.Now, remoteUrl)); + sw.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} ATTENZIONE! Installer NON disponibile | {remoteUrl}"); } } } @@ -149,7 +176,7 @@ namespace SteamWare // scrivo file in area target... using (StreamWriter sw = File.AppendText(localFile)) { - sw.WriteLine(string.Format("{0:yyyy-MM-dd HH:mm:ss} Errore in fase di download installers per {1}", DateTime.Now, remoteUrl)); + sw.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} Errore in fase di download installers{Environment.NewLine}XML: {remoteUrl}{Environment.NewLine}URL: {DownloadURL}"); sw.WriteLine(exc.ToString()); } } diff --git a/TestBench/MainFOrm.cs b/TestBench/MainFOrm.cs index 223029c..cfe7829 100644 --- a/TestBench/MainFOrm.cs +++ b/TestBench/MainFOrm.cs @@ -64,7 +64,7 @@ namespace TestBench private void btnDownload_Click(object sender, EventArgs e) { var currUpdMan = new UpdateMan(txtUser.Text.Trim(), txtPass.Text.Trim()); - currUpdMan.downloadLatest(txtRemoteUrl.Text.Trim(), "c:\\Temp", "MP-STATS"); + currUpdMan.downloadLatest(txtRemoteUrl.Text.Trim(), "c:\\Temp", "TEST-FILE"); } private void btnReadUpdMan_Click(object sender, EventArgs e)