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

[XaraXtreme-commits] Commit Complete



Commit by  : alex
Repository : xara
Revision   : 1096
Date       : Wed May 17 11:48:24 BST 2006

Changed paths:
   M /Trunk/XaraLX/Kernel/app.cpp
   M /Trunk/XaraLX/Kernel/app.h
   M /Trunk/XaraLX/Kernel/statline.h
   M /Trunk/XaraLX/wxOil/camelot.cpp
   M /Trunk/XaraLX/wxOil/camelot.h
   M /Trunk/XaraLX/wxOil/camresource.cpp
   M /Trunk/XaraLX/wxOil/camresource.h

Proper interface to idle events
Allow production of a checksum


Diff:
Index: Trunk/XaraLX/Kernel/app.cpp
===================================================================
--- Trunk/XaraLX/Kernel/app.cpp	(revision 1095)
+++ Trunk/XaraLX/Kernel/app.cpp	(revision 1096)
@@ -1314,6 +1314,8 @@
 	Entry = new ListItemOpPtr;
 	Entry->pOp = pOp;
 	Current->AddTail(Entry);
+
+	NeedMoreIdles(); // ensure it gets at least a first idle event
 }
 
 
@@ -1360,8 +1362,30 @@
 	}
 }
 
+/********************************************************************************************
 
+>	void Application::NeedMoreIdles()
 
+	Author:		Alex Bligh <alex@xxxxxxxxxxx>
+	Created:	17/5/2006
+	Inputs:		-
+	Returns:	-
+	Purpose:	Tells the application we need more idles
+
+	Notes:		This tells the application that we need further idle events, e.g. in the
+				scenario of a newly added idle handler, or an idle handler that previously
+				returned FALSE now returning true. This avoids waiting for the next event.
+
+	Errors:		-
+	SeeAlso:	Application::CallIdleProcessors
+
+********************************************************************************************/
+
+void Application::NeedMoreIdles()
+{
+	CCamApp::NeedMoreIdles();
+}
+
 /********************************************************************************************
 
 >	BOOL Application::CallIdleProcessors()
Index: Trunk/XaraLX/Kernel/statline.h
===================================================================
--- Trunk/XaraLX/Kernel/statline.h	(revision 1095)
+++ Trunk/XaraLX/Kernel/statline.h	(revision 1096)
@@ -223,7 +223,7 @@
 
 	void OnTimer()
 	{
-		::wxWakeUpIdle(); // a bodge to ensure the idle handler is awake
+		GetApplication()->NeedMoreIdles();
 	}
 
 	class StatusTimer : public KernelTimer
Index: Trunk/XaraLX/Kernel/app.h
===================================================================
--- Trunk/XaraLX/Kernel/app.h	(revision 1095)
+++ Trunk/XaraLX/Kernel/app.h	(revision 1096)
@@ -346,6 +346,7 @@
 	BOOL OnIdle(BOOL IdleRedraw);
 	void RemoveIdleProcessor(INT32 Priority, Operation* pOp);
 	void RegisterIdleProcessor(INT32 Priority, Operation* pOp);
+	void NeedMoreIdles();
 
 	// Dubugging dump ops
 	void DumpAllOps(Document* pDoc);			// Dumps entire op history
Index: Trunk/XaraLX/wxOil/camresource.cpp
===================================================================
--- Trunk/XaraLX/wxOil/camresource.cpp	(revision 1095)
+++ Trunk/XaraLX/wxOil/camresource.cpp	(revision 1096)
@@ -126,6 +126,7 @@
 BOOL CamResource::HaveCheckedResourcePath = FALSE;
 wxLocale * CamResource::m_pLocale = NULL;
 wxHelpProvider * CamResource::m_pHelpProvider = NULL;
+BOOL CamResource::s_GenerateXRCCheck = FALSE;
 
 ResourceStringToBitmap * CamResource::pBitmapHash = NULL;
 
@@ -730,7 +731,6 @@
 
 ********************************************************************************************/
 
-
 wxString CamResource::GetResourceFilePath( const wxString &str, BOOL AllowOverride )
 {
 	// If we are given a full path, then return. For the time being that's anything with a colon or a slash in it
@@ -780,90 +780,126 @@
 	return mfn + str;
 }
 
+
 /********************************************************************************************
 
->	static BOOL CamResource::CheckResourcePath( const wxString &str1, const wxString &str2 )
+>	static void * CamResource::LoadFile( const wxString &str1, UINT32 * pSize )
 
 
 	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
 	Created:	02/12/2005
-	Inputs:		str1, str2 - filenames to check
-	Outputs:	
-	Returns:	TRUE if the files are identical, else false
+	Inputs:		str1 - filename to load
+	Outputs:	size - the size of the file
+	Returns:	A pointer to the file (free with free()) or NULL
 	Purpose:	-
 	Errors:		-
 	SeeAlso:	-
 
-This routine compares two small files. If they are equal, it returns true, else it
-returns false. This allows checking of the checksum. This is reasonably resilient to
-some fool creating a huge xrc.check as we only read the files if the lengths are
-equal, which means we never read more than the size of the file bound into the
-executable.
-
 ********************************************************************************************/
 
-BOOL CamResource::CheckResourcePath( const wxString &str1, const wxString &str2 )
+void * CamResource::LoadFile( const wxString &str1, UINT32* pSize )
 {
-	if (!pwxFileSystem) return FALSE;
-
 	wxFSFile * pTwxFSFile1 = pwxFileSystem->OpenFile(str1);
-	wxFSFile * pTwxFSFile2 = pwxFileSystem->OpenFile(str2);
-	if (!pTwxFSFile1 || !pTwxFSFile2)
+	if (!pTwxFSFile1)
 	{
-		if (!pTwxFSFile1) delete pTwxFSFile1;
-		if (!pTwxFSFile1) delete pTwxFSFile1;
-		return FALSE;
+		delete pTwxFSFile1;
+		return NULL;
 	}
 
 	wxInputStream * pStream1 = pTwxFSFile1->GetStream(); // we don't have to delete this ourselves
-	wxInputStream * pStream2 = pTwxFSFile2->GetStream(); // we don't have to delete this ourselves
-	if (!pStream1 || !pStream2)
+	if (!pStream1)
 	{
 		delete (pTwxFSFile1);
-		delete (pTwxFSFile2);
-		return FALSE;
+		return NULL;
 	}
 
 	UINT32 size1=pStream1->GetSize();
-	UINT32 size2=pStream2->GetSize();
 
-	if (!size1 || !size2 || (size1 != size2))
+	if (!size1)
 	{
 		delete (pTwxFSFile1);
-		delete (pTwxFSFile2);
-		return FALSE;
+		return NULL;
 	}
 
 	void * mem1 = malloc(size1+4); // safety
 	if (!mem1)
 	{
 		delete (pTwxFSFile1);
-		delete (pTwxFSFile2);
-		return FALSE;
+		return NULL;
 	}
 
-	void * mem2 = malloc(size2+4); // safety
-	if (!mem2)
-	{
-		free(mem1);
-		delete (pTwxFSFile1);
-		delete (pTwxFSFile2);
-		return FALSE;
-	}
-
 	memset(mem1, 0, size1);
-	memset(mem2, 0, size2);
 	pStream1->Read(mem1, size1); // throws exceptions if can't read
-	pStream2->Read(mem2, size2); // throws exceptions if can't read
 	
 	delete (pTwxFSFile1); // Closes it
-	delete (pTwxFSFile2); // Closes it
 
-	BOOL same=(!memcmp(mem1, mem2, size1));
+	if (pSize)
+		*pSize=size1;
+	return mem1;
+}
 
