new naming to support plain config

This commit is contained in:
rustdesk 2022-05-14 17:00:21 +08:00
parent 8fd2e1a0ed
commit 750a800c08
2 changed files with 41 additions and 9 deletions

View File

@ -11,7 +11,7 @@ pub struct License {
pub api: String,
}
pub fn get_license_from_string(s: &str) -> ResultType<License> {
fn get_license_from_string_(s: &str) -> ResultType<License> {
let tmp: String = s.chars().rev().collect();
const PK: &[u8; 32] = &[
88, 168, 68, 104, 60, 5, 163, 198, 165, 38, 12, 85, 114, 203, 96, 163, 70, 48, 0, 131, 57,
@ -28,3 +28,42 @@ pub fn get_license_from_string(s: &str) -> ResultType<License> {
bail!("sign:verify failed");
}
}
pub fn get_license_from_string(s: &str) -> ResultType<License> {
let s = if s.to_lowercase().ends_with(".exe") {
&s[0..s.len() - 4]
} else {
s
};
if s.contains("host=") {
let strs: Vec<&str> = s.split("host=").collect();
if strs.len() == 2 {
let strs2: Vec<&str> = strs[1].split(",key=").collect();
let host;
let mut key = "";
if strs2.len() == 2 {
host = strs2[0];
key = strs2[1];
} else {
host = strs[0];
}
return Ok(License {
host: host.to_owned(),
key: key.to_owned(),
api: "".to_owned(),
});
}
} else {
let strs = if s.contains("-licensed-") {
s.split("-licensed-")
} else {
s.split("--")
};
for s in strs {
if let Ok(lic) = get_license_from_string_(s) {
return Ok(lic);
}
}
}
bail!("Failed to parse");
}

View File

@ -1204,14 +1204,7 @@ fn get_reg_of(subkey: &str, name: &str) -> String {
fn get_license_from_exe_name() -> ResultType<License> {
let exe = std::env::current_exe()?.to_str().unwrap_or("").to_owned();
let tmp: Vec<&str> = exe.split("-licensed-").collect();
if let Some(tmp) = tmp.last() {
let tmp: Vec<&str> = tmp.split(".").collect();
if let Some(tmp) = tmp.first() {
return get_license_from_string(tmp);
}
}
Ok(Default::default())
get_license_from_string(exe)
}
#[inline]