コード例 #1
0
ファイル: Source.cpp プロジェクト: kenjinote/SHA-1
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static HWND hList;
	static HFONT hFont;
	static DWORD dwSplitLine;
	switch (msg)
	{
	case WM_CREATE:
		InitCommonControls();
		hFont = CreateFont(26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS ゴシック"));
		hList = CreateWindowEx(0, TEXT("LISTBOX"), 0, WS_VISIBLE | WS_CHILD | WS_VSCROLL | LBS_NOINTEGRALHEIGHT | LBS_OWNERDRAWFIXED | LBS_EXTENDEDSEL | LBS_MULTIPLESEL, 0, 0, 0, 0, hWnd, (HMENU)IDC_LIST, ((LPCREATESTRUCT)lParam)->hInstance, 0);
		SendMessage(hList, WM_SETFONT, (WPARAM)hFont, 0);
		EditDefProc = (WNDPROC)SetWindowLong(hList, GWL_WNDPROC, (LONG)ListProc);
		{
			int n;
			LPTSTR* argv = CommandLineToArgvW(GetCommandLine(), &n);
			for (int i = 1; i<n; i++)
			{
				CalcSha1(hList, argv[i]);
				const DWORD dwTempWidth = GetStringWidth(hList, PathFindFileName(argv[i]));
				if (dwTempWidth>dwSplitLine)dwSplitLine = dwTempWidth;
			}
			if (argv) GlobalFree(argv);
			const DWORD dwLastItem = SendMessage(hList, LB_GETCOUNT, 0, 0);
			SendMessage(hList, LB_SELITEMRANGE, TRUE, MAKELPARAM(0, dwLastItem - 1));
		}
		DragAcceptFiles(hWnd, TRUE);
		break;
	case WM_ERASEBKGND:
		return 1;
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case ID_COPYTOCLIPBOARD:
		{
			const int nSelItems = SendMessage(hList, LB_GETSELCOUNT, 0, 0);
			if (nSelItems > 0)
			{
				int* pBuffer = (int*)GlobalAlloc(0, sizeof(int) * nSelItems);
				SendMessage(hList, LB_GETSELITEMS, nSelItems, (LPARAM)pBuffer);
				INT nLen = 0;
				for (int i = 0; i < nSelItems; i++)
				{
					DATA* pData = (DATA*)SendMessage(hList, LB_GETITEMDATA, pBuffer[i], 0);
					nLen += lstrlen(pData->szFilePath);
					nLen += lstrlen(pData->szHashValue);
					nLen += 3;
				}
				HGLOBAL hMem = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, sizeof(TCHAR)*(nLen + 1));
				LPTSTR lpszBuflpszBuf = (LPTSTR)GlobalLock(hMem);
				lpszBuflpszBuf[0] = 0;
				for (int i = 0; i < nSelItems; i++)
				{
					DATA* pData = (DATA*)SendMessage(hList, LB_GETITEMDATA, pBuffer[i], 0);
					lstrcat(lpszBuflpszBuf, pData->szFilePath);
					lstrcat(lpszBuflpszBuf, TEXT("\t"));
					lstrcat(lpszBuflpszBuf, pData->szHashValue);
					lstrcat(lpszBuflpszBuf, TEXT("\r\n"));
				}
				lpszBuflpszBuf[nLen] = 0;
				GlobalFree(pBuffer);
				GlobalUnlock(hMem);
				OpenClipboard(NULL);
				EmptyClipboard();
				SetClipboardData(CF_UNICODETEXT, hMem);
				CloseClipboard();
			}
		}
		break;
		case ID_SELECTALL:
			SendMessage(hList, LB_SETSEL, 1, -1);
			break;
		case ID_DELETE:
		{
			const int nSelItems = SendMessage(hList, LB_GETSELCOUNT, 0, 0);
			if (nSelItems > 0)
			{
				int* pBuffer = (int*)GlobalAlloc(0, sizeof(int) * nSelItems);
				SendMessage(hList, LB_GETSELITEMS, nSelItems, (LPARAM)pBuffer);
				for (int i = nSelItems - 1; i >= 0; i--)
				{
					DeleteItem(hList, pBuffer[i]);
				}
				GlobalFree(pBuffer);
				dwSplitLine = 0;
				const int nCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
				for (int i = 0; i < nCount; i++)
				{
					const DATA* pData = (const DATA*)SendMessage(hList, LB_GETITEMDATA, i, 0);
					const DWORD dwTemp = GetStringWidth(hList, PathFindFileName(pData->szFilePath));
					if (dwTemp>dwSplitLine)dwSplitLine = dwTemp;
				}
			}
		}
		break;
		}
		break;
	case WM_MEASUREITEM:
		((LPMEASUREITEMSTRUCT)lParam)->itemHeight = 32;
		return 0;
	case WM_SIZE:
		MoveWindow(hList, 0, 0, LOWORD(lParam), HIWORD(lParam), 0);
		break;
	case WM_EXITTHREAD:
	{
		DATA* pData = (DATA*)lParam;
		WaitForSingleObject(pData->hThread, INFINITE);
		CloseHandle(pData->hThread);
		pData->hThread = 0;
		InvalidateRect(hList, 0, 0);
	}
	break;
	case WM_DRAWITEM:
		if ((UINT)wParam == IDC_LIST)
		{
			LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
			if (lpdis->itemID == -1)
			{
				if (!SendMessage(hList, LB_GETCOUNT, 0, 0))
				{
					RECT rect;
					GetClientRect(hList, &rect);
					HBRUSH hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
					FillRect(lpdis->hDC, &rect, hBrush);
					DeleteObject(hBrush);
					SetTextColor(lpdis->hDC, GetSysColor(COLOR_GRAYTEXT));
					DrawText(lpdis->hDC, TEXT("ここにファイルをドラッグ"), -1, &rect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_CENTER);
				}
				break;
			}
			DATA* pData = (DATA*)SendMessage(hList, LB_GETITEMDATA, lpdis->itemID, 0);
			if ((lpdis->itemState)&(ODS_SELECTED))
			{
				SetBkColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT));
				SetTextColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
			}
			else
			{
				SetBkColor(lpdis->hDC, GetSysColor(COLOR_WINDOW));
				SetTextColor(lpdis->hDC, GetSysColor(COLOR_WINDOWTEXT));
			}
			RECT rect1 = lpdis->rcItem;
			rect1.right = dwSplitLine + 16;
			const LPCTSTR lpszFileName = PathFindFileName(pData->szFilePath);
			SetTextAlign(lpdis->hDC, TA_RIGHT);
			ExtTextOut(lpdis->hDC, rect1.right, rect1.top + 4, ETO_OPAQUE, &rect1, lpszFileName, lstrlen(lpszFileName), 0);
			RECT rect2 = lpdis->rcItem;
			rect2.left = dwSplitLine + 16;
			SetTextAlign(lpdis->hDC, TA_LEFT);
			ExtTextOut(lpdis->hDC, rect2.left + 32, rect2.top + 4, ETO_OPAQUE, &rect2, pData->szHashValue, lstrlen(pData->szHashValue), 0);
		}
		break;
	case WM_DROPFILES:
	{
		HDROP hDrop = (HDROP)wParam;
		TCHAR szFileName[MAX_PATH];
		UINT i;
		const DWORD dwFastItem = SendMessage(hList, LB_GETCOUNT, 0, 0);
		SendMessage(hList, LB_SETSEL, 0, -1);
		const UINT nFiles = DragQueryFile((HDROP)hDrop, 0xFFFFFFFF, NULL, 0);
		for (i = 0; i<nFiles; i++)
		{
			DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
			CalcSha1(hList, szFileName);
			const DWORD dwTempWidth = GetStringWidth(hList, PathFindFileName(szFileName));
			if (dwTempWidth>dwSplitLine)dwSplitLine = dwTempWidth;
		}
		DragFinish(hDrop);
		const DWORD dwLastItem = SendMessage(hList, LB_GETCOUNT, 0, 0);
		SendMessage(hList, LB_SELITEMRANGE, TRUE, MAKELPARAM(dwFastItem, dwLastItem - 1));
		SetForegroundWindow(hWnd);
	}
	break;
	case WM_CLOSE:
		DestroyWindow(hWnd);
		break;
	case WM_DESTROY:
	{
		const int nCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
		for (int i = nCount - 1; i >= 0; i--)
		{
			DeleteItem(hList, i);
		}
	}
	DeleteObject(hFont);
	PostQuitMessage(0);
	break;
	default:
		return DefDlgProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}
