예제 #1
0
int
ProcQueryExtension(ClientPtr client)
{
    xQueryExtensionReply reply;
    int i;
    REQUEST(xQueryExtensionReq);

    REQUEST_FIXED_SIZE(xQueryExtensionReq, stuff->nbytes);

    memset(&reply, 0, sizeof(xQueryExtensionReply));
    reply.type = X_Reply;
    reply.length = 0;
    reply.major_opcode = 0;
    reply.sequenceNumber = client->sequence;

    if ( ! NumExtensions )
        reply.present = xFalse;
    else
    {
	i = FindExtension((char *)&stuff[1], stuff->nbytes);
        if (i < 0 || XaceHook(XACE_EXT_ACCESS, client, extensions[i]))
            reply.present = xFalse;
        else
        {            
            reply.present = xTrue;
	    reply.major_opcode = extensions[i]->base;
	    reply.first_event = extensions[i]->eventBase;
	    reply.first_error = extensions[i]->errorBase;
	}
    }
    WriteReplyToClient(client, sizeof(xQueryExtensionReply), &reply);
    return Success;
}
예제 #2
0
파일: extension.c 프로젝트: theqvd/qvd-nx
void
DeclareExtensionSecurity(char *extname, Bool secure)
{
#ifdef XCSECURITY
    int i = FindExtension(extname, strlen(extname));
    if (i >= 0)
    {
	int majorop = extensions[i]->base;
	extensions[i]->secure = secure;
	if (secure)
	{
	    UntrustedProcVector[majorop] = ProcVector[majorop];
	    SwappedUntrustedProcVector[majorop] = SwappedProcVector[majorop];
	}
	else
	{
	    UntrustedProcVector[majorop]	= ProcBadRequest;
	    SwappedUntrustedProcVector[majorop] = ProcBadRequest;
	}
    }
#endif
#ifdef LBX
    LbxDeclareExtensionSecurity(extname, secure);
#endif
}
예제 #3
0
ALERROR CDesignCollection::BeginLoadAdventure (SDesignLoadCtx &Ctx, CAdventureDesc *pAdventure)

//	BeginLoadAdventure
//
//	Begin loading an adventure (not just the desc)

	{
	ASSERT(pAdventure);

	SExtensionDesc *pEntry = FindExtension(pAdventure->GetExtensionUNID());
	if (pEntry == NULL)
		{
		ASSERT(false);
		Ctx.sError = CONSTLIT("ERROR: Unexpectedly unable to find adventure");
		return ERR_FAIL;
		}

	pEntry->bLoaded = true;

	//	Set context

	Ctx.pExtension = pEntry;

	return NOERROR;
	}
예제 #4
0
		void	RemoveExtension( char * p_path )
		{
			char * ext = const_cast< char * >( FindExtension( p_path ) );
			if ( ext )
			{
				*ext = '\0';
			}
		}
예제 #5
0
파일: Console.cpp 프로젝트: tsaikd/MagicKD
int main(int argc, char* argv[])
{
	CxImage image;

    if (argc<3) {
        fprintf(stderr, image.GetVersion());
        fprintf(stderr, "\nConsole demo\n");
        fprintf(stderr, "usage: %s input-file output-file\n", argv[0]);
        return 1;
    }

	CString filein(argv[1]);
	CString extin(FindExtension(filein));
	extin.MakeLower();
	int typein = FindFormat(extin);
	if (typein == CXIMAGE_FORMAT_UNKNOWN) {
        fprintf(stderr, "unknown extension for %s\n", argv[1]);
        return 1;
	}

	CString fileout(argv[2]);
	CString extout(FindExtension(fileout));
	extout.MakeLower();
	int typeout = FindFormat(extout);
	if (typeout == CXIMAGE_FORMAT_UNKNOWN) {
        fprintf(stderr, "unknown extension for %s\n", argv[2]);
        return 1;
	}


	if (!image.Load(argv[1],typein)){
        fprintf(stderr, "%s\n", image.GetLastError());
        fprintf(stderr, "error loading %s\n", argv[1]);
        return 1;
	}

	if (!image.Save(argv[2],typeout)){
        fprintf(stderr, "%s\n", image.GetLastError());
        fprintf(stderr, "error saving %s\n", argv[2]);
        return 1;
	}

	printf("Done!\n");
	return 0;
}
예제 #6
0
/**	Opens a file
 *
 *	@param filename	A String containing the filename requested to open
 *	@param create		Whether the file should be created if not found
 *
 *	@returns A Handle to the file opened.  NULL is returned, if not found
 *
 *	This method requires the filename to contain the extension for the
 *	plugin required to open the file, if the file has no extension, 
 *	use VirtualFS::Open(char *, char *) to open the file, forcing an 
 *	extension to be used
 *
 *	NOTE:	If no extension is appended to the filename, this method will crash upon attempting the read the file
 */