-	free (mem1);
-	free (mem2);
+/********************************************************************************************
 
+>	static BOOL CamResource::CheckResourcePath( const wxString &str1, const wxString &str2 )
+
+
+	Author:		Alex_Bligh <alex@xxxxxxxxxxx>
+	Created:	02/12/2005
+	Inputs:		str1, str2 - filenames to check
+	Outputs:	
+	Returns:	TRUE if the files are identical, else false
+	Purpose:	-
+	Errors:		-
+	SeeAlso:	-
+
+This routine compares two small files. If they are equal, it returns true, else it
+returns false. This allows checking of the checksum. This is reasonably resilient to
+some fool creating a huge xrc.check as we only read the files if the lengths are
+equal, which means we never read more than the size of the file bound into the
+executable.
+
+********************************************************************************************/
+
+BOOL CamResource::CheckResourcePath( const wxString &str1, const wxString &str2 )
+{
+	if (!pwxFileSystem) return FALSE;
+
+	UINT32 size1=0;
+	UINT32 size2=0;
+	void * mem1=LoadFile(str1, &size1);
+	void * mem2=LoadFile(str2, &size2);
+
+	if (!mem1)
+	{
+		if (mem2)
+			free(mem2);
+		return FALSE; // and we can't generate an xrc.check
+	}
+
+	BOOL same = mem2 && ( size1 == size2) && !memcmp(mem1, mem2, size1);
+
+	if (!same && s_GenerateXRCCheck)
+	{
+		wxMessageBox(_T("You have requested XaraLX to generate a checksum for resources which may not match the binary in question. "
+						"A checksum will be generated, but the program may not be stable."), _T("XaraLX Resource system warning"));
+
+		wxFile f;
+		f.Create(str2, wxFile::write);
+		if (!f.IsOpened() || (f.Write(mem1, size1) != size1))
+		{
+			wxMessageBox(_T("Failed to write xrc.check file ")+str2, _T("XaraLX resource system"));
+		}
+		f.Close();
+		same=TRUE;
+	}
+
+
+	if (mem1)
+		free (mem1);
+
+	if (mem2)
+		free (mem2);
+
 	return same;
 }
 
Index: Trunk/XaraLX/wxOil/camelot.h
===================================================================
--- Trunk/XaraLX/wxOil/camelot.h	(revision 1095)
+++ Trunk/XaraLX/wxOil/camelot.h	(revision 1096)
@@ -168,6 +168,7 @@
 	BOOL allowRegistryWrite;						// if a copy of camelot is open, and we try do load another one,
 													// and exit (we prevent this), then we don't wan't to write to
 													// the registry !!!!
+	static void NeedMoreIdles() { ::wxWakeUpIdle(); }
 };
 
 DECLARE_APP( CCamApp )
Index: Trunk/XaraLX/wxOil/camresource.h
===================================================================
--- Trunk/XaraLX/wxOil/camresource.h	(revision 1095)
+++ Trunk/XaraLX/wxOil/camresource.h	(revision 1096)
@@ -214,6 +214,7 @@
 	static wxFileSystem * pwxFileSystem;
 	static wxLocale * m_pLocale;
 	static wxHelpProvider * m_pHelpProvider;
+	static BOOL s_GenerateXRCCheck;
 
 public:
 	CCLexFile * Open ( ResourceID ID, BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE);
@@ -330,6 +331,8 @@
 
 	static wxArrayString BitmapExtensions;
 
+	static void SetGenerateXRCCheck(BOOL flag) {s_GenerateXRCCheck=flag;}
+	static void * LoadFile( const wxString &str1, UINT32 * pSize );
 };
 
 
Index: Trunk/XaraLX/wxOil/camelot.cpp
===================================================================
--- Trunk/XaraLX/wxOil/camelot.cpp	(revision 1095)
+++ Trunk/XaraLX/wxOil/camelot.cpp	(revision 1096)
@@ -353,6 +353,7 @@
 #if defined(_DEBUG)
 		{ wxCMD_LINE_OPTION, _T("u"), _T("user"), _T("set username for debug tracing") },
 		{ wxCMD_LINE_SWITCH, _T("m"), _T("memorycheck"), _T("check memory") },
+		{ wxCMD_LINE_SWITCH, _T("x"), _T("xrccheckgen"), _T("generate xrc.check file") },
 		{ wxCMD_LINE_OPTION, _T("l"), _T("listdebug"), _T("list debug level") , wxCMD_LINE_VAL_NUMBER },
 #endif
 		{ wxCMD_LINE_SWITCH, _T("v"), _T("version"),	_T("Display the version information") },
@@ -372,6 +373,11 @@
 		{
 			CamResource::SetResourceFilePath(ResourceDir);
 		}
+
+		if ( parser.Found( _T("x") ) )
+		{
+			CamResource::SetGenerateXRCCheck(TRUE);
+		}
 	}
 
 	if( parser.Found( _T("v") ) )


Xara