public static bool CheckIsUpdateAvailable(out string _UpdateTextData) { _UpdateTextData = ""; if (System.IO.File.Exists("wyUpdate.exe") == false) { return(false); } AssertVersionWycFile(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "wyUpdate.exe"; startInfo.Arguments = "/quickcheck /justcheck /noerr /outputinfo"; startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; var wyUpdateProcess = Process.Start(startInfo); string data = ""; while (wyUpdateProcess.HasExited == false) { Utility.SoftThreadSleep(100); data += wyUpdateProcess.StandardOutput.ReadToEnd(); } data += wyUpdateProcess.StandardOutput.ReadToEnd(); int exitCode = wyUpdateProcess.ExitCode; data = data.Replace(":\n\n", "\n"); _UpdateTextData = data; if (exitCode == 2) { return(true); } //Return value 0 == no update //Return value 1 == Error //Return value 2 == Update return(false); }
private static void _LaunchWow(string _Config, string _RealmName, ProcessStartInfo _WowProcessStartInfo) { if (System.IO.File.Exists("VF_WowLauncherTools\\NotAdmin.exe") == false) { VF_Utility.AssertDirectory("VF_WowLauncherTools"); System.IO.File.WriteAllBytes("VF_WowLauncherTools\\NotAdmin.exe", Properties.Resources.NotAdmin); } Logger.LogText("Started Launching"); WowVersionEnum wowVersion = WowVersionEnum.Vanilla; string realmListFile = ""; if (Settings.Instance.RealmLists.ContainsKey(_RealmName) == true) { var realmList = Settings.Instance.RealmLists[_RealmName]; realmListFile = realmList.GetRealmListWTF(); wowVersion = realmList.WowVersion; } else { Logger.LogText("Unexpected Error: No such Realm exists!"); return; } if (_Config != "Active Wow Config") { ConfigWTF config = ConfigProfiles.GetProfileConfigFile(_Config); config.SaveWTFConfigFile(wowVersion); Settings.Instance.AddLaunchShortcut(_Config, _RealmName); } DateTime startCheck = DateTime.UtcNow; if (System.IO.File.Exists(Settings.GetWowDirectory(wowVersion) + "realmlist.wtf") == false || System.IO.File.ReadAllText(Settings.GetWowDirectory(wowVersion) + "realmlist.wtf") != realmListFile) { System.IO.File.WriteAllText(Settings.GetWowDirectory(wowVersion) + "realmlist.wtf", realmListFile); if (System.IO.File.Exists(Settings.GetWowDirectory(wowVersion) + "realmlist.wtf") == false) { Logger.LogText("Unexpected Error: There is no realmlist.wtf!"); return; } Logger.LogText("Waiting for realmlist.wtf to get saved correctly"); startCheck = DateTime.UtcNow; while ((startCheck - System.IO.File.GetLastWriteTimeUtc(Settings.GetWowDirectory(wowVersion) + "realmlist.wtf")).Seconds > 10) { Logger.LogText(".", false); System.Threading.Thread.Sleep(20); if ((DateTime.UtcNow - startCheck).Seconds > 10) { Logger.LogText("Unexpected Error: Took too long trying to create the new realmlist.wtf!"); return; } } } Logger.LogText("realmlist.wtf is saved, Launching World of Warcraft!"); Process[] processesBeforeStart = Process.GetProcessesByName("Wow"); var wowProcess = Process.Start(_WowProcessStartInfo); if (_WowProcessStartInfo.FileName.ToLower().EndsWith("wow.exe") == false) { wowProcess = null; while (wowProcess == null && (DateTime.UtcNow - startCheck).TotalSeconds < 30) { Utility.SoftThreadSleep(500); Process[] currentProcesses = Process.GetProcessesByName("Wow"); foreach (var currProcess in currentProcesses) { if (processesBeforeStart.Length == 0 || processesBeforeStart.FirstOrDefault((_Value) => _Value.Id == currProcess.Id) == null) { //Logger.LogText("found new Wow.exe Process!"); wowProcess = currProcess; break; } } } } if (wowProcess == null) { Utility.MessageBoxShow("There was an error, WoW could not be launched"); return; } startCheck = DateTime.UtcNow; try { while (wowProcess.WaitForInputIdle(50) == false && (DateTime.UtcNow - startCheck).TotalSeconds < 20) { System.Windows.Forms.Application.DoEvents(); } } catch (Exception ex) { Logger.LogException(ex); } //wait 1 extra second Utility.SoftThreadSleep(1000); Logger.LogText("Done Launching"); }
bool ValidateUserID(string _UserID) { if (_UserID.Contains("Unknown.123456") || _UserID == "") { Utility.MessageBoxShow("You must fill in the correct UserID"); return(false); } if (RealmPlayersUploader.IsValidUserID(c_txtUserID.Text) == false) { Utility.MessageBoxShow("UserID is not valid format, must be <name(a-z)>.<number> example of valid UserID: Unknown.123456"); return(false); } if (char.IsUpper(c_txtUserID.Text[0]) == false || c_txtUserID.Text.Last((char _Char) => char.IsUpper(_Char)) == c_txtUserID.Text[0]) { Utility.MessageBoxShow("UserID have to start with capital letter and not contain any other capital letters in the UserName section!"); return(false); } Socket tcpSocket = null; try { DateTime startConnectionTime = DateTime.Now; tcpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); var ipAddress = System.Net.Dns.GetHostEntry(ServerComm.g_Host).AddressList[0]; IAsyncResult ar = tcpSocket.BeginConnect(ipAddress, 18374, null, null); System.Threading.WaitHandle waitHandle = ar.AsyncWaitHandle; try { for (int t = 0; t < 5; ++t) { if (waitHandle.WaitOne(TimeSpan.FromSeconds(1), false)) { break; } Application.DoEvents(); //Console.Write("."); } Console.Write("\r\n"); if (!waitHandle.WaitOne(TimeSpan.FromSeconds(1), false)) { tcpSocket.Close(); Utility.SoftThreadSleep(1000); waitHandle.Close(); Utility.MessageBoxShow("Could not validate UserID because connection to server failed, try again later."); return(false); } tcpSocket.EndConnect(ar); } finally { waitHandle.Close(); } tcpSocket.ReceiveTimeout = 5000; tcpSocket.SendTimeout = 5000; byte[] bytes = System.Text.Encoding.UTF8.GetBytes("NullNullNullNullNullNullNullNull"); byte[] header = System.Text.Encoding.UTF8.GetBytes("Command=UserCheck;UserID=" + _UserID + ";FileSize=" + bytes.Length + "%"); tcpSocket.Send(header); tcpSocket.Send(bytes); tcpSocket.Shutdown(SocketShutdown.Send); Byte[] readBuffer = new Byte[1024]; int i = 0; string data = ""; while ((i = tcpSocket.Receive(readBuffer, readBuffer.Length, SocketFlags.None)) != 0) { data += System.Text.Encoding.UTF8.GetString(readBuffer, 0, i); if ((DateTime.Now - startConnectionTime).TotalSeconds > 10) { throw new Exception("Transfer took longer than 10 seconds, should not be allowed, canceling"); } } bool wasSuccess = false; if (data.Contains(";") && data.Contains("=")) { string[] dataSplit = data.Split(';'); foreach (string currDataSplit in dataSplit) { if (currDataSplit.Contains("=")) { string[] currValue = currDataSplit.Split('='); if (currValue[0] == "VF_RPP_Success") { wasSuccess = ConvertBool(currValue[1]); } else if (currValue[0] == "Message") { Utility.MessageBoxShow(currValue[1]); } } } } if (wasSuccess == true) { Utility.MessageBoxShow("The UserID \"" + _UserID + "\" was valid and is now in use! The program will now start upload your inspected database automatically everytime you close wow(if started using the WowLauncher)."); return(true); } else { Utility.MessageBoxShow("The UserID \"" + _UserID + "\" is not valid. Please enter the correct UserID that was given to you."); } } catch (Exception ex) { Utility.MessageBoxShow("Could not validate UserID because of a connection error. Printscreen this message and PM to Dilatazu @ realmplayers forums or try again later.\r\nException:\r\n" + ex.ToString()); } return(false); }