Files
BeWoPlaner/BeWoLauncher/Logic/Behavior/ViewSwitchBehavior.cs
rene 4fbfdbaf2c Unit Tests erstellt
Informationen ausgelagert
Kleines Spy/Test Programm erstellt
Mehr Exceptions/InvalidUpdateFileRequestException.cs
Launcher Host in Download Server geändert
Download Server macht zusätzlich Abfrage an den Hauptserver
Download geht jetzt stückweise von statten
2022-12-28 16:36:59 +01:00

169 lines
4.9 KiB
C#

using BeWoLauncher.Logic.Controller;
using BeWoLauncher.Logic.Utils;
using BeWoLauncher.View;
using BeWoLauncher.View.Frames;
using BS.SharedLauncher.Enums;
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Threading;
using static BeWoLauncher.Logic.Controller.ViewController;
namespace BeWoLauncher.Logic.Behavior
{
public class ViewSwitchBehavior
{
private UserControl _currentView;
private FrameBase _currentFrame;
private LauncherMode _currentLauncherMode;
private UserControl CurrentView
{
get => _currentView;
set
{
_currentView = value;
CurrentWindow.Dispatcher.BeginInvoke(DispatcherPriority.Render,
(Action)delegate
{
CurrentWindow.SetMainContent(value);
});
}
}
private FrameBase CurrentFrame
{
get => _currentFrame;
set
{
_currentFrame = value;
if (CurrentView is FrameView frameview)
CurrentWindow.Dispatcher.BeginInvoke(DispatcherPriority.Render,
(Action)delegate
{
frameview.SetFrame(value);
});
else
CurrentView = new FrameView(value);
}
}
public ViewSwitchBehavior()
{
}
public void ShowView(ViewType vt)
{
CurrentView = ViewController.ViewBuilder.GetNewView(vt);
}
public void ShowFrame(FrameType ft)
{
CurrentFrame = ViewController.ViewBuilder.GetNewFrame(ft);
}
public void ShowInfo()
{
ViewController.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
if (LauncherAppdataConfig.GetFirstInstallationSuccess() &&
File.Exists(LauncherPaths.GetPlanerExePath()))
{
ShowFrame(FrameType.UpdateInfo);
}
else
{
ShowFrame(FrameType.InstallInfo);
}
}));
}
public void ShowError(Exception exception)
{
ViewController.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
Error = exception;
ShowFrame(FrameType.GenericFail);
}));
}
public void ShowUninstallInfo()
{
ViewController.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
ShowFrame(FrameType.UninstallInfo);
}));
}
public void ShowLoading()
{
ViewController.Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
{
ShowFrame(FrameType.LoadingScreen);
}));
}
public void BackToLogin(object sender, EventArgs e)
{
ShowView(ViewType.LoginView);
}
public void LoginSuccessful(object sender, EventArgs e)
{
ViewController.LaunchBehavior.LoginSuccessful();
}
public void InstallInfoAccept(object sender, EventArgs e)
{
var install = sender as InstallInfoFrame;
if (CheckForPermissions(install.InstallLocation))
{
LauncherPaths.SetAndSaveInstallLocation(install.InstallLocation);
LauncherAppdataConfig.SetFirstInstallationSuccess(true);
ShowFrame(FrameType.InstallProgress);
}
else
{
ShowFrame(FrameType.NoPermissionInfo);
}
}
public void InstallSuccesss(object sender, EventArgs e)
{
LauncherAppdataConfig.SetFirstInstallationSuccess(true);
ShowFrame(FrameType.LoadingScreen);
}
public void InstallFailed(object sender, EventArgs e)
{
ShowFrame(FrameType.InstallFailed);
}
public void UpdateFailed(object sender, EventArgs e)
{
ShowFrame(FrameType.UpdateFailed);
}
public void UninstallFailed(object sender, EventArgs e)
{
ShowFrame(FrameType.UninstallFailed);
}
public void UpdateStarting(object sender, EventArgs e)
{
ShowFrame(FrameType.UpdateProgress);
}
public void UpdateSuccess(object sender, EventArgs e)
{
ShowFrame(FrameType.LoadingScreen);
}
public void UninstallStarting(object sender, EventArgs e)
{
ShowFrame(FrameType.UninstallProgress);
}
public void UninstallSuccess(object sender, EventArgs e)
{
ShowFrame(FrameType.UninstallSuccessful);
}
}
}