Skip to content

Commit d60cd61

Browse files
authored
remove hard code of inf path
1 parent 2b3b64c commit d60cd61

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

ForTunCli/src/device_ops.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::process::Command;
55

66
use anyhow::{anyhow, bail, Context};
77
use cidr_utils::cidr::IpCidr;
8+
use std::fs::Path;
89
use std::thread::sleep;
910
use std::time::Duration;
1011
use version_compare::Version;
@@ -127,10 +128,10 @@ impl AdapterDevice {
127128
}
128129
}
129130

130-
pub fn init_device(
131+
pub fn init_device<T:AsRef<Path>>(
131132
device_guid: &GUID,
132133
name: &str,
133-
inf_path: &str,
134+
inf_path: T,
134135
) -> anyhow::Result<AdapterDevice> {
135136
let devices = enum_device(&FOR_TUN_DEV_CLASS, FOR_TUN_HWID)?;
136137
if devices.is_empty() {

ForTunCli/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub use device_ops::init_device;
88
pub use device_ops::net_config;
99
pub use device_ops::AdapterDevice;
1010
use std::sync::Arc;
11+
use std::fs::Path;
1112
use tokio::io;
1213
use windows::core::GUID;
1314
use windows::Win32::Foundation::CloseHandle;
@@ -61,9 +62,8 @@ impl Drop for WriteFile {
6162

6263
pub type TunSocket = (ReadFile, WriteFile, AdapterDevice);
6364

64-
pub fn create_async_tun(device_id: &GUID, name: &str) -> anyhow::Result<TunSocket> {
65-
//TODO: inf_path change to compile path
66-
let device = init_device(device_id, name, "C:/DriverTest/Drivers/ForTun.inf")?;
65+
pub fn create_async_tun<T:AsRef<Path>>(device_id: &GUID, name: &str, inf_path: T) -> anyhow::Result<TunSocket> {
66+
let device = init_device(device_id, name, inf_path/*"C:/DriverTest/Drivers/ForTun.inf"*/)?;
6767
let file = device.start_adapter()?;
6868
let file = match WinOverlappedFile::new(file) {
6969
Ok(file) => Arc::new(file),

0 commit comments

Comments
 (0)