Skip to content

Commit

Permalink
支持自定义安装位置
Browse files Browse the repository at this point in the history
  • Loading branch information
super1207 committed Mar 30, 2024
1 parent 7335fc4 commit 9018a14
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
goblin = "0.8.0"
log = "0.4.21"
path-clean = "1.0.1"
regex = "1.10.4"
reqwest = "0.12.2"
serde_json = "1.0.115"
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,34 @@ Fully automatic installation of LLOneboT and LiteLoaderQQNT on Windows.

Double clicking the exe is all you need, just try a few more times if you have network problems.

## Installation Location

你可以通过编写配置文件`llob_install.json`来指定`QQ.exe`的目录,如:
```json
{
"qq_exe_path":"D:\\NTQQ\\QQ.exe"
}
```

你也可以将`llob_install.exe`拖入`QQ.exe`所在目录再运行。

**否则,将自动从Windows注册表中读取`QQ.exe`的安装路径。**

优先级:配置文件 > llob_install.exe 目录 > 注册表

You can specify the directory of `QQ.exe` by writing a configuration file `llob_install.json`, like this:
```json
{
"qq_exe_path":"D:\\NTQQ\\QQ.exe"
}
```

Alternatively, you can drag `llob_install.exe` into the directory where `QQ.exe` is located and then run it.

**Otherwise, the installation path of `QQ.exe` will be automatically read from the Windows registry.**

Priority: Configuration file > llob_install.exe directory > Registry

## Thanks

[LiteLoaderQQNT](https://github.com/LiteLoaderQQNT/LiteLoaderQQNT)
Expand Down
62 changes: 59 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,74 @@
use std::{fs::{self}, path::PathBuf, process::Command, str::FromStr, sync::Arc};

use path_clean::PathClean;
use regex::Regex;
use reqwest::header::{HeaderName, HeaderValue};
use time::UtcOffset;
use ::time::format_description;

fn get_qq_path() -> Result<PathBuf, Box<dyn std::error::Error>> {

fn get_apath(path:&PathBuf) -> PathBuf {
let apath;
if path.is_absolute() {
apath = path.clean();
}else{
apath = std::env::current_dir().unwrap().join(path).clean();
}
apath
}

fn get_qq_path_by_reg() -> Result<PathBuf, Box<dyn std::error::Error>> {
let hkcu = winreg::RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE);
let qq_setting: winreg::RegKey = hkcu.open_subkey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\QQ")?;
let qq_path:String = qq_setting.get_value("UninstallString")?;
let q = PathBuf::from_str(&qq_path)?.parent().ok_or("can't find qq path")?.to_owned();
Ok(q)
}

fn get_qq_path_by_current_exe_path() -> Result<PathBuf, Box<dyn std::error::Error>> {
let current_exe_path = std::env::current_exe()?;
let current_path = current_exe_path.parent().ok_or("can't find current path")?;
let qq_path = current_path.join("QQ.exe");
if qq_path.is_file() {
return Ok(current_path.to_path_buf());
}
Err("can't find qq.exe on current path".into())
}

fn get_qq_path_by_cfg() -> Result<PathBuf, Box<dyn std::error::Error>> {
let current_exe_path = std::env::current_exe()?;
let current_path = current_exe_path.parent().ok_or("can't find current path")?;
let cfg_file = current_path.join("llob_install.json");
let json_str = fs::read_to_string(cfg_file)?;
let json:serde_json::Value = serde_json::from_str(&json_str)?;
let qq_path_str = json["qq_exe_path"].as_str().ok_or("failed to get qq_exe_path")?;
let qq_exe_path = PathBuf::from(qq_path_str);
let qq_exe_path_t = get_apath(&qq_exe_path);
if qq_exe_path_t.is_file() {
return Ok(qq_exe_path_t.parent().ok_or("can't find qq path")?.to_path_buf());
}
Err("can't find qq.exe llob_install.json".into())
}

fn get_qq_path() -> Result<PathBuf, Box<dyn std::error::Error>> {
// 先看配置文件
if let Ok(qq_path) = get_qq_path_by_cfg() {
log::info!("从配置文件获取到QQ.exe");
return Ok(qq_path);
}
// 再看当前目录
if let Ok(qq_path) = get_qq_path_by_current_exe_path() {
log::info!("从当前位置获取到QQ.exe");
return Ok(qq_path);
}
// 再看注册表
if let Ok(qq_path) = get_qq_path_by_reg() {
log::info!("从注册表获取到QQ.exe");
return Ok(qq_path);
}
Err("can't find qq path".into())
}

fn is_qq_run(qq_path:&PathBuf) -> Result<bool, Box<dyn std::error::Error>> {
let system = sysinfo::System::new_all();
let process_name = "QQ.exe";
Expand Down Expand Up @@ -233,15 +289,15 @@ fn main(){

fn mymain() -> Result<(), Box<dyn std::error::Error>>{


let rt_ptr:Arc<tokio::runtime::Runtime> = Arc::new(tokio::runtime::Runtime::new().unwrap());

init_log();

log::info!("欢迎使用LLOB安装器0.0.1 by super1207");

log::info!("正在检查是否拥有管理员权限...");
if is_admin().unwrap() {
let has_admin = is_admin().unwrap();
if has_admin {
log::info!("拥有管理员权限");
} else {
log::error!("没有管理员权限");
Expand Down

0 comments on commit 9018a14

Please sign in to comment.