Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace EQVersion
- {
- public partial class EQVersionForm : Form
- {
- public EQVersionForm()
- {
- InitializeComponent();
- }
- private void quitButton_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void EQVersionForm_Shown(object sender, EventArgs e)
- {
- exeLocationTextBox.Text = Path.Combine(Directory.GetCurrentDirectory(), "eqgame.exe");
- if (!File.Exists(exeLocationTextBox.Text))
- {
- SelectFile();
- }
- else
- {
- ReadAndDisplayVersion();
- }
- }
- private void SelectFile()
- {
- this.Enabled = false;
- exeOpenFileDialog.InitialDirectory = exeLocationTextBox.Text;
- DialogResult drResult = exeOpenFileDialog.ShowDialog();
- if (drResult != DialogResult.OK)
- Application.Exit();
- exeLocationTextBox.Text = exeOpenFileDialog.FileName;
- ReadAndDisplayVersion();
- this.Enabled = true;
- }
- private void exeLocationButton_Click(object sender, EventArgs e)
- {
- SelectFile();
- }
- private void ReadAndDisplayVersion()
- {
- try
- {
- FileStream fs = File.OpenRead(exeOpenFileDialog.FileName);
- byte[] buffer = new byte[fs.Length];
- int bytesRead = fs.Read(buffer, 0, buffer.Length);
- fs.Close();
- if (bytesRead > 0)
- {
- string tmpBuffer = ASCIIEncoding.ASCII.GetString(buffer);
- int startLoc = tmpBuffer.IndexOf("Client Version: %s %s") + 48;
- versionTextBox.Text = tmpBuffer.Substring(startLoc);
- startLoc += versionTextBox.TextLength + 1;
- versionTextBox.Text += " " + tmpBuffer.Substring(startLoc);
- }
- else
- {
- versionTextBox.Text = "Unknown";
- }
- }
- catch (Exception ex)
- {
- versionTextBox.Text = ex.Message;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement