private static void UnpackScriptResources() { if (g_resources_unpacked) { return; } Guid python_plugin_id = new Guid("814d908a-e25c-493d-97e9-ee3861957f49"); var plugin = Rhino.PlugIns.PlugIn.Find(python_plugin_id); if (plugin == null) { return; } g_resources_unpacked = true; // Unpack ghcomponents.py to the Python plug directory string settings_directory = plugin.SettingsDirectory; string marker_file = Path.Combine(settings_directory, "ghpy_version.txt"); try { if (File.Exists(marker_file)) { string text = File.ReadAllText(marker_file); Version markedversion = new Version(text); Version this_version = typeof(ZuiPythonComponent).Assembly.GetName().Version; if (markedversion == this_version) { #if !DEBUG // everything looks good, bail out return; #endif } } } catch (Exception ex) { HostUtils.ExceptionReport(ex); } try { // if we get to here, we need to unpack the resources if (!Directory.Exists(settings_directory)) { Directory.CreateDirectory(settings_directory); } string ghpython_package_dir = Path.Combine(settings_directory, "lib", PythonEnvironment.GHPYTHONLIB_NAME); if (Directory.Exists(ghpython_package_dir)) { Directory.Delete(ghpython_package_dir, true); } Directory.CreateDirectory(ghpython_package_dir); System.Reflection.Assembly a = typeof(ZuiPythonComponent).Assembly; string[] names = a.GetManifestResourceNames(); const string prefix = "GhPython.package."; foreach (string name in names) { if (!name.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase)) { continue; } Stream resource_stream = a.GetManifestResourceStream(name); if (resource_stream == null) { continue; } StreamReader stream = new StreamReader(resource_stream); string s = stream.ReadToEnd(); stream.Close(); string filename = name.Replace(prefix, ""); string path = Path.Combine(ghpython_package_dir, filename); File.WriteAllText(path, s); } // Write the marker file at the very end to ensure that we actually got to this point. // If an exception occured for some reason like a file was in use, then the plug-in // will just attempt to unpack the resources next time. string str = a.GetName().Version.ToString(); File.WriteAllText(marker_file, str); } catch (Exception ex) { HostUtils.DebugString("Exception while unpacking resources: " + ex.Message); } }