kintomiko / jodconverter

Automatically exported from code.google.com/p/jodconverter
0 stars 0 forks source link

OfficeUtils.getDefaultOfficeHome() returns incorrect location when run in a 64bit JVM on Windows #68

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The environment variable "ProgramFiles" used by 
OfficeUtils#getDefaultOfficeHome to determine where OO is installed is not 
reliable as its value changes depending on whether the process accessing 
the  variable is 64 or 32 bit. 

The variable "ProgramFiles(x86)" should be used instead with a fall back to 
"ProgramFiles" for 32bit Windows builds.

Index: src/main/java/org/artofsolving/jodconverter/office/OfficeUtils.java
===================================================================
--- src/main/java/org/artofsolving/jodconverter/office/OfficeUtils.java 
(revision 155)
+++ src/main/java/org/artofsolving/jodconverter/office/OfficeUtils.java 
(working copy)
@@ -72,8 +72,12 @@
         if (System.getProperty("office.home") != null) {
             return new File(System.getProperty("office.home"));
         }
-        if (PlatformUtils.isWindows()) {
-            return new File(System.getenv("ProgramFiles"), "OpenOffice.org 
3");
+        if (PlatformUtils.isWindows()) {           
+           String programFiles = System.getenv("ProgramFiles(x86)");
+           if (programFiles == null) {
+               programFiles = System.getenv("ProgramFiles");
+           }
+            return new File(programFiles, "OpenOffice.org 3");
         } else if (PlatformUtils.isMac()) {
             return new File("/Applications/OpenOffice.org.app/Contents");
         } else {

Original issue reported on code.google.com by hutchiko@gmail.com on 26 Mar 2010 at 6:01

GoogleCodeExporter commented 8 years ago

Original comment by mirko.na...@gmail.com on 15 May 2010 at 11:13

GoogleCodeExporter commented 8 years ago
The proposed fix assumes that the 64bit Windows is running a 32bit copy of OO.
I think it would be better to try for a 64bit version first, falling back to 
32bit if that does not exist:
         if (PlatformUtils.isWindows()) {
-            return new File(System.getenv("ProgramFiles"), "OpenOffice.org 3");
+            File officeHome = new File(System.getenv("ProgramFiles"), 
"OpenOffice.org 3");
+            if (!officeHome.exists() && (null != 
System.getenv("ProgramFiles(x86)"))) {
+                officeHome = new File(System.getenv("ProgramFiles(x86)"), 
"OpenOffice.org 3");
+            }
+            return officeHome;
         } else if (PlatformUtils.isMac()) {
             return new File("/Applications/OpenOffice.org.app/Contents");
         } else {

Original comment by yay...@spudsoft.co.uk on 11 Oct 2010 at 11:23

GoogleCodeExporter commented 8 years ago
This was fixed by rev204, I suppose?

Original comment by benjamin...@uni-siegen.de on 16 Aug 2011 at 7:42

GoogleCodeExporter commented 8 years ago
Yep this was actually fixed as part of issue #83

Original comment by mirko.na...@gmail.com on 22 Aug 2011 at 8:17