TslLauncher/TslGameLauncher/MainWindow.xaml.cs

70 lines
No EOL
2.1 KiB
C#

using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
namespace TslLauncher
{
public partial class MainWindow : Window
{
private const string TargetDirectory = @"TslGame\Binaries\Win64";
private const string TargetExecutable = "TslGame.exe";
private const string Arguments = "-LobbyUrl=https://lobby.ogbattlegrounds.com/ -NoVerifyGC -NoEAC -NoBattleEye";
private DispatcherTimer _timer;
private int _dotCount = 0;
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
InitializeStatusTextAnimation();
}
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
await Task.Delay(5000);
LaunchGame();
}
private void LaunchGame()
{
string targetPath = Path.Combine(Environment.CurrentDirectory, TargetDirectory, TargetExecutable);
if (File.Exists(targetPath))
{
ProcessStartInfo startInfo = new ProcessStartInfo(targetPath)
{
Arguments = Arguments,
UseShellExecute = false
};
Process.Start(startInfo);
Application.Current.Shutdown();
}
else
{
MessageBox.Show(this,"游戏文件不完整,请尝试重新下载!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
Application.Current.Shutdown();
}
}
private void InitializeStatusTextAnimation()
{
_timer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(500)
};
_timer.Tick += Timer_Tick;
_timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
_dotCount = (_dotCount + 1) % 5;
StatusText.Text = "游戏启动中" + new string('.', _dotCount);
}
}
}