Files
BeWoPlaner/BeWoLauncher/Logic/Controller/ViewController.cs
2022-12-02 13:00:27 +01:00

90 lines
2.4 KiB
C#

using BeWoLauncher.Logic.Behavior;
using BeWoLauncher.Logic.Utils;
using BeWoLauncher.View;
using BeWoLauncher.View.Frames;
using BS.SharedLauncher.Logic;
using System;
using System.Configuration;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Threading;
namespace BeWoLauncher.Logic.Controller
{
public enum ViewType
{
LoginView,
FrameView
}
public enum FrameType
{
InstallInfo,
InstallProgress,
InstallFailed,
UpdateInfo,
UpdateProgress,
UpdateFailed,
UninstallInfo,
UninstallProgress,
UninstallFailed,
UninstallSuccessful,
LoadingScreen,
NoPermissionInfo
}
public static class ViewController
{
public static Exception Error{ get; set; }
public static LauncherWindow CurrentWindow { get; private set; }
public static Dispatcher Dispatcher => CurrentWindow.Dispatcher;
public static ViewSwitchBehavior ViewBehavior { get; set; }
public static LaunchBehavior LaunchBehavior { get; set; }
public static ViewBuilder ViewBuilder { get; set; }
static ViewController()
{
LaunchBehavior = new LaunchBehavior();
ViewBehavior = new ViewSwitchBehavior();
ViewBuilder = new ViewBuilder();
}
public static void InitWindow(LauncherWindow window)
{
if (CurrentWindow is null)
CurrentWindow = window;
}
public static void StartView()
{
ViewBehavior.ShowView(ViewType.LoginView);
}
public static void RestartView()
{
ViewBehavior.ShowView(ViewType.LoginView);
CurrentWindow.Show();
CurrentWindow.Activate();
}
public static void StartWaiting() => CurrentWindow.StartWaiting();
public static void EndWaiting() => CurrentWindow.EndWaiting();
public static bool CheckForPermissions(string path)
{
return FileController.IsDirectoryWritable(path, false);
}
public static void CheckForAutoLogin(object sender, EventArgs e)
{
var autologin = bool.TryParse(ConfigurationManager.AppSettings.Get("AutoLogin"), out bool c) && c;
if (autologin)
if (sender is LoginView loginPage)
loginPage.ClickLogin();
}
}
}