10 #ifndef SUOI_FORCEDELETE
11 #define SUOI_FORCEDELETE 1
14 int whelk_win32_error(lua_State *L,DWORD err)
21 n=FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER|\
22 FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,0,err,0,
26 if (n>2 && buf[n-2]=='\r' && buf[n-1]=='\n')
28 utf8=whelk_utf16_to_utf8(buf,n);
30 lua_pushstring(L,utf8);
34 lua_pushstring(L,"Unknown error");
35 lua_pushinteger(L,err);
40 * SetupCopyOEMInf(source_inf_file_name,oem_source_media_location,
41 * oem_source_media_type,copy_style)
43 * oem_source_media_type is one of:
45 * No source media information is stored.
48 * oem_source_media_location contains a path to the source media
52 * oem_source_media_locationcontains a universal resource locator.
54 * copy_style is one of:
55 * SP_COPY_DELETESOURCE
56 * Delete source file on successful copy.
58 * Copy only if this file already exists in the Inf directory.
60 * Copy only if this file does not already exist in the Inf
62 * SP_COPY_OEMINF_CATALOG_ONLY
63 * The specified .inf file's corresponding catalog files is
64 * copied to %windir%\Inf.
66 * Returns two strings: the destination .inf file path (including file name)
67 * and just the file name component.
70 int whelk_setup_copy_oem_inf(lua_State *L)
77 WCHAR *source_inf_file_name=whelk_utf8_to_utf16(luaL_checkstring(L,1),-1);
78 WCHAR *oem_source_media_location;
79 int oem_source_media_type=luaL_checkint(L,3);
80 int copy_style=luaL_checkint(L,4);
81 WCHAR *dest_in_file_name_component;
82 s=luaL_checklstring(L,2,&n);
83 oem_source_media_location=s?whelk_utf8_to_utf16(s,n):NULL;
85 dest_in_file_name_component=NULL;
86 result=SetupCopyOEMInfW(source_inf_file_name,oem_source_media_location,
87 oem_source_media_type,copy_style,path,sizeof(path)/sizeof(*path),NULL,
88 &dest_in_file_name_component);
89 free(source_inf_file_name);
90 free(oem_source_media_location);
92 return whelk_win32_error(L,GetLastError());
93 utf8=whelk_utf16_to_utf8(path,-1);
94 lua_pushstring(L,utf8);
96 if (dest_in_file_name_component)
98 utf8=whelk_utf16_to_utf8(dest_in_file_name_component,-1);
99 lua_pushstring(L,utf8);
108 * SetupUninstallOEMInf(inf_file_name[,flags])
110 * The following flags are recognised:
112 * Delete the .inf file even if an installed device uses it.
114 * Returns non-nil on success.
117 int whelk_setup_uninstall_oem_inf(lua_State *L)
120 WCHAR *inf_file_name=whelk_utf8_to_utf16(luaL_checkstring(L,1),-1);
121 int flags=lua_isnone(L,2)?0:luaL_checkint(L,2);
122 #ifdef HAVE_SETUPUNINSTALLOEMINFW
123 result=SetupUninstallOEMInfW(inf_file_name,flags,NULL);
126 BOOL (WINAPI *SetupUninstallOEMInfW)(WCHAR *inf_file_name,DWORD flags,
128 lib=LoadLibrary("setupapi.dll");
131 SetupUninstallOEMInfW=GetProcAddress(lib,"SetupUninstallOEMInfW");
132 if (SetupUninstallOEMInfW)
133 result=SetupUninstallOEMInfW(inf_file_name,flags,NULL);
138 return whelk_win32_error(L,ERROR_NOT_SUPPORTED);
145 return whelk_win32_error(L,ERROR_NOT_SUPPORTED);
150 return whelk_win32_error(L,GetLastError());
151 lua_pushinteger(L,1); /* Something other than nil */
155 void whelk_open_setup(lua_State *L)
157 whelk_reg_const(L,SPOST_NONE);
158 whelk_reg_const(L,SPOST_PATH);
159 whelk_reg_const(L,SPOST_URL);
160 whelk_reg_const(L,SP_COPY_DELETESOURCE);
161 whelk_reg_const(L,SP_COPY_REPLACEONLY);
162 whelk_reg_const(L,SP_COPY_NOOVERWRITE);
163 whelk_reg_const(L,SP_COPY_OEMINF_CATALOG_ONLY);
164 whelk_reg_const(L,SUOI_FORCEDELETE);