Ejemplo n.º 1
0
void CMainWnd::MakeOpenFilter(LPTSTR* ppszFilter, BOOL fGsGetFile)
{
	CTempStr str;
	TCHAR szExt[MAX_PATH];
	TCHAR szExtDesc[MAX_PATH];
	TCHAR szTemp[MAX_PATH * 2];
	MAP_DEC_PLUGIN* pPlugIn;

	EXT_INFO* pExt;
	CMultiBuff extbuff;

	BOOL fFound;
	int i, j;
	int nBuf = OPEN_FILTER_BUF;
	int nPlugIn = MAP_GetDecoderPlugInCount(m_hMap);
	int nExt;

	*ppszFilter = new TCHAR[nBuf];
	*ppszFilter[0] = NULL;

	if (fGsGetFile) {
		str.LoadNormal(IDS_FILTER_OPEN_SUPPORTED);
		_tcscpy(*ppszFilter, str);
	}

	for (i = 0; i < nPlugIn; i++) {
		pPlugIn = MAP_GetDecoderPlugIn(m_hMap, i);
		if (!pPlugIn)
			continue;

		nExt = pPlugIn->GetFileExtCount();
		for (j = 0; j < nExt; j++) {
			memset(szExt, 0, sizeof(szExt));
			memset(szExtDesc, 0, sizeof(szExtDesc));
			if (pPlugIn->GetFileExt(j, szExt, szExtDesc) && _tcslen(szExt)) {
				if (!IsDefSupportedExt(szExt)) {
					fFound = FALSE;
					for (int k = 0; k < extbuff.GetCount(); k++) {
						pExt = (EXT_INFO*)extbuff.GetAt(k);
						if (_tcsicmp(pExt->szExt, szExt) == 0) {
							fFound = TRUE;
							break;
						}
					}
					if (!fFound) {
						if (fGsGetFile) {
							if (nBuf - 1 < (int)(_tcslen(*ppszFilter) + _tcslen(szExt) + 3)) {
								nBuf += OPEN_FILTER_BUF;
								LPTSTR pszNew = new TCHAR[nBuf];
								_tcscpy(pszNew, *ppszFilter);
								delete *ppszFilter;
								*ppszFilter = pszNew;
							}

							_tcscat(*ppszFilter, _T(";*."));
							_tcscat(*ppszFilter, szExt);
						}

						pExt = new EXT_INFO;
						_tcscpy(pExt->szExt, szExt);
						_tcscpy(pExt->szExtDesc, szExtDesc);
						extbuff.Add((DWORD)pExt);
					}
				}
			}
		}
	}

	str.LoadNormal(IDS_FILTER_OPEN_INTERNAL);
	if (nBuf - 1 < (int)(_tcslen(*ppszFilter) + _tcslen(str))) {
		nBuf += OPEN_FILTER_BUF;
		LPTSTR pszNew = new TCHAR[nBuf];
		_tcscpy(pszNew, *ppszFilter);
		delete *ppszFilter;
		*ppszFilter = pszNew;
	}
	if (_tcslen(*ppszFilter))
		_tcscat(*ppszFilter, str);
	else
		_tcscpy(*ppszFilter, (LPTSTR)str + 1);

	while (!extbuff.IsEmpty()) {
		pExt = (EXT_INFO*)extbuff.RemoveAt(0);
		if (!_tcslen(pExt->szExtDesc)) {
			str.LoadNormal(IDS_FMT_NULL_FILE_TYPE);
			wsprintf(pExt->szExtDesc, str, pExt->szExt, pExt->szExt);
		}
		wsprintf(szTemp, _T("|%s|*.%s"), pExt->szExtDesc, pExt->szExt);
		if (nBuf - 1 < (int)(_tcslen(*ppszFilter) + _tcslen(szTemp))) {
			nBuf += OPEN_FILTER_BUF;
			LPTSTR pszNew = new TCHAR[nBuf];
			_tcscpy(pszNew, *ppszFilter);
			delete *ppszFilter;
			*ppszFilter = pszNew;
		}
		_tcscat(*ppszFilter, szTemp);

		delete pExt;
	}

	str.LoadNormal(IDS_FILTER_OPEN_ALL);
	if (nBuf - 1 < (int)(_tcslen(*ppszFilter) + _tcslen(str))) {
		nBuf += OPEN_FILTER_BUF;
		LPTSTR pszNew = new TCHAR[nBuf];
		_tcscpy(pszNew, *ppszFilter);
	}
	_tcscat(*ppszFilter, str);

	LPTSTR psz = *ppszFilter;
	while (psz = _tcschr(psz, _T('|'))) {
		*psz++ = NULL;
	}
}
Ejemplo n.º 2
0
LRESULT CDlgFileAssoc::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) {

	switch (uMsg) {
		
		case WM_INITDIALOG: {

#ifdef SHELL_AYGSHELL
			// Initializes menubar		
			SHMENUBARINFO mbi;
			memset(&mbi, 0, sizeof(SHMENUBARINFO));
			mbi.cbSize = sizeof(SHMENUBARINFO);
			mbi.hwndParent = hWnd;
			mbi.nToolBarId = MNU_OKCANCEL;
			mbi.hInstRes = player()->hInstance;
			mbi.nBmpId = 0;
			mbi.cBmpImages = 0;
			if (SHCreateMenuBar(&mbi)) {
				hWndMenuBar = mbi.hwndMB;
				SetSoftkeyText(hWndMenuBar, 0, _str(STR_CANCEL));
				SetSoftkeyText(hWndMenuBar, 1, _str(STR_OK));
			} else {
				hWndMenuBar = NULL;
			}
#else
            hWndMenuBar = NULL;
#endif

#ifdef SHELL_AYGSHELL
			// Initializes fullscreen dialog
			SHINITDLGINFO shidi;
			shidi.dwMask = SHIDIM_FLAGS;
			shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN|SHIDIF_DONEBUTTON|SHIDIF_WANTSCROLLBAR;
			shidi.hDlg = hWnd;
			SHInitDialog(&shidi);
#endif

			SetWindowText(hWnd, _str(STR_FILEASSOCIATIONS));
			SetDlgItemText(hWnd, LBL_USETOOPEN, _str(STR_USENITROGENTOOPE));
			SetDlgItemText(hWnd, BTN_SELALL, _str(STR_SELECTALL));
			SetDlgItemText(hWnd, BTN_SELNONE, _str(STR_SELECTNONE));
			SetDlgItemText(hWnd, LBL_NOTRUNNING, _str(STR_IFTHEPLAYERISNOT));
			SetDlgItemText(hWnd, LBL_RUNNING, _str(STR_IFTHEPLAYERISALR));

			int rActions[3] = {STR_SETFILEASPLAYLIS, STR_ADDFILETOPLAYLIS, STR_SETFOLDERASPLAYL};
			for (int i = 0; i < 3; i++) {
				SendDlgItemMessage(hWnd, CBB_NOTRUNNING, CB_ADDSTRING, 0, (LPARAM)_str(rActions[i]));
				SendDlgItemMessage(hWnd, CBB_RUNNING, CB_ADDSTRING, 0, (LPARAM)_str(rActions[i]));
			}

			SendDlgItemMessage(hWnd, CBB_NOTRUNNING, CB_SETCURSEL, (WPARAM)player()->lpConfig->cf.FileAssNotRunning, 0);
			SendDlgItemMessage(hWnd, CBB_RUNNING, CB_SETCURSEL, (WPARAM)player()->lpConfig->cf.FileAssRunning, 0);

			ListView_SetExtendedListViewStyle(GetDlgItem(hWnd, LST_EXTENSIONS), LVS_EX_CHECKBOXES|LVS_EX_FULLROWSELECT);
		
			LVCOLUMN nCol;
			memset(&nCol, 0, sizeof(LVCOLUMN));
			nCol.mask = LVCF_TEXT;
			nCol.pszText = NULL;
			ListView_InsertColumn(GetDlgItem(hWnd, LST_EXTENSIONS), 0, &nCol);

			LPWSTR assc[4] = {L"Skin files (*.sk2)", L"MPEG Layer-3 files (*.mp3)", L"Ogg Vorbis files (*.ogg)", L"Wave Audio files (*.wav)"};
			LPWSTR exts[4] = {L"sk2", L"mp3", L"ogg", L"wav"};

			int y = 0;

			for (int i = 0; i < 4; i++) {
				LVITEM nItem;
				memset(&nItem, 0, sizeof(LVITEM));
				nItem.mask = LVIF_TEXT;
				nItem.iSubItem = 0;
				nItem.pszText = assc[i];
				nItem.iItem = y;
				ListView_InsertItem(GetDlgItem(hWnd, LST_EXTENSIONS), &nItem);
				PrevAssoc[y] = IsExtAssignedDyn(exts[i]);
				if (PrevAssoc[y]) {
					ListView_SetCheckState(GetDlgItem(hWnd, LST_EXTENSIONS), y, true);
				}
				y++;
			}
			for (int i = 0; i < MAP_GetDecoderPlugInCount(player()->MAP); i++) {

				MAP_DEC_PLUGIN * mplug = MAP_GetDecoderPlugIn(player()->MAP, i);
				
				for (int x = 0; x < mplug->GetFileExtCount(); x++) {

					TCHAR ExtName[MAX_PATH];
					TCHAR ExtDesc[MAX_PATH];
					mplug->GetFileExt(x, ExtName, ExtDesc);
					LVITEM nItem;
					memset(&nItem, 0, sizeof(LVITEM));
					nItem.mask = LVIF_TEXT;
					nItem.iSubItem = 0;
					nItem.pszText = ExtDesc;
					nItem.iItem = y;
					
					ListView_InsertItem(GetDlgItem(hWnd, LST_EXTENSIONS), &nItem);	
					PrevAssoc[y] = IsExtAssignedDyn(ExtName);
					if (PrevAssoc[y]) {
						ListView_SetCheckState(GetDlgItem(hWnd, LST_EXTENSIONS), y, true);
					}

					y++;
				}
			}

			RECT rc;
			GetClientRect(GetDlgItem(hWnd, LST_EXTENSIONS), &rc);
			ListView_SetColumnWidth(GetDlgItem(hWnd, LST_EXTENSIONS), 0, rc.right-rc.left);

			break;

		}

 		case WM_COMMAND: {

			int wmId = LOWORD(wParam); 
			if ((wmId == IDM_OK) || (wmId == IDOK)) {

				player()->lpConfig->cf.FileAssNotRunning = SendDlgItemMessage(hWnd, CBB_NOTRUNNING, CB_GETCURSEL, 0, 0);
				player()->lpConfig->cf.FileAssRunning = SendDlgItemMessage(hWnd, CBB_RUNNING, CB_GETCURSEL, 0, 0);
				
				LPWSTR exts[4] = {L"sk2", L"mp3", L"ogg", L"wav"};
				for (int i = 0; i < 4; i++) {
					
					bool NewAssoc = ListView_GetCheckState(GetDlgItem(hWnd, LST_EXTENSIONS), i);

					if (NewAssoc && !PrevAssoc[i]) {
						ExtAssignDyn(exts[i], L"\"%1\"", 102+(int)(i == 0));
					}

					if (!NewAssoc && PrevAssoc[i]) {
						ExtUnassignDyn(exts[i]);
					}

				}

				int y = 4;

				for (int i = 0; i < MAP_GetDecoderPlugInCount(player()->MAP); i++) {
		
					MAP_DEC_PLUGIN * mplug = MAP_GetDecoderPlugIn(player()->MAP, i);
				
					for (int x = 0; x < mplug->GetFileExtCount(); x++) {

						bool NewAssoc = ListView_GetCheckState(GetDlgItem(hWnd, LST_EXTENSIONS), y);
	
						TCHAR ExtName[MAX_PATH];
						TCHAR ExtDesc[MAX_PATH];
						mplug->GetFileExt(x, ExtName, ExtDesc);
						
						if (NewAssoc && !PrevAssoc[y]) {
							ExtAssignDyn(ExtName, L"\"%1\"", 102);
						}

						if (!NewAssoc && PrevAssoc[y]) {
							ExtUnassignDyn(ExtName);
						}

						y++;
					}
				}

				EndDialog(hWnd, 0);

			} else if (wmId == BTN_SELALL) {
		
				HWND ls = GetDlgItem(hWnd, LST_EXTENSIONS);
				for (int i = 0; i < ListView_GetItemCount(ls); i++) {
					ListView_SetCheckState(ls, i, true);
				}

			} else if (wmId == BTN_SELNONE) {
		
				HWND ls = GetDlgItem(hWnd, LST_EXTENSIONS);
				for (int i = 0; i < ListView_GetItemCount(ls); i++) {
					ListView_SetCheckState(ls, i, false);
				}

			} else if (wmId == IDM_CANCEL) {
			
				EndDialog(hWnd, 0);
			
			}

			break;
		}

		case WM_DESTROY:
			CommandBar_Destroy(hWndMenuBar);
			break;

		case WM_ACTIVATE:
			
			if ((wParam == WA_INACTIVE) && ((HWND)lParam == player()->lpWndMain->hWnd)) {
				EndDialog(hWnd, 0);
			} else {
				return DefWindowProc(hWnd, uMsg, wParam, lParam);
			}
			break;

		default:
			DefWindowProc(hWnd, uMsg, wParam, lParam);
	}

	return 0;
}