Exemplo n.º 1
0
short AELoadCart(AppleEvent* aev, AppleEvent* reply, long refCon)
{
short err;
FSSpec cart;
AEDescList docList;
AEKeyword keyWd;
DescType typ;
long items,siz;

	err = AEGetParamDesc(aev,keyDirectObject,typeAEList,&docList);
	if(err==0) {
		err = AECountItems(&docList,&items);
		for(short i=1;i<=items;i++) {
			err = AEGetNthPtr(&docList,i,typeFSS,&keyWd,&typ,(Ptr)&cart,sizeof(FSSpec),&siz);
			if(err==0) {
				if(CheckFileType(&cart,'Cart')) {
					LoadCartridgeFile(&cart);
					AEDisposeDesc(&docList);
					return 0;
				}
			}
		}
		AEDisposeDesc(&docList);
	}
	
	return err;
}
Exemplo n.º 2
0
HRESULT STDMETHODCALLTYPE CHdrPropSheet::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpDatObj, HKEY hkeyProgID)
{
//OutputDebugString(_T("CHdrPropSheet::Initialize()\n"));
	if (lpDatObj == NULL) {
		return E_FAIL;
	}
	FORMATETC fmtetc;
	STGMEDIUM medium;
	fmtetc.cfFormat = CF_HDROP;
	fmtetc.ptd      = NULL;
	fmtetc.dwAspect = DVASPECT_CONTENT;
	fmtetc.lindex   = -1;
	fmtetc.tymed    = TYMED_HGLOBAL;
	if (FAILED(lpDatObj->GetData(&fmtetc, &medium))) {
		return E_FAIL;
	}
	HDROP hDrop = static_cast<HDROP>(medium.hGlobal);
	if (::DragQueryFile(hDrop, -1, NULL, 0) != 1) { // not multi files.
		::ReleaseStgMedium(&medium);
		return E_FAIL;
	}
	::DragQueryFile(hDrop, 0, m_szPath, lengthof(m_szPath));
	::ReleaseStgMedium(&medium);
	return CheckFileType();
}
Exemplo n.º 3
0
FileInfo::FileInfo(StringRef filePath):mFullPath(filePath)
{
	MEDUSA_ASSERT_NOT_NULL_OR_EMPTY_STRING(mFullPath,"");

	intp index=mFullPath.LastIndexOf('.');
	if (index>0)
	{
		//this is a file
		size_t length=(size_t)(mFullPath.Length()-index+1);
		filePath.CopyTo(mFileExtension.Buffer(),mFileExtension.Size(),(size_t)(index),length);
		mFileExtension.ForceSetLength(length);
		mFileType=CheckFileType(mFileExtension);


		intp index2= filePath.LastIndexOfAny(Path::DirectorySeparatorChars);
		if (index2>0)
		{
			mFullName= mFullPath.SubString(index2+1);
			mName=mFullPath.SubString(index2+1,index-index2-1);
			mDirectoryPath=mFullPath.SubString(0,index2);
		}
		else
		{
			mFullName=mFullPath;
			mName=mFullPath;
		}
	}
	else
	{
		//this is a directory
		mDirectoryPath=mFullPath;
	}
}
bool TypeNotSupportedException::RegisterFileType(std::string name) {
    std::transform(name.begin(), name.end(), name.begin(), tolower);
    if(CheckFileType(name)) return false;
    _supportedTypes.insert(name);
    return true;

}
Exemplo n.º 5
0
void Data::ShowFName( const QString &fname )
{
  FName = fname;
  QString dfname = fname;

  SelectedFile->setText( dfname );
  CheckFileType( fname );
  emit AskToGetNewView( dataType, FSDialog->directory().absolutePath() );
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
    int fd;
    char *pFile;
    int ret;
    int iType;
    Elf32_Ehdr ehdr;
    const CarcodeStruct *pCarCode = NULL;

    if (argc == 2) {
        pFile = argv[1];
        ret = CheckFileType(pFile);
        iType = INFO_ALL;
    } else if (argc == 3) {
        pFile = argv[2];
        ret = CheckFileType(pFile);
        iType = CheckParam(argv[1]);
    } else {
        ShowUsage();
        goto err;
    }

    if (ret || iType == INFO_NULL) {
        goto err;
    }

    fd = open(pFile, O_RDONLY, 0);
    if(fd == -1) {
        printf("open %s failed! <%s,line:%d>\n", pFile, __FUNCTION__, __LINE__);
        goto err;
    }

    ret = CheckFileFormat(fd, &ehdr);
    if (ret) {
        goto err;
    }

    pCarCode = (CarcodeStruct *)ReadResourceSection(fd, &ehdr);
    if (NULL == pCarCode) {
        goto err;
    }

    if (RESOURCE_MATIC != pCarCode->uMagic) {
        printf("resource section magic mismatch!!\n");
        goto err;
    }

    switch (iType) {
        case INFO_GET_BUILDDATE:
            printf("bd:0x%x\n", pCarCode->bDate);
            break;

        case INFO_GET_CARCODE:
            printf("fp:0x%x\n", pCarCode->cCode);
            break;

        case INFO_GET_URN:
            printf("urn:%s\n", pCarCode->puRn);
            break;

        case INFO_DEPENDENCE:
            getdependence(pCarCode->puRn + pCarCode->uSize);
            break;

        case INFO_ALL:
            printf("%s resource infomation:\n", pFile);
            printf("build date: 0x%x\n", pCarCode->bDate);
            printf("carcode:    0x%x\n", pCarCode->cCode);
            printf("uRn:        %s\n", pCarCode->puRn);
            getdependence(pCarCode->puRn + pCarCode->uSize);
            break;

        default:
            printf("Error!!\n");
            break;
    }

err:
    if (gbuf)
        free((void *)gbuf);
    if (pCarCode)
        free((void *)pCarCode);
    return 0;
}
Exemplo n.º 7
0
DWORD WINAPI Import(LPVOID lpParameter)
{
    BOOL   bIsDirectory;
    CHAR   szFileName[MAX_PATH];
    PBYTE  pbFile;
    LPSTR  lpPath, lpFileName;
    HANDLE hFile, hMap, hFind;
    DWORD  dwFileAttributes, dwSize, dwNewSize, dwCount, dwTotal;
    FILETYPE FileType;
    WIN32_FIND_DATA wfd;

    lpPath = (LPSTR)lpParameter;
    dwNewSize = dwCount = dwTotal = 0;
    dwFileAttributes = GetFileAttributes(lpPath);
    if (dwFileAttributes == INVALID_FILE_ATTRIBUTES)
    {
        return 0;
    }

    bIsDirectory = dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
    if (bIsDirectory)
    {
        sprintf(szFileName, "%s\\*.*", lpPath);
        hFind = FindFirstFile(szFileName, &wfd);
        if (hFind == INVALID_HANDLE_VALUE)
        {
            return 0;
        }
        lpFileName = szFileName;
    }
    else
    {
        lpFileName = lpPath;
    }

    while (ReleaseSemaphore(g_hSemaphore, 1, NULL) == FALSE)
    {
        Sleep(1);
    }

    do
    {
        if (bIsDirectory)
        {
            if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                continue;
            }
            sprintf(szFileName, "%s\\%s", lpPath, wfd.cFileName);
        }

        ++dwTotal;
        hFile = CreateFile(FILE_NAME,
                           GENERIC_READ|GENERIC_WRITE,
                           FILE_SHARE_READ|FILE_SHARE_WRITE,
                           NULL,
                           OPEN_EXISTING,
                           FILE_ATTRIBUTE_NORMAL,
                           NULL);
        if (hFile == INVALID_HANDLE_VALUE)
        {
            printf("CreateFile() failed: %s\n", FILE_NAME);
            continue;
        }

        dwSize = GetFileSize(hFile, NULL);

        if (dwSize != 0)
        {
            hMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwSize, NULL);
            if (hMap == NULL)
            {
                printf("CreateFileMapping() failed: %s\n", FILE_NAME);
                CloseHandle(hFile);
                continue;
            }

            pbFile = (PBYTE)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
            CloseHandle(hMap);
            if (pbFile == NULL)
            {
                printf("MapViewOfFile() failed: %s\n", FILE_NAME);
                CloseHandle(hFile);
                continue;
            }

            FileType = CheckFileType(pbFile, dwSize, PathFindFileName(FILE_NAME));
            if (FileType != UNKNOWN)
            {
                ReplaceString(pbDict, pbFile, dwSize);
                dwNewSize = StringToAnsi(pbFile, FileType, dwSize);
                ++dwCount;
            }

            UnmapViewOfFile(pbFile);
            if (dwNewSize != 0)
            {
                SetFilePointer(hFile, dwNewSize, 0, FILE_BEGIN);
                SetEndOfFile(hFile);
            }
        }
        CloseHandle(hFile);
    } while (bIsDirectory && FindNextFile(hFind, &wfd));

    if (bIsDirectory)
    {
        FindClose(hFind);
    }

    WaitForSingleObject(g_hSemaphore, INFINITE);
    return dwCount;
}
Exemplo n.º 8
0
Medusa::FileType FileInfo::GetType( StringRef filePath )
{
	StringRef ext=GetExtension(filePath);
	return CheckFileType(ext);
}
bool TypeNotSupportedException::UnregisterFileType(std::string name) {
    std::transform(name.begin(), name.end(), name.begin(), tolower);
    if(CheckFileType(name) == false) return false;
    _supportedTypes.erase(_supportedTypes.find(name));
    return true;
}
Exemplo n.º 10
0
_MY_C_HEAD_
#include "LZMA/7zVersion.h"
#include "LZMA/Alloc.h"
#include "LZMA/Lzma86.h"
_MY_C_TAIL_

