use super::raw::{reaper_plugin_info_t, HINSTANCE};
use super::ReaperPluginContext;
use std::error::Error;
use std::panic::{catch_unwind, UnwindSafe};
pub fn firewall<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Option<R> {
catch_unwind(f).ok()
}
pub fn bootstrap_extension_plugin(
_h_instance: HINSTANCE,
rec: *mut reaper_plugin_info_t,
init: fn(&ReaperPluginContext) -> Result<(), Box<dyn Error>>,
) -> i32 {
firewall(|| {
let context = match ReaperPluginContext::from_extension_plugin(rec) {
Err(_) => return 0,
Ok(c) => c,
};
match init(&context) {
Ok(_) => 1,
Err(_) => 0,
}
})
.unwrap_or(0)
}