diff --git a/lib/src/locate_ndk.dart b/lib/src/locate_ndk.dart index 8fd0895..ef594d8 100644 --- a/lib/src/locate_ndk.dart +++ b/lib/src/locate_ndk.dart @@ -378,10 +378,17 @@ class NDKLocator { /// Expands a path template with environment variables and glob patterns. static List expandPath(String pathTemplate) { - final path = pathTemplate.replaceAll( - '\$HOME', - Platform.environment['HOME']!, - ); + final homeDirectory = Platform.isWindows + ? Platform.environment['USERPROFILE']?.replaceAll('\\', '/') + : Platform.environment['HOME']; + + if (homeDirectory == null) { + throw Exception( + 'Failed to find home directory. Please ensure that the HOME environment variable is set. On Windows, the USERPROFILE environment variable should be set instead.', + ); + } + + final path = pathTemplate.replaceAll('\$HOME', homeDirectory); final glob = Glob(path); final matches = glob.listSync(); return matches;