diff --git a/BeWoLauncher/Logic/Behavior/LaunchBehavior.cs b/BeWoLauncher/Logic/Behavior/LaunchBehavior.cs index fd3002427..8d37488b3 100644 --- a/BeWoLauncher/Logic/Behavior/LaunchBehavior.cs +++ b/BeWoLauncher/Logic/Behavior/LaunchBehavior.cs @@ -70,13 +70,15 @@ namespace BeWoLauncher.Logic.Behavior { try { - DownloadController.Manager.GetUpdatePlan(); + DownloadController.Manager.CheckForConnection(); } catch(Exception ex) { DownloadController.CanStartWithoutDownloadServer = true; } + DownloadController.Manager.GetUpdatePlan(); + if (!DownloadController.CanStartWithoutDownloadServer && DownloadController.Manager.UpdatePlanResponse.HasToDo()) LaunchUpdateInfo(); else diff --git a/BeWoLauncher/Logic/Utils/Download/DownloadManager.cs b/BeWoLauncher/Logic/Utils/Download/DownloadManager.cs index fce1eae94..6f827bfd1 100644 --- a/BeWoLauncher/Logic/Utils/Download/DownloadManager.cs +++ b/BeWoLauncher/Logic/Utils/Download/DownloadManager.cs @@ -1,5 +1,4 @@ using BeWoLauncher.ServiceProxy; -using BS.SharedLauncher; using BS.SharedLauncher.DataContract; using BS.SharedLauncher.Enums; using BS.SharedLauncher.Exceptions; @@ -9,16 +8,9 @@ using BS.SharedLauncher.Logic; using BS.SharedLauncher.Update; using BS.SharedLauncher.Utils; using System; -using System.Collections.Generic; using System.ComponentModel; using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Text; using System.Threading; -using System.Threading.Tasks; -using System.Windows; -using System.Xml.Serialization; namespace BeWoLauncher.Logic.Utils.Download { @@ -30,7 +22,7 @@ namespace BeWoLauncher.Logic.Utils.Download public string RootFolder => LauncherPaths.GetRootPath(); public string DownloadFolder => LauncherPaths.GetDownloadPath(); public string ApplyFolder => LauncherPaths.GetApplyPath(); - + public bool SkipLock { get; set; } public Action Feedback { get; set; } @@ -41,7 +33,7 @@ namespace BeWoLauncher.Logic.Utils.Download public DownloadManager() { - CanStartWithoutDownloadServer = false; + } public void GetUpdatePlan() @@ -63,6 +55,8 @@ namespace BeWoLauncher.Logic.Utils.Download if (!ApplyFolder.IsFolderEmpty()) UpdatePlanResponse.FilesToDeleteInApply = FileController.GetAppliedFiles(ApplyFolder, false); } + + UpdatePlanResponse.IsUninstall = true; } public void StartProcess(BackgroundWorker worker) @@ -72,7 +66,7 @@ namespace BeWoLauncher.Logic.Utils.Download worker.ReportProgress((int)progress); Thread.Sleep(waitms); }); - + report(LauncherProgress.ProgressStart, 1000); if (FilesToDownloadCount > 0) @@ -119,19 +113,32 @@ namespace BeWoLauncher.Logic.Utils.Download DownloadFolder.SaveCurrentInfo("current"); - UpdateFileRequest req = new UpdateFileRequest(UpdatePlanResponse.CurrentPackage.Version); + UpdateFileRequest req = new UpdateFileRequest(UpdatePlanResponse); foreach (var file2request in UpdatePlanResponse.FilesToRequest) { req.UpdateFile = file2request; - var res = AskForFile(req); + UpdateFileResponse response = null; + + for (int i = 0; i < 5; i++) + { + response = AskForFile(req); + + //if (response is object) + // break; + } + + if (response is null) + { + throw new DownloadFileFailedException($"file: {file2request.RelativePath}"); + } var download_path = DownloadFolder.Combine(file2request.RelativePath); Path.GetDirectoryName(download_path).CreateFolder(); - download_path.SaveFile(res.FileData); + download_path.SaveFile(response.FileData); - var size = NonspecificTools.SizeSuffix((ulong)res.FileData.Length); + var size = NonspecificTools.SizeSuffix((ulong)response.FileData.Length); Feedback((int)LauncherProgress.DownloadUpdate, new DownloadProgressEventArgs(size, file2request)); } @@ -146,7 +153,7 @@ namespace BeWoLauncher.Logic.Utils.Download if (UpdatePlanResponse.FilesToApply is object) UpdatePlanResponse.FilesToApply.ForEach(ApplyFile); - + if (UpdatePlanResponse.FilesToRequest is object) UpdatePlanResponse.FilesToRequest.ForEach(ApplyFile); @@ -180,6 +187,12 @@ namespace BeWoLauncher.Logic.Utils.Download DownloadFolder.ClearFolder(); ApplyFolder.Unlock(SkipLock); + + if (UpdatePlanResponse.IsUninstall) + { + ApplyFolder.DeleteFolder(); + DownloadFolder.ClearFolder(); + } } private void CreateUpdatePlanRequest() @@ -220,5 +233,10 @@ namespace BeWoLauncher.Logic.Utils.Download // UpdatePlanResponse.FilesToApply.AddRange(UpdatePlanResponse.FilesToRequest); } + + public void CheckForConnection() + { + LauncherServiceFacade.DoDownloadBeWoServiceSyncWithException(x => x.DownloadInfo(null)); + } } } diff --git a/BeWoLauncher/Logic/ViewBuilder.cs b/BeWoLauncher/Logic/ViewBuilder.cs index c9e176c2e..c00427749 100644 --- a/BeWoLauncher/Logic/ViewBuilder.cs +++ b/BeWoLauncher/Logic/ViewBuilder.cs @@ -122,7 +122,7 @@ namespace BeWoLauncher.Logic private FrameBase getUninstallProgressFrame() { - var progress = new ProgressFrame(LauncherMode.Update); + var progress = new ProgressFrame(LauncherMode.Uninstall); progress.Successful += ViewBehavior.UninstallSuccess; progress.Exception += ViewBehavior.UninstallFailed; @@ -151,7 +151,7 @@ namespace BeWoLauncher.Logic return updateError; } - + private FrameBase getUpdateProgressFrame() { var progress = new ProgressFrame(LauncherMode.Update); diff --git a/Service/ServiceImplementations/DownloadBeWoServiceImp.cs b/Service/ServiceImplementations/DownloadBeWoServiceImp.cs index 61dcb7fc0..4811e570f 100644 --- a/Service/ServiceImplementations/DownloadBeWoServiceImp.cs +++ b/Service/ServiceImplementations/DownloadBeWoServiceImp.cs @@ -66,7 +66,11 @@ namespace BeWo.Service.ServiceImplementations { var exception = UpdateRequestValidator.Validate(request, Tenant); if (exception is object) + { + UpdateServerSessionManager.CloseSession(request.UpdateSessionId); + throw new InvalidUpdateFileRequestException(exception); + } UpdateServerSessionManager.LoadAbsolutePath(request); diff --git a/Service/ServiceUtils/Update/UpdateRequestValidator.cs b/Service/ServiceUtils/Update/UpdateRequestValidator.cs index 3b6713ff0..46dfb27aa 100644 --- a/Service/ServiceUtils/Update/UpdateRequestValidator.cs +++ b/Service/ServiceUtils/Update/UpdateRequestValidator.cs @@ -46,7 +46,7 @@ namespace BeWo.Service.ServiceUtils.Update if (session.Tenant != tenant) return "Tenant konnte nicht bestätigt werden."; - if (session.FileLimiterDict.ContainsKey( + if (!session.FileLimiterDict.ContainsKey( request.UpdateFile.RelativePath)) return $"Angefragte Datei nicht verfügbar. Anfrage an \"{request.UpdateFile.RelativePath}\""; diff --git a/Service/ServiceUtils/Update/UpdateServerSessionManager.cs b/Service/ServiceUtils/Update/UpdateServerSessionManager.cs index 580e80991..9dfb2006b 100644 --- a/Service/ServiceUtils/Update/UpdateServerSessionManager.cs +++ b/Service/ServiceUtils/Update/UpdateServerSessionManager.cs @@ -61,6 +61,8 @@ namespace BeWo.Service.ServiceUtils.Update }; _UpdateServerSessions.Add(session_id, session); + + res.Session_Id = session_id; } finally { @@ -111,16 +113,18 @@ namespace BeWo.Service.ServiceUtils.Update { Monitor.Enter(_Lock); + var file_id = request.UpdateFile.RelativePath; + var session_id = request.UpdateSessionId; var session = _UpdateServerSessions[session_id]; - var limiter = session.FileLimiterDict[request.UpdateFile.RelativePath]; + var limiter = session.FileLimiterDict[file_id]; request.UpdateFile.AbsolutePath = limiter.UpdateFile.AbsolutePath; limiter.RequestsLeft--; if (!limiter.CanRequestMore) - _UpdateServerSessions.Remove(session_id); + session.FileLimiterDict.Remove(file_id); if (!session.FileLimiterDict.Any()) CloseSession(session_id); diff --git a/SharedLauncher/DataContract/UpdateFileRequest.cs b/SharedLauncher/DataContract/UpdateFileRequest.cs index 17c227512..89bbee071 100644 --- a/SharedLauncher/DataContract/UpdateFileRequest.cs +++ b/SharedLauncher/DataContract/UpdateFileRequest.cs @@ -18,11 +18,17 @@ namespace BS.SharedLauncher.DataContract } - public UpdateFileRequest(string version) : base() + public UpdateFileRequest(string version, string session_id) : base() { Version = version; + UpdateSessionId = session_id; } + public UpdateFileRequest(UpdatePlanResponse response) : this(response.CurrentPackage.Version, response.Session_Id) + { + + } + [DataMember] public string Version { get; set; } diff --git a/SharedLauncher/DataContract/UpdatePlanResponse.cs b/SharedLauncher/DataContract/UpdatePlanResponse.cs index 0273dfe4c..58593058b 100644 --- a/SharedLauncher/DataContract/UpdatePlanResponse.cs +++ b/SharedLauncher/DataContract/UpdatePlanResponse.cs @@ -17,6 +17,9 @@ namespace BS.SharedLauncher.DataContract } + [DataMember] + public string Session_Id { get; set; } + [DataMember] public UpdatePlanDC CurrentPackage { get; set; } @@ -31,5 +34,6 @@ namespace BS.SharedLauncher.DataContract [DataMember] public long DownloadSize { get; set; } + public bool IsUninstall { get; set; } } } diff --git a/SharedLauncher/Exceptions/DownloadFileFailedException.cs b/SharedLauncher/Exceptions/DownloadFileFailedException.cs new file mode 100644 index 000000000..a265468c1 --- /dev/null +++ b/SharedLauncher/Exceptions/DownloadFileFailedException.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BS.SharedLauncher.Exceptions +{ + public class DownloadFileFailedException : UpdateException + { + public DownloadFileFailedException() + { + } + + public DownloadFileFailedException(string message) : base(message) + { + } + + public DownloadFileFailedException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/SharedLauncher/Extensions/PathExtensions.cs b/SharedLauncher/Extensions/PathExtensions.cs index 43951636b..f60ec7694 100644 --- a/SharedLauncher/Extensions/PathExtensions.cs +++ b/SharedLauncher/Extensions/PathExtensions.cs @@ -19,6 +19,10 @@ namespace BS.SharedLauncher.Extensions { Directory.CreateDirectory(path); } + public static void DeleteFolder(this string path) + { + Directory.Delete(path); + } public static bool Exists(this string path) { try diff --git a/SharedLauncher/SharedLauncher.csproj b/SharedLauncher/SharedLauncher.csproj index 0f93921e5..6656a122f 100644 --- a/SharedLauncher/SharedLauncher.csproj +++ b/SharedLauncher/SharedLauncher.csproj @@ -56,6 +56,7 @@ +