Advertisement
buesingniklas

Untitled

Jan 10th, 2022
3,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.07 KB | None | 0 0
  1. fn extract_sciter() -> anyhow::Result<String> {
  2.     for file in std::fs::read_dir(std::env::temp_dir())? {
  3.         if let Ok(entry) = file {
  4.             let path = entry.path();
  5.             if path.is_dir()
  6.                 && path
  7.                     .file_name()
  8.                     .unwrap_or_default()
  9.                     .to_os_string()
  10.                     .into_string()
  11.                     .unwrap_or_default()
  12.                     .starts_with("sciter")
  13.             {
  14.                 std::fs::remove_dir_all(path).ok();
  15.             }
  16.         }
  17.     }
  18.  
  19.     let sciter = include_bytes!("../resources/sciter.dll.zs");
  20.  
  21.     let tmp_dir = tempfile::Builder::new().prefix("sciter").tempdir()?;
  22.     let tmp_file = tmp_dir.path().join("sciter.dll");
  23.  
  24.     zstd::stream::copy_decode(&sciter[..], File::create(&tmp_file)?)?;
  25.  
  26.     let path = &tmp_file
  27.         .into_os_string()
  28.         .into_string()
  29.         .or(Err(anyhow::anyhow!(
  30.             "Couldn't convert temp file into appropriate path"
  31.         )))?;
  32.  
  33.     tmp_dir.into_path();
  34.  
  35.     Ok(path.to_owned())
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement