summaryrefslogtreecommitdiff
path: root/xmerge/source/activesync
diff options
context:
space:
mode:
authormarkm <markm@openoffice.org>2002-08-22 14:12:49 +0000
committermarkm <markm@openoffice.org>2002-08-22 14:12:49 +0000
commit353e3665e608cf88635bb98cc14bfd986ba143b0 (patch)
tree61e75410f96a3bab86424487eca47941fb996700 /xmerge/source/activesync
parent093c5207d3aee0a15f822ec6c548f7602bb3563d (diff)
#102574# Update for classpath generation and performance enhancement.
Diffstat (limited to 'xmerge/source/activesync')
-rw-r--r--xmerge/source/activesync/XMergeFilter.cpp268
-rw-r--r--xmerge/source/activesync/XMergeFilter.h7
-rw-r--r--xmerge/source/activesync/XMergeSync.dsp143
3 files changed, 270 insertions, 148 deletions
diff --git a/xmerge/source/activesync/XMergeFilter.cpp b/xmerge/source/activesync/XMergeFilter.cpp
index 0acd972ab3be..9599326f8f70 100644
--- a/xmerge/source/activesync/XMergeFilter.cpp
+++ b/xmerge/source/activesync/XMergeFilter.cpp
@@ -42,10 +42,24 @@ const LPTSTR CXMergeFilter::m_pszPXLImportShortDesc = _T("Pocket Excel");
CXMergeFilter::CXMergeFilter() : m_cRef(1)
{
+ m_bHaveExcel = FALSE;
+ m_bHaveWord = FALSE;
+
+ m_szClasspath = NULL;
+ m_szJavaBaseDir = NULL;
}
CXMergeFilter::~CXMergeFilter()
{
+ if (m_szClasspath != NULL)
+ {
+ delete m_szClasspath;
+ }
+
+ if (m_szJavaBaseDir != NULL)
+ {
+ delete m_szJavaBaseDir;
+ }
}
@@ -153,20 +167,63 @@ STDMETHODIMP CXMergeFilter::NextConvertFile(int nConversion, CFF_CONVERTINFO *pc
si.cb = sizeof(si);
- // Locate Java Home
- TCHAR* szJavaDir = GetJavaBaseDir();
- if (szJavaDir == NULL)
+ /*
+ * First step: Locate Java and establish the classpath. If these can't
+ * be done succesfully, then avoid all further processing.
+ */
+
+ // Locate Java Home if it hasn't already been done.
+ if (m_szJavaBaseDir == NULL)
{
- *perr = ERR_NOJAVA;
+ m_szJavaBaseDir = GetJavaBaseDir();
+
+ if (m_szJavaBaseDir == NULL)
+ {
+ *perr = ERR_NOJAVA;
+ return HRESULT_FROM_WIN32(E_FAIL);
+ }
+ }
+
+ // Get the StarOffice/OpenOffice class directory
+ if (m_szClasspath == NULL)
+ {
+ m_szClasspath = GetXMergeClassPath();
+
+ if (m_szClasspath == NULL)
+ {
+ *perr = ERR_BADCLASSPATH;
+ return HRESULT_FROM_WIN32(E_FAIL);
+ }
+ }
+
+
+ /*
+ * Second step: Check the files we're going to process. If we don't have
+ * an XMerge plugin for the file then we can't convert.
+ */
+ if ((!lstrcmp(psf->szExtension, "sxw") || !lstrcmp(psf->szExtension, "psw"))
+ && !m_bHaveWord)
+ {
+ *perr = ERR_BADCLASSPATH;
+ return HRESULT_FROM_WIN32(E_FAIL);
+ }
+ else if ((!lstrcmp(psf->szExtension, "sxc") || !lstrcmp(psf->szExtension, "pxl"))
+ && !m_bHaveExcel)
+ {
+ *perr = ERR_BADCLASSPATH;
return HRESULT_FROM_WIN32(E_FAIL);
}
- // Make sure that there is a Java executable
- appName += szJavaDir;
+ /*
+ * Third step: Locate the Java executable and build and execute the command
+ * line to carry out the conversion.
+ */
+
+ // Find the Java executable and make sure it exists
+ appName += m_szJavaBaseDir;
appName += "\\bin\\javaw.exe";
- // Make sure that Java actually exists
if (GetFileAttributes(appName.c_str()) == INVALID_FILE_SIZE)
{
*perr = ERR_NOJAVA;
@@ -178,19 +235,10 @@ STDMETHODIMP CXMergeFilter::NextConvertFile(int nConversion, CFF_CONVERTINFO *pc
appName.append("\"");
- // Get the StarOffice/OpenOffice class directory
- TCHAR* szClassPath = GetXMergeClassPath();
- if (szClassPath == NULL)
- {
- *perr = ERR_BADCLASSPATH;
- delete szJavaDir;
-
- return HRESULT_FROM_WIN32(E_FAIL);
- }
// Need to build the entire command line for calling out to Java
appArgs = appName + " -Djava.class.path=";
- appArgs += szClassPath;
+ appArgs += m_szClasspath;
appArgs += " org.openoffice.xmerge.util.ActiveSyncDriver ";
if (!lstrcmp(psf->szExtension, "sxw"))
@@ -234,9 +282,6 @@ STDMETHODIMP CXMergeFilter::NextConvertFile(int nConversion, CFF_CONVERTINFO *pc
&si,
&pi))
{
- delete szClassPath;
- delete szJavaDir;
-
*perr = ERR_INITJAVA;
return HRESULT_FROM_WIN32(E_FAIL);
}
@@ -244,9 +289,6 @@ STDMETHODIMP CXMergeFilter::NextConvertFile(int nConversion, CFF_CONVERTINFO *pc
// Wait for the new process to work
WaitForSingleObject(pi.hProcess, INFINITE);
- delete szClassPath;
- delete szJavaDir;
-
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
@@ -331,154 +373,84 @@ TCHAR* CXMergeFilter::GetJavaBaseDir()
TCHAR* CXMergeFilter::GetXMergeClassPath()
{
-
- /*
- * The Office base directory can be found in the sversion.ini file in the
- * user's profile directory.
- *
- * Supposed to be platform agnostic, but not quite sure yet!
- */
-
- TCHAR szIniPath[MAX_PATH];
-
-
/*
- * On Windows ME and Windows 2000, the SHGetFolderPath function is incorporated
- * into SHELL32.dll. Unfortunately, this is not the case in Windows 95/98 so
- * the SHFOLDER library needs to be dynamically loaded to get an address for the
- * procedure.
+ * The DLL will be installed by setup in the program directory of
+ * the installation. The XMerge Jar files, if present, will be
+ * located in the classes directory below program.
*/
- SHGETFOLDERPATH SHGetFolderPath;
- HMODULE hModSHFolder = LoadLibrary("shfolder.dll");
- if ( hModSHFolder != NULL )
- {
- SHGetFolderPath = (SHGETFOLDERPATH)GetProcAddress(hModSHFolder, "SHGetFolderPathA");
- }
- else
- {
- FreeLibrary(hModSHFolder);
- SHGetFolderPath = NULL;
- }
+ TCHAR szJarPath[MAX_PATH];
+ TCHAR szTmpPath[MAX_PATH];
- if (SHGetFolderPath != NULL )
- {
- if(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, NULL, szIniPath) != S_OK)
- {
- FreeLibrary(hModSHFolder);
- return NULL;
- }
- }
- else
- {
- FreeLibrary(hModSHFolder);
- return NULL;
- }
+ ZeroMemory(szJarPath, MAX_PATH);
+ ZeroMemory(szTmpPath, MAX_PATH);
- FreeLibrary(hModSHFolder);
+ WIN32_FILE_ATTRIBUTE_DATA fInfo;
+ std::string clsPath;
- lstrcat(szIniPath, "\\sversion.ini");
+ // Get the location of the module.
+ GetModuleFileName(_Module.m_hInst, szTmpPath, MAX_PATH);
- // Should check the existence of the file here
- TCHAR* szSectVal;
- WIN32_FILE_ATTRIBUTE_DATA fInfo;
+ // Strip off the xmergesync.dll component
+ char* modName = strstr(szTmpPath, "xmergesync.dll");
+ strncpy(szJarPath, szTmpPath, modName - szTmpPath);
- if (!GetFileAttributesEx(szIniPath, GetFileExInfoStandard, &fInfo))
- return NULL;
+ // Append the classes directory
+ strncat(szJarPath, "classes\\", 8);
- szSectVal = new char[fInfo.nFileSizeLow];
+ // The core xmerge.jar must be present
+ ZeroMemory(szTmpPath, MAX_PATH);
+ _snprintf(szTmpPath, MAX_PATH, "%s%s\0", szJarPath, "xmerge.jar");
- if (!GetPrivateProfileSection("Versions", szSectVal, 3000, szIniPath))
+ if (!GetFileAttributesEx(szTmpPath, GetFileExInfoStandard, &fInfo))
{
- delete szSectVal;
return NULL;
}
-
- char* token = szSectVal;
- std::string clsDir;
-
- while (*token != '\0')
+ else
{
- // Clear the clsDir each time we go around
- clsDir = "";
-
- // Check for a compatible StarOffice/OpenOffice version
- if (!strncmp(token, "StarOffice 6", 12) || !strncmp(token, "OpenOffice.org 1", 12))
- {
- char* uri = token;
-
- // Jump past the equals sign
- uri = strchr(uri, '=') + 1;
-
- // Lose the file:///
- uri += 8;
-
- for (int j = 0; j < strlen(uri); j++)
- {
- switch (uri[j])
- {
- case '/':
- clsDir += '\\';
- break;
-
- case '%':
- // Read in the two following characters
- char* stop;
- char buf[3];
- buf[0] = uri[++j]; buf[1] = uri[++j]; buf[2] = '\0';
- clsDir += (char)strtol(buf, &stop, 16);
- break;
-
- default:
- clsDir += uri[j];
- }
- }
- }
- else
- {
- token += strlen(token) + 1;
- continue;
- }
-
-
- // Append the JAR file subdirectory
- clsDir += "\\program\\classes\\";
-
- // Check for the existence of the necessary JAR files
- std::string jars[3] = { clsDir + "xmerge.jar", clsDir + "pocketword.jar", clsDir + "pexcel.jar" };
- BOOL found = TRUE;
+ clsPath += szTmpPath;
+ clsPath += ";";
+ }
- for (int k = 0; k < 3; k++)
- {
- if (!GetFileAttributesEx(jars[k].c_str(), GetFileExInfoStandard, &fInfo))
- {
- found = FALSE;
- break;
- }
- }
- if (!found)
- {
- token += strlen(token) + 1;
- continue;
- }
+ // Now check for Pocket Word
+ ZeroMemory(szTmpPath, MAX_PATH);
+ _snprintf(szTmpPath, MAX_PATH, "%s%s\0", szJarPath, "pocketword.jar");
- // All files are present so return the classpath. Add in quotes in case of spaces
- std::string clsPath = "\"" + jars[0] + ";" + jars[1] + ";" + jars[2] + ";" + "\"";
-
- char* cPath = new char[clsPath.length() + 1];
- ZeroMemory(cPath, clsPath.length() + 1);
- strcpy(cPath, clsPath.c_str());
+ if (!GetFileAttributesEx(szTmpPath, GetFileExInfoStandard, &fInfo))
+ {
+ m_bHaveWord = FALSE;
+ }
+ else
+ {
+ m_bHaveWord = TRUE;
+ clsPath += szTmpPath;
+ clsPath += ";";
+ }
- delete szSectVal;
+ // Now check for Pocket Excel
+ ZeroMemory(szTmpPath, MAX_PATH);
+ _snprintf(szTmpPath, MAX_PATH, "%s%s\0", szJarPath, "pexcel.jar");
- return cPath;
+ if (!GetFileAttributesEx(szTmpPath, GetFileExInfoStandard, &fInfo))
+ {
+ m_bHaveExcel = FALSE;
}
+ else
+ {
+ m_bHaveExcel = TRUE;
+ clsPath += szTmpPath;
+ clsPath += ";";
+ }
+
+ // Quotes may be need around the ClassPath
+ clsPath.insert(0, "\"");
+ clsPath += "\"";
- delete szSectVal;
- return NULL;
+ // Return the data
+ return _strdup(clsPath.c_str());
}
diff --git a/xmerge/source/activesync/XMergeFilter.h b/xmerge/source/activesync/XMergeFilter.h
index fedeeeb48a34..54128f325125 100644
--- a/xmerge/source/activesync/XMergeFilter.h
+++ b/xmerge/source/activesync/XMergeFilter.h
@@ -22,6 +22,13 @@ private:
TCHAR* GetXMergeClassPath();
TCHAR* GetJavaBaseDir();
+ TCHAR* m_szJavaBaseDir;
+ TCHAR* m_szClasspath;
+
+ BOOL m_bHaveExcel;
+ BOOL m_bHaveWord;
+
+
public:
static const LPTSTR m_pszPSWExportCLSID;
static const LPTSTR m_pszPSWExportExt;
diff --git a/xmerge/source/activesync/XMergeSync.dsp b/xmerge/source/activesync/XMergeSync.dsp
new file mode 100644
index 000000000000..3c13e028e50b
--- /dev/null
+++ b/xmerge/source/activesync/XMergeSync.dsp
@@ -0,0 +1,143 @@
+# Microsoft Developer Studio Project File - Name="XMergeSync" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=XMergeSync - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "XMergeSync.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "XMergeSync.mak" CFG="XMergeSync - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "XMergeSync - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "XMergeSync - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""$/XMergeSync", BAAAAAAA"
+# PROP Scc_LocalPath "."
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "XMergeSync - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "XMERGESYNC_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "C:\Program Files\Windows CE Tools\wce300\Pocket PC 2002\support\ActiveSync\inc" /I "C:\Java\j2sdk1.4.0\include" /I "C:\Java\j2sdk1.4.0\include\win32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "XMERGESYNC_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x1809 /d "NDEBUG"
+# ADD RSC /l 0x1809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+
+!ELSEIF "$(CFG)" == "XMergeSync - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "XMERGESYNC_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "C:\Program Files\Windows CE Tools\wce300\Pocket PC 2002\support\ActiveSync\inc" /I "C:\Java\j2sdk1.4.0\include" /I "C:\Java\j2sdk1.4.0\include\win32" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "XMERGESYNC_EXPORTS" /FR /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x1809 /d "_DEBUG"
+# ADD RSC /l 0x1809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"C:\Java\j2sdk1.4.0\lib"
+
+!ENDIF
+
+# Begin Target
+
+# Name "XMergeSync - Win32 Release"
+# Name "XMergeSync - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\stdafx.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMergeFactory.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMergeFilter.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMergeSync.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMergeSync.def
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMergeSync.rc
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\stdafx.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMergeFactory.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMergeFilter.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMergeSync.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project