Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Game_Launcher {
- public partial class Form1 : Form {
- // Variables
- bool isPlaying = false;
- string lastGameLaunched = null;
- public Form1() {
- InitializeComponent();
- }
- public void DetectProgramClose() {
- if (lastGameLaunched == null) {
- isPlaying = false;
- } else {
- var procs = Process.GetProcessesByName(lastGameLaunched);
- if (procs != null && procs.Length > 0) {
- var prog = procs[0];
- if (prog.HasExited) {
- isPlaying = false;
- lastGameLaunched = false;
- }
- } else {
- isPlaying = false;
- lastGameLaunched = null;
- }
- }
- }
- // New Game
- public void newGame(string fileLocation, TextBox textBoxNew) {
- Process.Start(fileLocation);
- isPlaying = true;
- // Grab exe name from location string
- lastGameLaunched = fileLocation.Substring(lastGameLaunched.LastIndexOf('\\')+1);
- if (isPlaying == true) {
- textBoxNew.Clear();
- textBoxNew.BackColor = System.Drawing.Color.Lime;
- textBoxNew.ForeColor = System.Drawing.Color.DarkGreen;
- textBoxNew.Text = "Now Playing";
- }
- if (isPlaying == false) {
- textBoxNew.Clear();
- textBoxNew.BackColor = System.Drawing.Color.White;
- textBoxNew.ForeColor = System.Drawing.Color.Black;
- textBoxNew.Text = "Not Playing";
- }
- }
- // Buttons
- private void button1_Click(object sender, EventArgs e) {
- newGame(@"C:\Program Files (x86)\StandingStoneGames\The Lord of the Rings Online\LotroLauncher.exe", textBox3);
- }
- private void button2_Click(object sender, EventArgs e) {
- newGame(@"H:\Steam Library 2\steamapps\common\Warframe\Tools\Launcher.exe", textBox4);
- }
- private void button3_Click(object sender, EventArgs e) {
- newGame(@"C:\Users\Gavin\Desktop\Ravenfield\Ravenfield.exe", textBox5);
- }
- private void button4_Click(object sender, EventArgs e) {
- newGame(@"C:\Program Files (x86)\Steam\steamapps\common\Sekiro\sekiro.exe", textBox6);
- }
- // Runs every time the timer ticks...
- private void timer_Tick(object sender, EventArgs e) {
- DetectProgramClose();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement