Skip to content

Commit ca88823

Browse files
1.0.1
1 parent 6cf5c68 commit ca88823

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

src/csharp/Julia.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using System.Runtime.InteropServices;
6+
using System.IO;
67

78
//Written by Johnathan Bizzano
89
namespace JuliaInterface
@@ -15,10 +16,11 @@ public class Julia
1516

1617
public static void Init()
1718
{
19+
var os = OperatingEnvironment.GetEnvironment();
1820
var proc = new Process {
1921
StartInfo = new ProcessStartInfo {
20-
FileName = "where.exe",
21-
Arguments = "Julia",
22+
FileName = os.GetWhereExe(),
23+
Arguments = "julia",
2224
UseShellExecute = false,
2325
RedirectStandardOutput = true,
2426
CreateNoWindow = true
@@ -28,25 +30,26 @@ public static void Init()
2830
while (!proc.StandardOutput.EndOfStream)
2931
{
3032
string location = proc.StandardOutput.ReadLine();
31-
if (location.Contains("julia.exe")){
32-
Init(location.Substring(1, location.Length - 11));
33+
if (location.Contains("julia")){
34+
location = os.TrimJuliaPath(location);
35+
Init(location);
3336
return;
34-
}
35-
37+
}
3638
}
3739
throw new Exception("Julia Path Not Found");
3840
}
3941

40-
4142

4243
public static void Init(string dir){
43-
JuliaCalls.SetDllDirectory(dir);
44+
var env = Environment.CurrentDirectory;
45+
Environment.CurrentDirectory = dir;
4446
JuliaCalls.jl_init();
4547
JuliaCalls.jl_eval_string(System.Text.Encoding.UTF8.GetString(Resource1.JuliaInterface));
4648
JLModule.init_mods();
4749
JLType.init_types();
4850
JLFun.init_funs();
4951
NativeSharp.init();
52+
Environment.CurrentDirectory = env;
5053
}
5154

5255
public static void SetGlobal(JLModule m, JLSym sym, JLVal val)
@@ -68,6 +71,7 @@ public static void CheckExceptions(){
6871
}
6972

7073
public static void Exit(int code) => JuliaCalls.jl_atexit_hook(code);
74+
7175
public static JLVal Eval(string str){
7276
var val = JuliaCalls.jl_eval_string(str);
7377
CheckExceptions();

src/csharp/JuliaCalls.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ namespace JuliaInterface
88
public class JuliaCalls
99
{
1010

11-
12-
[DllImport("kernel32.dll")]
13-
public static extern bool SetDllDirectory(string path);
14-
1511

1612
public enum JLIMAGESEARCH{
1713
JL_IMAGE_CWD = 0,

src/csharp/OperatingEnvironment.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Runtime.InteropServices;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace JuliaInterface
9+
{
10+
public abstract class OperatingEnvironment
11+
{
12+
13+
public OperatingEnvironment() { }
14+
15+
public abstract string GetWhereExe();
16+
public abstract string TrimJuliaPath(string s);
17+
18+
public static OperatingEnvironment GetEnvironment(){
19+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
20+
return new WindowsEnvironment();
21+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
22+
return new LinuxEnvironment();
23+
else throw new Exception("Unsupported Operating System!");
24+
}
25+
}
26+
27+
public class WindowsEnvironment : OperatingEnvironment
28+
{
29+
30+
public override string GetWhereExe() => "where.exe";
31+
32+
public override string TrimJuliaPath(string s) => s.Substring(0, s.Length - 10);
33+
}
34+
35+
public class LinuxEnvironment : OperatingEnvironment
36+
{
37+
public override string GetWhereExe() => "which";
38+
39+
public override string TrimJuliaPath(string s) => s;
40+
}
41+
42+
43+
}

0 commit comments

Comments
 (0)