Skip to content
Permalink
Browse files

[FIXED JENKINS-24265] provide a proper detection of the %LOCALAPPDATA…

…% directory on Windows based on Unity3d recommendation (look for CSIDL_LOCAL_APPDATA)
  • Loading branch information
lacostej committed May 26, 2015
1 parent 4d94511 commit a7e66b6e3942f7e76c7cee8acf28216c9add5330
@@ -2,7 +2,6 @@

import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
import hudson.Util;
@@ -128,9 +127,17 @@ private File getEditorLogFile(String customLogFile) {
if (customLogFile != null) return new File(customLogFile);

if (Functions.isWindows()) {
String localAppData = EnvVars.masterEnvVars.get("LOCALAPPDATA");
if (localAppData == null) {
throw new RuntimeException("Empty LOCALAPPDATA environment variable. Use -logFile command line argument as workaround. Unable to find Editor.log location (see JENKINS-24265).");
String localAppData;
try {
localAppData = Win32Util.getLocalAppData();
log.fine("Found %LOCALAPPDATA% under " + localAppData);
} catch (RuntimeException re) {
log.warning("Unable to find %LOCALAPPDATA%, reverting to Environment variable " + re.getMessage());
localAppData = EnvVars.masterEnvVars.get("LOCALAPPDATA");
log.fine("Found %LOCALAPPDATA% (from environment variable) under " + localAppData);
if (localAppData == null) {
throw new RuntimeException("Empty LOCALAPPDATA environment variable. Use -logFile command line argument as workaround. Unable to find Editor.log location (see JENKINS-24265).");
}
}
File applocaldata = new File(localAppData);
return new File(applocaldata, "Unity/Editor/Editor.log");
@@ -0,0 +1,65 @@
package org.jenkinsci.plugins.unity3d;

import java.util.HashMap;
import java.util.Map;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeMapped;
import com.sun.jna.PointerType;
import com.sun.jna.win32.W32APIFunctionMapper;
import com.sun.jna.win32.W32APITypeMapper;


public class Win32Util {

static String getLocalAppData() {
HWND hwndOwner = null;
int nFolder = Shell32.CSIDL_LOCAL_APPDATA;
HANDLE hToken = null;
int dwFlags = Shell32.SHGFP_TYPE_CURRENT;
char[] pszPath = new char[Shell32.MAX_PATH];
int hResult = Shell32.INSTANCE.SHGetFolderPath(hwndOwner, nFolder, hToken, dwFlags, pszPath);
if (Shell32.S_OK == hResult) {
String path = new String(pszPath);
int len = path.indexOf('\0');
return path.substring(0, len);
} else {
throw new RuntimeException("Unable to find PATH under CSIDL_LOCAL_APPDATA [" + hResult + "]");
}

}

private static Map<String, Object> OPTIONS = new HashMap<String, Object>();
static {
OPTIONS.put(Library.OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
OPTIONS.put(Library.OPTION_FUNCTION_MAPPER,
W32APIFunctionMapper.UNICODE);
}
static class HANDLE extends PointerType implements NativeMapped {
}

static class HWND extends HANDLE {
}

static interface Shell32 extends Library {
public static final int MAX_PATH = 260;
public static final int CSIDL_LOCAL_APPDATA = 0x001c;
public static final int SHGFP_TYPE_CURRENT = 0;
//public static final int SHGFP_TYPE_DEFAULT = 1;
public static final int S_OK = 0;

static Shell32 INSTANCE = (Shell32) Native.loadLibrary("shell32",
Shell32.class, OPTIONS);

/**
* see http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx
*
* HRESULT SHGetFolderPath( HWND hwndOwner, int nFolder, HANDLE hToken,
* DWORD dwFlags, LPTSTR pszPath);
*/
public int SHGetFolderPath(HWND hwndOwner, int nFolder, HANDLE hToken,
int dwFlags, char[] pszPath);

}
}

0 comments on commit a7e66b6

Please sign in to comment.
You can’t perform that action at this time.