Guest User

Untitled

a guest
Jan 22nd, 2015
2,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.20 KB | None | 0 0
  1. Imports System
  2. Imports System.IO
  3. Imports System.Diagnostics
  4. Imports System.Threading
  5.  
  6. Public Class Form1 ' My class
  7.  
  8.     Private _Lines As String() ' Creates an array for my lines
  9.     Dim fifa15configfile As StreamWriter ' Declare the variable for writing to the config file
  10.  
  11.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' Upon loading my form do...
  12.         If My.Computer.FileSystem.FileExists(".\config.txt") Then ' Check for file existing
  13.             _Lines = File.ReadAllLines(".\config.txt") ' If it exists, put the text in _Lines variable
  14.             TextBox1.Text = _Lines(0) ' Text box displays the 1st line inside ".\config.txt"
  15.         Else ' If it doesn't exist
  16.             fifa15configfile = My.Computer.FileSystem.OpenTextFileWriter(".\config.txt", True) ' create this text file
  17.             fifa15configfile.WriteLine("") ' Write an empty line
  18.             fifa15configfile.Close() ' Close the file
  19.         End If
  20.  
  21.         If My.Computer.FileSystem.FileExists("C:\Program Files (x86)\Origin\Origin Games\FIFA 15\fifa15.exe") Then ' If this file exists then...
  22.             TextBox1.Text = "C:\Program Files (x86)\Origin\Origin Games\FIFA 15\fifa15.exe" ' Set the textbox to this path
  23.         Else ' Otherwise do nothing
  24.         End If
  25.  
  26.         Dim lines() As String = System.IO.File.ReadAllLines(".\config.txt") ' Read this config file into the array
  27.         If lines(0).Contains(".exe") Then ' If array(0) contains .exe then...
  28.             Button1.PerformClick() ' Simulate the Go button being pressed
  29.         End If
  30.  
  31.     End Sub
  32.  
  33.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ' When go is clicked
  34.  
  35.         Dim fifa15 As New ProcessStartInfo
  36.         Dim fifa15config As FileInfo
  37.  
  38.         If TextBox1.Text = "" Then ' If the textbox is empty...
  39.             MsgBox("Please select the fifa15.exe", MsgBoxStyle.Critical, "Error") ' Display this message
  40.  
  41.         Else ' If it's not
  42.             fifa15config = My.Computer.FileSystem.GetFileInfo(TextBox1.Text)    ' Get full path of .exe file
  43.             Dim fifa15configpath As String = fifa15config.DirectoryName ' Get the directory of the .exe without including the /XXXX.exe part
  44.             fifa15.WorkingDirectory = fifa15configpath ' Set the working directory to the path of the .exe
  45.             fifa15.FileName = TextBox1.Text ' Set the process to be started to match that of what is in the textbox
  46.             Process.Start(fifa15) ' Start the fifa15.exe process
  47.  
  48.             Dim lines() As String = System.IO.File.ReadAllLines(".\config.txt") ' Read every line in config.txt
  49.             lines(0) = TextBox1.Text ' Line 0 is set to whatever is inside Textbox1.text
  50.             File.WriteAllLines(".\config.txt", lines) ' Write every line inside the lines array into the config.txt
  51.  
  52.         End If
  53.  
  54.     End Sub
  55.  
  56.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  57.         Me.Close() ' Close the program
  58.     End Sub
  59.  
  60.     Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  61.  
  62.         Dim openFile As New OpenFileDialog
  63.  
  64.         If My.Computer.FileSystem.FileExists("C:\Program Files (x86)\Origin\Origin Games\FIFA 15\fifa15.exe") Then ' If this file exists then...
  65.             openFile.InitialDirectory = "C:\Program Files (x86)\Origin\Origin Games\FIFA 15" ' Set the initial window when you click Browse to this location
  66.         Else ' Or
  67.             openFile.InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" ' Set it to My Computer/This PC, this is the GUID
  68.             TextBox1.Text = ""
  69.         End If
  70.  
  71.         openFile.FileName = "" ' Sets the Browse textbox as blank
  72.         openFile.Multiselect = False ' Disables selecting multiple files
  73.         openFile.Filter = "FIFA 15 (fifa15.exe)|fifa15.exe" ' Display the first part in the drop down | only allow the selection and viewing of fifa15.exe
  74.  
  75.         If openFile.ShowDialog = DialogResult.OK Then ' If the file is opened successfully
  76.             Dim fileName As String = openFile.SafeFileName ' Set this variable as the file path that has just been opened
  77.             TextBox1.Text = openFile.FileName ' Sets the text box as the file path
  78.         End If
  79.  
  80.     End Sub
  81.  
  82.     Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  83.         MsgBox("Made by ellessess," & vbNewLine & "http://steamcommunity.com/id/infused_essy/" & vbNewLine & vbNewLine & "For Jakey!", MsgBoxStyle.OkOnly, "About") ' Parameters for the About window
  84.  
  85.     End Sub
  86.  
  87.     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  88.  
  89.         Dim CheckFIFAConfigProcess = Process.GetProcessesByName("fifaconfig") ' Search for fifaconfig.exe
  90.  
  91.         If CheckFIFAConfigProcess.Count > 0 Then ' If the process is found
  92.             AppActivate("FIFA 15") ' Activate the fifaconfig window
  93.             SendKeys.Send("{ENTER}") ' Simulate an enter key press
  94.             CheckFIFAConfigProcess(0).CloseMainWindow() ' Close the process window after enter has been sent
  95.             Thread.Sleep(5000) ' Wait for five seconds
  96.             End ' End my program, it's not needed anymore as it has fufilled function
  97.         End If
  98.     End Sub
  99. End Class
Advertisement
Add Comment
Please, Sign In to add comment