using System; using System.IO; using System.Windows; using System.Threading; using System.Diagnostics; using System.Windows.Media; using System.Windows.Input; using System.ComponentModel; using System.Windows.Controls; using System.Windows.Resources; using System.Windows.Navigation; using System.Collections.Generic; using System.Windows.Media.Imaging; using Launcher_Client.Networking; using Launcher_Client.Utilitys; using Launcher_Client.Utilitys.Types; namespace Launcher_Client { public partial class MainWindow : Window { private Client Login; private BackgroundWorker PatchWorker = new BackgroundWorker(); private FileSystem VersionSystem = new FileSystem(); public MainWindow() { InitializeComponent(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Title = String.Format("{0} Launcher", Properties.Settings.Default.ServerName); } private void Window_MouseDown(Object Sender, MouseButtonEventArgs Args) { if (Args.Source == this) { DragMove(); } } private void CurrentDomain_UnhandledException(Object Sender, UnhandledExceptionEventArgs Args) { Exception Error = (Exception)Args.ExceptionObject; File.WriteAllText(String.Concat(Environment.CurrentDirectory, "/Broken.txt"), Error.ToString()); } private void Grid_Initialized(Object Sender, EventArgs Args) { LauncherUpdate(); if (Web.LoadVote()) { DateTime LastVote = DateTime.Now; if (File.Exists(String.Format("{0}{1}{2}", Utility.LocalPath, Properties.Settings.Default.LauncherFolder, Properties.Settings.Default.VoteFile))) { try { using (StreamReader Reader = new StreamReader(String.Format("{0}{1}{2}", Utility.LocalPath, Properties.Settings.Default.LauncherFolder, Properties.Settings.Default.VoteFile))) { LastVote = DateTime.Parse(Reader.ReadLine()); } } catch { using (StreamWriter Writer = new StreamWriter(String.Format("{0}{1}{2}", Utility.LocalPath, Properties.Settings.Default.LauncherFolder, Properties.Settings.Default.VoteFile))) { Writer.WriteLine(DateTime.Now.AddHours(12)); } } } else { using (StreamWriter Writer = new StreamWriter(String.Format("{0}{1}{2}", Utility.LocalPath, Properties.Settings.Default.LauncherFolder, Properties.Settings.Default.VoteFile))) { Writer.WriteLine(DateTime.Now.AddHours(12)); } } if (LastVote <= DateTime.Now) { Hide(); Vote VWindow = new Vote(); VWindow.ShowDialog(); Show(); using (StreamWriter Writer = new StreamWriter(String.Format("{0}{1}{2}", Utility.LocalPath, Properties.Settings.Default.LauncherFolder, Properties.Settings.Default.VoteFile))) { Writer.WriteLine(DateTime.Now.AddHours(12)); } } } if (File.Exists(String.Format("{0}{1}{2}", Utility.LocalPath, Properties.Settings.Default.LauncherFolder, Properties.Settings.Default.UsernameFile))) { Username.Text = File.ReadAllText(String.Format("{0}{1}{2}", Utility.LocalPath, Properties.Settings.Default.LauncherFolder, Properties.Settings.Default.UsernameFile)); } Login = new Client(); Login.Completed += Login_Completed; Show(); SetupPatchWorker(); } private void Login_Completed(String ServerMessage) { if (!ServerMessage.StartsWith("Login#All Good!") && !ServerMessage.Contains("Register#")) { Dispatcher.BeginInvoke((Action)(() => { Play.IsEnabled = true; })); Dispatcher.BeginInvoke((Action)(() => { Username.IsEnabled = true; })); Dispatcher.BeginInvoke((Action)(() => { Password.IsEnabled = true; })); MessageBox.Show(ServerMessage.Replace("Login#", "")); } else { Utility.StartSecurity(ServerMessage.Split('#')[2]); Dispatcher.BeginInvoke((Action)(() => { Hide(); })); } } private void LauncherUpdate() { if (File.Exists(String.Format("{0}{1}{2}", Utility.LocalPath, Properties.Settings.Default.LauncherFolder, Properties.Settings.Default.UpdateFile))) { String StartupInformation = "1"; ProcessStartInfo StartInfo = new ProcessStartInfo(Properties.Settings.Default.UpdateExe, StartupInformation); StartInfo.UseShellExecute = false; Process StartUpdate = new Process(); StartUpdate.StartInfo = StartInfo; StartUpdate.Start(); Utility.Shutdown(); } } private void SetupPatchWorker() { PatchWorker.DoWork += PatchWorker_DoWork; PatchWorker.RunWorkerCompleted += PatchWorker_RunWorkerCompleted; PatchWorker.RunWorkerAsync(); } private void PatchWorker_DoWork(Object Sender, DoWorkEventArgs Args) { Dictionary Patchlist = Web.LoadPatches(); while (Patchlist.Count > VersionSystem.ReadVersion()) { Patch CurrentPatch = Patchlist[VersionSystem.ReadVersion() + 1]; Download DownloadPatch = new Download(); DownloadPatch.FileName = CurrentPatch.FileName; DownloadPatch.SavePath = CurrentPatch.SavePath; DownloadPatch.Address = CurrentPatch.Address; DownloadPatch.Information = Information; DownloadPatch.Progress = Progress; DownloadPatch.StartDownload(); while (!DownloadPatch.IsFinished) { Thread.Sleep(1000); } Extract ExtractPatch = new Extract(); ExtractPatch.FileName = CurrentPatch.FileName; ExtractPatch.FilePath = CurrentPatch.SavePath; ExtractPatch.Information = Information; ExtractPatch.Progress = Progress; ExtractPatch.StartExtract(); while (!ExtractPatch.IsFinished) { Thread.Sleep(1000); } VersionSystem.WriteVersion(CurrentPatch.Version); } LauncherUpdate(); } private void PatchWorker_RunWorkerCompleted(Object Sender, RunWorkerCompletedEventArgs Args) { Dispatcher.BeginInvoke((Action)(() => { Play.IsEnabled = true; })); Dispatcher.BeginInvoke((Action)(() => { Username.IsEnabled = true; })); Dispatcher.BeginInvoke((Action)(() => { Password.IsEnabled = true; })); Dispatcher.BeginInvoke((Action)(() => { Information.Content = "Client Up To Date!"; })); Dispatcher.BeginInvoke((Action)(() => { Progress.Value = 100; })); } private ImageBrush ResourceBrush(String RName) { Uri RUri = new Uri(String.Format("Resources/{0}.png", RName), UriKind.Relative); StreamResourceInfo RInfo = Application.GetResourceStream(RUri); BitmapFrame RFrame = BitmapFrame.Create(RInfo.Stream); ImageBrush RBrush = new ImageBrush(); RBrush.ImageSource = RFrame; return RBrush; } private void Repatch_MouseLeftButtonUp(Object Sender, MouseButtonEventArgs Args) { VersionSystem.WriteVersion(0); Process.Start("Lumia Launcher.exe"); Utility.Shutdown(); } private void Donate_MouseLeftButtonUp(Object Sender, MouseButtonEventArgs Args) { Process.Start("http://store.exillionstudio.com/"); } private void Forums_MouseLeftButtonUp(Object Sender, MouseButtonEventArgs Args) { Process.Start("http://community.exillionstudio.com"); } private void Play_MouseLeftButtonUp(Object Sender, MouseButtonEventArgs Args) { if (Username.Text == "") { Utility.Information("Please Enter A Username!"); } else if (Password.Password == "") { Utility.Information("Please Enter A Password!"); } else { Dispatcher.BeginInvoke((Action)(() => { Play.IsEnabled = false; })); Dispatcher.BeginInvoke((Action)(() => { Username.IsEnabled = false; })); Dispatcher.BeginInvoke((Action)(() => { Password.IsEnabled = false; })); Login.SendLogin(Username.Text, Password.Password); } } private void Hompage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { //Open Homepage } private void Vote_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { //Open Vote } private void UserCP_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { //Open UserCP } private void Register_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { Process.Start("http://registerpvp.playfyre.net/"); } } }