コード例 #1
0
int Sys_StreamOpen(int code, streamHandle_t *handle)
{
	// Find a free handle
	*handle = GetFreeHandle();
	if (*handle == 0)
	{
		return -1;
	}

	// Find the file size
	sound_file_t*	crap	= soundLookup->Find(code);
	int				size	= -1;
	if(crap)
	{
		size	= crap->size;
	}

	if (size < 0)
	{
		*handle = 0;
		return -1;
	}

	// Init stream data
	s_Streams[*handle].used = true;
	s_Streams[*handle].opening = true;
	s_Streams[*handle].reading = false;
	s_Streams[*handle].error = false;

	// Send an open request to the thread
	IORequest req;
	req.type = IOREQ_OPEN;
	req.handle = *handle;
	req.data[0] = code;
	_sendIORequest(req);

	// Return file size
	return size;
}
コード例 #2
0
void FSUpdateStorage::InitializeVolumeRoot(FileSystemVolume* pVolume, FS_FILEINFO& findData)
{
    FSUpdateHeader header;
    UINT32 searchHandle = 0;
    
    if(SUCCEEDED(pVolume->FindOpen(L"\\", &searchHandle)))
    {
        BOOL found = FALSE;
    
        if(g_FSUpdateStorage.m_defaultVolume == NULL)
        {
            g_FSUpdateStorage.m_defaultVolume = pVolume;
        }
        
        while(SUCCEEDED(pVolume->FindNext(searchHandle, &findData, &found)) && found)
        {
            int len = FS_LWSTR_LEN((WCHAR*)findData.FileName);
    
            if(len >= 4 && findData.FileName[len-4] == L'.' && findData.FileName[len-3] == L'N' && findData.FileName[len-2] == L'M' && findData.FileName[len-1] == L'F')
            {
                UINT32 fileHandle = 0;
                WCHAR path[128];
                int idx = 0;
                
                path[idx++] = L'\\';
                
                idx += FS_LWSTR_COPY(&path[1], ARRAYSIZE(path)-1, (WCHAR*)findData.FileName);

                path[idx] = 0;
                    
                if(SUCCEEDED(pVolume->Open((LPCWSTR)path, &fileHandle)))
                {
                    int bytesRead = 0;
                    bool fDeleteFile = false;

                    if(SUCCEEDED(pVolume->Read(fileHandle, (UINT8*)&header, sizeof(header), &bytesRead)))
                    {
                        if(header.fileSignature == c_FileSignature)
                        {
                            INT32 handle = GetFreeHandle();
                    
                            int idx = FS_LWSTR_COPY(g_FSUpdateStorage.m_files[handle].FilePath, ARRAYSIZE(g_FSUpdateStorage.m_files[handle].FilePath), (WCHAR*)path);

                            g_FSUpdateStorage.m_files[handle].FilePath[idx] = 0;
                            
                            g_FSUpdateStorage.m_files[handle].Volume     = pVolume;
                            g_FSUpdateStorage.m_files[handle].Size       = header.storageHeader.UpdateSize + sizeof(header);
                            g_FSUpdateStorage.m_files[handle].ID         = header.storageHeader.UpdateID;
                            g_FSUpdateStorage.m_files[handle].Type       = header.storageHeader.UpdateType;
                            g_FSUpdateStorage.m_files[handle].SubType    = header.storageHeader.UpdateSubType;
                            g_FSUpdateStorage.m_files[handle].Handle     = fileHandle;
                        }
                        else
                        {
                            fDeleteFile = true;
                        }
                    }
    
                    if(fDeleteFile) 
                    {
                        pVolume->Close(fileHandle);
                        pVolume->Delete((LPCWSTR)path);
                    }
                }
            }
        }
    
        pVolume->FindClose(searchHandle);
    }
    
}