1 package org.simantics.msvc.runtime;
4 import java.io.UnsupportedEncodingException;
6 import java.net.URLDecoder;
8 import org.eclipse.core.runtime.Path;
11 * @author Tuukka Lehtonen
13 public final class Runtimes {
15 public static final String VC_2010 = "vc2010";
17 static boolean vc100Initialized = false;
19 public static void initialize(String vc) {
20 OSType os = OSType.calculate();
21 if (os == OSType.WINDOWS) {
22 if (VC_2010.equals(vc) && !vc100Initialized) {
28 static synchronized void initializeVC100() {
30 // Works in OSGi environment.
31 System.loadLibrary("msvcr100");
32 System.loadLibrary("msvcp100");
33 vc100Initialized = true;
34 } catch (UnsatisfiedLinkError e) {
35 // Try to load from a workspace in POJO environment.
37 String archStr = ARCHType.calculate().toString().toLowerCase();
38 URL url = Runtimes.class.getResource(".");
39 File dir = new File(URLDecoder.decode(url.getPath(), "UTF-8") + "../../../../../../org.simantics.msvc.runtime." + archStr);
40 dir = new Path(dir.getAbsolutePath()).toFile();
41 String vcr = new File(dir, "msvcr100.dll").getAbsolutePath();
42 String vcp = new File(dir, "msvcp100.dll").getAbsolutePath();
45 vc100Initialized = true;
46 } catch (UnsupportedEncodingException e1) {
47 throw new Error("UTF-8 not supported, impossible");
52 public enum ARCHType {
53 PPC, PPC_64, SPARC, X86, X86_64, UNKNOWN;
55 public static ARCHType calculate() {
56 String osArch = System.getProperty("os.arch");
57 assert osArch != null;
58 osArch = osArch.toLowerCase();
59 if (osArch.equals("i386") || osArch.equals("i586") || osArch.equals("i686") || osArch.equals("x86"))
61 if (osArch.startsWith("amd64") || osArch.startsWith("x86_64"))
63 if (osArch.equals("ppc"))
65 if (osArch.startsWith("ppc"))
67 if (osArch.startsWith("sparc"))
74 APPLE, LINUX, SUN, WINDOWS, UNKNOWN;
76 public static OSType calculate() {
77 String osName = System.getProperty("os.name");
78 assert osName != null;
79 osName = osName.toLowerCase();
80 if (osName.startsWith("mac os x"))
82 if (osName.startsWith("windows"))
84 if (osName.startsWith("linux"))
86 if (osName.startsWith("sun"))