Skip to content

Commit f5f8996

Browse files
kmcnaughtJuliusSweetland
authored andcommitted
Update Presage checks for 32/64 bit apps
Updates logic to be consistent with v4 64 bit builds and avoiding the implicit assumption of a 32 bit process
1 parent c599992 commit f5f8996

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

src/JuliusSweetland.OptiKey.Core/OptiKeyApp.cs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,42 +167,66 @@ protected static bool PresageInstallationProblemsDetected()
167167
//1.Check the install path to detect if the wrong bitness of Presage is installed
168168
string presagePath = null;
169169
string presageStartMenuFolder = null;
170-
string osBitness = DiagnosticInfo.OperatingSystemBitness;
171-
170+
string processBitness = DiagnosticInfo.ProcessBitness;
171+
172172
try
173173
{
174174
presagePath = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Presage", "", string.Empty).ToString();
175175
presageStartMenuFolder = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Presage", "Start Menu Folder", string.Empty).ToString();
176176
}
177177
catch (Exception ex)
178178
{
179+
Log.Error("Cannot find Presage entries in the registry, is it installed?");
179180
Log.ErrorFormat("Caught exception: {0}", ex);
180181
}
181182

182-
Log.InfoFormat("Presage path: {0} | Presage start menu folder: {1} | OS bitness: {2}", presagePath, presageStartMenuFolder, osBitness);
183+
Log.InfoFormat("Presage path: {0} | Presage start menu folder: {1} | process bitness: {2}", presagePath, presageStartMenuFolder, processBitness);
184+
185+
List<string> presageOptions = new List<string>();
186+
if (processBitness.Contains("64"))
187+
{
188+
presageOptions.Add("presage - 0.9.1 - 64bit");
189+
presageOptions.Add("presage-0.9.2~beta20150909-64bit");
190+
}
191+
else
192+
{
193+
presageOptions.Add("presage - 0.9.1 - 32bit");
194+
presageOptions.Add("presage-0.9.2~beta20150909-32bit");
195+
}
183196

184197
if (string.IsNullOrEmpty(presagePath)
185198
|| string.IsNullOrEmpty(presageStartMenuFolder))
186199
{
187200
Settings.Default.SuggestionMethod = SuggestionMethods.NGram;
188-
Log.Error("Invalid Presage installation detected (path(s) missing). Must install 'presage-0.9.1-32bit' or 'presage-0.9.2~beta20150909-32bit'. Changed SuggesionMethod to NGram.");
201+
string msg = "Invalid Presage installation detected (path(s) missing).\n";
202+
msg += $"Must install '{ String.Join("' or '", presageOptions.ToArray()) }'. Changed SuggestionMethod to NGram.";
203+
Log.Error(msg);
189204
return true;
190205
}
191206

192207
if (presageStartMenuFolder != "presage-0.9.2~beta20150909"
193208
&& presageStartMenuFolder != "presage-0.9.1")
194209
{
195210
Settings.Default.SuggestionMethod = SuggestionMethods.NGram;
196-
Log.Error("Invalid Presage installation detected (valid version not detected). Must install 'presage-0.9.1-32bit' or 'presage-0.9.2~beta20150909-32bit'. Changed SuggesionMethod to NGram.");
211+
string msg = "Invalid Presage installation detected (valid version not detected).\n";
212+
msg += $"Must install '{ String.Join("' or '", presageOptions.ToArray()) }'. Changed SuggestionMethod to NGram.";
213+
Log.Error(msg);
197214
return true;
198215
}
199216

200-
if ((osBitness == "64-Bit" && presagePath != @"C:\Program Files (x86)\presage")
201-
|| (osBitness == "32-Bit" && presagePath != @"C:\Program Files\presage"))
202-
{
203-
Settings.Default.SuggestionMethod = SuggestionMethods.NGram;
204-
Log.Error("Invalid Presage installation detected (incorrect bitness? Install location is suspect). Must install 'presage-0.9.1-32bit' or 'presage-0.9.2~beta20150909-32bit'. Changed SuggesionMethod to NGram.");
205-
return true;
217+
// On Windows 32 bit, we will only be able to install 32 bit Presage and 32 bit Optikey so don't need to check bitness.
218+
// Presage's install location will be \Program Files\ since there is only one Program Files folder available.
219+
220+
// On Windows 64 bit, 32 bit apps get installed into Program Files (x86) and 64 bit apps into Program Files.
221+
// We need to check that Optikey and Presage have the same bitness
222+
if (DiagnosticInfo.OperatingSystemBitness.Contains("64")) {
223+
if ((processBitness == "64-Bit" && presagePath != @"C:\Program Files\presage")
224+
|| (processBitness == "32-Bit" && presagePath != @"C:\Program Files (x86)\presage"))
225+
{
226+
Settings.Default.SuggestionMethod = SuggestionMethods.NGram;
227+
Log.Error("Invalid Presage installation detected (incorrect bitness? Install location is suspect). Must install 'presage-0.9.1-32bit' or 'presage-0.9.2~beta20150909-32bit'. Changed SuggesionMethod to NGram.");
228+
return true;
229+
}
206230
}
207231

208232
if (!Directory.Exists(presagePath))

0 commit comments

Comments
 (0)