#region ;**** 参数创建于 ACNWrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
Global $KeyFileName, $KeyS, $Array_KeyS[1]
Local $iLabel = ""
$Form1 = GUICreate("MS_Key提取整理去重复工具", 874, 451)
$Label1 = GUICtrlCreateLabel("MS Key 提取整理去重复小工具", 217, 16, 438, 42, $SS_CENTER)
GUICtrlSetFont(-1, 22, 400, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x0000FF)
$Label2 = GUICtrlCreateLabel($iLabel, 824, 48, 36, 17, $SS_RIGHT)
$Label3 = GUICtrlCreateLabel("", 166, 56, 540, 3, BitOR($SS_GRAYRECT, $WS_TABSTOP))
GUICtrlSetBkColor(-1, 0x808080)
$Group1 = GUICtrlCreateGroup(" 输入 ", 8, 72, 361, 369)
$Input1 = GUICtrlCreateInput("", 24, 104, 273, 21)
$Edit1 = GUICtrlCreateEdit("", 24, 144, 273, 281)
GUICtrlSetFont(-1, 9, 400, 0, "Courier New")
$Button1 = GUICtrlCreateButton("浏览", 312, 104, 41, 25)
$Button2 = GUICtrlCreateButton("从剪贴板", 304, 200, 57, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup(" 输出 ", 504, 72, 361, 369)
$Input2 = GUICtrlCreateInput("", 520, 104, 273, 21)
$Edit2 = GUICtrlCreateEdit("", 520, 144, 273, 281)
GUICtrlSetFont(-1, 9, 400, 0, "Courier New")
$Button3 = GUICtrlCreateButton("浏览", 808, 104, 41, 25)
$Button4 = GUICtrlCreateButton("到剪贴板", 800, 200, 57, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button5 = GUICtrlCreateButton("开始", 392, 208, 89, 57)
$Button6 = GUICtrlCreateButton("退出", 392, 308, 89, 41)
$Button7 = GUICtrlCreateButton("关于", 392, 408, 89, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Local $InFile, $OutFile
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
_InputFile()
Case $Button2
_GetFrClip()
;Case $Button3
; _OutputFile()
;Case $Button4
; _PutTo()
Case $Button5
_GOGOGO()
Case $Button6
Exit
Case $Button7
_ABOUT()
EndSwitch
WEnd
Func _InputFile()
$InFile = FileOpenDialog("选择欲导入的保存有Key的文件", @ScriptDir, "(*.txt)", 3)
If @error Then
MsgBox(16, "", "没有选择文件或者无效文件类型!")
Else
Local $File = FileOpen($InFile)
If $File = -1 Then
MsgBox(4096, "错误", "不能打开文件.")
Else
Local $chars = FileRead($File, -1)
;MsgBox(4096, "读取的字符:", $chars)
GUICtrlSetData($Input1, $InFile)
GUICtrlSetData($Edit1, $chars)
EndIf
EndIf
FileClose($InFile)
EndFunc ;==>_InputFile
Func _GetFrClip()
Local $Clip = ClipGet()
If @error Then
MsgBox(16, "", "剪切板为空或为非文本")
Else
GUICtrlSetData($Input1, "")
GUICtrlSetData($Edit1, $Clip)
EndIf
EndFunc ;==>_GetFrClip
Func _GOGOGO()
Local $Data1 = GUICtrlRead($Edit1)
;MsgBox(0,"",$Data)
$KeyFileName = @TempDir & "\MS_Key_tmp.txt"
_FileCreate($KeyFileName)
FileOpen($KeyFileName)
FileWrite($KeyFileName, $Data1)
FileClose($KeyFileName)
$KeyS = _GetKey($KeyFileName)
;MsgBox(0,"找到的Key数量(可能有重复的):",$KeyS)
;_ArrayDisplay($Array_KeyS)
Local $aNewArray = _ArrayUnique($Array_KeyS)
;_ArrayDisplay($aNewArray)
Local $Data2 = _ArrayToString($aNewArray, @CRLF, 1)
;MsgBox(0,"xxxxxx",$Data)
GUICtrlSetData($Edit2, $Data2)
FileDelete($KeyFileName)
EndFunc ;==>_GOGOGO
Func _ABOUT()
MsgBox(0x00000040, "自编自用程序", _
"MS Key 提取整理去重复小工具" & @CRLF & @CRLF & _
"说明------------------------------------" & @CRLF & _
"说明------------------------------------")
EndFunc ;==>_ABOUT
Func _GetKey($KeyFileName)
FileOpen($KeyFileName)
$KeyS = 0
Local $line = 1, $KeyH = 1, $Key
While 1
$Key = FileReadLine($KeyFileName, $line)
If @error = -1 Then ExitLoop
$line += 1
$KeyH = StringReplace($Key, " ", "")
$Key = StringRegExp($KeyH, "([A-Za-z0-9]{5}-){4}[A-Za-z0-9]{5}", 0)
If $Key = 1 Then $KeyS += 1
WEnd
;MsgBox(0, "", "个数:" & $KeyS)
If $KeyS <> 0 Then
ReDim $Array_KeyS[$KeyS]
$line = 1
$KeyS = 0
While 1
$Key = FileReadLine($KeyFileName, $line)
If @error = -1 Then ExitLoop
$line += 1
$KeyH = StringReplace($Key, " ", "")
$Key = StringRegExp($KeyH, "([A-Za-z0-9]{5}-){4}[A-Za-z0-9]{5}", 2)
If Not @error Then
$K = $Key[0]
$Array_KeyS[$KeyS] = $K
;_ArrayDisplay($Array_KeyS)
$KeyS += 1
EndIf
WEnd
EndIf
FileClose($KeyFileName)
Return $KeyS
EndFunc ;==>_GetKey