예제 #1
0
bool CTemplateManager::GetTemplateFilename( UINT32 ordNumberOfTemplate, String_256* pStrNameOfFile )
{
	// Fill the list with all templates (user local, begin second will over-write system ones)
	CTemplateList		setSortFilename;
	GetTemplateList( &setSortFilename, m_TemplatesPath, false );
	GetTemplateList( &setSortFilename, m_LocalTemplatesPath, true );

	// If the template with ordinal doesn't exist, fail
	if( ordNumberOfTemplate > UINT32(setSortFilename.size()) )
		return false;

	// Get enbry for template
	CTemplateList::iterator iter = setSortFilename.begin();
	for( UINT32 i = 1; i < ordNumberOfTemplate; ++i, ++iter )
	{ /*Do nothing!*/ }

	// Pre-pend the path to the template
	PathName			pathTemplates = iter->second ? m_LocalTemplatesPath : m_TemplatesPath;
	pathTemplates.SetFileNameAndType( iter->first );

	*pStrNameOfFile = pathTemplates.GetPath();
	TRACEUSER( "jlh92", _T("Final(%d) = %s\n"), ordNumberOfTemplate, PCTSTR(*pStrNameOfFile) );

	return true;
}
예제 #2
0
파일: thumb.cpp 프로젝트: vata/xarino
BOOL SGThumbs::OpenThumbnailFile( CCDiskFile* pFile, const PathName& ThumbFileName ) const
{
	ERROR3IF( pFile==NULL, "SGThumbs::OpenThumbnailFile passed a null ptr" );
	
	TRACEUSER( "Martin", _T("Open thumb file: %s\n"), (const TCHAR *)ThumbFileName.GetPath() );

	BOOL Found = FALSE;

	if(!ThumbFileName.IsValid())
	{
		// either xarainfo\\<filename> or the actual clipart file
		ERROR3("SGThumbs::OpenThumbnailFile received an invalid xarainfo\\<filename> file");
		Error::ClearError();
		return FALSE;
	}

	// Open file and check if it exists at the same time
	if( !( Found = pFile->open( ThumbFileName, ios::in | ios::binary ) ) )
	{
		Found = FALSE;
		Error::ClearError();
	}

	return Found;
}
예제 #3
0
BOOL PlugInPathList::DeletePathName( const PathName& OldPath )
{
	String_256 OldPathStr = OldPath.GetPath();
	PlugInPath* pPath = (PlugInPath *)GetHead();
	while (pPath)
	{
		PathName Path = pPath->GetPathName();
		if (Path.GetPath() == OldPathStr)
		{
			RemoveItem(pPath);
			// remove item returns NULL if problem
			if (pPath == NULL)
				return FALSE;
			delete pPath;
			return TRUE;
		}

		// Try the next pathname in the list
		pPath = (PlugInPath *)GetNext(pPath);
	}

	// Failed to find the path in the list
	return FALSE;
}
예제 #4
0
void OpConvertFileFormats::Do(OpDescriptor*)
{
	ERROR3 ("Please read the following comments BEFORE using this op!");	// comment this out to use the op

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
	
	// set up the search path, file util allows us just to pass the path/*.xar
	String_256 SearchPath = TEXT ("d:\\clipart\\xara\\");		// YOU MUST CHANGE THIS PATH
	
	String_256 FileSpecifier = SearchPath;						// YOU MUST CHANGE THIS EXTENSION
				FileSpecifier += TEXT("*.art");
	String_256 FileSpecifier2 = TEXT("xar");					// YOU MUST CHANGE THIS EXTENSION

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

	BOOL ok = FileUtil::StartFindingFiles(&FileSpecifier);
	active = TRUE;
	String_256 Filename;
	while (ok)
	{
		// fileutil will give us the next filename
		ok = FileUtil::FindNextFile(&Filename);
		String_256 FilePath = SearchPath;
		FilePath += Filename;
		PathName Path (FilePath);

		if (ok)
		{
			CDocument* pDoc = theApp.OpenDocumentFile((TCHAR*)FilePath);
			if (pDoc!=NULL)
			{
				// Make sure that the files name is sensible
				theApp.MakeDocumentNative(pDoc, &Path);
				
				Path.SetType (FileSpecifier2);
				String_256 newPath = Path.GetPath ();
				pDoc->DoSave ((TCHAR*) newPath, TRUE);

				FileCloseAction ();
			}
		}
	}
	active = FALSE;
	FileUtil::StopFindingFiles ();
}
예제 #5
0
INT32 PluginOILFilter::HowCompatible(PathName& FileName)
{
	INT32 HowCompatible = 0;

	// Here we need to run the plugin synchronously with the following options
	// -c -f <filename>

	// Check stderr for errors
	// Get HowCompatible from stdout
	if (!m_CanImport.IsEmpty())
	{
		wxString sCommand(m_CanImport);
		sCommand.Replace(_T("%IN%"), (LPCTSTR)FileName.GetPath());

		TRACEUSER("Gerry", _T("Running '%s'"), sCommand.c_str());

		wxArrayString saOutput;
		wxArrayString saErrors;
		INT32 code = wxExecute(sCommand, saOutput, saErrors, wxEXEC_NODISABLE);
		TRACEUSER("Gerry", _T("wxExecute returned %d"), code);
		if (code == 0)
		{
			// Extract the value from saOutput
			if (saOutput.Count() > 0)
			{
				INT32 Val = wxAtoi(saOutput[0]);
				TRACEUSER("Gerry", _T("Command '%s' returned string '%s'"), sCommand.c_str(), saOutput[0].c_str());
				TRACEUSER("Gerry", _T("Value = %d"), Val);
				if (Val >= 0 && Val <= 10)
				{
					HowCompatible = Val;
				}
			}
			else
			{
				TRACEUSER("Gerry", _T("Command '%s' returned no output value"), sCommand.c_str());
			}
		}
		else
		{
			TRACEUSER("Gerry", _T("Command '%s' exited with code %d"), sCommand.c_str(), code);
		}
	}

	return(HowCompatible);
}
예제 #6
0
파일: gendwnd.cpp 프로젝트: vata/xarino
void OpGenericDownload::OnDownloadSuccess()
{
	// get a pointer to the OpParam so that I can retrieve some useful information
	GenericDownloadParam* pGenericParam = (GenericDownloadParam*) pParam;

	String_256 GenericFile = (pGenericParam->file).GetFileName();
	if (IsUserName("Olivier"))
		TRACE1("OpGenericDownload::OnDownloadSuccess(), file = %s\n", (TCHAR*)GenericFile);

	Filter* pFilter = pGenericParam->m_pFilter;
	PathName Path = pGenericParam->file;
	String_256 URL = pGenericParam->strURL;
	SelOperation* Op = pGenericParam->m_Op;

	// call the DoImport function from OpMenuImport class
	((OpMenuImport*)Op)->DoImport(Path, pFilter, &URL);

	// remove the temporary file
	remove((TCHAR*) (String_256) Path.GetPath());
}
예제 #7
0
파일: sgscanf.cpp 프로젝트: vata/xarino
INT32 LibraryFile::Init(SuperGallery *ParentGal, PathName *APath, SGLibType Type, BOOL Updated, BOOL DoScroll)
{
#ifndef EXCLUDE_GALS
	if(ParentGal == NULL || APath == NULL || !Libraries.IsEmpty())
	{
		ERROR3("LibraryFile::Init - NULL parameters are illegal OR Init called > 1 times");
		if(!Libraries.IsEmpty())
			return(Libraries.GetCount());
		else
			return 0;
	}

	BOOL ok = TRUE;

	// Tidy up Path a bit
	String_256 OurPath(APath->GetPath());
	LibraryFile::TidyUpSubPath(&OurPath);

	// Now point Path to the new pathname
	PathName ModifiedPath(OurPath);
	PathName *Path = &ModifiedPath;

	if(!ModifiedPath.IsValid())
	{
		ERROR3("LibraryFile::Init -> Modified library path is invalid");
		return 0;
	}

	// Remember the pathname and type
	MyPath = *Path;
	MyType = Type;

	ParentGallery = ParentGal;
	if(ParentGallery->IsKindOf(CC_RUNTIME_CLASS(LibraryGallery)))
		ParentLibraryGallery = (LibraryGallery *)ParentGal;
	else
	{
		ERROR3("LibraryFile::Init passed a non-library gallery - yikes...");
		return 0;
	}

	// Need to reset the Quiet status before a stream of Library::Init calls
	ParentLibraryGallery->SetQuietStatus(FALSE);

	BOOL Retry = TRUE;
	while(Retry)
	{
		Retry = FALSE;
	
		// Would be nice to have a way of adding a file to a path in PathName... Is there one ?
		if(!SGLibOil::FileExists(Path))
		{
			// We're opening the font gallery, but can't find the font library path - don't warn
			if(Type == SGLib_Font)
				return 0;

			// tell the user that the directory doesn't exist
			String_256 WarnMsg;
			String_256 DefaultIndex;
			String_256 IndexDesc;
			BOOL CanGenerate;
		
			ok = LibraryFile::GetSubIndexDetails(ParentLibraryGallery, &DefaultIndex, &IndexDesc, &CanGenerate);

			String_256 TmpPath(Path->GetLocation(FALSE));
			LibraryFile::TidyUpSubPath(&TmpPath);

			// Taken out by Graham 30/10/97: If the gallery had no directory specified,
			//we used to throw a warning which said "do you want to specify another folder?"
			//We don't do this any more, because the default is to open all galleries empty and
			//then download stuff from the Xara web site
#if 0 
			WarnMsg.MakeMsg(_R(IDS_BROWSE_OR_SCAN), (TCHAR *)IndexDesc, (TCHAR *)TmpPath);
			Error::SetError(0, WarnMsg, 0);
			INT32 ButtonPressed = InformWarning(0, _R(IDS_BROWSE), _R(IDS_RETRY), _R(IDS_CANCEL)/*, _R(IDS_HELP)*/);
#else	// WEBSTER
			INT32 ButtonPressed = 3;
#endif  // WEBSTER
			TRACEUSER( "Richard", _T("ButtonPressed: %d\n"), ButtonPressed);
			Error::ClearError();
			switch(ButtonPressed)
			{
				case 1:
				{
					// Open the Browse dialog (or the Add.. dialog as it seems to be called now)
					PathName ThePath(*Path);
				
					// This returns FALSE if Cancel was hit, or an error occurred.
 					if(!SGLibOil::GetLibPath(ParentLibraryGallery, &ThePath, CanGenerate, Type))
					{
						ERROR3("GetLibPath returned FALSE in LF::Init");
						return 0;
					}
					else
					{
						ModifiedPath = ThePath;
						if(!ModifiedPath.IsValid())
						{
							ERROR3("LibraryFile::Init -> scanned library path is invalid");
							return 0;
						}

						// Remember the pathname
						MyPath = ThePath;

						switch(Type)
						{
							case SGLib_ClipArt:
							case SGLib_Bitmap:
								LibClipartSGallery::DefaultLibraryPath = MyPath.GetPath();
								LibClipartSGallery::ClipartPath = LibClipartSGallery::DefaultLibraryPath;
								break;

							case SGLib_ClipArt_WebThemes:
								LibClipartSGallery::DefaultLibraryPath = MyPath.GetPath();
								LibClipartSGallery::WebThemePath = LibClipartSGallery::DefaultLibraryPath;
								break;

#ifndef STANDALONE
							case SGLib_Texture:
							case SGLib_Fractal:
								LibFillsSGallery::DefaultLibraryPath = MyPath.GetPath();
								break;

							case SGLib_Font:
								// WEBSTER-Martin-09/01/97 - Put back by Ranbir.
								//#ifndef WEBSTER
								FontsSGallery::DefaultLibraryPath = MyPath.GetPath();
								break; // Not in webster so we get the error below
								//#endif // WEBSTER
#endif
							default:
								ERROR2(FALSE,"Library::ScanForLocation Type not present!");
								break;
						}
					}
					break;
				}						

				case 2:
					Retry = TRUE;
#if 0
					{
						// Scan
						String_256 Result;
						if(!Library::ScanForLocation(Type, &Result))
						{
							ERROR3("No libraries found...");
							return 0;
						}

						if(!ModifiedPath.SetPathName(Result))
						{
							ERROR3("LibraryFile::Init -> scanned library path is invalid");
							return 0;
						}

						// Remember the pathname and type
						MyPath = *Path;
					}
#endif
					break;

				case 3:
					// Cancel
					return 0;
			}
		}
	}

	// Wipe libraries added to gallery for scroll / redraw purposes...
	InitScrollRedrawSystem();

	// Check the actual path exists
   	if(SGLibOil::FileExists(Path))
	{
		// Would be nice to have a way of adding a file to a path in PathName... Is there one ?
		String_256 IndexFile((const TCHAR *)Path->GetPath(TRUE)); // "%s\\XaraInfo\\index.txt"
		IndexFile += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
		IndexFile += TEXT("\\") + String_16(_R(IDS_LIBRARIES_INDEX_FILENAME));

		PathName IndexFilePath(IndexFile);
		if(!IndexFilePath.IsValid())
		{
			ERROR3("LibraryFile::Init indexfilepath is invalid");
			return 0;
		}

		CCDiskFile MainIndex;
		if (!MainIndex.InitLexer(FALSE))
		{
			// SetError!
			ERROR3("LibraryFile::LibraryFile InitLexer failed");
			return(0);
		}

	   	if(SGLibOil::FileExists(&IndexFilePath))
		{
			// Count lines in index file
			INT32 Count = CountLines(&IndexFilePath);

			TRACEUSER( "Richard", _T("%d lines in index file\n"), Count);

			// Used for the percentage display
			INT32 CurrentGroupNumber = 0;

			// Just in case there's a slow job already going on...
			SmashSlowJob();
			String_64 SlowJob(_R(IDS_LIBRARY_SCANNING));
			BeginSlowJob(Count, FALSE, &SlowJob);
 		
			// Now use the index file to create each group in turn
			if (MainIndex.open(IndexFilePath, ios::in))
			{
				MainIndex.SetWhitespace("");		// Setting this to blank lets us read non-"'d strings
				MainIndex.SetDelimiters(",");		// ,s delimit our fields
				MainIndex.SetCommentMarker('#');	// #'d lines are commented out
				MainIndex.SetStringDelimiters("");	// No string delimiters

				String_64 Directory;
				String_64 Description;
				String_64 SubIndex;
				String_64 Kind;
				LexTokenType TT;
	
				BOOL EscapePressed = FALSE;

				while(ok && !EscapePressed)
				{
					if(!MainIndex.GetToken()) break;		// Get SubLib directory name

					// Keep reading tokens until we hit a normal one... (skips line ends and
					// comments for us
					TT = MainIndex.GetTokenType();		
					while (TT != TOKEN_NORMAL && ok)
					{
						ok = MainIndex.GetToken();
						if(!ok) break;
						TT = MainIndex.GetTokenType();		
						ok = (TT != TOKEN_EOF);
						if(!ok) break;
					}
					if(!ok) break;
	
					Directory = MainIndex.GetTokenBuf();
					KillLeadingSpaces(&Directory);

					if(!MainIndex.GetToken()) break;		// Get ','
					if(!MainIndex.GetToken()) break;		// Get Description
					String_256 Description256;
					Description256 = MainIndex.GetTokenBuf();
					KillLeadingSpaces(&Description256);
					Description256.Left(&Description, 60);

					if(!MainIndex.GetToken()) break;		// Get ','
					if(!MainIndex.GetToken()) break;		// Get Sub Library Index name
					SubIndex = MainIndex.GetTokenBuf();
					KillLeadingSpaces(&SubIndex);

					if(!MainIndex.GetToken()) break;		// Get ','
					if(!MainIndex.GetToken()) break;		// Get type of files in sublib
					Kind = MainIndex.GetTokenBuf();
					KillLeadingSpaces(&Kind);
	
					BOOL Match = FALSE;
					Match = ParentLibraryGallery->CheckForIndexMatch(&Kind);

					if(Match)
					{				
						// Show status of additions
						EscapePressed = !ContinueSlowJob(CurrentGroupNumber++);
				
						// Sort pathname of sublib directory out	
						String_256 SubP(Path->GetPath(TRUE));
						SubP += Directory;
						PathName SubPath(SubP);
						if(!SubPath.IsValid())
						{
							ERROR3("LibraryFile::Init - invalid subpath");
							if(MainIndex.isOpen())
								MainIndex.close();
							EndSlowJob();								
							return 0;
						}
																   
						// Go ahead and add the new group
						if(ok)
						{
							// Create the sub lib
							Library *NewSubLib = new Library;

							if (NewSubLib != NULL)
							{
								// Create the new group in the gallery (note the TRUE for create a virtualised one if
								// we can to save time / memory)
								if(NewSubLib->Init(ParentGal, &SubPath, &Description, &SubIndex, Type, Updated, TRUE))
								{
									Libraries.AddTail(NewSubLib);

									// Keep track of libraries added for redraw purposes...
									AddNewFolderToScrollRedrawSystem(NewSubLib);
								}
								else
								{
									// This check is new, should be ok...
									delete NewSubLib;
									NewSubLib = NULL;
									ERROR3("Library::Init failed in LibraryFile::Init");
									ok = FALSE;
								}
							}
						}
					}
				}

			} else {
				// Failed to open the index file...

				// SetError?!
				ERROR3("LibraryFile::LibraryFile couldn't open index file");
				ok = FALSE;
			}

			EndSlowJob();								

		} else {
			// The directory given had no XaraInfo\index.txt file, maybe it's a sublib, check
			// For defaults...
			ok = CheckForSubIndexes(ParentGal, Path, Type, Updated);
		}

		// reclaim lexer-buffer memory
		MainIndex.DeinitLexer();

		// And close the file
		if(MainIndex.isOpen())
			MainIndex.close();

		// Scroll / redraw the newly added groups...
		if(DoScroll)
			DoScrollRedraw();
	}
	else
	{
		TRACEUSER( "Richard", _T("Path doesn't exist\n"));
	}

	// And return the number of items created
	return(Libraries.GetCount());
#endif
	return 0;
}
예제 #8
0
BOOL PluginOILFilter::GetImportFile(CCLexFile* pFile, CCLexFile** ppNewFile)
{
	ERROR2IF(pFile == NULL, FALSE,"PluginOILFilter::GetImportFile no file to import from");
	ERROR2IF(ppNewFile == NULL, FALSE,"PluginOILFilter::GetImportFile no newfile pointer");

	*ppNewFile = NULL;

	// Here we should really run the plugin asynchronously with the following options
	// -i -g -f <filename>

	// Redirect stdout to a CCLexFile
	// Check stderr during the Xar import and abort if an error is reported

	m_TempXarFile.SetPathName(_T("/tmp/xpftemp.xar"));

	CCDiskFile TempFile;
	if (!TempFile.open(m_TempXarFile, ios::out | ios::trunc | ios::binary))
	{
		// report an error here
		return FALSE;
	}

	PathName FileName = pFile->GetPathName();

	wxString sCommand(m_DoImport);
	sCommand.Replace(_T("%IN%"), (LPCTSTR)FileName.GetPath());

	TRACEUSER("Gerry", _T("Running '%s'"), sCommand.c_str());

	// Create a process with the TempFile as the stdout
	PluginFilterProcess* pTheProc = new PluginFilterProcess((PluginNativeFilter*)Parent, NULL, &TempFile);

	INT32 code = pTheProc->Execute(sCommand);
	TempFile.close();
	if (code != 0)
	{
		TRACEUSER("Gerry", _T("Execution of '%s' failed."), sCommand.c_str());
		// Extract error from a derived CamProcess class and report it
		pTheProc->ReportError();
		delete pTheProc;
		return(FALSE);
	}

	pTheProc->ReportWarning();
	delete pTheProc;
	pTheProc = NULL;

	CCDiskFile* pTempFile = new CCDiskFile();
	if (pTempFile)
	{
		if (pTempFile->open(m_TempXarFile, ios::in | ios::binary))
		{
			*ppNewFile = pTempFile;
			return(TRUE);
		}

		delete pTempFile;
	}

	return(FALSE);
}
예제 #9
0
파일: nativeop.cpp 프로젝트: vata/xarino
void OpMenuSave::Do(OpDescriptor* pOpDesc)
{
	//First get the selected document
	Document* pdocToSave=Document::GetSelected();
	CCamDoc* pccamdocToSave = pdocToSave->GetOilDoc();

	if (pdocToSave==NULL || pccamdocToSave==NULL)
	{
		ERROR2RAW("No default document!");
		return;
	}

	//And we'll need a pointer to the application
	Application*		pCamelot = GetApplication();
	CTemplateManager&	TemplateManager( pCamelot->GetTemplateManager() );

	//And put the default templates path in the dialog
	PathName			pathToPutInDialog = TemplateManager.GetTemplatesPath();

	FileUtil::RecursiveCreateDirectory( pathToPutInDialog.GetPath() );
	
	//Now create the dialog
	SaveTemplateDialog	dialogToDisplay(pathToPutInDialog);
		
	//And show it
	if (dialogToDisplay.ShowModal() == wxID_OK)
	{
		//Then get the path they specified, using this amazingly bad, confusing and
		//undocumented file dialog code

		//The "CString" reference should ideally go in Winoil
		PathName pathToSaveTo;
		dialogToDisplay.GetChosenFileName(&pathToSaveTo);

		wxString cstrPathToSaveTo=pathToSaveTo.GetPath(FALSE);
		dialogToDisplay.AppendExtension(&cstrPathToSaveTo);

		String_256 strPathToSaveTo=cstrPathToSaveTo;
		pathToSaveTo=strPathToSaveTo;
						
		// Create the save file.
		CCDiskFile file(pathToSaveTo, ios::out | ios::binary | ios::trunc);

		// First find the filter.
		Filter *pFilter = FindFilter ( FILTERID_NATIVE );

		// Tell it to save attributes.
		pFilter->SetSaveAttributes ( TRUE );

		// Then save the image to the file.
		Save ( pFilter, &file );
		
		//Now, if we should make that path the default path
		if (SaveTemplateDialog::m_fUseAsDefault)
		{
			if (pdocToSave->IsAnimated())
			{
				CTemplateManager::SetDefaultAnimationTemplate( strPathToSaveTo );
			}
			else
			{
				CTemplateManager::SetDefaultDrawingTemplate( strPathToSaveTo );
			}
		}

		if (SaveTemplateDialog::m_fDefaultTemplatesFolder)
		{
			String_256	strDefaultPath = pathToSaveTo.GetLocation( TRUE );
			CTemplateManager::SetTemplatesPath( strDefaultPath );
		}
	}

	// Finished the operation
	End();
}
예제 #10
0
파일: nativeop.cpp 프로젝트: vata/xarino
BOOL OpMenuLoad::LoadFile(CCLexFile* pFileToLoad, UINT32 nPrefFilter)
{
	// Make sure we have a valid file to load.
/*	TRACEUSER( "JustinF", _T("In OpMenuLoad::LoadFile(%p, %u)\n"),
				(LPVOID) pFileToLoad, nPrefFilter);
*/	ERROR3IF(!pFileToLoad, "Null CCLexFile* in OpMenuLoad::LoadFile");
	
	// Find out the position of the filter selected by the user in the open dialog
	INT32 SelectedPos = 0;

#if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
	SelectedPos = BaseFileDialog::SelectedFilter;
#endif

	// Go get the first filter in the list
	Filter* pFilter = Filter::GetFirst();

	// Do we know which filter was used? (we know nothing about things in the recent file
	// list).  If we don't, then use the preferred one, by default the generic filter.
	if (nPrefFilter != FILTERID_USERCHOICE || SelectedPos == 0)
	{
		// We know nothing. We will have to go and have a look at all the possibles
		// We will find the Filter Family and ask it to try and load the file.
		UINT32 nID = (nPrefFilter != FILTERID_USERCHOICE) ? nPrefFilter : FILTERID_GENERIC;
		while (pFilter != NULL && pFilter->FilterID != nID)
		{
			// Try the next filter
			pFilter = Filter::GetNext(pFilter);
		}
	}
	else
	{
		// We know which type of filter the user had selected in the file dialog
		// Find the filter that the user chose.
		while (pFilter != NULL)
		{
			// This is the filter?
			if (pFilter->GetFlags().CanImport &&
				pFilter->pOILFilter->Position == SelectedPos)
					break;

			// Try the next filter
			pFilter = Filter::GetNext(pFilter);
		}
	}
	
	// Check that the Filter existed
	if (pFilter == NULL)
	{
		// It did not...
		InformError(_R(IDT_CANT_FIND_FILTER));
		return FALSE;
	}

	// Get pointer to current doc 'cos we'll need it several times...
	Document* pCurDoc = Document::GetCurrent();

	// If this is not a filter family, check for compatibility before asking
	// filter to load the file.
	// This means the user has chosen an explicit filter to handle the import
	PathName Path = pFileToLoad->GetPathName();
	String_256 FilePath = Path.GetPath();
	// FilePath will be null if a pathname is not valid
	if (!pFilter->IS_KIND_OF(FilterFamily) && !FilePath.IsEmpty())
	{
		UINT32		Size = 1024;
		size_t		FileSize;
		ADDR		FilterBuf = pFilter->LoadInitialSegment(Path, &Size, &FileSize);

		// If there has been a problem in the load initial segment then fail now.
		if (FilterBuf == NULL)
		{
			// Tell the user about the problem and get out now while the goings good 
			InformError();
			return FALSE;
		}

		// Inform any filters that we are about to do a HowCompatible call.
		// This would allow a set of filters which have common functionality hidden in a
		// filter that cannot import and cannot export handle this call and hence set
		// itself up. This would allow it to maybe cache a result which should only be
		// checked by the first filter in the group. 
		pFilter->PreHowCompatible();
		
		// Change this to be less than 8 as the filters like the Accusoft forms return
		// 8 and 9 to make sure that they are last in the chain.
		if (pFilter->HowCompatible(Path, FilterBuf, Size, UINT32(FileSize)) < 8)
		{
			// Not 100% happy with this file - ask for confirmation.
			ErrorInfo Question;
			Question.ErrorMsg = _R(IDW_OPENQUERY_NOTSURE);
			Question.Button[0] = _R(IDB_OPENQUERY_OPEN);
			Question.Button[1] = _R(IDB_OPENQUERY_DONTOPEN);

			if ((ResourceID)AskQuestion(&Question) != _R(IDB_OPENQUERY_OPEN))
			{
				// User asked for this to be cancelled.
				TRACEUSER( "Tim", _T("Filter compatibility was less than 10\n"));

				// Close the file, report the abort and finish.
				CCFree(FilterBuf);
				//InformMessage(_R(IDT_IMP_USERABORT));
				return FALSE;
			}
		}

		// Get rid of initial file header
		CCFree(FilterBuf);
	}

	// we have to try and open the file
	try
	{
		// Found the Filter, so ask it to import the file please
		if (!pFilter->DoImport(this, pFileToLoad, pCurDoc))
		{
			// Something went a bit wrong - tell the user what it was.
			// Only tell them if not special user cancelled error message
			if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
			{
				// Only supress the error if not the special user abort error
				// ***** For now use the native EPS filter
				if (pFilter->FilterID == FILTERID_NATIVE_EPS &&
					Error::GetErrorNumber() != _R(IDT_IMPORT_USERABORT))
				{
					Error::ClearError();
					InformError(_R(IDS_ERRORINARTFILE));
				}
				else
				{
					// Tell the user what the problem was
					InformError();
					wxMessageDialog dlg(
						NULL,
						_T( "Xara LX failed to load the design.\n\n")
						_T( "This is an early demonstration version of the program which does ")
						_T( "not yet support all of the data types that can appear in XAR designs."),
						_T("Load failed"),
						wxOK
					);
					dlg.ShowModal() ;
				}
			}
			else
			{
				// otherwise remove the error so it won't get reported
				Error::ClearError();
			}

			// and fail
			return FALSE;
		}

	}
	// See if there was a file io errir
	catch( CFileException )
	{
		// Report the error if no one else did, otherwise clear it.
		if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
			InformError();
		else
			Error::ClearError();

		// and fail
		return FALSE;
	}

	// Success.
	return TRUE;
}
예제 #11
0
BOOL OpBevel::ImportURL(WebAddress urlToGet)
{
	//First, set up some variables. We must do this now because I'm 
	//going to use a goto in a moment
	GenericDownloadParam* Param;
	OpDescriptor* pOpDesc;
	PathName pthTemp;

	//We want to import urlToGet using the best available filter

	//To get the best available filter, we simply download to the "All" filter
	//So get a pointer to the All filter
	Filter* pAllFilter=GetAllFilter();

	//Check we found it
	if (pAllFilter==NULL)
		goto ReturnError;

	//Now, get ready to download the file. This is rather complex.

	//First create a new set of download parameters
	//This object will be deleted when the download finishes
	Param = new GenericDownloadParam;
	
	//Now find the generic download OpDescriptor
	pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_OPGENERICDOWNLOAD);

	//And check we found it
	if (pOpDesc==NULL)
		goto ReturnError;
  
	//Now, create a temporary file to download to
	pthTemp=FileUtil::GetTemporaryPathName();

	//And now fill in our parameters
	Param->type = TYPE_HTML;
	Param->priority = AsynchDownload::PRIORITY_NORMAL;
	Param->strDescription = String_256(_R(IDS_HTMLIMPORT_FILEDOWNLOAD));
	Param->file = pthTemp.GetPath();

	Param->strURL = urlToGet.GetWebAddress();
				
	Param->Output = NULL;

	Param->m_pFilter = pAllFilter;
	Param->m_Op = this;						
	Param->pDoc = Document::GetCurrent();

	//And, finally, start the download going, if we've got a URL to download
	if (!Param->strURL.IsEmpty())
		pOpDesc->Invoke((OpParam*) Param);
	
	//And return TRUE
	return TRUE;

ReturnError:
	if (Param)
		delete Param;

	return FALSE;
}