-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
70 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#![deny(clippy::all)] | ||
#![feature(absolute_path)] | ||
#[macro_use] | ||
extern crate napi_derive; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,69 @@ | ||
use lnk_parser::LNKParser; | ||
use napi::Result; | ||
use std::path::PathBuf; | ||
use std::path::{absolute, PathBuf}; | ||
pub mod exelook; | ||
|
||
#[napi] | ||
pub fn parse_lnk(path: String) -> Result<String> { | ||
pub fn parse_lnk(path: String) -> Result<LnkData> { | ||
let lnk_file = LNKParser::from_path(&path); | ||
match lnk_file { | ||
Ok(f) => Ok(serde_json::to_string(&f).unwrap()), | ||
Err(e) => Err(napi::Error::from_reason(e.to_string())), | ||
Ok(f) => { | ||
let name_string = f.get_name_string().as_ref().map(|f| f.to_string()); | ||
let full_path = f | ||
.get_target_full_path() | ||
.as_ref() | ||
.map(|f| { | ||
if f.starts_with("MY_COMPUTER\\") { | ||
Some(f.to_string().replace("MY_COMPUTER\\", "")) | ||
} else { | ||
Some(f.to_string()) | ||
} | ||
}) | ||
.map_or(None, |f| f); | ||
let working_dir = f.get_working_dir().as_ref().map(|f| f.to_string()); | ||
let icon_location = f.get_icon_location().as_ref().map(|f| f.to_string()); | ||
|
||
Ok(LnkData { | ||
name_string, | ||
full_path, | ||
working_dir, | ||
icon_location, | ||
}) | ||
} | ||
Err(_) => { | ||
let lnk_path = std::path::Path::new(&path); | ||
let lnk = parselnk::Lnk::try_from(lnk_path); | ||
match lnk { | ||
Ok(l) => { | ||
let s = absolute( | ||
PathBuf::from(lnk_path) | ||
.parent() | ||
.unwrap() | ||
.join(l.string_data.relative_path.unwrap()), | ||
) | ||
.map_or(None, |f| Some(f)); | ||
|
||
Ok(LnkData { | ||
name_string: l.string_data.name_string, | ||
full_path: convert(s), | ||
working_dir: convert(l.string_data.working_dir), | ||
icon_location: convert(l.string_data.icon_location), | ||
}) | ||
} | ||
Err(e) => Err(napi::Error::from_reason(e.to_string())), | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[napi] | ||
pub struct LnkData { | ||
pub name_string: Option<String>, | ||
pub relative_path: Option<String>, | ||
pub full_path: Option<String>, | ||
pub working_dir: Option<String>, | ||
pub icon_location: Option<String>, | ||
} | ||
|
||
fn convert(p: Option<PathBuf>) -> Option<String> { | ||
match p { | ||
Some(p) => Some(p.to_str().unwrap().to_string()), | ||
None => None, | ||
} | ||
} | ||
|
||
#[napi] | ||
pub fn parse_lnk_fallback(path: String) -> Result<LnkData> { | ||
let lnk_path = std::path::Path::new(&path); | ||
let lnk = parselnk::Lnk::try_from(lnk_path); | ||
match lnk { | ||
Ok(l) => Ok(LnkData { | ||
name_string: l.string_data.name_string, | ||
relative_path: convert(l.string_data.relative_path), | ||
working_dir: convert(l.string_data.working_dir), | ||
icon_location: convert(l.string_data.icon_location), | ||
}), | ||
Err(e) => Err(napi::Error::from_reason(e.to_string())), | ||
} | ||
p.map(|f| f.to_string_lossy().to_string()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { existsSync } from "fs"; | ||
import { getSystemApp } from "./src" | ||
|
||
console.time("1") | ||
getSystemApp((e) => { | ||
console.log(e); | ||
|
||
await getSystemApp((e) => { | ||
if (!existsSync(e.execPath)) { | ||
console.log(e); | ||
} | ||
}) | ||
console.timeEnd("1") |