Exemple #1
0
// ****************************************************************************
//
//  Function Name:	RMergeData::OpenFile( )
//
//  Description:		Make this MergeData takes its values from a choosen file
//
//  Returns:			Nothing
//
//  Exceptions:		None
//
// ****************************************************************************
//
BOOLEAN RMergeData::OpenFile( BOOL& bCancelled )
	{
	RMBCString	fileName;
	bCancelled = FALSE;
	BOOL bCompatibleMode = FALSE;

#ifdef	_WINDOWS
	RMBCString	fileExtension;
	RMBCString	fileFilter;
	ReturnFileExtension( fileExtension, FALSE );
	ReturnFileFilter( fileFilter, FALSE );
	CFileDialog	dialog( TRUE, (LPCTSTR)fileExtension, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
								(LPCTSTR)fileFilter, NULL );
	if ( dialog.DoModal( ) == IDCANCEL )
	{
		bCancelled = TRUE;
		return FALSE;
	}

	fileName	= dialog.GetPathName( );

	// did the user pick a PSD4 file?
	ReturnFileExtension( fileExtension, TRUE );

	// we have to add a '.' to the start of what GetFileExt()
	// returns so we can do the comparision.
	CString	szExtension('.' + dialog.GetFileExt() );
	
	if ( szExtension.CompareNoCase( fileExtension ) == 0 )
		bCompatibleMode = TRUE;

#else		//	MAC

#endif	//	_WINDOWS

	//	Validate we can read the file
	try
	{
		RStorage	storage( fileName, kRead );
	}
	catch( YException exception )
	{
		if ( exception != kEndOfFile )
			return FALSE;
	}
	catch( ... )
	{
		return FALSE;
	}

	return OpenFile( fileName, bCompatibleMode );
	}
STDMETHODIMP CSimplePointWorkspaceFactory::ContainsWorkspace(BSTR parentDirectory, IFileNames *FileNames, VARIANT_BOOL *ContainsWorkspace)
{
  if (! ContainsWorkspace) return E_POINTER;
	if (! parentDirectory) return E_POINTER;

  if (! FileNames)
    return IsWorkspace(parentDirectory, ContainsWorkspace);

	*ContainsWorkspace = VARIANT_FALSE;

	if (!IsDirectory(parentDirectory))
		return S_FALSE;

	CComBSTR sName; 
	CComBSTR sExt;
  VARIANT_BOOL bIsDir;
  FileNames->Reset();
  
	while (S_OK == FileNames->Next(&sName))
  {
    FileNames->IsDirectory(&bIsDir); // is the current file a directory?
    if (bIsDir)
      continue;

		ReturnFileExtension(sName, &sExt);
		sExt.ToUpper();
		if (sExt == g_sExtUpper)
    {
      *ContainsWorkspace = VARIANT_TRUE;
      return S_OK;
    }
  }

	return S_FALSE;
}
STDMETHODIMP CSimplePointWorkspaceFactory::GetWorkspaceString(BSTR parentDirectory, IFileNames *FileNames, BSTR *wksString)
{
	HRESULT hr;
	if (!parentDirectory || ! wksString) return E_POINTER;

	// Initialize return string to null
	*wksString = 0;

	VARIANT_BOOL bIsWorkspace = VARIANT_FALSE;

	if (! FileNames)
	{
		 hr = IsWorkspace(parentDirectory, &bIsWorkspace);
     if (!bIsWorkspace)
			 return S_FALSE;
	}
  else 
	{
  	if (!IsDirectory(parentDirectory))
	  	return S_FALSE;

		CComBSTR sName;
		CComBSTR sExt;
		VARIANT_BOOL bIsDir = VARIANT_FALSE;
		FileNames->Reset();
  
		while (S_OK == FileNames->Next(&sName))
		{
			FileNames->IsDirectory(&bIsDir); // is the current file a directory?
			if (bIsDir) continue;

			ReturnFileExtension(sName, &sExt);
			sExt.ToUpper();
			if (sExt == g_sExtUpper)
			{
				bIsWorkspace = VARIANT_TRUE;
				FileNames->Remove();
			}
		}
  }

	// if it is a workspace, set the workspace string to be the parent directory
	if (bIsWorkspace)
	{
		CComBSTR sWorkspaceString(parentDirectory);		
		*wksString = sWorkspaceString.Detach();
		return S_OK;
	}

	return S_FALSE;
}
Exemple #4
0
// ****************************************************************************
//
//  Function Name:	RMergeData::SaveAsFile( )
//
//  Description:		Make this MergeData takes its values from a choosen file
//							
//  Returns:			Nothing
//
//  Exceptions:		None
//
// ****************************************************************************
//
BOOLEAN RMergeData::SaveAsFile( )
	{

	try
	{
		RMBCString	fileName;

	#ifdef	_WINDOWS
		RMBCString	fileExtension;
		RMBCString	fileFilter;
		ReturnFileExtension( fileExtension, TRUE );
		ReturnFileFilter( fileFilter, TRUE );
		CFileDialog	dialog( FALSE, (LPCTSTR)fileExtension, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
									(LPCTSTR)fileFilter, NULL );
		if ( dialog.DoModal( ) == IDCANCEL )
			return FALSE;
		fileName	= dialog.GetPathName( );
	#else	//	MAC
	#endif	//	_WINDOWS

		if ( fileName.GetStringLength() > 0 )
			{
			RMBCString	oldFileName	= m_FileName;
			m_FileName = fileName;
			if ( !SaveFile( ) )
				{
				m_FileName = oldFileName;
				return FALSE;
				}
			}
	}
	catch( YException exception )
		{
		::ReportException( exception );
		return FALSE;
		}
	catch( ... )
		{
		::ReportException( kUnknownError );
		return FALSE;
		}

	return TRUE;
	}