extern "C" void __declspec(dllexport) IsUserAdmin( HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { EXDLL_INIT(); BOOL b = false; SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; PSID AdministratorsGroup; b = AllocateAndInitializeSid( &NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup); if(b) { if (!CheckTokenMembership( NULL, AdministratorsGroup, &b)) { setuservariable( INST_0, "0" ); } else { setuservariable( INST_0, "1" ); } FreeSid(AdministratorsGroup); } }
extern "C" void __declspec(dllexport) GetMediaCenterPath( HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { EXDLL_INIT(); HRESULT hr = CoInitialize(NULL); char *mediaCenterPath = (char*)GlobalAlloc(GPTR, string_size); hr = SHGetFolderPathA( NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, mediaCenterPath ); setuservariable( INST_0, mediaCenterPath ); }
extern "C" void __declspec(dllexport) CheckForVista( HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { EXDLL_INIT(); OSVERSIONINFOEX versionInfo; ZeroMemory(&versionInfo, sizeof(OSVERSIONINFOEX)); versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); GetVersionEx( (OSVERSIONINFO *) &versionInfo ); if ( versionInfo.dwMajorVersion < 6 || versionInfo.wProductType != VER_NT_WORKSTATION ) { setuservariable( INST_0, "0"); return; } setuservariable( INST_0, "1"); }
__declspec(dllexport) void download (HWND parent, int string_size, char *variables, stack_t **stacktop) { static char buf[1024]; static char url[1024]; static char filename[1024]; int wasen=0; HWND hwndL=0; HWND hwndB=0; static char szDownloading[32];//= "Downloading %s"; static char szConnecting[32];//= "Connecting ..."; static char szSecond[32];//= "second"; static char szMinute[32];//= "minute"; static char szHour[32];//= "hour"; static char szPlural[32];//= "s"; static char szProgress[128];//= "%dkB (%d%%) of %dkB @ %d.%01dkB/s"; static char szRemaining[128];//= " (%d %s%s remaining)"; g_parent = parent; EXDLL_INIT(); popstring(url); if (!lstrcmpi(url, "/TRANSLATE")) { popstring(szDownloading); popstring(szConnecting); popstring(szSecond); popstring(szMinute); popstring(szHour); popstring(szPlural); popstring(szProgress); popstring(szRemaining); popstring(url); } else { lstrcpy(szDownloading, "Downloading %s"); lstrcpy(szConnecting, "Connecting ..."); lstrcpy(szSecond, "second"); lstrcpy(szMinute, "minute"); lstrcpy(szHour, "hour"); lstrcpy(szPlural, "s"); lstrcpy(szProgress, "%dkB (%d%%) of %dkB @ %d.%01dkB/s"); lstrcpy(szRemaining, " (%d %s%s remaining)"); } lstrcpyn(buf, url, 10); if (!lstrcmpi(buf, "/TIMEOUT=")) { g_timeout_ms=my_atoi(url+9); popstring(url); } popstring(filename); HANDLE hFile = CreateFile(filename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); if (hFile == INVALID_HANDLE_VALUE) { wsprintf (buf, "Unable to open %s", filename); setuservariable(INST_0, buf); } else { if (g_parent) { g_childwnd=FindWindowEx(g_parent,NULL,"#32770",NULL); hwndL=GetDlgItem(g_childwnd,1016); hwndB=GetDlgItem(g_childwnd,1027); if (hwndL && IsWindowVisible(hwndL)) ShowWindow(hwndL,SW_HIDE); else hwndL=NULL; if (hwndB && IsWindowVisible(hwndB)) ShowWindow(hwndB,SW_HIDE); else hwndB=NULL; wasen=EnableWindow(GetDlgItem(g_parent,IDCANCEL),1); lpWndProcOld = (void *) GetWindowLong(g_parent,GWL_WNDPROC); SetWindowLong(g_parent,GWL_WNDPROC,(long)ParentWndProc); g_dialog = CreateDialog((HINSTANCE)hModule, MAKEINTRESOURCE(IDD_DIALOG1), g_childwnd, DownloadDialogProc); if (g_dialog) { GetWindowRect(g_dialog,&cr); ScreenToClient(g_dialog,(LPPOINT)&cr); ScreenToClient(g_dialog,((LPPOINT)&cr)+1); GetWindowRect(GetDlgItem(g_childwnd,1016),&r); ScreenToClient(g_childwnd,(LPPOINT)&r); ScreenToClient(g_childwnd,((LPPOINT)&r)+1); SetWindowPos(g_dialog,0,r.left,r.top,r.right-r.left,cr.bottom-cr.top,SWP_NOACTIVATE|SWP_NOZORDER); AdjustSize(IDC_STATIC2); AdjustSize(IDC_PROGRESS1); ShowWindow(g_dialog,SW_SHOWNA); char *p=filename; while (*p) p++; while (*p != '\\' && p != filename) p=CharPrev(filename,p); wsprintf(buf,szDownloading, p+1); SetDlgItemText(g_childwnd,1006,buf); SetDlgItemText (g_dialog, IDC_STATIC2, szConnecting); } } g_hwndProgressBar = GetDlgItem (g_dialog, IDC_PROGRESS1); JNL_HTTPGet *get; char *error=NULL; { WSADATA wsaData; WSAStartup(MAKEWORD(1, 1), &wsaData); static char buf[8192]=""; char *p=NULL; HKEY hKey; if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS) { DWORD l = 4; DWORD t; DWORD v; if (RegQueryValueEx(hKey,"ProxyEnable",NULL,&t,(unsigned char *)&v,&l) == ERROR_SUCCESS && t == REG_DWORD && v) { l=8192; if (RegQueryValueEx(hKey,"ProxyServer",NULL,&t,(unsigned char *)buf,&l ) == ERROR_SUCCESS && t == REG_SZ) { p=strstr(buf,"http="); if (!p) p=buf; else { p+=5; } char *tp=strstr(p,";"); if (tp) *tp=0; char *p2=strstr(p,"="); if (p2) p=0; // we found the wrong proxy } } buf[8192-1]=0; RegCloseKey(hKey); } DWORD start_time=GetTickCount(); get=new JNL_HTTPGet(JNL_CONNECTION_AUTODNS,16384,(p&&p[0])?p:NULL); int st; int has_printed_headers = 0; int cl; int len; int sofar = 0; DWORD last_recv_time=start_time; get->addheader ("User-Agent: NSISDL/1.2 (Mozilla)"); get->addheader ("Accept: */*"); get->connect (url); while (1) { if (g_dialog) { MSG msg; while (PeekMessage(&msg,g_dialog,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } Sleep(25); if (g_cancelled) break; st = get->run (); if (st == -1) { error=get->geterrorstr(); break; } else if (st == 1) { if (sofar < cl) error="download incomplete"; break; } else { if (get->get_status () == 0) { // progressFunc ("Connecting ...", 0); if (last_recv_time+g_timeout_ms < GetTickCount()) { error = "Timed out on connecting."; break; } } else if (get->get_status () == 1) { progress_callback("Reading headers", 0); if (last_recv_time+g_timeout_ms < GetTickCount()) { error = "Timed out on getting headers."; break; } } else if (get->get_status () == 2) { if (! has_printed_headers) { has_printed_headers = 1; last_recv_time=GetTickCount(); cl = get->content_length (); if (cl == 0) { error = "Server did not specify content length."; break; } else if (g_dialog) { SendMessage(g_hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0,30000)); g_file_size=cl; } } while ((len = get->bytes_available ()) > 0) { if (len > 8192) len = 8192; len = get->get_bytes (buf, len); if (len > 0) { last_recv_time=GetTickCount(); DWORD dw; WriteFile(hFile,buf,len,&dw,NULL); sofar += len; int time_sofar=(GetTickCount()-start_time)/1000; int bps=sofar/(time_sofar?time_sofar:1); int remain=MulDiv(time_sofar,cl,sofar) - time_sofar; char *rtext=szSecond; if (remain >= 60) { remain/=60; rtext=szMinute; if (remain >= 60) { remain/=60; rtext=szHour; } } wsprintf (buf, szProgress, sofar/1024, MulDiv(100,sofar,cl), cl/1024, bps/1024,((bps*10)/1024)%10 ); if (remain) wsprintf(buf+lstrlen(buf),szRemaining, remain, rtext, remain==1?"":szPlural ); progress_callback(buf, sofar); } else { if (sofar < cl) error = "Server aborted."; break; } } if (GetTickCount() > last_recv_time+g_timeout_ms) { error = "Downloading timed out."; break; } } else { error = "Bad response status."; break; } } } WSACleanup(); } CloseHandle(hFile); if (g_parent) { if (g_dialog) DestroyWindow(g_dialog); if (lpWndProcOld) SetWindowLong(g_parent,GWL_WNDPROC,(long)lpWndProcOld); if (g_childwnd) { if (hwndB) ShowWindow(hwndB,SW_SHOWNA); if (hwndL) ShowWindow(hwndL,SW_SHOWNA); } if (wasen) EnableWindow(GetDlgItem(g_parent,IDCANCEL),0); } if (g_cancelled) { setuservariable(INST_0, "cancel"); DeleteFile(filename); } else if (error == NULL) { setuservariable(INST_0, "success"); } else { DeleteFile(filename); setuservariable(INST_0, error); } delete get; } }
extern "C" void __declspec(dllexport) SetupGameExplorerRequirements( HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { EXDLL_INIT(); char *cBinPath = NULL, *cInstallDir = NULL, *allUsers = NULL; cBinPath = (char*)GlobalAlloc(GPTR, string_size); cInstallDir = (char*)GlobalAlloc(GPTR, string_size); allUsers = (char*)GlobalAlloc(GPTR, string_size); popstring( cBinPath ); popstring( cInstallDir ); popstring( allUsers ); WCHAR wBinPath[512], wInstallDir[512]; mbstowcs(wBinPath, cBinPath, 512 ); mbstowcs(wInstallDir, cInstallDir, 512 ); HRESULT hr = CoInitialize(NULL); if( FAILED(hr) ) { MessageBox( hwndParent, L"Failed to register Darwinia: Vista Edition with Games Explorer", L"Darwinia: Vista Edition", MB_OK|MB_ICONERROR ); setuservariable( INST_0, "0" ); return; } IGameExplorer *gameExplorerInterface = NULL; hr = CoCreateInstance(__uuidof(GameExplorer), 0, CLSCTX_INPROC_SERVER, __uuidof(IGameExplorer), (LPVOID *)&gameExplorerInterface); if( FAILED(hr) ) { MessageBox( hwndParent, L"Failed to register Darwinia: Vista Edition with Games Explorer", L"Darwinia: Vista Edition", MB_OK|MB_ICONERROR ); setuservariable( INST_0, "0" ); return; } GAME_INSTALL_SCOPE installScope = GIS_CURRENT_USER; if( strcmp( allUsers, "1" ) == 0 ) { installScope = GIS_ALL_USERS; } GUID guid = GUID_NULL; // Remove the Game Explorer /*StringToGuid( &guid, "{88FE1129-ED85-4674-B245-89AB7B9C267B}"); gameExplorerInterface->RemoveGame( guid ); setuservariable( INST_0, "0" ); return;*/ hr = RetrieveGUIDForApplication( wBinPath, NULL ); if( SUCCEEDED(hr) ) { MessageBox( hwndParent, L"Darwinia: Vista Edition is already registered with Games Explorer", L"Darwinia: Vista Edition", MB_OK|MB_ICONEXCLAMATION); setuservariable( INST_0, "0" ); return; } hr = gameExplorerInterface->AddGame( wBinPath, wInstallDir, installScope, &guid ); if( FAILED(hr) ) { MessageBox( hwndParent, L"Failed to register Darwinia: Vista Edition with Games Explorer", L"Darwinia: Vista Edition", MB_OK|MB_ICONERROR ); setuservariable( INST_0, "0" ); return; } WCHAR *gameExplorerPath = (WCHAR*)GlobalAlloc(GPTR, string_size); if( strcmp( allUsers, "1" ) == 0 ) { hr = SHGetFolderPath( NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, gameExplorerPath ); } else { hr = SHGetFolderPath( NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, gameExplorerPath ); } if( FAILED(hr) ) { gameExplorerInterface->RemoveGame(guid); MessageBox( hwndParent, L"Failed to register Darwinia: Vista Edition with Games Explorer", L"Darwinia: Vista Edition", MB_OK|MB_ICONERROR ); setuservariable( INST_0, "0" ); return; } WCHAR guidString[128]; hr = StringFromGUID2( guid, guidString, 128 ); char cExplorerPath[1024]; char cGuid[128]; wcstombs( cExplorerPath, gameExplorerPath, 1024 ); wcstombs( cGuid, guidString, 128 ); char fullPath[1024]; sprintf( fullPath, "%s\\Microsoft\\Windows\\GameExplorer\\%s\\PlayTasks\\0", cExplorerPath, cGuid ); char fileName[1024]; sprintf( fileName, "%s\\Play.lnk", fullPath ); CreateLink( cBinPath, fullPath, fileName, NULL ); //gameExplorerInterface->RemoveGame(guid); //pushstring(cGuid); SetupRichSavedGamesW( SAVE_EXTENTION, wBinPath, NULL ); setuservariable( INST_0, cGuid ); }
void __declspec(dllexport) Utf8ToAnsi(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) { EXDLL_INIT(); TCHAR path[1024]; popstringn(path, 1024); setuservariable(INST_9, utf_8_to_ansi(path)); }