コード例 #2
0
ファイル: Builder.cpp プロジェクト: mefest/apdvmupdater
void Builder::run()
{
    VLM_LatestError = BUILDER_NO_ERROR;
    //InterfaceArchiver * archives =new InterfaceArchiver();
    QString MCL_CurrentFilePath = "";
    int count;
    QFile VXL_UpdateListFile(VCM_OutputFilePath);
    QFileInfo VXL_UpdateListFileInfo;
    QDir VXL_UpdateListDir;
    //On vérirife l'existence du dossier
    VXL_UpdateListFileInfo.setFile(VXL_UpdateListFile);
    VXL_UpdateListDir = VXL_UpdateListFileInfo.absoluteDir();
    if(!VXL_UpdateListDir.exists())
    {
       VXL_UpdateListDir.mkpath(VXL_UpdateListFileInfo.absolutePath());
    }
    else
    {
        //On vérifie la présence du fichier
        if(VXL_UpdateListFile.exists())
        {
            //On le supprime
            VXL_UpdateListFile.remove();
        }
    }

    //On ouvre le fichier
    if (!VXL_UpdateListFile.open(QIODevice::WriteOnly | QIODevice::Text))
    {
            emit NotifyErrorMsg("Unable to open UpdateList File");
            VLM_LatestError = BUILDER_ERROR_CANT_OPEN_FILE;
            return;
    }
    //On créé le buffer pour insèrer du texte
    QTextStream VXL_OutTextStream(&VXL_UpdateListFile);
    count = OMM_ListFilesToTreate.size();
    VXL_OutTextStream << "[files]" <<"\n" << "fcount=" << count << "\n";
    for(int i=0; i<OMM_ListFilesToTreate.size();i++)
    {
        MCL_CurrentFilePath = 	OMM_ListFilesToTreate[i]->getPath() + "/"
                + OMM_ListFilesToTreate[i]->getFilename().section('/', -1);
        qDebug() << MCL_CurrentFilePath;
        //On calcul le hash du fichier
        OMM_ListFilesToTreate[i]->setSha1(CalcSha1(MCL_CurrentFilePath));

        //Si demandé, on affiche le fichier en cours de traitement
        #ifdef ENABLE_DEBUG_SHOWLISTS
            #ifdef QT_DEBUG
                    qDebug()    << "File :" << i+1 << "/" <<OMM_ListFilesToTreate.size()
                                << OMM_ListFilesToTreate[i]->getFilename() 	<< "|"
                                << OMM_ListFilesToTreate[i]->getpriority()	<< "|"
                                << OMM_ListFilesToTreate[i]->getPath()		<< "|"
                                << OMM_ListFilesToTreate[i]->getSha1() ;
            #endif //QT_DEBUG
        #endif //ENABLE_DEBUG_SHOWLISTS

        //On écris la ligne qui le concerne
        if(QString::compare(MCL_CurrentFilePath, VCM_ReferenceFilePath) == 0)
        {//Fichier de référence

        }
        else
        {//Fichier "normal"
                    count++;
            VXL_OutTextStream     << "F"<<i<<"="
            << OMM_ListFilesToTreate[i]->getFilename() 	<< "|"
            << OMM_ListFilesToTreate[i]->getSha1()		<< "|"
            << OMM_ListFilesToTreate[i]->getpriority()
            << "\n";
        }
        /***********TODO****************/
        QString fileToCopy(OMM_ListFilesToTreate[i]->getPath() + "/"
                           + OMM_ListFilesToTreate[i]->getFilename().section('/', -1));
        QString subPath(OMM_ListFilesToTreate[i]->getFilename().section('/', 0, -2));
        VXL_UpdateListDir.mkpath(subPath);
        QFile::copy(fileToCopy, VCM_ReferenceFilePath+OMM_ListFilesToTreate[i]->getFilename());
        // QFile::copy(OMM_ListFilesToTreate[i]->getFilename(),OMM_ListFilesToTreate[i]->getFilename());
        // On Maj la ProgressBar
        emit NotifyProgress(i+1,OMM_ListFilesToTreate.size());
    }
    return;
}