Skip to content

Instantly share code, notes, and snippets.

@trentpolack
Last active December 31, 2017 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trentpolack/203806b53fe06ee46bc5f24a41467211 to your computer and use it in GitHub Desktop.
Save trentpolack/203806b53fe06ee46bc5f24a41467211 to your computer and use it in GitHub Desktop.
Houdini Engine for Unreal (Improved Path Handling on Windows)
// [GIST NOTE] Added at the bottom of the existing class (for editor and runtime).
// Check the system environment variables for HOUDINI_PATH (instead of just hard-coded path searching like the default plugin does).
public static bool GetHoudiniPath( int PluginVersionMajor, int PluginVersionMinor, int PluginVersionPatch, out string HoudiniPathOut )
{
string version = null;
// Do the easy check: an environment variable I recommend to people (trent, 12/31/17).
HoudiniPathOut = System.Environment.GetEnvironmentVariable("HOUDINI_PATH", System.EnvironmentVariableTarget.User);
if ( !string.IsNullOrEmpty( HoudiniPathOut ) )
{
// NOTE (trent, 12/31/17): Can't do a version check in this case (I have it installed to a \Houdini\ path instead of \Houdini <version>\). Maybe could do a regex for "{number}.{number}.{number}" somewhere if needed?
// Ensure that any backslashes are replaced with forward slashes (or the C++ code gets angry).
HoudiniPathOut = HoudiniPathOut.Replace( "\\", "/" );
System.Console.WriteLine( string.Format( "[Houdini Engine Plugin (Editor)]: Found Houdini path successfully ({0}).", HoudiniPathOut ) );
return true;
}
// Interrogate the Win32 registry.
Microsoft.Win32.RegistryKey sideEffectsKey = Microsoft.Win32.RegistryKey.OpenBaseKey( Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Default ).OpenSubKey( "SOFTWARE\\Side Effects Software" );
if( sideEffectsKey == null )
{
// Likely does not have Houdini uninstalled.
HoudiniPathOut = null;
System.Console.WriteLine( "[Houdini Engine Plugin (Editor)] WARNING: HOUDINI_PATH (and registry) failed to locate Houdini." );
return false;
}
version = sideEffectsKey.GetValue( "ActiveVersion" ) as string;
if( string.IsNullOrEmpty( version ) )
{
// Likely does not have Houdini uninstalled.
System.Console.WriteLine( "[Houdini Engine Plugin (Editor)] WARNING: HOUDINI_PATH (and registry) failed to locate Houdini." );
return false;
}
// Query the path specified in the Houdini regkey.
string key = string.Format( "SOFTWARE\\Side Effects Software\\Houdini {0}", version );
Microsoft.Win32.RegistryKey houdiniKey = Microsoft.Win32.RegistryKey.OpenBaseKey( Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Default ).OpenSubKey( key );
if( houdiniKey == null )
{
// Likely does not have Houdini uninstalled.
System.Console.WriteLine( "[Houdini Engine Plugin (Editor)] WARNING: HOUDINI_PATH (and registry) failed to locate Houdini." );
return false;
}
HoudiniPathOut = houdiniKey.GetValue( "InstallPath", "" ) as string;
if( string.IsNullOrEmpty( HoudiniPathOut ) )
{
// Failed to find the path.
System.Console.WriteLine( "[Houdini Engine Plugin (Editor)] WARNING: HOUDINI_PATH (and registry) failed to locate Houdini." );
return false;
}
// Do a little bit more to check the version.
string pluginVersion = PluginVersionMajor + "." + PluginVersionMinor + "." + PluginVersionPatch;
// Do a trivial check for the same version.
if( version == pluginVersion )
{
// Neat.
return true;
}
// Parse the version key for comparison with the plugin version.
// NOTE (trent, 12/31/17): I'm only spitting out a warning if the installed version predates the plugin version; if only a direct match is desired, this can all be removed and replaced with a string comparison.
{
string[] versionValues = System.Text.RegularExpressions.Regex.Split( version, @"\D+" );
int iteration = 0;
foreach ( string value in versionValues )
{
if( !string.IsNullOrEmpty( value ) )
{
int i = int.Parse( value );
if( i < ( ( iteration == 0 ) ? PluginVersionMajor : ( iteration == 1 ? PluginVersionMinor : PluginVersionPatch ) ) )
{
string versionWarning = string.Format( "[Houdini Engine Plugin (Editor)] WARNING: Houdini version found ({0}) precedes plugin version ({1}).", version, pluginVersion );
System.Console.WriteLine( versionWarning );
break;
}
}
++iteration;
}
}
// Ensure that any backslashes are replaced with forward slashes (or the C++ code gets angry).
HoudiniPathOut = HoudiniPathOut.Replace( "\\", "/" );
string foundRegistryPath = string.Format( "[Houdini Engine Plugin (Editor)]: Found Houdini path successfully ({0}).", HoudiniPathOut );
System.Console.WriteLine( foundRegistryPath );
return true;
}
// [GIST NOTE]: Replace class definition line.
// Runtime:
[SupportedPlatforms(UnrealTargetPlatform.Win64)]
public class HoudiniEngineRuntime : ModuleRules
// Editor:
[SupportedPlatforms(UnrealTargetPlatform.Win64)]
public class HoudiniEngineEditor : ModuleRules
// [GIST NOTE]: Replaces the existing version string (just builds it from the int values).
int versionMajor = 16, versionMinor = 5, versionPatch = 332;
string HoudiniVersion = versionMajor + "." + versionMinor + "." + versionPatch;
// [GIST NOTE]: Replaces existing Windows path logic.
if( platformId == PlatformID.Win32NT )
{
if( !GetHoudiniPath( versionMajor, versionMinor, versionPatch, out HFSPath ) )
{
// We first check if Houdini Engine is installed.
// NOTE (trent, 12/31/17): The more useful way using a user-set environment variables (HOUDINI_PATH) or, if that fails, checking the registry. If that still fails, then use the hard-coded versioned path.
string HPath = "C:/Program Files/Side Effects Software/Houdini Engine " + HoudiniVersion;
if( !Directory.Exists( HPath ) )
{
// If Houdini Engine is not installed, we check for Houdini installation.
HPath = "C:/Program Files/Side Effects Software/Houdini " + HoudiniVersion;
if( !Directory.Exists( HPath ) )
{
if ( !Directory.Exists( HFSPath ) )
{
string Err = string.Format( "Houdini Engine : Please install Houdini or Houdini Engine {0}", HoudiniVersion );
System.Console.WriteLine( Err );
}
}
else
{
HFSPath = HPath;
}
}
else
{
HFSPath = HPath;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment