Reimplement code extracting information from file name.
This code tokenizes the file name based on commas and extracts relevant parts sequentially. `host=` is expected to be the first part. Since Windows renames files adding (1), (2) etc. before the .exe in case of duplicates, which causes the host or key values to be garbled. This allows using a `,` (comma) symbol as a final delimiter. Fixes #4162
This commit is contained in:
parent
96560d9199
commit
5a25573125
@ -36,24 +36,38 @@ pub fn get_license_from_string(s: &str) -> ResultType<License> {
|
||||
} else {
|
||||
s
|
||||
};
|
||||
/*
|
||||
* The following code tokenizes the file name based on commas and
|
||||
* extracts relevant parts sequentially.
|
||||
*
|
||||
* host= is expected to be the first part.
|
||||
*
|
||||
* Since Windows renames files adding (1), (2) etc. before the .exe
|
||||
* in case of duplicates, which causes the host or key values to be
|
||||
* garbled.
|
||||
*
|
||||
* This allows using a ',' (comma) symbol as a final delimiter.
|
||||
*/
|
||||
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[1];
|
||||
let stripped = &s[s.find("host=").unwrap_or(0)..s.len()];
|
||||
let strs: Vec<&str> = stripped.split(",").collect();
|
||||
let mut host = "";
|
||||
let mut key = "";
|
||||
let strs_iter = strs.iter();
|
||||
for el in strs_iter {
|
||||
if el.starts_with("host=") {
|
||||
host = &el[5..el.len()];
|
||||
}
|
||||
|
||||
if el.starts_with("key=") {
|
||||
key = &el[4..el.len()];
|
||||
}
|
||||
return Ok(License {
|
||||
host: host.to_owned(),
|
||||
key: key.to_owned(),
|
||||
api: "".to_owned(),
|
||||
});
|
||||
}
|
||||
return Ok(License {
|
||||
host: host.to_owned(),
|
||||
key: key.to_owned(),
|
||||
api: "".to_owned(),
|
||||
});
|
||||
} else {
|
||||
let strs = if s.contains("-licensed-") {
|
||||
s.split("-licensed-")
|
||||
|
Loading…
x
Reference in New Issue
Block a user