const Path Instance::GetTmpPath(GenericString file)
		{
			Path path;
			path.Reserve( 255 );

			if (uint length = ::GetTempPath( path.Capacity() + 1, path.Ptr() ))
			{
				if (length > path.Capacity() + 1)
				{
					path.Reserve( length - 1 );
					length = ::GetTempPath( path.Capacity() + 1, path.Ptr() );
				}

				if (length)
					path = GetLongPath( path.Ptr() );
			}

			if (path.Length())
				path.MakePretty( true );
			else
				path << ".\\";

			if (file.Empty())
				file = L"nestopia.tmp";

			path << file;

			return path;
		}
Ejemplo n.º 2
0
		const Path Browser::SelectDirectory()
		{
			Path path;
			path.Reserve( MAX_PATH*2 );

			Object::Pod<BROWSEINFO> bi;

			bi.hwndOwner      = Application::Instance::GetActiveWindow();
			bi.pszDisplayName = path.Ptr();
			bi.ulFlags        = BIF_RETURNONLYFSDIRS;

			if (LPITEMIDLIST const idl = ::SHBrowseForFolder( &bi ))
			{
				if (::SHGetPathFromIDList( idl, path.Ptr() ) && path.Validate())
					path.MakePretty( true );
				else
					path.Clear();

				IMalloc* pMalloc;

				if (SUCCEEDED(::SHGetMalloc( &pMalloc )))
				{
					pMalloc->Free( idl );
					pMalloc->Release();
				}
			}
			else
			{
				path.Clear();
			}

			return path;
		}
		const Path Instance::GetLongPath(wcstring const shortPath)
		{
			Path longPath;

			longPath.Reserve( 255 );
			uint length = ::GetLongPathName( shortPath, longPath.Ptr(), longPath.Capacity() + 1 );

			if (length > longPath.Capacity() + 1)
			{
				longPath.Reserve( length - 1 );
				length = ::GetLongPathName( shortPath, longPath.Ptr(), longPath.Capacity() + 1 );
			}

			if (!length)
				return shortPath;

			const wchar_t slashed = GenericString(shortPath).Back();

			longPath.ShrinkTo( length );
			longPath.MakePretty( slashed == '\\' || slashed == '/' );

			return longPath;
		}