void __cdecl main2(int argc, wchar_t **argv)
{
    if (argc < 3)
    {
        printf("Too few parameters\n");
        return;
    }

    Byte  *outBuffer, FileType, bLZMA;
    SizeT  inSize, outSize, outMaxSize;
    WCHAR  szFileName[MAX_PATH];
    WCHAR  *szFileType[] = { L"UCA", L"UCI", L"AAC", L"M4A", L"Unknown" };
    PBYTE  pbFile;
    DWORD  dwFileNumber, dwErrorCount, dwMaxNumber, dwFileSize, dwRead;
    DWORD  dwBufferSize, dwMaxFileNumber, dwMethod[] = {'ACU', 'ICU', 'CAA', 'A4M', 'KNU'};
    HANDLE hFind, hHeap, hFile, hDestFile;
    WIN32_FIND_DATAW wfd;
    TSpiArchiveInfo *pSpiArcInfo;
    LARGE_INTEGER liFrequency, liStart, liStop;

    setlocale(LC_CTYPE, "");

    hDestFile = CreateFileW(argv[2],
                    GENERIC_READ|GENERIC_WRITE,
                    FILE_SHARE_READ|FILE_SHARE_WRITE,
                    NULL,
                    CREATE_ALWAYS,
                    FILE_ATTRIBUTE_NORMAL,
                    NULL);
    if (hDestFile == INVALID_HANDLE_VALUE)
    {
        wprintf(L"Can't create %s\n", argv[2]);
        return;
    }

    swprintf(szFileName, L"%s\\*.*", argv[1]);
    hFind = FindFirstFileW(szFileName, &wfd);
    if (hFind == INVALID_HANDLE_VALUE)
    {
        wprintf(L"Can't find %s\n", szFileName);
        return;
    }

    outMaxSize   = 0;
    dwBufferSize = 0;
    dwErrorCount = 0;
    dwFileNumber = 0;
    dwMaxNumber  = 1000;
    hHeap = GetProcessHeap();
    pbFile = (PBYTE)HeapAlloc(hHeap, 0, 0);
    outBuffer = (Byte *)HeapAlloc(hHeap, 0, 0);
    pSpiArcInfo = (TSpiArchiveInfo *)HeapAlloc(hHeap,
                        HEAP_ZERO_MEMORY, dwMaxNumber * sizeof(*pSpiArcInfo));
    WriteFile(hDestFile, pSpiArcInfo, 0x10, &dwRead, NULL);

    bLZMA = argc >= 4 ? (Byte)wcstoul(argv[3], NULL, 10) : 1;
    dwMaxFileNumber = argc == 5 ? wcstoul(argv[4], NULL, 10) : -1;
    QueryPerformanceFrequency(&liFrequency);
    QueryPerformanceCounter(&liStart);

    do
    {
        if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            continue;

        swprintf(szFileName, L"%s\\%s", argv[1], wfd.cFileName);
        hFile = CreateFileW(szFileName,
                    GENERIC_READ,
                    FILE_SHARE_READ,
                    NULL,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL,
                    NULL);
        if (hFile == INVALID_HANDLE_VALUE)
        {
            wprintf(L"Open %s failed.\n", szFileName);
            ++dwErrorCount;
            continue;
        }

        if (dwFileNumber >= dwMaxNumber)
        {
            dwMaxNumber = dwMaxNumber + (dwMaxNumber >> 1);
            pSpiArcInfo = (TSpiArchiveInfo *)HeapReAlloc(hHeap, HEAP_ZERO_MEMORY,
                pSpiArcInfo, dwMaxNumber * sizeof(*pSpiArcInfo));
        }

        dwFileSize = GetFileSize(hFile, NULL);
        if (dwFileSize > dwBufferSize)
        {
            dwBufferSize = dwFileSize;
            pbFile = (PBYTE)HeapReAlloc(hHeap, 0, pbFile, dwBufferSize);
        }

        ReadFile(hFile, pbFile, dwFileSize, &dwRead, NULL);
        CloseHandle(hFile);

        FileType = CheckFileType(pbFile);

        wprintf(L"Packing %s ... %s ", szFileName, szFileType[FileType]);
        pSpiArcInfo[dwFileNumber].position = SetFilePointer(hDestFile, 0, 0, FILE_CURRENT);
        if (dwFileSize > 300 && bLZMA && FileType != UCI && FileType != M4A && FileType != AAC)
        {
            outSize = dwFileSize / 20 * 21 + (1 << 16) + 4;
            if (outSize > outMaxSize)
            {
                outMaxSize = outSize;
                outBuffer = (Byte *)HeapReAlloc(hHeap, 0, outBuffer, outSize);
            }
            Lzma86_Encode(outBuffer, &outSize, (Byte *)pbFile, dwFileSize, 9, 1 << 27, 0);
            pSpiArcInfo[dwFileNumber].compsize = outSize;
            WriteFile(hDestFile, outBuffer, outSize, &dwRead, NULL);
            wprintf(L"@ compressed ... ");
        }
        else
        {
            if (FileType != UCI && FileType != UCA)
            {
                WriteFile(hDestFile, &dwFileSize, 4, &dwRead, NULL);
            }
            WriteFile(hDestFile, pbFile, dwFileSize, &dwRead, NULL);
            pSpiArcInfo[dwFileNumber].compsize = dwFileSize;
        }

		if (FileType != UNKNOWN)
        {
			*(LPDWORD)&pSpiArcInfo[dwFileNumber].method = dwMethod[FileType];
		}

        int w, h, b;
        CHAR *p;
        HSTREAM hStream;
        static BOOL bBassInit = FALSE;
        
        WideCharToMultiByte(936,
                    0,
                    wfd.cFileName,
                    -1,
                    pSpiArcInfo[dwFileNumber].filename,
                    sizeof(pSpiArcInfo[dwFileNumber].filename),
                    NULL, NULL);
		if (FileType == UNKNOWN)
		{
			CHAR *pExt = PathFindExtensionA(pSpiArcInfo[dwFileNumber].filename);
			if (pExt++)
			{
				lstrcpynA((LPSTR)pSpiArcInfo[dwFileNumber].method, pExt, sizeof(pSpiArcInfo->method));
			}
			else
			{
				*(LPDWORD)&pSpiArcInfo[dwFileNumber].method = 'KNU';
			}
		}
        
        p = PathFindExtensionA(pSpiArcInfo[dwFileNumber].filename);
        switch (FileType)
        {
        case UCA:
            UCADecode(pbFile, dwFileSize, NULL,(int *)&pSpiArcInfo[dwFileNumber].filesize);
            if (p)
            {
                lstrcpyA(p + 1, "wav");
            }
            printf("OK!");
            break;

        case UCI:
            UCIDecode(pbFile, dwFileSize, NULL, NULL, &w, &h, &b);
            pSpiArcInfo[dwFileNumber].filesize =
                (w * b / 8 + (b == 0x18 ? (w & 3) : 0)) * h + sizeof(TBitMapHeader);
            if (p)
            {
                lstrcpyA(p + 1, "bmp");
            }
            printf("OK!");
            break;

        case AAC:
        case M4A:
            if (bBassInit == FALSE)
            {
                bBassInit = TRUE;
                if (BASS_Init(0, 44100, 0, NULL, NULL) == FALSE)
                {
                    ++dwErrorCount;
                    printf("failed!");
                    break;
                }
            }

            hStream = FileType == AAC ? 
                BASS_AAC_StreamCreateFile(TRUE, pbFile, 0, dwFileSize, BASS_STREAM_DECODE) :
                BASS_MP4_StreamCreateFile(TRUE, pbFile, 0, dwFileSize, BASS_STREAM_DECODE);
            if (hStream)
            {
                pSpiArcInfo[dwFileNumber].filesize =
                    (DWORD)BASS_ChannelGetLength(hStream, BASS_POS_BYTE) +  + sizeof(TWaveHeader);

                BASS_StreamFree(hStream);

                if (p)
                {
                    lstrcpyA(p + 1, "wav");
                }

                printf("OK!");
            }
            else
            {
                ++dwErrorCount;
                printf("failed!");
            }
            break;

        default:
            pSpiArcInfo[dwFileNumber].filesize = dwFileSize;
            printf("OK!");
        }
        wprintf(L"\n");

        ++dwFileNumber;

    } while (dwFileNumber < dwMaxFileNumber && FindNextFileW(hFind, &wfd));