<commit_before>#include "opt.h"
#ifdef HAVE_WINDOWS_H
#include "cmd-install.h"
#include "util.h"

char* sbcl_bin_extention(struct install_options* param) {
  return ".msi";
}

int sbcl_bin_expand(struct install_options* param) {
  char* impl=param->impl;
  char* version=q(param->version);
  int ret;
  char* home=configdir();
  char* arch= arch_(param);
  char* archive=cat(impl,"-",version,"-",arch,".msi",NULL);
  char* log_path=cat(home,"impls",SLASH,"log",SLASH,impl,"-",version,"-",arch,SLASH,"install.log",NULL);
  char* dist_path;
  int pos=position_char("-",impl);
  impl=(pos!=-1)?subseq(impl,0,pos):q(impl);
  dist_path=cat(home,"src",SLASH,impl,"-",version,"-",arch,SLASH,NULL);
  
  char* msiexec_path="msiexec.exe";
  if(!file_exist_p(msiexec_path))
  {
	  msiexec_path="C:\\Windows\\System32\\msiexec.exe";
	  if(!file_exist_p(msiexec_path))
	  {
		  printf("Msiexec.exe not found in the system path\n");
		  return 0;
	  }
  }
  
  printf("Extracting the msi archive. %s to %s\n",archive,dist_path);
  archive=s_cat(q(home),q("archives"),q(SLASH),archive,NULL);
  delete_directory(dist_path,1);
  ensure_directories_exist(dist_path);
  ensure_directories_exist(log_path);<commit_msg>Updated the code to retrieve msiexce path from the register<commit_after>#include "opt.h"
#ifdef HAVE_WINDOWS_H
#include "cmd-install.h"
#include "util.h"
#include <windows.h>

char* sbcl_bin_extention(struct install_options* param) {
  return ".msi";
}


char* msi_exec_path_from_register(void)
{
  DWORD keyType = 0;
  DWORD length = 0;
  const DWORD flags = RRF_RT_REG_SZ; // Only read strings (REG_SZ)
  LONG result = RegGetValueA(
            HKEY_LOCAL_MACHINE, 
            "SYSTEM\\CurrentControlSet\\Services\\msiserver",
			"ImagePath", 
			flags, 
            &keyType, 
            NULL, // pvData == nullptr ? Request buffer size
            &length);
  
  if (result != ERROR_SUCCESS) 	
  {
		return NULL;
  }
  
  char* textBuffer=(char*)alloc(length); 
  

  result= RegGetValueA(
            HKEY_LOCAL_MACHINE, 
            "SYSTEM\\CurrentControlSet\\Services\\msiserver",
			"ImagePath", 
			flags, 
            NULL, 
            textBuffer, // Write string in this destination buffer
            &length);
	
	if (result != ERROR_SUCCESS) 	
	{
		return NULL;
	}
	
	//Skip trailing blanks take the full path of the executable then cut at the first blank afterwards 
	char* start=textBuffer;
	
	while(*start==' ' && *start!=0)
		start++;
	if(*start==0)
		return NULL;
	
	char* end=start;
	
	while(*end!=0)
	{
		if(*end==' ')
		{
			*end=0;
			break;
		}
		end++;
	}
	
	return start;
}


int sbcl_bin_expand(struct install_options* param) {
  char* impl=param->impl;
  char* version=q(param->version);
  int ret;
  char* home=configdir();
  char* arch= arch_(param);
  char* archive=cat(impl,"-",version,"-",arch,".msi",NULL);
  char* log_path=cat(home,"impls",SLASH,"log",SLASH,impl,"-",version,"-",arch,SLASH,"install.log",NULL);
  char* dist_path;
  int pos=position_char("-",impl);
  impl=(pos!=-1)?subseq(impl,0,pos):q(impl);
  dist_path=cat(home,"src",SLASH,impl,"-",version,"-",arch,SLASH,NULL);
 
  char* msiexec_path=msi_exec_path_from_register(); 
  if(!file_exist_p(msiexec_path))
  {
	  msiexec_path="msiexec.exe";
	  if(!file_exist_p(msiexec_path))
	  {
		  printf("Msiexec.exe not found in the system path\n");
		  return 0;
	  }
  }
  
  printf("Extracting the msi archive. %s to %s\n",archive,dist_path);
  archive=s_cat(q(home),q("archives"),q(SLASH),archive,NULL);
  delete_directory(dist_path,1);
  ensure_directories_exist(dist_path);
  ensure_directories_exist(log_path);
{'fraction_non_alphanumeric': 0.16348018841784429, 'fraction_numerical': 0.004433361041839845, 'mean_word_length': 4.135135135135135, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2861888', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1351, 'n_words': 230}