[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-commits] Commit Complete



Commit by  : gerry
Repository : xara
Revision   : 1181
Date       : Tue May 23 18:45:28 BST 2006

Changed paths:
   M /Trunk/XaraLX/Kernel/xpfilter.cpp
   M /Trunk/XaraLX/wxOil/camprocess.cpp
   M /Trunk/XaraLX/wxOil/camprocess.h
   M /Trunk/XaraLX/wxOil/xpoilflt.cpp
   M /Trunk/XaraLX/wxOil/xpoilflt.h
   M /Trunk/XaraLX/wxOil/xrc/EN/xpfres-strings.xrc

Plugin filter progress and error reporting


Diff:
Index: Trunk/XaraLX/Kernel/xpfilter.cpp
===================================================================
--- Trunk/XaraLX/Kernel/xpfilter.cpp	(revision 1180)
+++ Trunk/XaraLX/Kernel/xpfilter.cpp	(revision 1181)
@@ -456,6 +456,7 @@
 
 	String_64 Str(_R(IDS_EXPORTING_DOCUMENT));
 	StartProgressBar(&Str);
+	SetProgressBarCount(0);
 	SetTotalProgressBarCount(100);
 
 	// Call OIL layer to do the translation
@@ -1043,8 +1044,12 @@
 
 BOOL PluginNativeFilter::SetProgressBarCount(UINT32 n)
 {
-//	TRACE( _T("PluginNativeFilter::SetProgressBarCount(%d)
"), n);
-	
+	TRACE( _T("PluginNativeFilter::SetProgressBarCount(%d)
"), n);
+
+	TRACE(_T("Offset = %d"), m_ProgressOffset);
+	TRACE(_T("pProgress = 0x%08x"), pProgress);
+	TRACE(_T("Total = %d"), TotalProgressBarCount);
+
 	ProgressBarCount = 	m_ProgressOffset + n;
 
 	if (pProgress != NULL && TotalProgressBarCount > 0)
@@ -1065,6 +1070,6 @@
 String_256 PluginNativeFilter::GetNewBitmapName()
 {
 	String_256 Str;
-	Str._MakeMsg(_T("%d"), ++m_BitmapCount);
+	Str._MakeMsg(_T("#1%d"), ++m_BitmapCount);
 	return(Str);
 }
Index: Trunk/XaraLX/wxOil/xpoilflt.cpp
===================================================================
--- Trunk/XaraLX/wxOil/xpoilflt.cpp	(revision 1180)
+++ Trunk/XaraLX/wxOil/xpoilflt.cpp	(revision 1181)
@@ -351,20 +351,20 @@
 		wxString sCommand(m_CanImport);
 		sCommand.Replace(_T("%IN%"), (LPCTSTR)FileName.GetPath());
 
-		TRACE(_T("Running '%s'"), sCommand.c_str());
+		TRACEUSER("Gerry", _T("Running '%s'"), sCommand.c_str());
 
 		wxArrayString saOutput;
 		wxArrayString saErrors;
 		INT32 code = wxExecute(sCommand, saOutput, saErrors);
-		TRACE(_T("wxExecute returned %d"), code);
+		TRACEUSER("Gerry", _T("wxExecute returned %d"), code);
 		if (code == 0)
 		{
 			// Extract the value from saOutput
 			if (saOutput.Count() > 0)
 			{
 				INT32 Val = wxAtoi(saOutput[0]);
-				TRACE(_T("Command '%s' returned string '%s'"), sCommand.c_str(), saOutput[0].c_str());
-				TRACE(_T("Value = %d"), Val);
+				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;
@@ -372,12 +372,12 @@
 			}
 			else
 			{
-				TRACE(_T("Command '%s' returned no output value"), sCommand.c_str());
+				TRACEUSER("Gerry", _T("Command '%s' returned no output value"), sCommand.c_str());
 			}
 		}
 		else
 		{
-			TRACE(_T("Command '%s' exited with code %d"), sCommand.c_str(), code);
+			TRACEUSER("Gerry", _T("Command '%s' exited with code %d"), sCommand.c_str(), code);
 		}
 	}
 
@@ -428,22 +428,26 @@
 	wxString sCommand(m_DoImport);
 	sCommand.Replace(_T("%IN%"), (LPCTSTR)FileName.GetPath());
 
-	TRACE(_T("Running '%s'"), sCommand.c_str());
+	TRACEUSER("Gerry", _T("Running '%s'"), sCommand.c_str());
 
 	// Create a process with the TempFile as the stdout
-	// We will need to derive a new class from CamProcess to handle
-	// the processing of stderr for errors, warnings and progress
-	CamProcess TheProc(NULL, &TempFile);
+	PluginFilterProcess* pTheProc = new PluginFilterProcess((PluginNativeFilter*)Parent, NULL, &TempFile);
 
-	INT32 code = TheProc.Execute(sCommand);
+	INT32 code = pTheProc->Execute(sCommand);
 	TempFile.close();
 	if (code != 0)
 	{
-		TRACE(_T("Execution of '%s' failed."), sCommand.c_str());
+		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)
 	{
@@ -540,16 +544,18 @@
 	sCommand.Replace(_T("%OUT%"), (LPCTSTR)pPath->GetPath());
 	sCommand.Replace(_T("%XML%"), m_XMLFile.GetFullPath());
 
-	TRACE(_T("Running '%s'"), sCommand.c_str());
+	TRACEUSER("Gerry", _T("Running '%s'"), sCommand.c_str());
 
 	wxArrayString saOutput;
 	wxArrayString saErrors;
 	INT32 code = wxExecute(sCommand, saOutput, saErrors);
 
+#ifdef _DEBUG
 	for (UINT32 i = 0; i < saErrors.GetCount(); i++)
 	{
-		TRACE(_T("stderr: %s"), saErrors[i].c_str());
+		TRACEUSER("Gerry", _T("stderr: %s"), saErrors[i].c_str());
 	}
+#endif
 
 	if (code == 0)
 	{
@@ -562,7 +568,7 @@
 	}
 	else
 	{
-		TRACE(_T("Command '%s' exited with code %d"), sCommand.c_str(), code);
+		TRACEUSER("Gerry", _T("Command '%s' exited with code %d"), sCommand.c_str(), code);
 
 		// Get error message from saErrors
 		return(FALSE);
@@ -606,7 +612,7 @@
 	sCommand.Replace(_T("%OUT%"), (LPCTSTR)pPath->GetPath());
 	sCommand.Replace(_T("%XML%"), m_XMLFile.GetFullPath());
 
-	TRACE(_T("Running '%s'"), sCommand.c_str());
+	TRACEUSER("Gerry", _T("Running '%s'"), sCommand.c_str());
 
 	CCDiskFile TempFile(CCFILE_DEFAULTSIZE, FALSE, FALSE);
 	if (!TempFile.open(m_TempXarFile, ios::in | ios::binary))
@@ -616,19 +622,23 @@
 	}
 
 	// Create a process with the TempFile as the stdin
-	// We will need to derive a new class from CamProcess to handle
-	// the processing of stderr for errors, warnings and progress
-	CamProcess TheProc(&TempFile, NULL);
+	PluginFilterProcess* pTheProc = new PluginFilterProcess((PluginNativeFilter*)Parent, &TempFile, NULL);
 
-	INT32 code = TheProc.Execute(sCommand);
+	INT32 code = pTheProc->Execute(sCommand);
+	TRACEUSER("Gerry", _T("Execute returned %d"), code);
 	TempFile.close();
 	if (code != 0)
 	{
-		TRACE(_T("Execution of '%s' failed."), sCommand.c_str());
-		// Extract error from a derived CamProcess class and report it
+		TRACEUSER("Gerry", _T("Execution of '%s' failed (%d)"), sCommand.c_str(), code);
+		// Extract error and report it
+		pTheProc->ReportError();
+		delete pTheProc;
 		return(FALSE);
 	}
 
+	pTheProc->ReportWarning();
+	delete pTheProc;
+
 	return(TRUE);
 }
 
@@ -650,7 +660,6 @@
 
 BOOL PluginOILFilter::BuildCapabilityTree(wxString strXmlFilename, CapabilityTree* pCapTree)
 {
-
 	// First we need to load the XML into an XML DOM object
 
 	// Set Parser flags here?
@@ -1521,11 +1530,107 @@
 
 void PluginOILFilter::Cleanup()
 {
-PORTNOTE("other","PluginFilter COM bits removed")
-#if !defined(EXCLUDE_FROM_XARALX)
-	ReleaseFilterObject();
-#endif
 }
 
 
 
+PluginFilterProcess::PluginFilterProcess(PluginNativeFilter* pFilter, CCLexFile* pInFile, CCLexFile* pOutFile) :
+	CamProcess(pInFile, pOutFile)
+{
+	TRACEUSER("Gerry", _T("PluginFilterProcess::PluginFilterProcess"));
+	m_pFilter = pFilter;
+}
+
+
+PluginFilterProcess::~PluginFilterProcess()
+{
+	TRACEUSER("Gerry", _T("PluginFilterProcess::~PluginFilterProcess"));
+}
+
+
+void PluginFilterProcess::ProcessStdErr()
+{
+//	TRACEUSER("Gerry", _T("PluginFilterProcess::ProcessStdErr"));
+
+	if (IsErrorAvailable())
+	{
+		wxTextInputStream tis(*GetErrorStream());
+
+		// This assumes that the output is always line buffered
+//		while (!GetErrorStream()->Eof())
+		while (IsErrorAvailable())
+		{
+			wxString line;
+			line << tis.ReadLine();
+//			TRACEUSER("Gerry", _T("(stderr):%s"), line.c_str());
+
+			if (!line.IsEmpty())
+			{
+				// If line begins "MESSAGE:" then it is a debug message and can be discarded
+				wxString rest;
+				if (line.StartsWith(_T("MESSAGE:"), &rest))
+				{
+//					TRACEUSER("Gerry", _T("XPFDebug:%s"), rest.c_str());
+				}
+				else if (line.StartsWith(_T("PROGRESS:"), &rest))
+				{
+//					TRACEUSER("Gerry", _T("XPFProgress:%s"), rest.c_str());
+					if (m_pFilter)
+					{
+						unsigned long Val = wxStrtoul(rest.c_str(), NULL, 10);
+						if (Val > 0)
+						{
+//							TRACEUSER("Gerry", _T("Setting progress to %d"), Val);
+							m_pFilter->SetProgressBarCount((UINT32)Val);
+						}
+					}
+				}
+				else if (line.StartsWith(_T("WARNING:"), &rest))
+				{
+//					TRACEUSER("Gerry", _T("XPFWarning:%s"), rest.c_str());
+					m_Warnings.Add(rest);
+				}
+				else if (line.StartsWith(_T("ERROR:"), &rest))
+				{
+//					TRACEUSER("Gerry", _T("XPFError:%s"), rest.c_str());
+					m_Errors.Add(rest);
+				}
+				else
+				{
+//					TRACEUSER("Gerry", _T("XPFError:%s"), line.c_str());
+					m_Errors.Add(line);
+				}
+			}
+		}
+	}
+}
+
+
+BOOL PluginFilterProcess::ReportError()
+{
+	TRACEUSER("Gerry", _T("PluginFilterProcess::ReportError"));
+
+	// Get the first entry from m_ErrorList and pass it to Error::SetError
+	if (m_Errors.GetCount() > 0)
+	{
+		Error::SetError(0, m_Errors[0].c_str(), 0);
+	}
+	else
+	{
+		ERROR1(FALSE, _R(IDS_XPF_NO_ERROR_SET));
+	}
+
+	return(FALSE);
+}
+
+
+void PluginFilterProcess::ReportWarning()
+{
+	TRACEUSER("Gerry", _T("PluginFilterProcess::ReportWarning"));
+
+	// Show the user the contents of m_WarningList
+	for (size_t i = 0; i < m_Warnings.GetCount(); i++)
+	{
+		TRACEUSER("Gerry", _T("WARNING:%s"), m_Warnings[i].c_str());
+	}
+}
Index: Trunk/XaraLX/wxOil/xpoilflt.h
===================================================================
--- Trunk/XaraLX/wxOil/xpoilflt.h	(revision 1180)
+++ Trunk/XaraLX/wxOil/xpoilflt.h	(revision 1181)
@@ -102,43 +102,31 @@
 #define INC_XPOILFLT
 
 #include "oilfltrs.h"
-PORTNOTE("other","PluginFilter COM bits removed")
-#if !defined(EXCLUDE_FROM_XARALX)
-#include <atlbase.h>	// For CRegKey and CComPtr
-
-#include "xpfapi.h"
-#endif
-
 #include "xpfcaps.h"
 #include "xmlutils.h"
+#include "camprocess.h"
 
 class PluginNativeFilter;
 
-PORTNOTE("other","PluginFilter COM bits removed")
-#if !defined(EXCLUDE_FROM_XARALX)
-class PluginFilterCallback : public CCmdTarget
+class PluginFilterProcess : public CamProcess
 {
-	DECLARE_DYNCREATE( PluginFilterCallback )
-
 public:
-	PluginFilterCallback(PluginNativeFilter* pFilter = NULL);	// Constructor
-	~PluginFilterCallback();									// Destructor
+	PluginFilterProcess(PluginNativeFilter* pFilter, CCLexFile* pInFile = NULL, CCLexFile* pOutFile = NULL);
+	virtual ~PluginFilterProcess();
 
-	IXPFCallback* GetInterface() { return &m_x_XPFCallback; }
+	// These are called to handle the various streams
+	virtual void ProcessStdErr();
 
-	DECLARE_INTERFACE_MAP()
-	
-	BEGIN_INTERFACE_PART(_XPFCallback, IXPFCallback)
-		STDMETHOD(Progress)(/*[in]*/INT32 lProgress);
-	END_INTERFACE_PART(_XPFCallback)
+	BOOL ReportError();
+	void ReportWarning();
 
 protected:
 	PluginNativeFilter* m_pFilter;
+	wxArrayString m_Errors;
+	wxArrayString m_Warnings;
 };
-#endif
 
 
-
 /********************************************************************************************
 
 >	class PluginOILFilter : public OILFilter
Index: Trunk/XaraLX/wxOil/camprocess.cpp
===================================================================
--- Trunk/XaraLX/wxOil/camprocess.cpp	(revision 1180)
+++ Trunk/XaraLX/wxOil/camprocess.cpp	(revision 1181)
@@ -132,7 +132,8 @@
 	// Make sure redirection happens
 	Redirect();
 
-	if (!wxExecute(cmd, wxEXEC_ASYNC, this))
+	long pid = wxExecute(cmd, wxEXEC_ASYNC, this);
+	if (pid == 0)
 	{
 		// Report problem
 		m_bDead = true;
@@ -147,7 +148,7 @@
 	if (m_pInFile)
 	{
 		InFileLeft = m_pInFile->Size();
-		TRACEUSER("Gerry", _T("InFileSize = %d"), InFileLeft);
+//		TRACEUSER("Gerry", _T("InFileSize = %d"), InFileLeft);
 	}
 
 	// Loop until m_bDead is true
@@ -157,11 +158,13 @@
 		// Call the virtual function to process any output on stderr
 		ProcessStdErr();
 
+		wxYield();
+
 		// If we have an output file
 		if (m_pOutFile)
 		{
 			// If there is output from the process
-			if (IsInputAvailable())
+			if (!m_bDead && IsInputAvailable())
 			{
 				// Copy the data to the file
 
@@ -186,14 +189,18 @@
 		else
 		{
 			// Call the virtual function to process the output
-			ProcessStdOut();
+			if (!m_bDead)
+				ProcessStdOut();
 		}
 
+		wxYield();
+
 		// If we have an input file
 		if (m_pInFile)
 		{
 			// Copy some data to the process
-			while (bMoreInput)
+			// This was a while loop
+			if (!m_bDead && bMoreInput)
 			{
 				// If there is nothing in the buffer
 				if (ReadBytes == 0)
@@ -205,7 +212,7 @@
 					if (ReadBytes > 0)
 					{
 						// Read a buffer full
-						TRACEUSER("Gerry", _T("Reading %d"), ReadBytes);
+//						TRACEUSER("Gerry", _T("Reading %d"), ReadBytes);
 						m_pInFile->read(ReadBuffer, ReadBytes);
 
 						InFileLeft -= ReadBytes;
@@ -214,28 +221,27 @@
 				}
 
 				// If there is something in the buffer
-				if (ReadBytes > 0)
+				if (ReadBytes > 0 && GetOutputStream()->IsOk())
 				{
-					TRACEUSER("Gerry", _T("Buffer contains %d"), ReadBytes);
+//					TRACEUSER("Gerry", _T("Buffer contains %d"), ReadBytes);
 					// Try to write it to the process
 					GetOutputStream()->Write(ReadPtr, ReadBytes);
 
 					size_t Done = GetOutputStream()->LastWrite();
-					TRACEUSER("Gerry", _T("Written %d"), Done);
+//					TRACEUSER("Gerry", _T("Written %d"), Done);
 					// If we couldn't write it all
 					if (Done < ReadBytes)
 					{
-						// Update the buffer pointer and size
-						ReadBytes -= Done;
+						// Update the buffer pointer
 						ReadPtr += Done;
-						break;				// go and process the other streams
 					}
-					ReadBytes = 0;
+					// This is correct for all, part or none written
+					ReadBytes -= Done;
 				}
 				else
 				{
 					// Indicate there is no more stdin
-					TRACEUSER("Gerry", _T("Buffer is empty - closing"));
+//					TRACEUSER("Gerry", _T("Buffer is empty - closing"));
 					CloseOutput();
 					bMoreInput = false;
 				}
@@ -244,13 +250,14 @@
 		else
 		{
 			// Call the virtual function to process the input
-			ProcessStdIn();
+			if (!m_bDead)
+				ProcessStdIn();
 		}
 
 		wxYield();
 	}
 
-	TRACEUSER("Gerry", _T("Exiting with %d"), m_ReturnCode);
+//	TRACEUSER("Gerry", _T("Exiting with %d"), m_ReturnCode);
 	return m_ReturnCode;
 }
 
@@ -267,11 +274,11 @@
 		wxTextInputStream tis(*GetInputStream());
 
 		// This assumes that the output is always line buffered
-		while (!GetInputStream()->Eof())
+		while (IsInputAvailable())
 		{
 			wxString line;
 			line << tis.ReadLine();
-			TRACEUSER("Gerry", _T("(stdout):%s"), line.c_str());
+//			TRACEUSER("Gerry", _T("(stdout):%s"), line.c_str());
 		}
 	}
 
@@ -285,11 +292,11 @@
 		wxTextInputStream tis(*GetErrorStream());
 
 		// This assumes that the output is always line buffered
-		while (!GetErrorStream()->Eof())
+		while (IsErrorAvailable())
 		{
 			wxString line;
 			line << tis.ReadLine();
-			TRACEUSER("Gerry", _T("(stderr):%s"), line.c_str());
+//			TRACEUSER("Gerry", _T("(stderr):%s"), line.c_str());
 		}
 	}
 }
@@ -297,7 +304,7 @@
 
 void CamProcess::OnTerminate(int /*TYPENOTE: Correct*/ pid, int /*TYPENOTE: Correct*/ status)
 {
-	TRACEUSER("Gerry", _T("CamProcess::OnTerminate pid = %d  status = %d"), pid, status);
+//	TRACEUSER("Gerry", _T("CamProcess::OnTerminate pid = %d  status = %d"), pid, status);
 	m_bDead = true;
 	m_ReturnCode = status;
 
Index: Trunk/XaraLX/wxOil/xrc/EN/xpfres-strings.xrc
===================================================================
--- Trunk/XaraLX/wxOil/xrc/EN/xpfres-strings.xrc	(revision 1180)
+++ Trunk/XaraLX/wxOil/xrc/EN/xpfres-strings.xrc	(revision 1181)
@@ -161,6 +161,12 @@
 					<label>Preparing to export document</label>
 				</object>
 			</object>
+			<object class="sizeritem">
+				<flag>wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE</flag>
+				<object class="wxStaticText" name="IDS_XPF_NO_ERROR_SET">
+					<label>Plugin filter reported an error but didn't provide a message</label>
+				</object>
+			</object>
 		</object>
 	</object>
 </resource>
Index: Trunk/XaraLX/wxOil/camprocess.h
===================================================================
--- Trunk/XaraLX/wxOil/camprocess.h	(revision 1180)
+++ Trunk/XaraLX/wxOil/camprocess.h	(revision 1181)
@@ -124,8 +124,8 @@
 	INT32 Execute(const wxString& cmd);
 
 protected:
-	bool m_bDead;
-	INT32 m_ReturnCode;
+	volatile bool m_bDead;
+	volatile INT32 m_ReturnCode;
 	CCLexFile* m_pInFile;
 	CCLexFile* m_pOutFile;
 	INT32 m_BytesIn;


Xara