Example #1
0
void TSorterListItem::Init()
{
	// Set DataType based on entry_ref
	BFile theFile; 
	if ( theFile.SetTo(&m_EntryRef, B_READ_WRITE) == B_OK )
	{		
		// Create node
		BNodeInfo nodeInfo(&theFile);
		if (nodeInfo.InitCheck() == B_NO_ERROR)
		{
			if (IsAudio(nodeInfo))
				m_DataType = kAudioType;
			else if (IsImage(nodeInfo))
				m_DataType = kPictureType;
			else if (IsText(nodeInfo))
				m_DataType = kTextType;
			else if (IsVideo(nodeInfo))
				m_DataType = kVideoType;
		}
		else
		{
			m_DataType = kUnknownType;	
		}	
		
		theFile.Unset();
	}
}
Example #2
0
bool TRefFilter::Filter(const entry_ref *theRef, BNode *theNode, struct stat_beos *theStat, const char *mimetype)
{
	//	Create BEntry and traverse to get source ref
	BEntry entry(theRef, true);
	if (entry.InitCheck() != B_OK)
	{
		ERROR("TRefFilter::Filter() - Error creating BEntry -\n");
		return false;
	}
		
	//	Create a node from ref
	BNode localNode(theRef);
	if (localNode.InitCheck() != B_OK)
	{
		ERROR("TRefFilter::Filter() - Error creating BNode -\n");
		return false;
	}
		
	//	Get node info
	BNodeInfo nodeInfo(&localNode);	 
	if (nodeInfo.InitCheck() != B_OK)
	{
		ERROR("TRefFilter::Filter() - Error getting BNodeInfo -\n");
		return false;
	}
	
	//	Get stat info
	struct stat st;
	if (entry.GetStat(&st) != B_OK)
	{
		ERROR("TRefFilter::Filter() - Error getting stat info -\n");
		return false;	
	}
	
	switch(m_FilterType)
	{
		case kAudioFilter:
		{
			// Allow directories
			if (S_ISDIR(st.st_mode)) 
				return true;
					
			// Allow audio
			if (IsAudio(nodeInfo))
				return true;
		}
		break;
	
		case kAudioAiffFilter:
		{
			// Allow directories
			if (S_ISDIR(st.st_mode)) 
				return true;
					
			// Allow audio
			if (IsAudioAiff(nodeInfo))
				return true;
		}
		break;
			
		case kImageFilter:
			{
				// Allow directories
				if (S_ISDIR(st.st_mode)) 
					return true;
					
				// Allow images
				if (IsImage(nodeInfo))
					return true;							
			}
			break;
			
		case kTextFilter:
			{
				// Allow directories
				if (S_ISDIR(st.st_mode)) 
					return true;
					
				// Allow text
				if (IsText(nodeInfo))
					return true;
			}
			break;
			
		case kVideoFilter:
			{
				// Allow directories
				if (S_ISDIR(st.st_mode)) 
					return true;
					
				// Allow video
				if (IsVideo(nodeInfo))
					return true;
			}
			break;
			
		case kCueSheetFilter:
			{
				// Allow directories
				if (S_ISDIR(st.st_mode)) 
					return true;
					
				// Allow CueSheets
				if (IsCueSheet(nodeInfo))
					return true;
			}
			break;
		
		case kDirectoryFilter:
		{
			// Allow directories
			if (S_ISDIR(st.st_mode)) 
				return true;					
		}
		break;
		
		default:
			return true;
	}	
	
	// Fail if we get here
	return false;
}
Example #3
0
HRESULT 
TrackWriter::Close(Atom* patm)
{
    smart_ptr<Atom> ptrak = patm->CreateAtom('trak');

    // track header tkhd
    smart_ptr<Atom> ptkhd = ptrak->CreateAtom('tkhd');
    BYTE b[24*4];
    ZeroMemory(b, (24*4));

    // duration in movie timescale
    LONGLONG scaledur = long(Duration() * m_pMovie->MovieScale() / UNITS);
    int cHdr = 6 * 4;
    if (scaledur > 0x7fffffff)
    {
        // use 64-bit version (64-bit create/modify and duration
        cHdr = 9*4;
        b[0] = 1;
        WriteLong(ID(), b+(5*4));
        WriteI64(scaledur, b+(7*4));
    }
    else
    {
        WriteLong(ID(), b+(3*4));     // 1-base track id
        WriteLong(long(scaledur), b+(5*4));
        cHdr = 6*4;
    }
    b[3] = 7;   // enabled, in movie and in preview

    if (IsAudio())
    {
        b[cHdr + 12] = 0x01;
    }
    b[cHdr + 17] = 1;
    b[cHdr + 33] = 1;
    b[cHdr + 48] = 0x40;
    if (IsVideo())
    {
		WriteShort(m_pType->Width(), &b[cHdr + 52]);
		WriteShort(m_pType->Height(), &b[cHdr + 56]);
    }

    ptkhd->Append(b, cHdr + 60);
    ptkhd->Close();

    // track ref tref
    Handler()->WriteTREF(ptrak);

    // edts -- used for first-sample offet
    // -- note, this is in movie timescale, not track
    m_Durations.WriteEDTS(ptrak, m_pMovie->MovieScale());

    smart_ptr<Atom> pmdia = ptrak->CreateAtom('mdia');

    // Media Header mdhd
    smart_ptr<Atom> pmdhd = pmdia->CreateAtom('mdhd');
    ZeroMemory(b, 9*4);
    
    // duration now in track timescale
    scaledur = m_Durations.Duration() * m_Durations.Scale() / UNITS;
    if (scaledur > 0x7fffffff)
    {
        b[0] = 1;       // 64-bit
        WriteLong(m_Durations.Scale(), b+20);
        WriteI64(scaledur, b+24);         
        cHdr = 8*4;
    }
    else
    {
        WriteLong(m_Durations.Scale(), b+12);
        WriteLong(long(scaledur), b+16);         
        cHdr = 5*4;
    }
    // 'eng' as offset from 0x60 in 0 pad bit plus 3x5-bit (05 0xe 07)
    b[cHdr] = 0x15;
    b[cHdr+1] = 0xc7;
    pmdhd->Append(b, cHdr + 4);
    pmdhd->Close();

    // handler id hdlr
    smart_ptr<Atom> phdlr = pmdia->CreateAtom('hdlr');
    ZeroMemory(b, 25);
	WriteLong(Handler()->DataType(), b+4);
    WriteLong(Handler()->Handler(), b+8);
    phdlr->Append(b, 25);
    phdlr->Close();
    
    smart_ptr<Atom> pminf = pmdia->CreateAtom('minf');

    // media information header vmhd/smhd
    ZeroMemory(b, sizeof(b));
    if (IsVideo())
    {
        smart_ptr<Atom> pvmhd = pminf->CreateAtom('vmhd');
        b[3] = 1;
        pvmhd->Append(b, 12);
        pvmhd->Close();
    } else if (IsAudio())
    {
        smart_ptr<Atom> psmhd = pminf->CreateAtom('smhd');
        psmhd->Append(b, 8);
        psmhd->Close();
    } else {
        smart_ptr<Atom> pnmhd = pminf->CreateAtom('nmhd');
        pnmhd->Append(b, 4);
        pnmhd->Close();
    }

    // dinf/dref -- data reference
    smart_ptr<Atom> pdinf = pminf->CreateAtom('dinf');
    smart_ptr<Atom> pdref = pdinf->CreateAtom('dref');
    WriteLong(0, b);        // ver/flags
    WriteLong(1, b+4);      // entries
    pdref->Append(b, 8);
    smart_ptr<Atom> purl = pdref->CreateAtom('url ');
    // self-contained flag set, and no string required
    // -- all data is in this file
    b[3] = 1;
    purl->Append(b, 4);
    purl->Close();
    pdref->Close();
    pdinf->Close();

    smart_ptr<Atom> pstbl = pminf->CreateAtom('stbl');

    // Sample description
    // -- contains one descriptor atom mp4v/mp4a/... for each data reference.
    smart_ptr<Atom> pstsd = pstbl->CreateAtom('stsd');
    WriteLong(0, b);    // ver/flags
    WriteLong(1, b+4);    // count of entries
    pstsd->Append(b, 8);
    Handler()->WriteDescriptor(pstsd, ID(), 1, m_Durations.Scale());   // dataref = 1
    pstsd->Close();

    HRESULT hr = m_Durations.WriteTable(pstbl);
    if (SUCCEEDED(hr))
    {
        hr = m_Syncs.Write(pstbl);
    }
    if (SUCCEEDED(hr))
    {
        hr = m_SC.Write(pstbl);
    }
    if (SUCCEEDED(hr))
    {
        hr = m_Sizes.Write(pstbl);
    }
    if (SUCCEEDED(hr))
    {
        hr = m_CO.Write(pstbl);
    }
    pstbl->Close();
    pminf->Close();
    pmdia->Close();
    ptrak->Close();

    return hr;
}
Example #4
0
ForceInline void main2(int argc, TCHAR **argv)
{
    if (argc < 2)
    {
        _tprintf(_T("%s input_dir\n"), findname(argv[0]));
        return;
    }

    TCHAR  szOutFile[MAX_PATH];
    HANDLE hOut, hHeap;
    DWORD  dwLength, dwEntryCount;
    PAZTYPE PazType;
    TMyPAZEntry *pEntry;

    hHeap = GetProcessHeap();
    ghHeap = hHeap;
    for (int i = 1; i != argc; ++i)
    {
        Char  (*pPazHeader)[sizeof(headers[0])];
        DWORD dwAttributes;

        dwAttributes = GetFileAttributes(argv[i]);
        if (dwAttributes == -1)
        {
            _tprintf(_T("\"%s\" doesn't exist.\n"), argv[i]);
            continue;
        }
        else if ((dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
        {
            _tprintf(_T("%s isn't a directory.\n"), argv[i]);
            continue;
        }

        LPCSTR lpPath;

        lstrcpy(szOutFile, argv[i]);
        dwLength = lstrlen(szOutFile);
        if (szOutFile[dwLength - 1] == '\\')
            szOutFile[dwLength - 1] = 0;
        lstrcat(szOutFile, ".paz");

        lpPath = argv[i];
        PazType = NONE;
        if (i + 2 < argc)
        {
            int j = i + 1;
            if (argv[j][0] == '-' && ((argv[j][1] & 0xDF) == 'T'))
            {
                ++j;
                for (int k = 0; k != countof(szType); ++k)
                {
                    if (!lstrcmpi(szType[k], argv[j]))
                    {
                        i = j;
                        PazType = (PAZTYPE)k;
                        break;
                    }
                }
            }
        }
        else
        {
            PazType = GetPazTypeFromFileName(szOutFile);
        }

        if (PazType == NONE)
        {
            _tprintf(_T("Please specify one PAZ type by -t type or use a special file name.\n")
                _T("Following type is valid: \n\t")
                );
            for (int i = 0; i != countof(szType); ++i)
            {
                printf("%s ", szType[i]);
                if (i == countof(szType) / 2)
                    printf("\n\t");
            }

            break;
        }

        dwKeyIndex = GetKeyIndex(szType[PazType], &GameInfo[dwInfoIndex]);
        if (dwKeyIndex == -1)
        {
            printf("%s: don't know encryption key.\n", szOutFile);
            continue;
        }

        hOut = CreateFile(szOutFile,
                        GENERIC_READ|GENERIC_WRITE,
                        FILE_SHARE_READ|FILE_SHARE_WRITE,
                        NULL,
                        CREATE_ALWAYS,
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);
        if (hOut == INVALID_HANDLE_VALUE)
        {
            _tprintf(_T("Can't create \"%s\"\n"), szOutFile);
            continue;
        }

        g_bIsMovie = IsMovie(szOutFile);
        bIsVoice = IsAudio(szOutFile);
        SetCurrentDirectory(lpPath);
        dwEntryCount = GenerateEntry(&pEntry);
        if (dwEntryCount == 0 || pEntry == NULL)
        {
            _tprintf(_T("There is no file in \"%s\"\n"), argv[i]);
            continue;
        }

        bNeedXor = strnicmp(szType[PazType], "pm", 2) != 0;
        _tprintf(_T("Packing %s ...\n"), szOutFile);
        if (bNeedXor)
        {
            pPazHeader = (Char (*)[32])headers[dwInfoIndex];
        }
        else
            pPazHeader = (Char (*)[32])headers[countof(headers) - 1];

        WriteFile(hOut, pPazHeader, sizeof(*pPazHeader), &dwLength, NULL);
        WriteEntry(hOut, pEntry, dwEntryCount, False);

        WriteFileToPaz(hOut, pEntry, dwEntryCount, PazType);
        WriteEntry(hOut, pEntry, dwEntryCount, True);

//        HeapFree(hHeap, 0, pEntry);
        FreeFileList(pEntry);
        CloseHandle(hOut);
    }
}