VFSHandle * VirtualFS::Open(char *filename, bool create)
{
	char *ext = FindExtension(filename);

	VFSHandle *h = Open(filename,ext,create);

	delete[] ext;

	return h;
}
예제 #7
0
파일: extension.c 프로젝트: theqvd/qvd-nx
/*
 * CheckExtension returns the extensions[] entry for the requested
 * extension name.  Maybe this could just return a Bool instead?
 */
ExtensionEntry *
CheckExtension(const char *extname)
{
    int n;

    n = FindExtension((char*)extname, strlen(extname));
    if (n != -1)
	return extensions[n];
    else
	return NULL;
}
예제 #8
0
파일: stream.cpp 프로젝트: hgwells/tive
bool wxFilterClassFactoryBase::CanHandle(const wxChar *protocol,
                                         wxStreamProtocolType type) const
{
    if (type == wxSTREAM_FILEEXT)
        return FindExtension(protocol) != wxString::npos;
    else
        for (const wxChar *const *p = GetProtocols(type); *p; p++)
            if (wxStrcmp(*p, protocol) == 0)
                return true;

    return false;
}
예제 #9
0
파일: Filename.c 프로젝트: iKarith/nulib2
/*
 * Try to associate some meaning with the file extension.
 */
void InterpretExtension(NulibState* pState, const char* pathName,
    uint32_t* pFileType, uint32_t* pAuxType)
{
    const char* pExt;

    Assert(pState != NULL);
    Assert(pathName != NULL);
    Assert(pFileType != NULL);
    Assert(pAuxType != NULL);

    pExt = FindExtension(pState, pathName);
    if (pExt != NULL)
        LookupExtension(pState, pExt+1, pFileType, pAuxType);
}
예제 #10
0
		int DeleteRecursive(const char * p_path, const char * p_extension)
		{
			SceUID fh;

			IO::Filename file;
			fh = sceIoDopen(p_path);

			if( fh )
			{
				while(sceIoDread( fh, &gDirEntry.Dirent ))
				{
					SceIoStat stat;
					IO::Path::Combine(file, p_path, gDirEntry.Dirent.d_name);

					sceIoGetstat( file, &stat );
					if( (stat.st_mode & 0x1000) == 0x1000 )
					{
						if(strcmp(gDirEntry.Dirent.d_name, ".") && strcmp(gDirEntry.Dirent.d_name, ".."))
						{
							//printf("Found directory\n");
						}
					}
					else
					{
						if (_strcmpi(FindExtension( file ), p_extension) == 0)
						{
							//DBGConsole_Msg(0, "Deleting [C%s]",file);
							sceIoRemove( file );
						}

					}
				}
				sceIoDclose( fh );
			}
			else
			{
				//DBGConsole_Msg(0, "Couldn't open the directory");
			}

			return 0;
		}
예제 #11
0
bool CDesignCollection::IsAdventureExtensionLoaded (DWORD dwUNID)

//	IsAdventureExtensionLoaded
//
//	Returns TRUE if adventure extension is loaded

	{
	//	0 = no extension
	if (dwUNID == 0)
		return true;

	SExtensionDesc *pExt = FindExtension(dwUNID);
	if (pExt == NULL)
		{
		ASSERT(false);
		return false;
		}

	ASSERT(pExt->iType == extAdventure);
	return pExt->bLoaded;
	}
