Implement dc_get_abs_path_safe

This commit is contained in:
Alexander Krotov
2019-08-05 19:21:31 +03:00
parent e9ff02bdc5
commit 76dbb37609
3 changed files with 84 additions and 158 deletions

View File

@@ -1,5 +1,3 @@
use std::ffi::CString;
use strum::{EnumProperty, IntoEnumIterator};
use strum_macros::{AsRefStr, Display, EnumIter, EnumProperty, EnumString};
@@ -9,7 +7,6 @@ use crate::dc_job::*;
use crate::dc_tools::*;
use crate::error::Error;
use crate::stock::StockMessage;
use crate::x::*;
/// The available configuration keys.
#[derive(
@@ -72,15 +69,7 @@ impl Context {
let value = match key {
Config::Selfavatar => {
let rel_path = self.sql.get_config(self, key);
rel_path.map(|p| {
let v = unsafe {
let n = CString::yolo(p);
dc_get_abs_path(self, n.as_ptr())
};
let r = to_string(v);
unsafe { free(v as *mut _) };
r
})
rel_path.map(|p| dc_get_abs_path_safe(self, &p).to_str().unwrap().to_string())
}
Config::SysVersion => Some(std::str::from_utf8(DC_VERSION_STR).unwrap().into()),
Config::SysMsgsizeMaxRecommended => Some(format!("{}", 24 * 1024 * 1024 / 4 * 3)),