Ejemplo n.º 1
0
//*****************************************************************************
UINT CDrodFileDialogWidget::GetExtensionType(const WSTRING& wFilename)
//Determine file type based on file name extension.
{
	UINT ext;
	for (ext = 0; ext < FileExtension::EXT_COUNT; ++ext)
	{
		WSTRING wstrExt = wszPeriod;
		wstrExt += g_pTheDB->GetMessageText(fileExtension[ext]);
		if (!WCSicmp(wFilename.c_str() + WCSlen(wFilename.c_str()) - wstrExt.size(), wstrExt.c_str()))
		{
			//Recognized file extension.
			return ext;
		}
	}

	//On older OSes, only 3-character extensions are recognized.
	//If none of the above matches worked, try matching against shortened extensions.
	for (ext = 0; ext < FileExtension::EXT_COUNT; ++ext)
	{
		WSTRING wstrExt = wszPeriod;
		wstrExt += g_pTheDB->GetMessageText(fileExtension[ext]);
		if (wstrExt.length() > 4) //don't retest extensions that were already short enough
		{
			wstrExt.resize(4); //.ext
			if (!WCSicmp(wFilename.c_str() + WCSlen(wFilename.c_str()) - wstrExt.size(), wstrExt.c_str()))
			{
				//Recognized file extension.
				return ext;
			}
		}
	}

	return FileExtension::EXT_COUNT; //extension not recognized
}
Ejemplo n.º 2
0
//*****************************************************************************
void CFileDialogWidget::GoToDirectory()
//Go to selected directory.
{
	const WSTRING wstrDirname = this->pDirListBoxWidget->GetSelectedItemText();
	if (wstrDirname.empty()) return; //nothing is selected
	if (!WCScmp(wszParentDir,wstrDirname.c_str()))
	{
		//Go up a directory.
		const int nSlashLoc=this->dirpath.rfind(wszSlash);
		if (nSlashLoc<0)
			this->dirpath.resize(0);
#ifndef WIN32
		else if (nSlashLoc == 0)
			this->dirpath.resize(1); // go to root dir
#endif
		else
			this->dirpath.resize(nSlashLoc);
#if defined(WIN32) || defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
	} else if (wstrDirname[0] == W_t('[')) {
		//Switch drives.
		WSTRING newDrive = wstrDirname.c_str() + 2;
		newDrive.resize(newDrive.size()-2);
		SetDirectory(newDrive.c_str());
		return;
#endif
	} else {
		//Go down a directory.
		if (this->dirpath.c_str() &&
				(this->dirpath.c_str()[this->dirpath.length()-1] != wszSlash[0]))
			this->dirpath += wszSlash;
		this->dirpath += wstrDirname;
	}

	SetDirectory();
}