예제 #12
0
void AudioStreamingServer::Serve(const std::shared_ptr<ISocket>& clientSocket)
{
    try {
        
        char recvBuffer[DEFAULT_BUFFER_SIZE];
        int read = clientSocket->Receive(recvBuffer, DEFAULT_BUFFER_SIZE);
        HttpRequest request(recvBuffer, read);

        std::string requestUrl = httpExtractor->ExtractGET(request);
        requestUrl = urlCodec->DecodeURL(requestUrl);

        const char* songsearch = "/songsearch/";
        if(requestUrl.find(songsearch) == 0) {
            
            std::string keyword = requestUrl.substr(strlen(songsearch));
            SendMediaList(clientSocket, keyword, httpExtractor->ExtractHOST(request));

        } else if(audioLibrary->FileExists(requestUrl.substr(1))) {

            std::ifstream audioFile(audioLibrary->GetFullPath(requestUrl), std::ifstream::binary);
            if(audioFile.is_open()) {
                std::string extension = FindExtension(requestUrl);
                std::transform(extension.begin(), extension.end(), extension.begin(), tolower);
                StreamFile(clientSocket, audioFile, EXTENSION_TO_CONTENT_TYPE[extension]);
            } else {
                SendNotFound(clientSocket);
            }

        } else {
            SendNotFound(clientSocket);
        }

    } catch(const GenericAudioStreamerException& e) {
        std::lock_guard<std::mutex> guard(stderrMutex);
        std::cerr << e.what();
    } catch(const IHttpRequestExtractor::HttpExtractionException& e) {
        HttpResponse response(HTTP_1_1, BAD_REQUEST, NONE, 0);
        SendResponseHeader(clientSocket, response);
    }
}
예제 #13
0
int
ProcQueryExtension(ClientPtr client)
{
    xQueryExtensionReply reply;
    int i;
    REQUEST(xQueryExtensionReq);

    REQUEST_FIXED_SIZE(xQueryExtensionReq, stuff->nbytes);
    
    memset(&reply, 0, sizeof(xQueryExtensionReply));
    reply.type = X_Reply;
    reply.length = 0;
    reply.major_opcode = 0;
    reply.sequenceNumber = client->sequence;

    if ( ! NumExtensions )
        reply.present = xFalse;
    else
    {
	i = FindExtension((char *)&stuff[1], stuff->nbytes);
        if (i < 0
#ifdef XCSECURITY
	    /* don't show insecure extensions to untrusted clients */
	    || (client->trustLevel == XSecurityClientUntrusted &&
		!extensions[i]->secure)
#endif
	    )
            reply.present = xFalse;
        else
        {            
            reply.present = xTrue;
	    reply.major_opcode = extensions[i]->base;
	    reply.first_event = extensions[i]->eventBase;
	    reply.first_error = extensions[i]->errorBase;
	}
    }
    WriteReplyToClient(client, sizeof(xQueryExtensionReply), &reply);
    return(client->noClientException);
}
예제 #14
0
CAdventureDesc *CDesignCollection::FindAdventureForExtension (DWORD dwUNID) const

//	FindAdventureForExtension
//
//	Returns the adventure desc that belongs to the given extension.
//	(Or NULL if not found).

	{
	int i;

	SExtensionDesc *pExtension = FindExtension(dwUNID);
	if (pExtension == NULL || pExtension->iType != extAdventure)
		return NULL;

	for (i = 0; i < pExtension->Table.GetCount(); i++)
		{
		CDesignType *pType = pExtension->Table.GetEntry(i);
		if (pType->GetType() ==	designAdventureDesc)
			return CAdventureDesc::AsType(pType);
		}

	return NULL;
	}
예제 #15
0
TRISTATE CFileFinder::FindFiles(char* szInDirectory, BOOL bDirs, char* szInName, char* szExtension)
{
	DIR*                pDIR;
	struct dirent*      pDirEnt;
	char				szFindName[MAX_PATH];
	char				szTemp[MAX_PATH];
	BOOL				bValid;
	char				szDirectory[MAX_PATH];
	char				szFile[MAX_PATH];
	char*				szFileExtension;
	int                 iStatus;
	struct stat         sBuffer;
	BOOL                bDir;
	CFileUtil           cFileUtil;

	if (!cFileUtil.FullPath(szDirectory, szInDirectory, MAX_PATH))
	{
		return TRIERROR;
	}

	pDIR = opendir(szDirectory);

	if (pDIR == NULL)
	{
		return TRITRUE;
	}

	pDirEnt = readdir(pDIR);
	while (pDirEnt != NULL)
	{
		bValid = TRUE;

		sprintf(szTemp, "%s%s%s", szDirectory, FILE_SEPARATOR, pDirEnt->d_name);
		iStatus = stat(szTemp, &sBuffer);
		if (iStatus == -1)
		{
			printf("%s: %s\n", strerror(errno), szTemp);
			return TRIERROR;
		}
		bDir = S_ISDIR(sBuffer.st_mode);
		if (bDir) //Directory
		{
			if (bDirs)
			{
				if (szInName != NULL)
				{
					strcpy(szFile, pDirEnt->d_name);
					RemoveExtension(szFile);
					if (StrIStr(szFile, szInName) == NULL)
					{
						bValid = FALSE;
					}
				}
				else
				{
					bValid = FALSE;
				}
			}
		}
		else
		{
			if (!bDirs)
			{
				if (szExtension != NULL)
				{
					szFileExtension = FindExtension(pDirEnt->d_name);
					szFileExtension++;
					if (StrICmp(szFileExtension, szExtension) != 0)
					{
						bValid = FALSE;
					}
				}
				if (szInName != NULL)
				{
					strcpy(szFile, pDirEnt->d_name);
					RemoveExtension(szFile);
					if (StrIStr(szFile, szInName) == NULL)
					{
						bValid = FALSE;
					}
				}
			}
			else
			{
				bValid = FALSE;
			}
		}

		if (bValid)
		{
			mcFiles.Add(szTemp, 0);
		}

		pDirEnt = readdir(pDIR);
	}

	closedir(pDIR);
	return TRITRUE;
}
예제 #16
0
ALERROR CDesignCollection::SelectExtensions (CAdventureDesc *pAdventure, TArray<DWORD> *pExtensionList, bool *retbBindNeeded, CString *retsError)

//	SelectExtensions
//
//	Enables all extensions in pExtensionList and disables all others
//	(if pExtensionList == NULL then we enable all extensions).
//
//	Returns an error if an extension on the list could not be found.

	{
	int i;
	bool bBindNeeded = false;

	TArray<bool> OldState;
	OldState.InsertEmpty(GetExtensionCount());

	//	Disable all extensions

	for (i = 0; i < GetExtensionCount(); i++)
		{
		SExtensionDesc *pEntry = GetExtension(i);
		if (pEntry->iType == extExtension)
			{
			OldState[i] = pEntry->bEnabled;
			pEntry->bEnabled = false;
			}
		}

	//	Enable all extensions in the list

	if (pExtensionList)
		{
		for (i = 0; i < pExtensionList->GetCount(); i++)
			{
			SExtensionDesc *pEntry = FindExtension(pExtensionList->GetAt(i));
			if (pEntry == NULL || pEntry->iType == extAdventure)
				{
				if (retsError)
					*retsError = strPatternSubst(CONSTLIT("Unable to find extension: %x"), pExtensionList->GetAt(i));
				return ERR_NOTFOUND;
				}

			if (pEntry->iType == extExtension
					&& IsExtensionCompatibleWithAdventure(pEntry, pAdventure))
				pEntry->bEnabled = true;
			}
		}
	else
		{
		//	Enable all extensions

		for (i = 0; i < GetExtensionCount(); i++)
			{
			SExtensionDesc *pEntry = GetExtension(i);
			if (pEntry->iType == extExtension 
					&& IsExtensionCompatibleWithAdventure(pEntry, pAdventure)
					&& (!pEntry->bDebugOnly || g_pUniverse->InDebugMode()))
				pEntry->bEnabled = true;
			}
		}

	//	See if we made any changes

	for (i = 0; i < GetExtensionCount(); i++)
		{
		SExtensionDesc *pEntry = GetExtension(i);
		if (pEntry->iType == extExtension && pEntry->bEnabled != OldState[i])
			{
			bBindNeeded = true;
			break;
			}
		}

	//	Done

	if (retbBindNeeded)
		*retbBindNeeded = bBindNeeded;

	return NOERROR;
	}
예제 #17
0
파일: stream.cpp 프로젝트: hgwells/tive
wxString wxFilterClassFactoryBase::PopExtension(const wxString& location) const
{
    return location.substr(0, FindExtension(location));
}
예제 #18
0
static bool RegisterGameFile(const char *FullName, FVirtualFileSystem* parentVfs = NULL)
{
	guard(RegisterGameFile);

//	printf("..file %s\n", FullName);
	// return false when MAX_GAME_FILES
	if (GNumGameFiles >= ARRAY_COUNT(GameFiles))
		return false;

	if (!parentVfs)		// no nested VFSs
	{
		const char* ext = strrchr(FullName, '.');
		if (ext)
		{
			guard(MountVFS);

			ext++;
			FVirtualFileSystem* vfs = NULL;
			FArchive* reader = NULL;

#if SUPPORT_ANDROID
			if (!stricmp(ext, "obb"))
			{
				GForcePlatform = PLATFORM_ANDROID;
				reader = new FFileReader(FullName);
				if (!reader) return true;
				reader->Game = GAME_UE3;
				vfs = new FObbVFS();
			}
#endif // SUPPORT_ANDROID
#if UNREAL4
			if (!stricmp(ext, "pak"))
			{
				reader = new FFileReader(FullName);
				if (!reader) return true;
				reader->Game = GAME_UE4;
				vfs = new FPakVFS();
				//!! detect game by file name
			}
#endif // UNREAL4
			//!! process other VFS types here
			if (vfs)
			{
				assert(reader);
				// read VF directory
				if (!vfs->AttachReader(reader))
				{
					// something goes wrong
					delete vfs;
					delete reader;
					return true;
				}
				// add game files
				int NumVFSFiles = vfs->NumFiles();
				for (int i = 0; i < NumVFSFiles; i++)
				{
					if (!RegisterGameFile(vfs->FileName(i), vfs))
						return false;
				}
				return true;
			}

			unguard;
		}
	}

	bool IsPackage;
	if (FindExtension(FullName, ARRAY_ARG(PackageExtensions)))
	{
		IsPackage = true;
	}
	else
	{
#if HAS_SUPORT_FILES
		if (!FindExtension(FullName, ARRAY_ARG(KnownExtensions)))
#endif
		{
			// perhaps this file was exported by our tool - skip it
			if (FindExtension(FullName, ARRAY_ARG(SkipExtensions)))
				return true;
			// unknown file type
			if (++GNumForeignFiles >= MAX_FOREIGN_FILES)
				appError("Too much unknown files - bad root directory (%s)?", RootDirectory);
			return true;
		}
		IsPackage = false;
	}

	// create entry
	CGameFileInfo *info = new CGameFileInfo;
	GameFiles[GNumGameFiles++] = info;
	info->IsPackage = IsPackage;
	info->FileSystem = parentVfs;
	if (IsPackage) GNumPackageFiles++;

	if (!parentVfs)
	{
		// regular file
		FILE* f = fopen(FullName, "rb");
		if (f)
		{
			fseek(f, 0, SEEK_END);
			info->SizeInKb = (ftell(f) + 512) / 1024;
			fclose(f);
		}
		else
		{
			info->SizeInKb = 0;
		}
		// cut RootDirectory from filename
		const char *s = FullName + strlen(RootDirectory) + 1;
		assert(s[-1] == '/');
		appStrncpyz(info->RelativeName, s, ARRAY_COUNT(info->RelativeName));
	}
	else
	{
		// file in virtual file system
		info->SizeInKb = parentVfs->GetFileSize(FullName);
		appStrncpyz(info->RelativeName, FullName, ARRAY_COUNT(info->RelativeName));
	}

	// find filename
	const char* s = strrchr(info->RelativeName, '/');
	if (s) s++; else s = info->RelativeName;
	info->ShortFilename = s;
	// find extension
	s = strrchr(info->ShortFilename, '.');
	if (s) s++;
	info->Extension = s;
//	printf("..  -> %s (pkg=%d)\n", info->ShortFilename, info->IsPackage);

#if UNREAL3
	if (info->IsPackage && (strnicmp(info->ShortFilename, "startup", 7) == 0))
	{
		// Register a startup package
		// possible name variants:
		// - startup
		// - startup_int
		// - startup_*
		int startupWeight = 0;
		if (info->ShortFilename[7] == '.')
			startupWeight = 30;							// "startup.upk"
		else if (strnicmp(info->ShortFilename+7, "_int.", 5) == 0)
			startupWeight = 20;							// "startup_int.upk"
		else if (strnicmp(info->ShortFilename+7, "_loc_int.", 9) == 0)
			startupWeight = 20;							// "startup_int.upk"
		else if (info->ShortFilename[7] == '_')
			startupWeight = 1;							// non-int locale, lower priority - use if when other is not detected
		if (startupWeight > GStartupPackageInfoWeight)
		{
			GStartupPackageInfoWeight = startupWeight;
			GStartupPackageInfo = info;
		}
	}
#endif // UNREAL3

	// insert CGameFileInfo into hash table
	int hash = GetHashForFileName(info->ShortFilename);
	info->HashNext = GGameFileHash[hash];
	GGameFileHash[hash] = info;

	return true;

	unguardf("%s", FullName);
}
예제 #19
0
파일: Filename.c 프로젝트: iKarith/nulib2
/*
 * Add a preservation string.
 *
 * "pathBuf" is assumed to have enough space to hold the current path
 * plus kMaxPathGrowth more.  It will be modified in place.
 */
static void AddPreservationString(NulibState* pState,
    const NuPathnameProposal* pPathProposal, char* pathBuf)
{
    char extBuf[kMaxPathGrowth +1];
    const NuRecord* pRecord;
    const NuThread* pThread;
    NuThreadID threadID;
    char* cp;

    Assert(pState != NULL);
    Assert(pPathProposal != NULL);
    Assert(pathBuf != NULL);
    Assert(NState_GetModPreserveType(pState));

    pRecord = pPathProposal->pRecord;
    pThread = pPathProposal->pThread;
    Assert(pRecord != NULL);
    Assert(pThread != NULL);

    cp = extBuf;

    /*
     * Cons up a preservation string.  On some platforms "sprintf" doesn't
     * return the #of characters written, so we add it up manually.
     */
    if (pRecord->recFileType < 0x100 && pRecord->recExtraType < 0x10000) {
        sprintf(cp, "%c%02x%04x", kPreserveIndic, pRecord->recFileType,
            pRecord->recExtraType);
        cp += 7;
    } else {
        sprintf(cp, "%c%08x%08x", kPreserveIndic, pRecord->recFileType,
            pRecord->recExtraType);
        cp += 17;
    }

    threadID = NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind);
    if (threadID == kNuThreadIDRsrcFork)
        *cp++ = kResourceFlag;
    else if (threadID == kNuThreadIDDiskImage)
        *cp++ = kDiskImageFlag;

    /*
     * If they've asked for "extended" type preservation, then we need
     * to retain either the existing extension or append an extension
     * based on the ProDOS file type.
     */
    if (NState_GetModPreserveTypeExtended(pState)) {
        const char* pExt;
        char* end;

        /*
         * Find extension.  Note FindExtension guarantees there's at least
         * one char after '.'.
         *
         * It's hard to know when this is right and when it isn't.  It's
         * fairly likely that a text file really ought to end in ".txt",
         * and it's fairly unlikely that a BIN file should be ".bin", but
         * where do the rest fall in?  We might want to force TXT files
         * to be ".txt", and perhaps do something clever for some others.
         */
        if (pRecord->recFileType == 0x04 || threadID == kNuThreadIDDiskImage)
            pExt = NULL;
        else
            pExt = FindExtension(pState, pathBuf);
        if (pExt != NULL) {
            pExt++; /* skip past the '.' */

            if (strlen(pExt) >= kMaxExtLen) {
                /* too long, forget it */
                pExt = NULL;
            } else {
                /* if strictly decimal-numeric, don't use it (.1, .2, etc) */
                (void) strtoul(pExt, &end, 10);
                if (*end == '\0') {
                    pExt = NULL;
                } else {
                    /* if '#' appears in it, don't use it -- it'll confuse us */
                    const char* ccp = pExt;
                    while (*ccp != '\0') {
                        if (*ccp == '#') {
                            pExt = NULL;
                            break;
                        }
                        ccp++;
                    }
                }
            }

        } else {
            /*
             * There's no extension on the filename.  Use the standard
             * ProDOS type, if one exists for this entry.  We don't use
             * the table if it's "NON" or a hex value.
             */
            if (threadID == kNuThreadIDDiskImage)
                pExt = "PO";    /* indicate it's a ProDOS-ordered image */
            else if (pRecord->recFileType) {
                pExt = GetFileTypeString(pRecord->recFileType);
                if (pExt[0] == '?' || pExt[0] == '$')
                    pExt = NULL;
            }
        }

        if (pExt != NULL) {
            *cp++ = kFilenameExtDelim;
            strcpy(cp, pExt);
            cp += strlen(pExt);
        }
    }

    /* make sure it's terminated */
    *cp = '\0';

    Assert(cp - extBuf <= kMaxPathGrowth);
    strcat(pathBuf, extBuf);
}
예제 #20
0
bool AudioLibrary::SupportsFileType(const std::string& filePath) const {
    std::string extension = FindExtension(filePath);
    std::transform(extension.begin(), extension.end(), extension.begin(), tolower);
    return SupportedFileTypes.find(extension) != SupportedFileTypes.end();
}
BOOL CFileUtil::FindFiles(const char*szInDirectory, BOOL bDirs, const char*szInName, const char*szExtension, CArrayChars* paszFiles, BOOL bHidden)
{
	WIN32_FIND_DATA		sFindData;
	CChars				szFindName;
	CChars				szTemp;
	HANDLE				hFindHandle;
	BOOL				bContinue;
	int					iFileExtension;
	BOOL				bValid;
	CChars				szFake;
	CChars				szDirectory;

	szDirectory.Init(szInDirectory);
	FullPath(&szDirectory);
	szFindName.Init(szDirectory);
	AppendToPath(&szFindName, "*.*");

	hFindHandle = FindFirstFile(szFindName.Text(), &sFindData);
	bContinue = (hFindHandle != INVALID_HANDLE_VALUE);

	if (!bContinue)
	{
		szDirectory.Kill();
		szFindName.Kill();
		return FALSE;
	}

	while (bContinue)
	{
		if (!(sFindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || bHidden)
		{
			bValid = TRUE;
			if (sFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				if (bDirs)
				{
					if (szInName != NULL)
					{
						szTemp.Init(sFindData.cFileName);
						RemoveExtension(&szTemp);
						if (!szTemp.ContainsIgnoreCase(szInName))
						{
							bValid = FALSE;
						}
						szTemp.Kill();
					}
				}
				else
				{
					bValid = FALSE;
				}
			}
			else
			{
				if (!bDirs)
				{
					if (szExtension != NULL)
					{
						szFake.Fake(sFindData.cFileName);
						iFileExtension = FindExtension(szFake.Text());
						if (iFileExtension != -1)
						{
							if (!(szFake.SubStringEquals(iFileExtension+1, szExtension)))
							{
								bValid = FALSE;
							}
						}
						else
						{
							//If there is no file extension on the current file and the
							//extension being looked for is not empty...
							if (szExtension[0] != 0)
							{
								//Then this file is not valid.
								bValid = FALSE;
							}
						}
					}
					if (szInName != NULL)
					{
						szTemp.Init(sFindData.cFileName);
						RemoveExtension(&szTemp);
						if (!szTemp.ContainsIgnoreCase(szInName))
						{
							bValid = FALSE;
						}
						szTemp.Kill();
					}
				}
				else
				{
					bValid = FALSE;
				}
			}
		}
		else
		{
			bValid = FALSE;
		}

		if (bValid)
		{
			if (!((strcmp(sFindData.cFileName, ".") == 0) || (strcmp(sFindData.cFileName, "..") == 0)))
			{
				szTemp.Init(szDirectory);
				AppendToPath(&szTemp, sFindData.cFileName);
				paszFiles->Add(szTemp.Text());
				szTemp.Kill();
			}
		}

		bContinue = FindNextFile(hFindHandle, &sFindData);
	}
	FindClose(hFindHandle);

	szDirectory.Kill();
	szFindName.Kill();
	return TRUE;
}
예제 #22
0
HINSTANCE TaLocale_LoadCorrespondingModuleByName (HINSTANCE hInstance, LPTSTR pszFilename, WORD wSearchPriority)
{
   HINSTANCE hDLL = NULL;

   TCHAR szFilename[ MAX_PATH ];
   if (lstrchr (pszFilename, TEXT('\\')) != NULL)
      lstrcpy (szFilename, pszFilename);
   else
      {
      GetModuleFileName (hInstance, szFilename, MAX_PATH);
      lstrcpy ((LPTSTR)FindBaseFileName (szFilename), pszFilename);
      }


   // If the caller was sloppy and didn't supply an instance handle,
   // assume we should find the module corresponding with the current .EXE.
   //
   if (hInstance == NULL)
      hInstance = GetModuleHandle(NULL);

   LPTSTR pchExtension;
   if ((pchExtension = (LPTSTR)FindExtension (szFilename)) != NULL)
      {

      // Find the filename associated with the specified module, remove its
      // extension, and append "_409.dll" (where the 409 is, naturally, the
      // current LANGID). Then try to load that library.
      //
      wsprintf (pchExtension, TEXT("_%lu.dll"), TaLocale_GetLanguage());
      if ((hDLL = LoadLibrary (szFilename)) == NULL)
         hDLL = LoadLibrary (FindBaseFileName (szFilename));

      // If we couldn't find the thing under that name, it's possible we
      // have a .DLL made for the proper language but not for the user's
      // specific sublanguage (say, a US English .DLL but we're running
      // in a Canadian English locale). Make an intelligent guess about
      // what the valid ID would be.
      //
      if (hDLL == NULL)
         {
         wsprintf (pchExtension, TEXT("_%lu.dll"), TaLocale_GuessBestLangID (TaLocale_GetLanguage()));
         if ((hDLL = LoadLibrary (szFilename)) == NULL)
            hDLL = LoadLibrary (FindBaseFileName (szFilename));
         }

      // If we STILL couldn't find a corresponding resource library,
      // we'll take anything we can find; this should cover the case
      // where a Setup program asked the user what language to use,
      // and just installed that matching library. Look in the
      // appropriate directory for any .DLL that fits the naming convention.
      //
      if (hDLL == NULL)
         {
         wsprintf (pchExtension, TEXT("_*.dll"));

         WIN32_FIND_DATA wfd;
         memset (&wfd, 0x00, sizeof(wfd));

         HANDLE hFind;
         if ((hFind = FindFirstFile (szFilename, &wfd)) != NULL)
            {
            if (wfd.cFileName[0])
               {
               wsprintf ((LPTSTR)FindBaseFileName (szFilename), wfd.cFileName);
               hDLL = LoadLibrary (szFilename);
               }
            FindClose (hFind);
            }
         }

      // If we EVEN NOW couldn't find a corresponding resource library,
      // we may have done our wildcard search in the wrong directory.
      // Try to find the Common subdirectory of our AFS installation,
      // and look for any matching DLL there.
      //
      if (hDLL == NULL)
         {
         wsprintf (pchExtension, TEXT("_*.dll"));

         TCHAR szCommonPath[ MAX_PATH ];
         if (FindAfsCommonPath (szCommonPath))
            {
            lstrcat (szCommonPath, TEXT("\\"));
            lstrcat (szCommonPath, FindBaseFileName (szFilename));

            WIN32_FIND_DATA wfd;
            memset (&wfd, 0x00, sizeof(wfd));

            HANDLE hFind;
            if ((hFind = FindFirstFile (szCommonPath, &wfd)) != NULL)
               {
               if (wfd.cFileName[0])
                  {
                  wsprintf ((LPTSTR)FindBaseFileName (szCommonPath), wfd.cFileName);
                  hDLL = LoadLibrary (szCommonPath);
                  }
               FindClose (hFind);
               }
            }
         }

      // If all else fails, we'll try to find the English library
      // somewhere on our path.
      //
      if (hDLL == NULL)
         {
         wsprintf (pchExtension, TEXT("_%lu.dll"), MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US));
         if ((hDLL = LoadLibrary (szFilename)) == NULL)
            hDLL = LoadLibrary (FindBaseFileName (szFilename));
         }

      // If we were successful in loading the resource library, add it
      // to our chain of modules-to-search
      //
      if (hDLL != NULL)
         {
         TaLocale_SpecifyModule (hDLL, wSearchPriority);
         }
      }

   return hDLL;
}