Skip to content

Commit b571b7f

Browse files
committed
add
1 parent 03069a6 commit b571b7f

6 files changed

Lines changed: 426 additions & 8 deletions

File tree

.github/workflows/build-release.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,16 @@ jobs:
5757
run: |
5858
brew install libpcap
5959
60-
- name: Install Windows dependencies
60+
- name: Install Windows dependencies (Npcap SDK)
6161
if: matrix.target == 'windows'
6262
shell: powershell
6363
run: |
64-
$wpcapUrl = "https://www.winpcap.org/install/bin/WpdPack_4_1_2.zip"
65-
$zipPath = "$env:TEMP\WpdPack.zip"
66-
$extractPath = "$env:TEMP\WpdPack"
67-
Invoke-WebRequest -Uri $wpcapUrl -OutFile $zipPath
64+
$sdkUrl = "https://npcap.com/dist/npcap-sdk-1.13.zip"
65+
$zipPath = "$env:TEMP\npcap-sdk.zip"
66+
$extractPath = "C:\npcap-sdk"
67+
Invoke-WebRequest -Uri $sdkUrl -OutFile $zipPath
6868
Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force
69-
$libDir = "$extractPath\WpdPack\Lib\x64"
70-
echo "LIB=$libDir;$env:LIB" >> $env:GITHUB_ENV
69+
echo "NPCAP_SDK_DIR=$extractPath" >> $env:GITHUB_ENV
7170
7271
- name: Install frontend dependencies
7372
run: npm ci

scripts/setup-npcap-sdk.ps1

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#Requires -Version 5.1
2+
<#
3+
.SYNOPSIS
4+
Npcap SDK をダウンロード・展開し、環境変数 NPCAP_SDK_DIR をセットする。
5+
.DESCRIPTION
6+
build.rs が NPCAP_SDK_DIR を読んで cargo:rustc-link-search を出力するため、
7+
このスクリプトでローカル開発環境を準備する。
8+
#>
9+
10+
Set-StrictMode -Version Latest
11+
$ErrorActionPreference = "Stop"
12+
13+
# ---------------------------------------------------------------------------
14+
# 設定値(変更が必要な場合はここを編集)
15+
# ---------------------------------------------------------------------------
16+
$SdkVersion = "1.13"
17+
$SdkUrl = "https://npcap.com/dist/npcap-sdk-$SdkVersion.zip"
18+
$InstallPath = "C:\npcap-sdk"
19+
$EnvVarName = "NPCAP_SDK_DIR"
20+
$ZipPath = Join-Path $env:TEMP "npcap-sdk-$SdkVersion.zip"
21+
22+
# ---------------------------------------------------------------------------
23+
# メイン処理
24+
# ---------------------------------------------------------------------------
25+
function Main {
26+
# 既にインストール済みか確認
27+
if (Test-Path $InstallPath) {
28+
Write-Host "[INFO] $InstallPath は既に存在します。"
29+
$answer = Read-Host "上書きしますか? (y/N)"
30+
if ($answer -ne "y") {
31+
Write-Host "[INFO] スキップしました。"
32+
Set-EnvVar
33+
return
34+
}
35+
Remove-Item -Recurse -Force $InstallPath
36+
Write-Host "[INFO] 既存ディレクトリを削除しました。"
37+
}
38+
39+
# ダウンロード
40+
Write-Host "[INFO] Npcap SDK $SdkVersion をダウンロード中..."
41+
try {
42+
Invoke-WebRequest -Uri $SdkUrl -OutFile $ZipPath -UseBasicParsing
43+
}
44+
catch {
45+
Write-Error "[ERROR] ダウンロードに失敗しました: $_"
46+
exit 1
47+
}
48+
49+
if (-not (Test-Path $ZipPath)) {
50+
Write-Error "[ERROR] ZIPファイルが見つかりません: $ZipPath"
51+
exit 1
52+
}
53+
54+
# 展開
55+
Write-Host "[INFO] $InstallPath に展開中..."
56+
try {
57+
Expand-Archive -Path $ZipPath -DestinationPath $InstallPath -Force
58+
}
59+
catch {
60+
Write-Error "[ERROR] 展開に失敗しました: $_"
61+
exit 1
62+
}
63+
64+
# ZIPファイルを削除
65+
Remove-Item -Force $ZipPath -ErrorAction SilentlyContinue
66+
67+
# 環境変数をセット
68+
Set-EnvVar
69+
70+
Write-Host ""
71+
Write-Host "[SUCCESS] Npcap SDK $SdkVersion のセットアップが完了しました。"
72+
Write-Host " インストール先 : $InstallPath"
73+
Write-Host " 環境変数 : $EnvVarName = $InstallPath"
74+
Write-Host ""
75+
Write-Host "※ 新しいターミナルを開くと環境変数が反映されます。"
76+
}
77+
78+
function Set-EnvVar {
79+
$currentValue = [System.Environment]::GetEnvironmentVariable($EnvVarName, "User")
80+
if ($currentValue -eq $InstallPath) {
81+
Write-Host "[INFO] 環境変数 $EnvVarName は既に設定済みです。"
82+
return
83+
}
84+
[System.Environment]::SetEnvironmentVariable($EnvVarName, $InstallPath, "User")
85+
# 現在のセッションにも反映
86+
$env:NPCAP_SDK_DIR = $InstallPath
87+
Write-Host "[INFO] ユーザー環境変数 $EnvVarName$InstallPath に設定しました。"
88+
}
89+
90+
Main

src-tauri/build.rs

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,95 @@
1+
/// Npcap SDK の環境変数名
2+
const NPCAP_SDK_ENV: &str = "NPCAP_SDK_DIR";
3+
4+
/// Windows 向けデフォルト検索パス候補(Lib/x64 サブディレクトリ付き)
5+
#[cfg(target_os = "windows")]
6+
const NPCAP_DEFAULT_SEARCH_PATHS: &[&str] = &[
7+
r"C:\npcap-sdk\Lib\x64",
8+
r"C:\Program Files\Npcap SDK\Lib\x64",
9+
];
10+
11+
/// Windows 環境で `USERPROFILE` 配下の候補パスを返す
12+
#[cfg(target_os = "windows")]
13+
fn userprofile_npcap_path() -> Option<std::path::PathBuf> {
14+
std::env::var("USERPROFILE").ok().map(|home| {
15+
std::path::PathBuf::from(home)
16+
.join(".npcap-sdk")
17+
.join("Lib")
18+
.join("x64")
19+
})
20+
}
21+
22+
/// Windows: Npcap SDK の `wpcap.lib` が含まれるディレクトリを検出し、
23+
/// `cargo:rustc-link-search=native=` で出力する。
24+
#[cfg(target_os = "windows")]
25+
fn configure_npcap_link_search() {
26+
// 環境変数が変更されたら再実行
27+
println!("cargo:rerun-if-env-changed={NPCAP_SDK_ENV}");
28+
29+
// 1. 環境変数 NPCAP_SDK_DIR が指定されている場合
30+
if let Ok(sdk_dir) = std::env::var(NPCAP_SDK_ENV) {
31+
let lib_path = std::path::PathBuf::from(&sdk_dir)
32+
.join("Lib")
33+
.join("x64");
34+
if lib_path.is_dir() {
35+
println!(
36+
"cargo:rustc-link-search=native={}",
37+
lib_path.display()
38+
);
39+
return;
40+
}
41+
panic!(
42+
"環境変数 {NPCAP_SDK_ENV} が設定されていますが、\
43+
'{path}' が見つかりません。\n\
44+
Npcap SDK を正しくインストールしてください。",
45+
path = lib_path.display()
46+
);
47+
}
48+
49+
// 2. デフォルトパス候補を順に探索
50+
for candidate in NPCAP_DEFAULT_SEARCH_PATHS {
51+
let path = std::path::Path::new(candidate);
52+
if path.is_dir() {
53+
println!("cargo:rustc-link-search=native={candidate}");
54+
return;
55+
}
56+
}
57+
58+
// 3. %USERPROFILE%\.npcap-sdk\Lib\x64
59+
if let Some(path) = userprofile_npcap_path() {
60+
if path.is_dir() {
61+
println!(
62+
"cargo:rustc-link-search=native={}",
63+
path.display()
64+
);
65+
return;
66+
}
67+
}
68+
69+
// 見つからなかった場合
70+
let mut msg = String::from(
71+
"Npcap SDK の Lib/x64 ディレクトリが見つかりませんでした。\n\
72+
以下のいずれかの方法で解決してください:\n\n\
73+
1. 環境変数 NPCAP_SDK_DIR に SDK ルートを設定する\n\
74+
2. 以下のいずれかのパスに Npcap SDK をインストールする:\n",
75+
);
76+
for candidate in NPCAP_DEFAULT_SEARCH_PATHS {
77+
msg.push_str(&format!(" - {candidate}\n"));
78+
}
79+
if let Some(path) = userprofile_npcap_path() {
80+
msg.push_str(&format!(" - {}\n", path.display()));
81+
}
82+
msg.push_str(
83+
"\nNpcap SDK は https://npcap.com/#download からダウンロードできます。",
84+
);
85+
panic!("{msg}");
86+
}
87+
88+
/// Linux / macOS では追加のリンク設定は不要
89+
#[cfg(not(target_os = "windows"))]
90+
fn configure_npcap_link_search() {}
91+
192
fn main() {
2-
tauri_build::build()
93+
configure_npcap_link_search();
94+
tauri_build::build();
395
}
23.2 KB
Binary file not shown.
14.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)