Skip to content

Latest commit

 

History

History
353 lines (265 loc) · 7.51 KB

File metadata and controls

353 lines (265 loc) · 7.51 KB

📦 Standalone .exe - ყველაფერი ერთ ფაილში

✅ რა შეიცვალა:

1. არანაირი გარე ფაილები არ არის საჭირო!

  • ❌ აღარ არის საჭირო scan_wia.ps1
  • ❌ აღარ არის საჭირო .bat ფაილები
  • ❌ აღარ არის საჭირო .vbs ფაილები
  • მხოლოდ scanner_helper.exe!

2. PowerShell Script Embedded

  • PowerShell კოდი ჩაშენებულია .exe-ში
  • Runtime-ზე ყველაფერი memory-დან მუშაობს

3. JSON Escape Fixed

  • გამოსწორდა "Bad escaped character in JSON" შეცდომა
  • იყენებს serde_json proper escaping-ისთვის

4. Startup Registration Removed

  • მოიხსნა ავტომატური Registry რეგისტრაცია
  • თქვენ თავად გადაწყვეტთ როდის დაარეგისტრიროთ

🚀 გამოყენება:

Build:

cargo build --release

გაშვება:

target\release\scanner_helper.exe

ეს ყველაფერი!

  • ✅ Console დამალული
  • ✅ Service გაშვებული
  • ✅ Scanner მზად არის

📁 რა ფაილები არის საჭირო:

scanner_helper.exe  ← მხოლოდ ეს!

არაფერი სხვა!


🔧 როგორ მუშაობს:

Embedded PowerShell Script:

const POWERSHELL_SCRIPT: &str = r#"
    // Full WIA scanning script embedded in .exe
    $deviceManager = New-Object -ComObject WIA.DeviceManager
    $device = $deviceManager.DeviceInfos.Item(1).Connect()
    $image = $scanItem.Transfer(...)
    $image.SaveFile($OutputPath)
"#;

// Execute from memory:
Command::new("powershell.exe")
    .args(&["-Command", POWERSHELL_SCRIPT])
    .output()

არ საჭიროებს გარე .ps1 ფაილს!


✅ JSON Error Fixed:

Before (❌):

// Manual escaping - არასწორი!
e.replace('"', "\\\"")  // Double escaping problem

After (✅):

// serde_json - სწორად escape-ს უკეთებს
use serde_json::json;
let error_json = json!({
    "success": false,
    "error": e  // Automatically escaped!
});

ახლა არ გამოვა "Bad escaped character" შეცდომა!


🎯 Deploy:

Single File Deploy:

REM 1. Build
cargo build --release

REM 2. Copy anywhere
copy target\release\scanner_helper.exe C:\MyApp\

REM 3. Run
C:\MyApp\scanner_helper.exe

REM That's it! ✅

🔍 რა ხდება Runtime-ზე:

scanner_helper.exe starts
    ↓
1. Hide console window
    ↓
2. Load embedded PowerShell script (from .exe)
    ↓
3. Start HTTP server (port 8765)
    ↓
4. Wait for scan requests
    ↓
User clicks "Scan Document"
    ↓
5. Execute PowerShell from memory
    ↓
6. PowerShell calls WIA API
    ↓
7. Scanner scans document
    ↓
8. Save to temp file
    ↓
9. Read and return to browser
    ↓
10. JSON properly escaped
    ↓
Browser displays scan ✅

📊 შედარება:

Before After
Files needed .exe + .ps1 + .bat/.vbs .exe only
Deployment Copy multiple files Copy 1 file
JSON errors ❌ Sometimes ✅ Never
Registry Auto-register Manual (optional)
Maintenance Update multiple files Update 1 file

🛠️ Optional: Manual Startup:

თუ გინდა Windows startup-ში დამატება:

Option 1: Task Scheduler

REM Create scheduled task
schtasks /create /tn "Scanner Helper" ^
  /tr "C:\path\to\scanner_helper.exe" ^
  /sc onlogon /rl highest

Option 2: Registry (manual)

REM Add to startup
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" ^
  /v "ScannerHelper" /t REG_SZ ^
  /d "C:\path\to\scanner_helper.exe" /f

Option 3: Startup Folder

REM Create shortcut in Startup folder
mklink "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\scanner_helper.lnk" ^
  "C:\path\to\scanner_helper.exe"

🐛 Troubleshooting:

"Bad escaped character in JSON"

გამოსწორდა!

ახალი კოდი იყენებს serde_json::json! რომელიც სწორად escape-ს უკეთებს backslash-ებს და quote-ებს.

"PowerShell script not found"

აღარ მოხდება!

PowerShell script embedded არის .exe-ში, არ საჭიროებს გარე ფაილს.

Console არ იმალება

REM Rebuild:
cargo clean
cargo build --release

📝 Code Changes:

1. Embedded Script:

const POWERSHELL_SCRIPT: &str = r#"
    // 70 lines of PowerShell WIA code
    // Embedded directly in binary
"#;

2. Execute from Memory:

Command::new("powershell.exe")
    .args(&["-Command", POWERSHELL_SCRIPT])  // No -File needed!
    .output()

3. JSON Escaping:

use serde_json::json;
let error_json = json!({
    "success": false,
    "error": error_message
});

4. No Registry:

// Removed:
// register_autostart()?;

🎉 შედეგი:

Deployment:

Before:
  windowsRust/
  ├── scanner_helper.exe
  ├── scan_wia.ps1          ← საჭირო იყო!
  ├── install_startup.bat   ← საჭირო იყო!
  └── start_hidden.vbs      ← საჭირო იყო!

After:
  scanner_helper.exe        ← მხოლოდ ეს!

Production:

Copy scanner_helper.exe → Done!

Errors:

JSON escaping: ✅ Fixed
File not found: ✅ Fixed

💡 რჩევები:

1. Portable:

REM Copy to USB
copy scanner_helper.exe E:\

REM Run from USB
E:\scanner_helper.exe

2. Multiple Locations:

REM Works from anywhere
C:\Apps\scanner_helper.exe
D:\Tools\scanner_helper.exe
E:\Portable\scanner_helper.exe

3. No Installation:

REM No install needed
REM Just copy and run!

🔐 უსაფრთხოება:

Embedded Code:

  • ✅ PowerShell კოდი readonly
  • ✅ არ იწერება დისკზე
  • ✅ Memory-დან ეშვება

No External Files:

  • ✅ არ შეიძლება .ps1-ის ჩანაცვლება
  • ✅ არ შეიძლება malicious script injection
  • ✅ .exe integrity protected

📦 Binary Size:

scanner_helper.exe: ~500 KB

Includes:
- Rust HTTP server (Tokio/Hyper)
- PowerShell script (embedded)
- WIA integration code
- JSON serialization
- Base64 encoding
- All dependencies

ყველაფერი ერთ ფაილში!


✅ Checklist:

  • PowerShell script embedded
  • JSON escaping fixed
  • No external files needed
  • Console auto-hide
  • Single .exe deploy
  • No Registry auto-register
  • Portable
  • Production ready

✅ scanner_helper.exe - Standalone, Self-Contained, Ready to Deploy!

📦 ერთი ფაილი - ყველაფერი რაც გჭირდება!

🚀 Copy → Run → Done!