Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. namespace Game_Launcher {
  2.     public partial class Form1 : Form {
  3.         // Variables
  4.         bool isPlaying = false;
  5.         string lastGameLaunched = null;
  6.        
  7.         public Form1() {
  8.             InitializeComponent();
  9.         }
  10.  
  11.         public void DetectProgramClose() {
  12.             if (lastGameLaunched == null) {
  13.                 isPlaying = false;
  14.             } else {
  15.                 var procs = Process.GetProcessesByName(lastGameLaunched);
  16.                 if (procs != null && procs.Length > 0) {
  17.                     var prog = procs[0];
  18.          
  19.                     if (prog.HasExited) {
  20.                         isPlaying = false;
  21.                         lastGameLaunched = false;
  22.                     }
  23.                 } else {
  24.                     isPlaying = false;
  25.                     lastGameLaunched = null;
  26.                 }
  27.             }
  28.         }
  29.  
  30.         // New Game
  31.         public void newGame(string fileLocation, TextBox textBoxNew) {
  32.             Process.Start(fileLocation);
  33.             isPlaying = true;
  34.             // Grab exe name from location string
  35.             lastGameLaunched = fileLocation.Substring(lastGameLaunched.LastIndexOf('\\')+1);
  36.  
  37.             if (isPlaying == true) {
  38.                 textBoxNew.Clear();
  39.                 textBoxNew.BackColor = System.Drawing.Color.Lime;
  40.                 textBoxNew.ForeColor = System.Drawing.Color.DarkGreen;
  41.                 textBoxNew.Text = "Now Playing";
  42.             }
  43.             if (isPlaying == false) {
  44.                 textBoxNew.Clear();
  45.                 textBoxNew.BackColor = System.Drawing.Color.White;
  46.                 textBoxNew.ForeColor = System.Drawing.Color.Black;
  47.                 textBoxNew.Text = "Not Playing";
  48.             }
  49.         }
  50.  
  51.         // Buttons
  52.         private void button1_Click(object sender, EventArgs e) {
  53.             newGame(@"C:\Program Files (x86)\StandingStoneGames\The Lord of the Rings Online\LotroLauncher.exe", textBox3);
  54.            
  55.         }
  56.  
  57.         private void button2_Click(object sender, EventArgs e) {
  58.             newGame(@"H:\Steam Library 2\steamapps\common\Warframe\Tools\Launcher.exe", textBox4);
  59.         }
  60.  
  61.         private void button3_Click(object sender, EventArgs e) {
  62.             newGame(@"C:\Users\Gavin\Desktop\Ravenfield\Ravenfield.exe", textBox5);
  63.         }
  64.  
  65.         private void button4_Click(object sender, EventArgs e) {
  66.             newGame(@"C:\Program Files (x86)\Steam\steamapps\common\Sekiro\sekiro.exe", textBox6);
  67.         }
  68.        
  69.         // Runs every time the timer ticks...
  70.         private void timer_Tick(object sender, EventArgs e) {
  71.             DetectProgramClose();
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement