//..............................................................................
//
// J-Link library detection on Windows
//

import "sys_Registry.jnc"

namespace io {

//..............................................................................

string_t detectJLinkLibPath() {
	static string_t fileName = sys.g_systemInfo.m_cpuKind == sys.CpuKind.Amd64 ?
		"JLink_x64.dll" :
		"JLinkARM.dll";

	sys.RegKey key;
	bool result = try key.open(
		sys.RegStdKey.CurrentUser,
		r"Software\SEGGER\J-Link",
		sys.RegKeyAccess.Read
	);

	if (result) {
		string_t installPath = key.readString("InstallPath");
		if (installPath)
			return $"$installPath\\$fileName";
	}

	return fileName;
}

//..............................................................................

} // namespace io
