From 750a800c08ab2ec430f063b16ee42185fa584f4f Mon Sep 17 00:00:00 2001 From: rustdesk Date: Sat, 14 May 2022 17:00:21 +0800 Subject: [PATCH] new naming to support plain config --- src/license.rs | 41 ++++++++++++++++++++++++++++++++++++++++- src/platform/windows.rs | 9 +-------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/license.rs b/src/license.rs index f5ec35501..5db983448 100644 --- a/src/license.rs +++ b/src/license.rs @@ -11,7 +11,7 @@ pub struct License { pub api: String, } -pub fn get_license_from_string(s: &str) -> ResultType { +fn get_license_from_string_(s: &str) -> ResultType { 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 { bail!("sign:verify failed"); } } + +pub fn get_license_from_string(s: &str) -> ResultType { + 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"); +} diff --git a/src/platform/windows.rs b/src/platform/windows.rs index e398a7b1b..7793c0369 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -1204,14 +1204,7 @@ fn get_reg_of(subkey: &str, name: &str) -> String { fn get_license_from_exe_name() -> ResultType { 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]