Advertisement
htw

EQVersion - Joey's 1st Grade Test

htw
Apr 19th, 2019
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace EQVersion
  13. {
  14.     public partial class EQVersionForm : Form
  15.     {
  16.         public EQVersionForm()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void quitButton_Click(object sender, EventArgs e)
  22.         {
  23.             Application.Exit();
  24.         }
  25.  
  26.         private void EQVersionForm_Shown(object sender, EventArgs e)
  27.         {
  28.             exeLocationTextBox.Text = Path.Combine(Directory.GetCurrentDirectory(), "eqgame.exe");
  29.             if (!File.Exists(exeLocationTextBox.Text))
  30.             {
  31.                 SelectFile();
  32.             }
  33.             else
  34.             {
  35.                 ReadAndDisplayVersion();
  36.             }
  37.         }
  38.  
  39.         private void SelectFile()
  40.         {
  41.             this.Enabled = false;
  42.             exeOpenFileDialog.InitialDirectory = exeLocationTextBox.Text;
  43.             DialogResult drResult = exeOpenFileDialog.ShowDialog();
  44.             if (drResult != DialogResult.OK)
  45.                 Application.Exit();
  46.             exeLocationTextBox.Text = exeOpenFileDialog.FileName;
  47.             ReadAndDisplayVersion();
  48.             this.Enabled = true;
  49.         }
  50.  
  51.         private void exeLocationButton_Click(object sender, EventArgs e)
  52.         {
  53.             SelectFile();
  54.         }
  55.  
  56.         private void ReadAndDisplayVersion()
  57.         {
  58.             try
  59.             {
  60.                 FileStream fs = File.OpenRead(exeOpenFileDialog.FileName);
  61.                 byte[] buffer = new byte[fs.Length];
  62.                 int bytesRead = fs.Read(buffer, 0, buffer.Length);
  63.                 fs.Close();
  64.                 if (bytesRead > 0)
  65.                 {
  66.                     string tmpBuffer = ASCIIEncoding.ASCII.GetString(buffer);
  67.                     int startLoc = tmpBuffer.IndexOf("Client Version: %s %s") + 48;
  68.                     versionTextBox.Text = tmpBuffer.Substring(startLoc);
  69.                     startLoc += versionTextBox.TextLength + 1;
  70.                     versionTextBox.Text += " " + tmpBuffer.Substring(startLoc);
  71.                 }
  72.                 else
  73.                 {
  74.                     versionTextBox.Text = "Unknown";
  75.                 }
  76.             }
  77.             catch (Exception ex)
  78.             {
  79.                 versionTextBox.Text = ex.Message;
  80.             }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement