[Shell] 纯文本查看 复制代码
#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <QRCode.au3>
#include <Misc.au3>
#include <Array.au3>
; 只允许运行一个实例
_Singleton(@ScriptName)
; 定义临时文件夹路径
Global $tempDir = @TempDir & "\es"
DirCreate($tempDir)
; 嵌入文件到临时文件夹
FileInstall("chfs.exe", $tempDir & "\chfs.exe", 1)
FileInstall("qrcode.dll", $tempDir & "\qrcode.dll", 1)
; 全局变量
Global $currentIP = ""
Global $selectedIP = ""
Global $processID = 0
Global $isRunning = False
Global $authUsername = "admin" ; 默认用户名
Global $authPassword = "password" ; 默认密码
; 获取所有活动网络适配器的 IP 地址
Global $NICList = _GetAllActiveNICIPs()
; 创建主界面
Global $mainForm = GUICreate("内网共享", 350, 150, -1, -1, $WS_CAPTION + $WS_SYSMENU)
Global $sharePathInput = GUICtrlCreateInput("", 65, 10, 186, 21)
Global $browseButton = GUICtrlCreateButton("浏览", 256, 9, 57, 23)
Global $labelSharePath = GUICtrlCreateLabel("共享目录:", 8, 13, 55, 17)
Global $labelSelectIP = GUICtrlCreateLabel("选择IP地址:", 8, 40, 70, 17)
Global $ipComboBox = GUICtrlCreateCombo("", 85, 38, 150, 21, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
Global $startStopButton = GUICtrlCreateButton("开始共享", 116, 65, 89, 25)
Global $labelShareURL = GUICtrlCreateLabel("共享网址:", 8, 95, 55, 17)
Global $labelCurrentIP = GUICtrlCreateLabel("", 65, 95, 246, 17)
GUISetState(@SW_SHOW)
; 初始化 IP 下拉菜单
If IsArray($NICList) Then
For $i = 0 To UBound($NICList) - 1
GUICtrlSetData($ipComboBox, $NICList[$i])
Next
GUICtrlSetData($ipComboBox, $NICList[0]) ; 默认选中第一个 IP
EndIf
; 主消息循环
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
; 关闭时清理资源
If $processID <> 0 Then ProcessClose($processID)
DirRemove($tempDir, 1)
Exit
Case $browseButton
$selectedDir = FileSelectFolder("请选择共享文件夹", "")
If @Error = 0 Then GUICtrlSetData($sharePathInput, $selectedDir)
Case $startStopButton
If $isRunning Then
ProcessClose($processID)
GUICtrlSetData($startStopButton, "开始共享")
GUICtrlSetData($labelCurrentIP, "")
$isRunning = False
Else
$selectedFolderDir = GUICtrlRead($sharePathInput)
$selectedIP = GUICtrlRead($ipComboBox)
If $selectedFolderDir = "" Then
MsgBox(48, "错误", "请选择共享目录")
ElseIf $selectedIP = "" Then
MsgBox(48, "错误", "请选择一个有效的 IP 地址")
Else
GUICtrlSetData($labelCurrentIP, "http://" & $selectedIP & ":8080" & " [打开二维码]")
$processID = Run($tempDir & '\chfs.exe -port 8080 -path "' & $selectedFolderDir & '" -auth ' & $authUsername & ':' & $authPassword, $tempDir, @SW_HIDE)
GUICtrlSetData($startStopButton, "停止共享")
$isRunning = True
EndIf
EndIf
Case $labelCurrentIP
If $isRunning Then _CreateQRCode()
EndSwitch
WEnd
; 获取所有活动网络适配器的 IP 地址
Func _GetAllActiveNICIPs()
Local $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
If Not IsObj($objWMIService) Then Return SetError(1, 0, "")
Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
If Not IsObj($colItems) Then Return SetError(2, 0, "")
Local $ips = []
For $objItem In $colItems
If IsArray($objItem.IPAddress) Then
For $i = 0 To UBound($objItem.IPAddress) - 1
If StringInStr($objItem.IPAddress[$i], ".") Then
ReDim $ips[UBound($ips) + 1]
$ips[UBound($ips) - 1] = $objItem.IPAddress[$i]
EndIf
Next
EndIf
Next
Return $ips
EndFunc
; 创建二维码
Func _CreateQRCode()
_QRCode_StartUp()
Local $qrCodeData = _QRCode_GetQRCode("http://" & $selectedIP & ":8080", $_QRCode_ECL_LOW)
Local $width = 200, $height = 200
Local $hGui = GUICreate("扫描二维码", $width, $height, -1, -1, $WS_CAPTION + $WS_THICKFRAME + $WS_SYSMENU)
GUISetState(@SW_SHOW, $hGui)
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphics)
Local $hBitmapGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hBitmapGraphics, 0xFFFFFFFF)
_QRCode_DrawQRCode($hBitmapGraphics, $qrCodeData, 5, ($width - 126) / 2, ($height - 126) / 2)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $width, $height)
Sleep(5000) ; 自动关闭二维码窗口
GUIDelete($hGui)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)
_QRCode_Shutdown()
EndFunc