Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.13 KB | None | 0 0
  1. #include <windows.h>
  2. #include <string.h>
  3. #include "resource.h"
  4. #include <shlobj.h>
  5. #include <objbase.h>
  6. #pragma comment(lib, "shell32.lib")
  7. #pragma comment(lib, "ole32.lib")
  8. #define BROWSE_REGISTRY_ROOT        HKEY_CURRENT_USER
  9. #define BROWSE_REGISTRY_PATH        "Software\\Connector"
  10.  
  11. void launchMW2(HWND hWnd, char* args)
  12. {
  13.     char* buf;
  14.     buf = (char*)GlobalAlloc(GPTR, 100);
  15.     GetDlgItemText(hWnd, IDC_TPATH, buf, 100);
  16.     strcat(buf,"\\iw4mp.exe");
  17.     ShellExecute( NULL, NULL, buf, args, NULL, SW_SHOW );
  18. }
  19. void SaveConfig(HWND hWnd)
  20. {
  21.     char* buf;
  22.     char Value[MAX_PATH];
  23.     HKEY Key = NULL;
  24.     //Open or create the registry before closing
  25.     if(RegCreateKeyEx(BROWSE_REGISTRY_ROOT, BROWSE_REGISTRY_PATH, NULL, NULL, NULL, KEY_ALL_ACCESS, NULL, &Key, NULL)!=ERROR_SUCCESS)
  26.         return;
  27.  
  28.    
  29.     buf = (char*)GlobalAlloc(GPTR, 100);
  30.     GetDlgItemText(hWnd, IDC_TPATH, buf, 100);
  31.     //Now delete all the old entries
  32.    
  33.     strcpy(Value,"MW2 PATH");
  34.     RegDeleteValue(Key, Value);
  35.  
  36.     RegSetValueEx(Key, Value, NULL, REG_SZ, (LPBYTE)buf, strlen(buf));
  37.  
  38.     //Now close it
  39.     RegCloseKey(Key);
  40. }
  41. void ReadConfig(HWND hWnd)
  42. {
  43.     HKEY Key = NULL;
  44.     char Value[MAX_PATH];
  45.     char szData[MAX_PATH];
  46.     DWORD cbData=sizeof(DWORD);
  47.     DWORD Data;
  48.     //Open the key, return if it does not exists
  49.     if(RegOpenKeyEx(BROWSE_REGISTRY_ROOT, BROWSE_REGISTRY_PATH, NULL, KEY_ALL_ACCESS, &Key)!=ERROR_SUCCESS)
  50.         return;
  51.  
  52.     //Variables to store data
  53.    
  54.  
  55.    
  56.    
  57.     cbData = sizeof(szData);
  58.     strcpy(Value,"MW2 PATH");
  59.  
  60.     //Read the registry and check if it is valid or leave
  61.     if(RegQueryValueEx( Key, Value, NULL, NULL, (LPBYTE)&szData, &cbData)==ERROR_SUCCESS)
  62.     {
  63.         SetDlgItemText(hWnd, IDC_TPATH, szData);
  64.     }
  65.  
  66.     //Now close the key
  67.     RegCloseKey(Key);
  68. }
  69.  
  70. BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
  71. {
  72.     switch(Message)
  73.     {
  74.         case WM_INITDIALOG:
  75.             // This is where we set up the dialog box, and initialise any default values
  76.  
  77.             SetDlgItemText(hwnd, IDC_TEXT, "IP:PORT");
  78.             SetDlgItemText(hwnd, IDC_TPATH, "Select your MW2 PATH");
  79.             ReadConfig(hwnd);
  80.  
  81.         break;
  82.         case WM_COMMAND:
  83.             switch(LOWORD(wParam))
  84.             {
  85.                 case IDC_CONNECT:
  86.                 {
  87.                
  88.                     int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_TEXT));
  89.                        
  90.                     if(len > 0)
  91.                     {
  92.  
  93.                         char* buf;
  94.                         char argument[100];
  95.  
  96.                         buf = (char*)GlobalAlloc(GPTR, len + 1);
  97.                         GetDlgItemText(hwnd, IDC_TEXT, buf, len + 1);
  98.                            
  99.                         strcpy(argument,"\"aiw://connect/");
  100.                         strcat(argument,buf);
  101.                         strcat(argument,"\""); 
  102.                         launchMW2(hwnd,argument);
  103.  
  104.                         //ShellExecute( NULL, NULL, buf, argument, NULL, SW_SHOW );
  105.                         GlobalFree((HANDLE)buf);
  106.                     }
  107.                     else
  108.                     {
  109.                         MessageBox(hwnd, "Enter IP:PORT to connect", "Warning", MB_OK);
  110.                     }
  111.  
  112.                 }
  113.                 break;
  114.                 case IDC_PLM:
  115.                     {
  116.                         launchMW2(hwnd,"\"aiw://connect/192.168.56.1:28961\"");
  117.                     }
  118.                 break;
  119.                 case IDC_Legion:
  120.                     {
  121.                         launchMW2(hwnd,"\"aiw://connect/192.168.56.1:28961\"");
  122.                     }
  123.                 break;
  124.                 case IDC_PATH:
  125.                 {
  126.                     TCHAR szFolder[MAX_PATH];
  127.  
  128.                     CoInitialize(NULL);
  129.  
  130.                     if (GetFolderSelection(NULL, szFolder, TEXT("Please select a folder.")))
  131.                     {
  132.                         SetDlgItemText(hwnd, IDC_TPATH, szFolder);
  133.                         SaveConfig(hwnd);
  134.                     }
  135.                     else
  136.                     {
  137.                         SetDlgItemText(hwnd, IDC_TPATH, "Failed to select a folder");
  138.                     }
  139.  
  140.                     CoUninitialize();
  141.                 }
  142.                 break;
  143.             }
  144.         break;
  145.         case WM_CLOSE:
  146.             EndDialog(hwnd, 0);
  147.         break;
  148.         default:
  149.             return FALSE;
  150.     }
  151.     return TRUE;
  152. }
  153.  
  154. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  155.     LPSTR lpCmdLine, int nCmdShow)
  156. {
  157.    return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
  158. }
  159. BOOL GetFolderSelection(HWND hWnd, LPTSTR szBuf, LPCTSTR szTitle)
  160. {
  161.     LPITEMIDLIST pidl     = NULL;
  162.     BROWSEINFO   bi       = { 0 };
  163.     BOOL         bResult  = FALSE;
  164.  
  165.     bi.hwndOwner      = hWnd;
  166.     bi.pszDisplayName = szBuf;
  167.     bi.pidlRoot       = NULL;
  168.     bi.lpszTitle      = szTitle;
  169.     bi.ulFlags        = BIF_RETURNONLYFSDIRS | BIF_USENEWUI;
  170.  
  171.     if ((pidl = SHBrowseForFolder(&bi)) != NULL)
  172.     {
  173.         bResult = SHGetPathFromIDList(pidl, szBuf);
  174.         CoTaskMemFree(pidl);
  175.     }
  176.  
  177.     return bResult;
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement