diff --git a/OpenFK/Form1.cs b/OpenFK/Form1.cs index faf49f2..837c20a 100644 --- a/OpenFK/Form1.cs +++ b/OpenFK/Form1.cs @@ -1,5 +1,6 @@ using AxShockwaveFlashObjects; using DiscordRPC; +using Microsoft.Win32; using OpenFK.Properties; using System; using System.Collections.Generic; @@ -137,6 +138,11 @@ namespace OpenFK if (Settings.Default.USBSupport == true) { + var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", true); + if (key == null) + throw new InvalidOperationException(@"Cannot open registry key HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers."); + using (key) + key.SetValue(Directory.GetParent(Directory.GetCurrentDirectory()) + @"\MegaByte\" + "MegaByte.exe", "VISTASP2"); Process MBRun = new Process(); ProcessStartInfo MBData = new ProcessStartInfo(); MBData.FileName = Directory.GetParent(Directory.GetCurrentDirectory()) + @"\MegaByte\" + "MegaByte.exe"; @@ -469,8 +475,15 @@ namespace OpenFK } if(Settings.Default.USBSupport == true) { - Process process = Process.GetProcessesByName("MegaByte")[0]; - process.Kill(); + try + { + Process process = Process.GetProcessesByName("MegaByte")[0]; + process.Kill(); + } + catch + { + Application.Exit(); + } } Application.Exit(); //Closes OpenFK Debug.WriteLine("radicaclose called, goodbye!"); //Debug output diff --git a/OpenFK/OpenFK.csproj b/OpenFK/OpenFK.csproj index 9399c85..c9e2bdd 100644 --- a/OpenFK/OpenFK.csproj +++ b/OpenFK/OpenFK.csproj @@ -151,6 +151,7 @@ Settings.settings True + diff --git a/OpenFK/Program.cs b/OpenFK/Program.cs index d2c0fb5..4808352 100644 --- a/OpenFK/Program.cs +++ b/OpenFK/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Windows.Forms; @@ -22,8 +23,24 @@ namespace OpenFK } else if (File.Exists(Directory.GetCurrentDirectory() + @"\Flash.ocx")) { - Application.Run(new Form1()); - }else MessageBox.Show("Flash.ocx is not found!", "OpenFK", MessageBoxButtons.OK, MessageBoxIcon.Error); + try + { + Application.Run(new Form1()); + } + catch + { + MessageBox.Show("There was an error starting the game! This could happen because of a 64 bit OCX running on a 32 bit OpenFK.", "OpenFK", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + }else if (MessageBox.Show("Flash.ocx is not found! Do you want to fetch a compatible OCX?", "OpenFK", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes) + { + File.WriteAllText(Directory.GetCurrentDirectory() + @"\FetchOCX.bat", Properties.Resources.FetchOCX); + ProcessStartInfo fetchocx = new ProcessStartInfo(Directory.GetCurrentDirectory() + @"\FetchOCX.bat"); + fetchocx.UseShellExecute = false; + var ocxprocess = Process.Start(fetchocx); + ocxprocess.WaitForExit(); + File.Delete(Directory.GetCurrentDirectory() + @"\FetchOCX.bat"); + Application.Restart(); + } } } } diff --git a/OpenFK/Properties/Resources.Designer.cs b/OpenFK/Properties/Resources.Designer.cs index 676d0c1..c14842b 100644 --- a/OpenFK/Properties/Resources.Designer.cs +++ b/OpenFK/Properties/Resources.Designer.cs @@ -59,5 +59,26 @@ namespace OpenFK.Properties { resourceCulture = value; } } + + /// + /// Looks up a localized string similar to @echo off + ///echo Welcome to OpenFK OCX fetcher! + ///echo Written by GittyMac + ///echo ------------------------------ + ///echo Downloading data... + ///mkdir tempdl + ///cd tempdl + ///powershell -Command "Invoke-WebRequest http://download.windowsupdate.com/d/msdownload/update/software/secu/2015/09/windows10.0-kb3087040-x64_ad0f78efb7b122fa9472dbb8050c4f358aceab49.msu -OutFile update.msu" + ///echo Extracting MSU... + ///expand -f:* update.msu ./ + ///echo Extracting CAB... + ///expand Windows10.0-KB3087040-x64.cab -F:* ./ + ///echo Fetching OCX... [rest of string was truncated]";. + /// + internal static string FetchOCX { + get { + return ResourceManager.GetString("FetchOCX", resourceCulture); + } + } } } diff --git a/OpenFK/Properties/Resources.resx b/OpenFK/Properties/Resources.resx index af7dbeb..708c11b 100644 --- a/OpenFK/Properties/Resources.resx +++ b/OpenFK/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,13 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\FetchOCX.bat;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + \ No newline at end of file diff --git a/OpenFK/Resources/FetchOCX.bat b/OpenFK/Resources/FetchOCX.bat new file mode 100644 index 0000000..63df37a --- /dev/null +++ b/OpenFK/Resources/FetchOCX.bat @@ -0,0 +1,27 @@ +@echo off +echo Welcome to OpenFK OCX fetcher! +echo Written by GittyMac +echo ------------------------------ +echo Downloading data... +mkdir tempdl +cd tempdl +powershell -Command "Invoke-WebRequest http://download.windowsupdate.com/d/msdownload/update/software/secu/2015/09/windows10.0-kb3087040-x64_ad0f78efb7b122fa9472dbb8050c4f358aceab49.msu -OutFile update.msu" +echo Extracting MSU... +expand -f:* update.msu ./ +echo Extracting CAB... +expand Windows10.0-KB3087040-x64.cab -F:* ./ +echo Fetching OCX... +IF EXIST "%PROGRAMFILES(X86)%" (GOTO 64BIT) ELSE (GOTO 32BIT) + +:64BIT +copy "%cd%\amd64_adobe-flash-for-windows_31bf3856ad364e35_10.0.10240.16513_none_33a2f3db043a608d\flash.ocx" "..\Flash.ocx" +GOTO END + +:32BIT +copy "%cd%\wow64_adobe-flash-for-windows_31bf3856ad364e35_10.0.10240.16513_none_3df79e2d389b2288\flash.ocx" "..\Flash.ocx" +GOTO END + +:END +cd .. +rmdir /s /q tempdl +echo Your Flash.OCX is served!