Exemplo n.º 1
0
        public static SettingConfig GetSavedSettings()
        {
            SettingConfig settings = null;

            if (File.Exists(SettingPath))
            {
                var text = File.ReadAllText(SettingPath);
                settings = Newtonsoft.Json.JsonConvert.DeserializeObject <SettingConfig>(text);
            }
            else
            {
                settings = new SettingConfig();
                //settings.LBTRootFolder = @"C:\Users\mingo\ladybug_tools_revit";
                settings.SaveSettings();
            }

            return(settings);
        }
Exemplo n.º 2
0
        private static string GetLadybugToolsInstallationPath()
        {
            // Mac
            if (System.Environment.OSVersion.Platform == PlatformID.Unix)
            {
                // this only looking for Rhino 6 for now
                var args = $"defaults read com.mcneel.rhinoceros User.PlugInRegistry.6.8b32d89c-3455-4c21-8fd7-7364c32a6feb.PlugIn.FileName";

                var startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.CreateNoWindow         = true;
                startInfo.UseShellExecute        = false;
                startInfo.FileName               = "/bin/bash";
                startInfo.Arguments              = $"-c \"{args}\"";
                startInfo.RedirectStandardOutput = true;

                using (var exeProcess = new System.Diagnostics.Process())
                {
                    exeProcess.StartInfo = startInfo;
                    exeProcess.Start();
                    exeProcess.WaitForExit();
                    string outputs = exeProcess.StandardOutput.ReadToEnd().Trim();

                    if (string.IsNullOrEmpty(outputs))
                    {
                        throw new ArgumentException("Ladybug Tools is not installed on this machine!");
                    }

                    // "/Users/mingbo/ladybug_tools2/rhino/HoneybeeRhino.PlugIn.Mac.rhp"
                    outputs = outputs.Split(new[] { "rhino" }, StringSplitOptions.RemoveEmptyEntries).First();

                    if (!Directory.Exists(outputs))
                    {
                        throw new ArgumentException("Ladybug Tools is not installed on this machine!");
                    }

                    return(outputs);
                }
            }
            else
            {
                // windows
                // check if there is a config in the folder
                var foundPath = SettingConfig.GetSavedSettings()?.LBTRootFolder;

                // find it from registry
                if (string.IsNullOrEmpty(foundPath) || !Directory.Exists(foundPath))
                {
                    foundPath = GetLBTRootFromRegistry();
                }

                // create a new ladybug_tools folder under ProgramFiles
                if (string.IsNullOrEmpty(foundPath) || !Directory.Exists(foundPath))
                {
                    var programFile = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                    foundPath = Directory.GetDirectories(programFile, "*ladybug_tools*", SearchOption.TopDirectoryOnly).FirstOrDefault();
                    if (!Directory.Exists(foundPath))
                    {
                        foundPath = Path.Combine(programFile, "ladybug_tools");
                        Directory.CreateDirectory(foundPath);
                    }
                }

                if (!Directory.Exists(foundPath))
                {
                    throw new ArgumentException($"Ladybug Tools is not installed on this machine! ({foundPath})");
                }

                return(foundPath);
            }
        }