Scan Logic
This document describes the scanning logic implemented in the Xdows Security Scan Page (targeting developers).
Feature Overview
Offers four virus-scanning modes: Quick, Full, File, and Folder, with support for multi-engine parallel scanning and asynchronous streaming UI updates.
| Input | Output |
|---|---|
| Scan Mode + User Path + Engine Toggles | Real-time progress, threat list, statistics, log entries |
Sequence Overview
Engine Priority
ts
async function scanFile(path: string): Promise<string | null> {
if (useSouXiao) return await souXiaoScan(path);
if (useLocal) return await localScan(path, deep, extra);
if (useJiSuSafeAXMode) return await AXScan(path);
if (useCloud) return await cloudScan(path);
if (useCzkCloud) return await czkCloudScan(path, apiKey);
return null; // safe
}Enumeration Strategy
| Mode | Scope | Key Implementation |
|---|---|---|
| Quick | Critical system folders + executable extensions | EnumerateQuickScanFiles() |
| Full | All local drives | SafeEnumerateFiles() skips inaccessible nodes |
| File | Single file | PickSingleFileAsync() |
| Folder | Recursive directory | SafeEnumerateFolder() uses stack + try-catch |
State Machine
| State | Trigger | UI Indication |
|---|---|---|
Idle | Initial / Scan finished | Buttons enabled, radar stopped |
Running | StartScanAsync | Buttons disabled, radar spinning |
Paused | OnPauseScanClick | Radar paused, resume button shown |
Canceled | token.Cancel() | Status shows "Scan canceled" |
Exception & Cancellation
csharp
catch (OperationCanceledException)
{
StatusText.Text = "Scan canceled";
}
catch (Exception ex)
{
LogText.AddNewLog(4, "Security - Failed", ex.Message);
}Note
Exceptions affect only the current file; the queue continues.
Performance & Threading
| Item | Strategy |
|---|---|
| Concurrency | One Task.Run(...) per file, loop delays 1 ms |
| UI Refresh | DispatcherQueue.TryEnqueue ensures thread safety |
| I/O Blocking | SafeEnumerate* patterns pre-catch permission issues |
Log Format
| Level | Module | Event | Details |
|---|---|---|---|
| 1 | Security - StartScan | Use LocalScan-DeepScan CloudScan | |
| 1 | Security - ScanFile | C:\Windows\notepad.exe | |
| 1 | Security - Find | MEMZUAC.Cloud.VirusFile |
FAQ
How to add a new scan engine?
- Register a toggle in settings.
- Read the toggle inside
StartScanAsync. - Append
if (useNewEngine) result = await NewScanAsync(path);in the engine chain. - Update the "Engine Priority" section of this doc.
Why does the UI stay responsive during large scans?
All heavy work runs on the ThreadPool; UI updates are marshaled via DispatcherQueue.
Need incremental scanning?
Cache LastScanTime and compare with LastWriteTime during enumeration to skip unchanged files.