102 lines
2.9 KiB
C#
102 lines
2.9 KiB
C#
using BeWoLauncher.Logic.Utils;
|
|
using BeWoLauncher.Logic.Utils.Download;
|
|
using BS.SharedLauncher.Extensions;
|
|
using BS.SharedLauncher.Information;
|
|
using BS.SharedLauncher.Utils;
|
|
using System;
|
|
using System.IO;
|
|
using System.Windows;
|
|
|
|
namespace BeWoLauncher.Logic.Controller
|
|
{
|
|
public static class DownloadController
|
|
{
|
|
public static DownloadManager Manager { get; set; }
|
|
|
|
public static long FreeSpace { get; set; }
|
|
public static long NeededSpace => Manager.UpdatePlanResponse.DownloadSize;
|
|
|
|
static DownloadController()
|
|
{
|
|
|
|
}
|
|
|
|
public static void InitLogger()
|
|
{
|
|
GenericTextLogger.Init(LauncherPaths.GetLoggerPath());
|
|
}
|
|
|
|
public static void GetCurrentUpdateplan(Action endWaiting = null)
|
|
{
|
|
bool not_called = true;
|
|
|
|
try
|
|
{
|
|
Manager = new DownloadManager();
|
|
|
|
if (LauncherAppdataConfig.GetFirstInstallationSuccess())
|
|
InitLogger();
|
|
|
|
GenericTextLogger.PostImportantInfo("Starting Download Process");
|
|
|
|
Manager.GetUpdatePlan();
|
|
|
|
not_called = false;
|
|
endWaiting?.Invoke();
|
|
|
|
var response = Manager.UpdatePlanResponse;
|
|
|
|
if (response.Successful)
|
|
{
|
|
var client_version = response.CurrentPackage.Version;
|
|
|
|
GenericTextLogger.Post($"Anfrage wurde erfolgreich verarbeitet. Server gibt Version {client_version} vor.");
|
|
|
|
SessionInformation.Session.Version = client_version;
|
|
|
|
if (response.HasToDo())
|
|
{
|
|
GenericTextLogger.Post("Launcher hat etwas zu tun.");
|
|
|
|
ViewController.ViewBehavior.ShowInfo();
|
|
}
|
|
else
|
|
{
|
|
GenericTextLogger.Post("Launcher ist aktuell.");
|
|
|
|
ViewController.ViewBehavior.ShowLoading();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GenericTextLogger.Post($"Server gibt Fehler zurück. Fehler: {response.Error}");
|
|
|
|
ViewController.ShowError(response.Error);
|
|
}
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
if(not_called)
|
|
endWaiting?.Invoke();
|
|
|
|
GenericTextLogger.PostException(e);
|
|
|
|
ViewController.ShowError(e);
|
|
}
|
|
}
|
|
|
|
public static string UpdateDiskSpace(string path)
|
|
{
|
|
FileInfo f = new FileInfo(path);
|
|
|
|
string drive = System.IO.Path.GetPathRoot(f.FullName);
|
|
FreeSpace = NonspecificTools.GetTotalFreeSpace(drive);
|
|
|
|
if (FreeSpace >= 0)
|
|
return NonspecificTools.SizeSuffix((ulong)FreeSpace);
|
|
else
|
|
return "error";
|
|
}
|
|
}
|
|
}
|