/**************************************************************************** * * Microsoft Confidential * Copyright (c) Microsoft Corporation 1994 * All rights reserved * * This module handles the File Association UI * ***************************************************************************/ #include "inetcplp.h" #include "mluisupp.h" #include // For definition of FTA_OpenIsSafe // the file class's open verb may be safely invoked for downloaded files #include "../inc/filetype.h" // Macros required for default button processing #define REMOVE_DEF_BORDER(hDlg, cntrl ) \ SendMessage( hDlg, DM_SETDEFID, -1, 0 ); \ SendDlgItemMessage( hDlg, cntrl, BM_SETSTYLE, BS_PUSHBUTTON, TRUE ); \ #define SET_DEF_BORDER(hDlg, cntrl ) \ SendMessage( hDlg, DM_SETDEFID, cntrl, 0 ); \ SendDlgItemMessage( hDlg, cntrl, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE ); \ // Editing modes #define NORMAL 0x00 #define ADDING 0x01 #define UPDATING 0x02 // Association status #define NEW 0x01 #define UPD 0x02 #define UNM 0x03 #define LocalRealloc(a, b) LocalReAlloc(a, b, LMEM_MOVEABLE) static TCHAR g_szDefaultIcon[] = TEXT("shell32.dll,3"); static TCHAR g_szIEUnix[] = TEXT("IEUNIX"); static TCHAR g_szIEUnixEntry[] = TEXT("IEUNIX Specific entry"); static TCHAR g_szEditFlags[] = TEXT("EditFlags"); static TCHAR g_szDocClass[] = TEXT("DocClass"); static TCHAR g_szMimeKey[] = TEXT("MIME\\Database\\Content Type"); static TCHAR g_szCmndSubKey[] = TEXT("Shell\\Open\\Command"); static TCHAR g_szPolicySubKey[] = REGSTR_PATH_INETCPL_RESTRICTIONS; static TCHAR g_szPolicyName[] = TEXT("Mappings"); int SwitchToAddMode( HWND hDlg ); int SwitchToNrmlMode( HWND hDlg ); BOOL CALLBACK EnterAssocDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); BOOL IsAssocEnabled() { HKEY hKey = NULL; LONG lResult = RegOpenKey(HKEY_CURRENT_USER, g_szPolicySubKey, &hKey); if( lResult == ERROR_SUCCESS ) { // Get then size first DWORD dwPolicy, dwType, dwSize = sizeof(DWORD); if (RegQueryValueEx( hKey, g_szPolicyName, NULL, &dwType, (LPBYTE)&dwPolicy, &dwSize ) == ERROR_SUCCESS ) { if( dwPolicy ) { RegCloseKey( hKey ); return FALSE; } } RegCloseKey( hKey ); } return TRUE; } /* ** AddStringToComboBox() ** ** Adds a string to a combo box. Does not check to see if the string has ** already been added. ** ** Arguments: ** ** Returns: ** ** Side Effects: none */ BOOL AddStringToComboBox(HWND hwndComboBox, LPCTSTR pcsz) { BOOL bResult; LONG lAddStringResult; lAddStringResult = SendMessage(hwndComboBox, CB_ADDSTRING, 0, (LPARAM)pcsz); bResult = (lAddStringResult != CB_ERR && lAddStringResult != CB_ERRSPACE); return(bResult); } /* ** SafeAddStringToComboBox() ** ** Adds a string to a combo box. Checks to see if the string has already been ** added. ** ** Arguments: ** ** Returns: ** ** Side Effects: none */ BOOL SafeAddStringToComboBox(HWND hwndComboBox, LPCTSTR pcsz) { BOOL bResult; if (SendMessage(hwndComboBox, CB_FINDSTRINGEXACT, 0, (LPARAM)pcsz) == CB_ERR) bResult = AddStringToComboBox(hwndComboBox, pcsz); else { bResult = TRUE; } return(bResult); } typedef struct ASSOCIATION { HWND hDlg; int mode; BOOL fInternalChange; BOOL fChanged; } ASSOCINFO, * LPASSOCTABINFO; typedef struct ENTERASSOC { LPASSOCTABINFO pgti; TCHAR *pszAssoc; } ENTERASSOC, * LPENTERASSOC; #define PGTI_FROM_HDLG( hDlg ) \ ((LPASSOCTABINFO)GetWindowLong(hDlg, DWL_USER)) \ #define PGTI_FROM_PARENT_HDLG( hDlg ) \ ((LPASSOCTABINFO)GetWindowLong(GetParent(hDlg), DWL_USER)) \ class CMime { public: TCHAR * m_mime; TCHAR * m_exts; CMime( TCHAR * name ); ~CMime(); // Operations defined for Asscociation }; CMime::CMime( TCHAR * name ) { m_mime = (TCHAR *) LocalAlloc( LPTR, (lstrlen(name) + 1)*sizeof(TCHAR) ); StrCpy( m_mime, name ); m_exts = NULL; } CMime::~CMime() { if( m_mime ) LocalFree( m_mime ); if( m_exts ) LocalFree( m_exts ); } HDPA mimeList = NULL; BOOL FreeExtensions( HDPA dpa ) { if( dpa == (HDPA)NULL ) return FALSE; int count = DPA_GetPtrCount( dpa ); for(int i=0; i 0 ) { LPTSTR firstExt = (LPTSTR)DPA_FastGetPtr( m_exts, 0 ); RegSetValueEx( hKey1, TEXT("extension"), NULL, REG_SZ, (LPBYTE)firstExt, (lstrlen(firstExt)+1)*sizeof(TCHAR) ); } RegCloseKey( hKey1 ); } } else { RegCloseKey( hKey1 ); } } if(mimeKey) LocalFree(mimeKey); // Add extention/document type association // [.ext // (--reg-val-- "Application") // (content.type "mimetype" ) // ] // First remove all the extensions for the current assoc from the // registry. HDPA prevExts = GetExtsOfAssoc(); if( prevExts ) { int extCount = DPA_GetPtrCount( prevExts ); for( int i=0; i< extCount; i++ ) RegDeleteKey( HKEY_CLASSES_ROOT, (LPTSTR)DPA_FastGetPtr( prevExts, i ) ); FreeExtensions( prevExts ); } if( m_exts ) { int count = DPA_GetPtrCount( m_exts ); for( int i=0; i0) RegSetValueEx( hKey1, TEXT("Content Type"), 0, dwType, (LPBYTE)m_mime, (dwLen+1)*sizeof(TCHAR) ); // Add IEUNIX tag to this entry dwLen = (lstrlen(g_szIEUnixEntry)+1)*sizeof(TCHAR); RegSetValueEx( hKey1, g_szIEUnix, 0, dwType, (LPBYTE)g_szIEUnixEntry, dwLen ); RegCloseKey( hKey1); hKey1 = NULL; } } } } else return FALSE; return TRUE; } CAssoc::Delete() { HKEY hKey; // Don't touch the safe keys if( m_safe ) return FALSE; // Delete Application from HKEY_CLASSES_ROOT EatSpaces(m_type); if(m_type && *m_type) { // NT restrictions TCHAR * key = (TCHAR *)LocalAlloc(LPTR, (lstrlen(m_type) + 200)*sizeof(TCHAR) ) ; if(!key) return FALSE; StrCpy( key, m_type ); StrCat( key, TEXT("\\defaulticon") ); RegDeleteKey(HKEY_CLASSES_ROOT, key); StrCpy( key, m_type ); StrCat( key, TEXT("\\") ); StrCat( key, g_szCmndSubKey ); RegDeleteKey(HKEY_CLASSES_ROOT, key); StrCpy( key, m_type ); StrCat( key, TEXT("\\shell\\open") ); RegDeleteKey(HKEY_CLASSES_ROOT, key); StrCpy( key, m_type ); StrCat( key, TEXT("\\shell") ); RegDeleteKey(HKEY_CLASSES_ROOT, key); RegDeleteKey(HKEY_CLASSES_ROOT, m_type); LocalFree( key ); } else return FALSE; // Delete Extensions from HKEY_CLASSES_ROOT if( m_exts ) { int count = DPA_GetPtrCount( m_exts ); for( int i=0; i= 127) tmpStr++; else *ptr++ = *tmpStr++; } *ptr = TEXT('\0'); LocalFree( tmpPtr ); return str; } TCHAR * ChopSpaces( TCHAR * str ) { if( !str ) return NULL; TCHAR *ptr = str; while( *ptr && (*ptr == TEXT(' ') || *ptr == TEXT('\t')) || (*ptr == TEXT('\n') || *ptr == TEXT('\r')) ) ptr++; TCHAR *tmpStr = DuplicateString( ptr ); TCHAR *tmpPtr = tmpStr + lstrlen(tmpStr); tmpPtr--; while( tmpPtr>= tmpStr && (*tmpPtr == TEXT(' ') || *tmpPtr == TEXT('\t')) || (*tmpPtr == TEXT('\n') || *tmpPtr == TEXT('\r')) ) tmpPtr--; tmpPtr++; *tmpPtr = TEXT('\0'); StrCpy( str, tmpStr ); LocalFree( tmpStr ); return str; } BOOL FreeAssociations( ) { if( assocList == (HDPA)NULL ) return FALSE; int assocCount = DPA_GetPtrCount( assocList ); for(int i=0; iLoad() == TRUE ) DPA_InsertPtr( assocList, 0x7FFF, (LPVOID)ptr); else { delete ptr; ptr = NULL; } RegCloseKey( hKey ); } // Check if this association needs to be protected. // - uses DDE // - has clsid // - has protected key. if(ptr) { StrCpy(tmpKey, buffer); StrCat(tmpKey, TEXT("\\shell\\open\\ddeexec") ); // wnsprintf(tmpKey, ARRAYSIZE(tmpKey), TEXT("%s\\shell\\open\\ddeexec"), buffer); lResult = RegOpenKeyEx( HKEY_CLASSES_ROOT, tmpKey, 0, KEY_QUERY_VALUE | KEY_READ, &hKey); if( lResult == ERROR_SUCCESS ) { ptr->m_safe = TRUE; RegCloseKey( hKey ); goto Cont; } StrCpy(tmpKey, buffer); StrCat(tmpKey, TEXT("\\clsid") ); //wnsprintf(tmpKey, ARRAYSIZE(tmpKey), TEXT("%s\\clsid"), buffer); lResult = RegOpenKeyEx( HKEY_CLASSES_ROOT, tmpKey, 0, KEY_QUERY_VALUE | KEY_READ, &hKey); if( lResult == ERROR_SUCCESS ) { ptr->m_safe = TRUE; RegCloseKey( hKey ); goto Cont; } StrCpy(tmpKey, buffer); StrCat(tmpKey, TEXT("\\protected") ); // wnsprintf(tmpKey, ARRAYSIZE(tmpKey), TEXT("%s\\protected"), buffer); lResult = RegOpenKeyEx( HKEY_CLASSES_ROOT, tmpKey, 0, KEY_QUERY_VALUE | KEY_READ, &hKey); if( lResult == ERROR_SUCCESS ) { ptr->m_safe = TRUE; RegCloseKey( hKey ); } } Cont: index++; } } if( tmpKey ) LocalFree( tmpKey ); if( buffer ) LocalFree( buffer ); return TRUE; } BOOL FreeMimeTypes( ) { if( mimeList == NULL ) return FALSE; int mimeCount = DPA_GetPtrCount( mimeList ); for(int i=0; im_exts = (TCHAR *)LocalAlloc( LPTR, (dwLen+1)*sizeof(TCHAR)); StrCpy(ptr->m_exts, buffer); } RegCloseKey( hKey ); } DPA_InsertPtr(mimeList, 0x7FFF, (LPVOID)ptr); index++; } } RegCloseKey( hKeyMime ); } if( buffer ) LocalFree( buffer ); return TRUE; } BOOL PrintAssociations() { printf("Listing Associations:\n"); if( !assocList ) return FALSE; int assocCount = DPA_GetPtrCount( assocList ); for(int i=0; iPrint(); } return TRUE; } BOOL FindCommand(HWND hDlg) { TCHAR szFile[MAX_PATH] = TEXT(""); TCHAR szFilter[5]; OPENFILENAME ofn; HWND hCmnd = GetDlgItem(hDlg, IDC_DOC_CMND ); memset((void*)&szFilter, 0, 5*sizeof(TCHAR)); szFilter[0] = TCHAR('*'); szFilter[2] = TCHAR('*'); memset((void*)&ofn, 0, sizeof(ofn)); ofn.lpstrFilter = szFilter; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hDlg; ofn.lpstrFile = szFile; ofn.nMaxFile = MAX_PATH; ofn.lpstrInitialDir = NULL; ofn.Flags = OFN_HIDEREADONLY|OFN_CREATEPROMPT; if (GetOpenFileName(&ofn)) { SendMessage(hCmnd, EM_SETSEL, 0, -1); SendMessage(hCmnd, EM_REPLACESEL, 0, (LPARAM)szFile); } return TRUE; } int FindIndex(LPTSTR doc) { if( ! assocList ) return -1; int assocCount = DPA_GetPtrCount( assocList ); for(int i = 0; i< assocCount;i++ ) { CAssoc * ptr = (CAssoc *)DPA_FastGetPtr( assocList, i ); if( !StrCmp(doc, ptr->m_type ) ) return i; } return -1; } HDPA CreateDPAForExts( TCHAR * strPassed, int * error, CAssoc * existing) { HKEY hKey; int bFound = 0; HDPA hdpaExts = NULL; // Check for existing associations not created by IEUNIX // [.ext // (--reg-val-- "Application") // (content.type "mimetype" ) // (g_szIEUnix "g_szIEUnixTag" ) // ] EatSpaces(strPassed); if(strPassed && *strPassed) { TCHAR *strExt = DuplicateString( strPassed ); TCHAR *pos, *ptr = strExt; BOOL bCont = TRUE; while(bCont && *ptr) { pos = StrChr(ptr, TEXT(';')); if(pos) { bCont = ( *pos == TEXT(';') )? TRUE : FALSE; *pos = TEXT('\0'); } else { bCont = FALSE; } if( !hdpaExts ) hdpaExts = DPA_Create(4); DPA_InsertPtr( hdpaExts, 0x7FFF, (LPVOID)DuplicateString( ptr ) ); if(*ptr == TEXT('.') && *(ptr+1) ) { int assocCount, extCount; assocCount = DPA_GetPtrCount( assocList ); for( int i = 0; i< assocCount; i++ ) { CAssoc * pAssoc = (CAssoc*)DPA_FastGetPtr( assocList, i ); if( pAssoc->m_exts == NULL || pAssoc == existing ) continue; extCount = DPA_GetPtrCount(pAssoc->m_exts) ; for(int j=0;jm_exts, j ) ) ) { bFound = IDS_ERROR_EXTS_ALREADY_EXISTS; break; } } if( bFound ) break; } } else { // Extension must start with a '.' bFound = IDS_ERROR_NOT_AN_EXT; break; } ptr = pos+1; } if(strExt) LocalFree(strExt); } else bFound = IDS_ERROR_MISSING_EXTS; *error = bFound; // Error occured while checking extensions if( bFound ) { if(hdpaExts) FreeExtensions( hdpaExts ); return NULL; } return hdpaExts; } // Following functions are called in response to the // actions performed on the associations. AssocDel( HWND hDlg ) { int index = 0; int lbindex = 0; HWND lb = GetDlgItem( hDlg, IDC_DOC_LIST ); if( (lbindex = SendMessage( lb, LB_GETCURSEL, 0, 0 ) )!= LB_ERR ) { LPTSTR str = (LPTSTR)SendMessage(lb, LB_GETITEMDATA, lbindex, 0 ); if(str) { if( (index = FindIndex( str ) ) != -1 ) { CAssoc * ptr = (CAssoc *)DPA_FastGetPtr( assocList, index ); TCHAR question[MAX_PATH]; wnsprintf( question, ARRAYSIZE(question), TEXT("Are you Sure you want to delete '%s'?"), ptr->m_desc ); if( MessageBox( GetParent(hDlg), question, TEXT("Delete Association"), MB_YESNO ) == IDYES ) { CAssoc *pAssoc = (CAssoc *)DPA_DeletePtr( assocList, index ); // Add to List of deleted entries if( assocDelList == NULL ) assocDelList = DPA_Create(4); if( assocDelList != NULL ) DPA_InsertPtr( assocDelList, 0x7FFF, pAssoc ); SendMessage( lb, LB_DELETESTRING, lbindex, 0 ); InitAssocDialog( hDlg ); SwitchToNrmlMode( hDlg ); PropSheet_Changed(GetParent(hDlg),hDlg); LocalFree( str ); } } } } return TRUE; } #ifdef 0 AssocUpd( HWND hDlg ) { BOOL bFound = FALSE; TCHAR szTemp [1024]; TCHAR szTitle [80]; CAssoc *ptr = NULL; TCHAR *str; int index, len; HDPA hdpaExts = NULL; HWND lb = GetDlgItem( hDlg, IDC_DOC_LIST ); HWND exts = GetDlgItem( hDlg, IDC_DOC_EXTS ); HWND desc = GetDlgItem( hDlg, IDC_DOC_DESC ); HWND mime = GetDlgItem( hDlg, IDC_DOC_MIME ); HWND cmnd = GetDlgItem( hDlg, IDC_DOC_CMND ); MLLoadString(IDS_ERROR_REGISTRY_TITLE, szTitle, sizeof(szTitle)); // Get the pointer to existing associations. if(PGTI_FROM_HDLG(hDlg)->mode == UPDATING) { ptr = GetCurrentAssoc( hDlg ); } //Check for Description len = SendMessage( GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXTLENGTH, 0, 0 ); if( len > 0 ) { str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXT, len+1, (LPARAM)str ); ChopSpaces( str ); if( *str == TEXT('\0') ) { LocalFree(str); MLLoadString(IDS_ERROR_MISSING_DESC, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_DESC) ); return FALSE; } int assocCount = DPA_GetPtrCount( assocList ); for( int i= 0; im_cmnd ) == NULL ) { LocalFree(str); MLLoadString(IDS_ERROR_DESC_ALREADY_EXISTS, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_DESC) ); return FALSE; } } LocalFree(str); } else { MLLoadString(IDS_ERROR_MISSING_DESC, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_DESC) ); return FALSE; } //Check for MIME len = SendMessage( GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXTLENGTH, 0, 0 ); if( len > 0 ) { str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXT, len+1, (LPARAM)str ); ChopSpaces( str ); if( *str != TEXT('\0') ) { if( !StrChr( str, TEXT('/') ) ) { LocalFree(str); MLLoadString(IDS_ERROR_INVALID_MIME, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_MIME) ); return FALSE; } } LocalFree(str); } //Check for command line len = SendMessage( GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXTLENGTH, 0, 0 ); if( len > 0 ) { str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXT, len+1, (LPARAM)str ); ChopSpaces( str ); if( *str == TEXT('\0') ) { LocalFree(str); MLLoadString(IDS_ERROR_MISSING_CMND, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_CMND) ); return FALSE; } LocalFree(str); } else { MLLoadString(IDS_ERROR_MISSING_CMND, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_CMND) ); return FALSE; } // Check for extensions. // User entered may already have associations in the // registry. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_EXTS), WM_GETTEXTLENGTH, 0, 0 ); str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_EXTS), WM_GETTEXT, len+1, (LPARAM)str ); int error; if(!(hdpaExts = CreateDPAForExts(EatSpaces(str), &error, ptr))) { LocalFree( str ); MLLoadString(error, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_EXTS) ); return FALSE; } LocalFree( str ); // Check and Add CAssoc if we are inserting a new entry. if(PGTI_FROM_HDLG(hDlg)->mode == ADDING) { LPTSTR firstExt = (LPTSTR)DPA_FastGetPtr( hdpaExts, 0 ); int len = lstrlen( firstExt ) + lstrlen(g_szDocClass) + 1; str = (TCHAR *)LocalAlloc( LPTR, len*sizeof(TCHAR) ); StrCpy( str, firstExt+1 ); StrCat( str, g_szDocClass ); ptr = new CAssoc( str ); ptr->m_safe = FALSE; // Since we are adding this entry. DPA_InsertPtr( assocList, 0x7FFF, ptr ); LocalFree( str ); } // We are not able to add or retrieve Assoc from the List if( ptr == NULL || ptr->m_safe == TRUE ) { FreeExtensions( hdpaExts ); return FALSE; } // Start replacing components of the Associations. // Replace Extensions if(ptr->m_exts) FreeExtensions( ptr->m_exts ); ptr->m_exts = hdpaExts; // Replace mime type len = SendMessage( GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXTLENGTH, 0, 0 ); str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXT, len+1, (LPARAM)str ); if( ptr->m_mime ) LocalFree( ptr->m_mime ); ptr->m_mime = EatSpaces(str); // Replace Description len = SendMessage( GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXTLENGTH, 0, 0 ); str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXT, len+1, (LPARAM)str ); if( ptr->m_desc ) LocalFree( ptr->m_desc); ptr->m_desc = ChopSpaces(str); // Replace Command Line len = SendMessage( GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXTLENGTH, 0, 0 ); str = (TCHAR *)LocalAlloc( LPTR, (len+4)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXT, len+1, (LPARAM)str ); if( ptr->m_cmnd ) LocalFree( ptr->m_cmnd ); ptr->m_cmnd = ChopSpaces(str); if (ptr->m_stat == NEW) if (!StrStr(ptr->m_cmnd, TEXT("%1"))) lstrcat(ptr->m_cmnd, TEXT(" %1")); { DWORD dwCurChar; BOOL bPath = FALSE; for (dwCurChar = 0; dwCurChar < lstrlen(ptr->m_cmnd); dwCurChar++) { if (ptr->m_cmnd[dwCurChar] == TEXT('/')) { bPath = TRUE; } if (ptr->m_cmnd[dwCurChar] == TEXT(' ')) { break; } } if (bPath) // if it's file name with no path we assume it's in the user's PATH { CHAR szExeFile[MAX_PATH]; TCHAR szWarning[MAX_PATH + 128]; #ifndef UNICODE lstrcpyn(szExeFile, ptr->m_cmnd, dwCurChar + 1); #else WCHAR wszExeFile[MAX_PATH]; lstrcpyn(wszExeFile, ptr->m_cmnd, dwCurChar + 1); SHUnicodeToAnsi(wszExeFile, szExeFile, ARRAYSIZE(szExeFile)); #endif if (access(szExeFile, X_OK) != 0) { #ifndef UNICODE wsprintf(szWarning, TEXT("File %s is not an executable file."), szExeFile); #else wsprintf(szWarning, TEXT("File %s is not an executable file."), wszExeFile); #endif MessageBox( GetParent(hDlg), szWarning, TEXT("Warning"), MB_OK); } } } if (Button_GetCheck(GetDlgItem(hDlg, IDC_ASSOC_EDIT)) != BST_UNCHECKED) ptr->m_edit &= (~FTA_OpenIsSafe ); else ptr->m_edit |= FTA_OpenIsSafe; ptr->m_stat = UPD; InitAssocDialog( hDlg, ptr ); SwitchToNrmlMode( hDlg); // SetFocus to Ok button again SetFocus( GetDlgItem(GetParent( hDlg ), IDOK ) ); PropSheet_Changed(GetParent(hDlg),hDlg); return TRUE; } AssocAdd( HWND hDlg) { SwitchToAddMode( hDlg ); PropSheet_Changed(GetParent(hDlg),hDlg); return TRUE; } #endif // 0 CAssoc * GetCurrentAssoc( HWND hDlg ) { int index = 0; HWND lb = GetDlgItem( hDlg, IDC_DOC_LIST ); if( (index = SendMessage( lb, LB_GETCURSEL, 0, 0 ) )!= LB_ERR ) { TCHAR * str = (LPTSTR)SendMessage( lb, LB_GETITEMDATA, index, 0 ); if(!str) return NULL; if(str && *str) { if( (index = FindIndex( str ) ) != -1 ) { CAssoc * ptr = (CAssoc *)DPA_FastGetPtr( assocList, index ); return ptr; } } } return NULL; } SwitchToNrmlMode( HWND hDlg ) { PGTI_FROM_HDLG(hDlg)->mode = NORMAL; EnableWindow(GetDlgItem(hDlg,IDC_DOC_DESC), FALSE ); EnableWindow(GetDlgItem(hDlg,IDC_DOC_EXTS), FALSE ); EnableWindow(GetDlgItem(hDlg,IDC_DOC_MIME), FALSE ); EnableWindow(GetDlgItem(hDlg,IDC_DOC_CMND), FALSE ); EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_EDIT), FALSE ); if (IsAssocEnabled()) { CAssoc *pAssoc = GetCurrentAssoc( hDlg ); EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_ADD), TRUE ); if( pAssoc ) { if( pAssoc->m_safe ) { EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), FALSE); EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_UPD), FALSE ); } else { EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), TRUE ); EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_UPD), TRUE ); } } } else { EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), FALSE); EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_UPD), FALSE ); EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_ADD), FALSE ); } REMOVE_DEF_BORDER(hDlg, IDC_ASSOC_ADD ); REMOVE_DEF_BORDER(hDlg, IDC_ASSOC_UPD ); REMOVE_DEF_BORDER(hDlg, IDC_ASSOC_DEL ); SET_DEF_BORDER( GetParent(hDlg), IDOK ); return TRUE; } SwitchToAddMode( HWND hDlg ) { PGTI_FROM_HDLG(hDlg)->mode = ADDING; LPASSOCTABINFO pgti = (LPASSOCTABINFO)GetWindowLong(hDlg, DWL_USER); // Remove Selection from Listbox. SendMessage( GetDlgItem(hDlg, IDC_DOC_LIST), LB_SETCURSEL, (WPARAM)-1, 0); pgti->fInternalChange = TRUE; // Clear all the fields SendMessage( GetDlgItem(hDlg, IDC_DOC_DESC), WM_SETTEXT, 0, LPARAM( TEXT("")) ); SendMessage( GetDlgItem(hDlg, IDC_DOC_MIME), WM_SETTEXT, 0, LPARAM( TEXT("")) ); SendMessage( GetDlgItem(hDlg, IDC_DOC_EXTS), WM_SETTEXT, 0, LPARAM( TEXT("")) ); SendMessage( GetDlgItem(hDlg, IDC_DOC_CMND), WM_SETTEXT, 0, LPARAM( TEXT("")) ); // Default value Button_SetCheck( GetDlgItem( hDlg, IDC_ASSOC_EDIT), TRUE ); pgti->fInternalChange = FALSE; // Enable all edit windows EnableWindow(GetDlgItem(hDlg,IDC_DOC_DESC), TRUE); EnableWindow(GetDlgItem(hDlg,IDC_DOC_MIME), TRUE); EnableWindow(GetDlgItem(hDlg,IDC_DOC_EXTS), TRUE); EnableWindow(GetDlgItem(hDlg,IDC_DOC_CMND), TRUE); EnableWindow(GetDlgItem(hDlg,IDC_BROWSE ), TRUE); EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_EDIT ), TRUE); // Enable Add option EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_ADD), FALSE); EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_UPD), TRUE ); EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), FALSE); // Remove Default Border REMOVE_DEF_BORDER( GetParent(hDlg), IDOK ); REMOVE_DEF_BORDER( hDlg, IDC_ASSOC_ADD); REMOVE_DEF_BORDER( hDlg, IDC_ASSOC_DEL); SET_DEF_BORDER( hDlg, IDC_ASSOC_UPD ); SetFocus( GetDlgItem( hDlg, IDC_ASSOC_UPD ) ); return TRUE; } SwitchToUpdMode( HWND hDlg ) { if(PGTI_FROM_HDLG(hDlg)->mode != NORMAL ) return FALSE; PGTI_FROM_HDLG(hDlg)->mode = UPDATING; // Enable Upd option EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_ADD), TRUE ); EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_UPD), TRUE ); EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), TRUE ); // Remove Default Border REMOVE_DEF_BORDER( GetParent(hDlg), IDOK ); REMOVE_DEF_BORDER( hDlg, IDC_ASSOC_ADD); REMOVE_DEF_BORDER( hDlg, IDC_ASSOC_DEL); SET_DEF_BORDER( hDlg, IDC_ASSOC_UPD); return TRUE; } void ListBoxResetContents(HWND listBox) { int count = SendMessage( listBox, LB_GETCOUNT, 0, 0 ); for( int i= 0; i< count; i++ ) { LPSTR data = (LPSTR)SendMessage( listBox, LB_GETITEMDATA, i, 0 ); if( data ) LocalFree( data ); } SendMessage( listBox, LB_RESETCONTENT, 0, 0 ); } BOOL FAR PASCAL InitAssocDialog(HWND hDlg, CAssoc * current) { HRESULT hr = E_FAIL; HKEY hKey; HWND listBox = GetDlgItem( hDlg, IDC_DOC_LIST ); TCHAR * displayString; // Allocate memory for a structure which will hold all the info // gathered from this page // LPASSOCTABINFO pgti = (LPASSOCTABINFO)GetWindowLong(hDlg, DWL_USER); pgti->fInternalChange = FALSE; ListBoxResetContents( listBox ); if( assocList == NULL ) return FALSE; int assocCount = DPA_GetPtrCount( assocList ); for(int i = 0; i< assocCount; i++ ) { CAssoc * ptr = (CAssoc *)DPA_FastGetPtr( assocList, i ); int index = SendMessage( listBox, LB_ADDSTRING, 0, (LPARAM)ptr->m_desc ); SendMessage( listBox, LB_SETITEMDATA, index, (LPARAM)DuplicateString( ptr->m_type ) ); } if( i>0 ) SendMessage( listBox, LB_SETCURSEL, 0, 0 ); else { SendMessage( GetDlgItem(hDlg, IDC_DOC_DESC), WM_SETTEXT, 0, LPARAM( TEXT("")) ); SendMessage( GetDlgItem(hDlg, IDC_DOC_MIME), WM_SETTEXT, 0, LPARAM( TEXT("")) ); SendMessage( GetDlgItem(hDlg, IDC_DOC_EXTS), WM_SETTEXT, 0, LPARAM( TEXT("")) ); SendMessage( GetDlgItem(hDlg, IDC_DOC_CMND), WM_SETTEXT, 0, LPARAM( TEXT("")) ); // Default value Button_SetCheck( GetDlgItem( hDlg, IDC_ASSOC_EDIT), TRUE ); } // Add Strings to Mimetype dialog int mimeCount = 0; if( mimeList && (mimeCount = DPA_GetPtrCount(mimeList))) { for(i=0; i< mimeCount; i++) { CMime * ptr = (CMime *)DPA_FastGetPtr( mimeList , i ); SafeAddStringToComboBox( GetDlgItem(hDlg, IDC_DOC_MIME) , ptr->m_mime) ; } } if( current ) SendMessage( listBox, LB_SELECTSTRING, -1, (LPARAM)current->m_desc ); HandleSelChange( pgti ); SwitchToNrmlMode( hDlg ); if( IsAssocEnabled() && i > 0 ) EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), TRUE); else EnableWindow(GetDlgItem(hDlg,IDC_ASSOC_DEL), FALSE); return TRUE; } void HandleSelChange( LPASSOCTABINFO pgti, BOOL bApplChange ) { int index = 0; HWND hDlg = pgti->hDlg; TCHAR str[MAX_PATH] = TEXT(""); if( hDlg == NULL ) return; HWND exts = GetDlgItem( hDlg, IDC_DOC_EXTS ); HWND desc = GetDlgItem( hDlg, IDC_DOC_DESC ); HWND mime = GetDlgItem( hDlg, IDC_DOC_MIME ); HWND cmnd = GetDlgItem( hDlg, IDC_DOC_CMND ); HWND brws = GetDlgItem( hDlg, IDC_BROWSE ); HWND edit = GetDlgItem( hDlg, IDC_ASSOC_EDIT ); CAssoc * ptr = GetCurrentAssoc( hDlg ); if(ptr) { SendMessage( desc, WM_SETTEXT, 0, (LPARAM)ptr->m_desc ); SendMessage( mime, WM_SETTEXT, 0, (LPARAM)ptr->m_mime ); SendMessage( cmnd, WM_SETTEXT, 0, (LPARAM)ptr->m_cmnd ); // Create Extension List if( ptr->m_exts ) { int i, count = DPA_GetPtrCount( ptr->m_exts ); for(i=0;im_exts, i ) ); StrCat( str, TEXT(";") ); } SendMessage( exts, WM_SETTEXT, 0, (LPARAM)str ); } Button_SetCheck( GetDlgItem( hDlg, IDC_ASSOC_EDIT), !(ptr->m_edit & FTA_OpenIsSafe) ); EnableWindow( desc, !(ptr->m_safe) ); EnableWindow( exts, !(ptr->m_safe) ); EnableWindow( mime, !(ptr->m_safe) ); EnableWindow( cmnd, !(ptr->m_safe) ); EnableWindow( brws, !(ptr->m_safe) ); EnableWindow( edit, !(ptr->m_safe) ); pgti->fInternalChange = FALSE; // Change back to the NORMAL mode if not coming from // edit. SwitchToNrmlMode( hDlg ); } } BOOL AssocOnCommand(LPASSOCTABINFO pgti, UINT id, UINT nCmd) { switch (id) { case IDC_BROWSE: switch (nCmd ) { case BN_CLICKED: { FindCommand( pgti->hDlg ); break; } } break; case IDC_ASSOC_ADD: switch (nCmd ) { case BN_CLICKED: { ENTERASSOC enter; enter.pgti = pgti; enter.pszAssoc = NULL; DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_ENTER_ASSOC), pgti->hDlg, EnterAssocDlgProc, (LPARAM) &enter); InitAssocDialog( pgti->hDlg, GetCurrentAssoc( pgti->hDlg ) ); SwitchToNrmlMode( pgti->hDlg); // SetFocus to Ok button again SetFocus( GetDlgItem(GetParent( pgti->hDlg ), IDOK ) ); if (pgti->fChanged) { pgti->fChanged = FALSE; PropSheet_Changed(GetParent(pgti->hDlg),pgti->hDlg); } //AssocAdd( pgti->hDlg ); break; } } break; case IDC_ASSOC_UPD: switch (nCmd ) { case BN_CLICKED: { HWND lb = GetDlgItem( pgti->hDlg, IDC_DOC_LIST ); int index; if( (index = SendMessage( lb, LB_GETCURSEL, 0, 0 ) )!= LB_ERR ) { TCHAR * str = (LPTSTR)SendMessage( lb, LB_GETITEMDATA, index, 0 ); ENTERASSOC enter; if(!str) return FALSE; enter.pgti = pgti; enter.pszAssoc = str; DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_ENTER_ASSOC), pgti->hDlg, EnterAssocDlgProc, (LPARAM) &enter); InitAssocDialog( pgti->hDlg, GetCurrentAssoc( pgti->hDlg ) ); SwitchToNrmlMode( pgti->hDlg); // SetFocus to Ok button again SetFocus( GetDlgItem(GetParent( pgti->hDlg ), IDOK ) ); if (pgti->fChanged) { pgti->fChanged = FALSE; PropSheet_Changed(GetParent(pgti->hDlg),pgti->hDlg); } } //AssocUpd( pgti->hDlg ); break; } } break; case IDC_ASSOC_DEL: switch (nCmd ) { case BN_CLICKED: { AssocDel( pgti->hDlg ); break; } } break; case IDC_DOC_LIST: switch (nCmd ) { case LBN_SELCHANGE: HandleSelChange( pgti ); break; case LBN_DBLCLK: { HWND lb = GetDlgItem( pgti->hDlg, IDC_DOC_LIST ); int index; if( (index = SendMessage( lb, LB_GETCURSEL, 0, 0 ) )!= LB_ERR ) { TCHAR * str = (LPTSTR)SendMessage( lb, LB_GETITEMDATA, index, 0 ); ENTERASSOC enter; CAssoc *pAssoc = GetCurrentAssoc( pgti->hDlg ); if(!IsAssocEnabled() || pAssoc->m_safe || !str) return FALSE; enter.pgti = pgti; enter.pszAssoc = str; DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_ENTER_ASSOC), pgti->hDlg, EnterAssocDlgProc, (LPARAM) &enter); InitAssocDialog( pgti->hDlg, GetCurrentAssoc( pgti->hDlg ) ); SwitchToNrmlMode( pgti->hDlg); // SetFocus to Ok button again SetFocus( GetDlgItem(GetParent( pgti->hDlg ), IDOK ) ); if (pgti->fChanged) { pgti->fChanged = FALSE; PropSheet_Changed(GetParent(pgti->hDlg),pgti->hDlg); } } //AssocUpd( pgti->hDlg ); break; } } break; #ifdef 0 case IDC_DOC_MIME: switch (nCmd) { case CBN_SELCHANGE: case CBN_EDITCHANGE: if (!pgti->fInternalChange) { pgti->fChanged = TRUE; SwitchToUpdMode( pgti->hDlg ); } break; } break; case IDC_ASSOC_EDIT: switch (nCmd ) { case BN_CLICKED: { if (!pgti->fInternalChange) { pgti->fChanged = TRUE; SwitchToUpdMode( pgti->hDlg ); } break; } } break; case IDC_DOC_TYPE: case IDC_DOC_EXTS: case IDC_DOC_DESC: case IDC_DOC_CMND: switch (nCmd) { case EN_CHANGE: if (!pgti->fInternalChange) { pgti->fChanged = TRUE; SwitchToUpdMode( pgti->hDlg ); } break; case EN_SETFOCUS: if ( pgti->mode == ADDING) { SET_DEF_BORDER( pgti->hDlg, IDC_ASSOC_UPD ); break; } } break; #endif //0 } return FALSE; } void AssocApply(HWND hDlg) { // Delete the associations removed by the user. if( assocDelList ) { int count = DPA_GetPtrCount( assocDelList ); for(int i=0;iDelete(); delete pAssoc; } } DPA_Destroy( assocDelList ); assocDelList = NULL; } // Save the currently changed associations. if( assocList ) { int count = DPA_GetPtrCount( assocList ); for(int i=0;iSave(); } } } } /**************************************************************************** * * AssocDlgProc * * ***************************************************************************/ BOOL CALLBACK AssocDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { // get our tab info structure LPASSOCTABINFO pgti; if (uMsg == WM_INITDIALOG) { // Set Limits for edit fields SetEditLimits( hDlg ); // Allocate memory for a structure which will hold all the info // gathered from this page // LPASSOCTABINFO pgti = (LPASSOCTABINFO)LocalAlloc(LPTR, sizeof(ASSOCINFO)); if (!pgti) { EndDialog(hDlg, 0); return FALSE; } pgti->hDlg = hDlg; pgti->mode = NORMAL; pgti->fInternalChange = FALSE; SetWindowLong(hDlg, DWL_USER, (LPARAM)pgti); // Create an association array from registry LoadAssociations(); LoadMimeTypes(); // Initailize dialog if( InitAssocDialog(hDlg) ) { HandleSelChange(pgti); return TRUE; } else { TCHAR szTitle[MAX_PATH]; MLLoadString(IDS_ERROR_REGISTRY_TITLE, szTitle, sizeof(szTitle)); MessageBox( GetParent(hDlg), TEXT("Cannot read associations from registry."), szTitle, MB_OK ); return FALSE; } } else pgti = (LPASSOCTABINFO)GetWindowLong(hDlg, DWL_USER); if (!pgti) return FALSE; switch (uMsg) { case WM_NOTIFY: { NMHDR *lpnm = (NMHDR *) lParam; switch (lpnm->code) { case PSN_QUERYCANCEL: case PSN_KILLACTIVE: case PSN_RESET: SetWindowLong( hDlg, DWL_MSGRESULT, FALSE ); return TRUE; case PSN_APPLY: AssocApply(hDlg); break; } break; } case WM_COMMAND: AssocOnCommand(pgti, LOWORD(wParam), HIWORD(wParam)); break; case WM_HELP: // F1 //ResWinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE, // HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs); break; case WM_CONTEXTMENU: // right mouse click //ResWinHelp( (HWND) wParam, IDS_HELPFILE, // HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs); break; case WM_DESTROY: #if 0 RemoveDefaultDialogFont(hDlg); #endif if (pgti) LocalFree(pgti); // Remove Associated data items for the listbos items. ListBoxResetContents( GetDlgItem( hDlg, IDC_DOC_LIST ) ); // Delete registry information FreeAssociations(); FreeMimeTypes(); SetWindowLong(hDlg, DWL_USER, (LONG)NULL); // make sure we don't re-enter break; } return FALSE; } BOOL AssocEnter( HWND hDlg ) { LPASSOCTABINFO pgti = ((LPENTERASSOC)GetWindowLong(hDlg, DWL_USER))->pgti; BOOL bFound = FALSE; TCHAR szTemp [1024]; TCHAR szTitle [80]; CAssoc *ptr = NULL; TCHAR *str; int index, len; HDPA hdpaExts = NULL; HWND exts = GetDlgItem( hDlg, IDC_DOC_EXTS ); HWND desc = GetDlgItem( hDlg, IDC_DOC_DESC ); HWND mime = GetDlgItem( hDlg, IDC_DOC_MIME ); HWND cmnd = GetDlgItem( hDlg, IDC_DOC_CMND ); MLLoadString(IDS_ERROR_REGISTRY_TITLE, szTitle, sizeof(szTitle)); // Get the pointer to existing associations. if(GetWindowLong(hDlg, DWL_USER)) { TCHAR *pszAssoc = ((LPENTERASSOC)GetWindowLong(hDlg, DWL_USER))->pszAssoc; if(pszAssoc && *pszAssoc) if( (index = FindIndex( pszAssoc ) ) != -1 ) ptr = (CAssoc *)DPA_FastGetPtr( assocList, index ); } //Check for Description len = SendMessage( GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXTLENGTH, 0, 0 ); if( len > 0 ) { str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXT, len+1, (LPARAM)str ); ChopSpaces( str ); if( *str == TEXT('\0') ) { LocalFree(str); MLLoadString(IDS_ERROR_MISSING_DESC, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_DESC) ); return FALSE; } int assocCount = DPA_GetPtrCount( assocList ); for( int i= 0; im_cmnd ) == NULL ) { LocalFree(str); MLLoadString(IDS_ERROR_DESC_ALREADY_EXISTS, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_DESC) ); return FALSE; } } LocalFree(str); } else { MLLoadString(IDS_ERROR_MISSING_DESC, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_DESC) ); return FALSE; } //Check for MIME len = SendMessage( GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXTLENGTH, 0, 0 ); if( len > 0 ) { str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXT, len+1, (LPARAM)str ); ChopSpaces( str ); if( *str != TEXT('\0') ) { if( !StrChr( str, TEXT('/') ) ) { LocalFree(str); MLLoadString(IDS_ERROR_INVALID_MIME, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_MIME) ); return FALSE; } } LocalFree(str); } //Check for command line len = SendMessage( GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXTLENGTH, 0, 0 ); if( len > 0 ) { str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXT, len+1, (LPARAM)str ); ChopSpaces( str ); if( *str == TEXT('\0') ) { LocalFree(str); MLLoadString(IDS_ERROR_MISSING_CMND, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_CMND) ); return FALSE; } LocalFree(str); } else { MLLoadString(IDS_ERROR_MISSING_CMND, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_CMND) ); return FALSE; } // Check for extensions. // User entered may already have associations in the // registry. len = SendMessage( GetDlgItem(hDlg, IDC_DOC_EXTS), WM_GETTEXTLENGTH, 0, 0 ); str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_EXTS), WM_GETTEXT, len+1, (LPARAM)str ); int error; if(!(hdpaExts = CreateDPAForExts(EatSpaces(str), &error, ptr))) { LocalFree( str ); MLLoadString(error, szTemp, sizeof(szTemp)); MessageBox(GetParent(hDlg), szTemp, szTitle, MB_OK); SetFocus( GetDlgItem(hDlg, IDC_DOC_EXTS) ); return FALSE; } LocalFree( str ); // Check and Add CAssoc if we are inserting a new entry. if(!((LPENTERASSOC)GetWindowLong(hDlg, DWL_USER))->pszAssoc) { LPTSTR firstExt = (LPTSTR)DPA_FastGetPtr( hdpaExts, 0 ); int len = lstrlen( firstExt ) + lstrlen(g_szDocClass) + 1; str = (TCHAR *)LocalAlloc( LPTR, len*sizeof(TCHAR) ); StrCpy( str, firstExt+1 ); StrCat( str, g_szDocClass ); ptr = new CAssoc( str ); ptr->m_safe = FALSE; // Since we are adding this entry. DPA_InsertPtr( assocList, 0x7FFF, ptr ); LocalFree( str ); } // We are not able to add or retrieve Assoc from the List if( ptr == NULL || ptr->m_safe == TRUE ) { FreeExtensions( hdpaExts ); return FALSE; } // Start replacing components of the Associations. // Replace Extensions if(ptr->m_exts) FreeExtensions( ptr->m_exts ); ptr->m_exts = hdpaExts; // Replace mime type len = SendMessage( GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXTLENGTH, 0, 0 ); str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_MIME), WM_GETTEXT, len+1, (LPARAM)str ); if( ptr->m_mime ) LocalFree( ptr->m_mime ); ptr->m_mime = EatSpaces(str); // Replace Description len = SendMessage( GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXTLENGTH, 0, 0 ); str = (TCHAR *)LocalAlloc( LPTR, (len+1)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_DESC), WM_GETTEXT, len+1, (LPARAM)str ); if( ptr->m_desc ) LocalFree( ptr->m_desc); ptr->m_desc = ChopSpaces(str); // Replace Command Line len = SendMessage( GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXTLENGTH, 0, 0 ); str = (TCHAR *)LocalAlloc( LPTR, (len+4)*sizeof(TCHAR) ); SendMessage(GetDlgItem(hDlg, IDC_DOC_CMND), WM_GETTEXT, len+1, (LPARAM)str ); if( ptr->m_cmnd ) LocalFree( ptr->m_cmnd ); ptr->m_cmnd = ChopSpaces(str); if (ptr->m_stat == NEW) if (!StrStr(ptr->m_cmnd, TEXT("%1"))) lstrcat(ptr->m_cmnd, TEXT(" %1")); { DWORD dwCurChar; BOOL bPath = FALSE; for (dwCurChar = 0; dwCurChar < lstrlen(ptr->m_cmnd); dwCurChar++) { if (ptr->m_cmnd[dwCurChar] == TEXT('/')) { bPath = TRUE; } if (ptr->m_cmnd[dwCurChar] == TEXT(' ')) { break; } } if (bPath) // if it's file name with no path we assume it's in the user's PATH { CHAR szExeFile[MAX_PATH]; TCHAR szWarning[MAX_PATH + 128]; #ifndef UNICODE lstrcpyn(szExeFile, ptr->m_cmnd, dwCurChar + 1); #else WCHAR wszExeFile[MAX_PATH]; lstrcpyn(wszExeFile, ptr->m_cmnd, dwCurChar + 1); SHUnicodeToAnsi(wszExeFile, szExeFile, ARRAYSIZE(szExeFile)); #endif if (access(szExeFile, X_OK) != 0) { #ifndef UNICODE wsprintf(szWarning, TEXT("File %s is not an executable file."), szExeFile); #else wsprintf(szWarning, TEXT("File %s is not an executable file."), wszExeFile); #endif MessageBox( GetParent(hDlg), szWarning, TEXT("Warning"), MB_OK); } } } if (Button_GetCheck(GetDlgItem(hDlg, IDC_ASSOC_EDIT)) != BST_UNCHECKED) ptr->m_edit &= (~FTA_OpenIsSafe ); else ptr->m_edit |= FTA_OpenIsSafe; ptr->m_stat = UPD; pgti->fChanged = TRUE; return TRUE; } BOOL FAR PASCAL InitEnterAssocDialog(HWND hDlg, LPENTERASSOC penter) { LPASSOCTABINFO pgti = penter->pgti; int index = 0; HWND hDlgParent = pgti->hDlg; TCHAR str[MAX_PATH] = TEXT(""); if( hDlg == NULL ) return; HWND exts = GetDlgItem( hDlg, IDC_DOC_EXTS ); HWND desc = GetDlgItem( hDlg, IDC_DOC_DESC ); HWND mime = GetDlgItem( hDlg, IDC_DOC_MIME ); HWND cmnd = GetDlgItem( hDlg, IDC_DOC_CMND ); HWND brws = GetDlgItem( hDlg, IDC_BROWSE ); HWND edit = GetDlgItem( hDlg, IDC_ASSOC_EDIT ); CAssoc * ptr = NULL; if(penter->pszAssoc && *(penter->pszAssoc)) if( (index = FindIndex( penter->pszAssoc ) ) != -1 ) ptr = (CAssoc *)DPA_FastGetPtr( assocList, index ); if(ptr) { SendMessage( desc, WM_SETTEXT, 0, (LPARAM)ptr->m_desc ); SendMessage( mime, WM_SETTEXT, 0, (LPARAM)ptr->m_mime ); SendMessage( cmnd, WM_SETTEXT, 0, (LPARAM)ptr->m_cmnd ); // Create Extension List if( ptr->m_exts ) { int i, count = DPA_GetPtrCount( ptr->m_exts ); for(i=0;im_exts, i ) ); StrCat( str, TEXT(";") ); } SendMessage( exts, WM_SETTEXT, 0, (LPARAM)str ); } Button_SetCheck( GetDlgItem( hDlg, IDC_ASSOC_EDIT), !(ptr->m_edit & FTA_OpenIsSafe) ); EnableWindow( desc, !(ptr->m_safe) ); EnableWindow( exts, !(ptr->m_safe) ); EnableWindow( mime, !(ptr->m_safe) ); EnableWindow( cmnd, !(ptr->m_safe) ); EnableWindow( brws, !(ptr->m_safe) ); EnableWindow( edit, !(ptr->m_safe) ); pgti->fInternalChange = FALSE; } SetWindowLong(hDlg, DWL_USER, (LPARAM)penter); int mimeCount = 0; if( mimeList && (mimeCount = DPA_GetPtrCount(mimeList))) { for(int i=0; i< mimeCount; i++) { CMime * ptr = (CMime *)DPA_FastGetPtr( mimeList , i ); SafeAddStringToComboBox( GetDlgItem(hDlg, IDC_DOC_MIME) , ptr->m_mime) ; } } } BOOL EnterAssocOnCommand(HWND hDlg, UINT id, UINT nCmd, BOOL *pbChanged) { switch (id) { case IDC_BROWSE: switch (nCmd ) { case BN_CLICKED: { FindCommand( hDlg ); break; } } break; case IDOK: switch (nCmd ) { case BN_CLICKED: { SwitchToUpdMode(GetParent(hDlg)); if (!*pbChanged || AssocEnter(hDlg)) return EndDialog(hDlg, 0); else break; } } break; case IDCANCEL: switch (nCmd ) { case BN_CLICKED: { return EndDialog(hDlg, 0); } } break; case IDC_DOC_MIME: switch (nCmd) { case CBN_SELCHANGE: case CBN_EDITCHANGE: if (!*pbChanged) { *pbChanged = TRUE; } break; } break; case IDC_ASSOC_EDIT: switch (nCmd ) { case BN_CLICKED: { if (!*pbChanged) { *pbChanged = TRUE; } break; } } break; case IDC_DOC_TYPE: case IDC_DOC_EXTS: case IDC_DOC_DESC: case IDC_DOC_CMND: switch (nCmd) { case EN_CHANGE: if (!*pbChanged) { *pbChanged = TRUE; } break; } break; } return FALSE; } BOOL CALLBACK EnterAssocDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static BOOL bChanged; if (uMsg == WM_INITDIALOG) { SendMessage(GetDlgItem( hDlg, IDC_DOC_MIME ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0); SendMessage(GetDlgItem( hDlg, IDC_DOC_EXTS ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0); SendMessage(GetDlgItem( hDlg, IDC_DOC_DESC ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0); SendMessage(GetDlgItem( hDlg, IDC_DOC_CMND ), EM_LIMITTEXT, (WPARAM) MAX_PATH-1, 0); InitEnterAssocDialog(hDlg, (LPENTERASSOC)lParam); bChanged = FALSE; } switch (uMsg) { case WM_COMMAND: return EnterAssocOnCommand(hDlg, LOWORD(wParam), HIWORD(wParam), &bChanged); break; } return FALSE; }