没啥技术含量,就不做介绍了,注释也懒得写了。
#Include <SendMessage.au3>
#include <ListviewConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
$g_szMyMp4Drive = GetMyMp4Drive()
$g_szMyMp4TargetFolder = "music\"
$g_szTargetFolder = $g_szMyMp4Drive & "\" & $g_szMyMp4TargetFolder
$g_szSourceFolder = "E:\我的文档\My Music\"
Dim $g_hGUI
Dim $g_hListView
Dim $g_arrFileList[1]
const $g_szAppName = "MP4Sync"
const $g_nAppVer = "1.0"
const $g_szFullAppName = $g_szAppName & " v" & $g_nAppVer
const $g_nListView = 500
$DEBUG = 0
Func GetMyMp4Drive($szDriveLabel = "V8000HDG")
$drives = DriveGetDrive( "all" )
If NOT @error Then
For $ii = 1 to $drives[0]
$label = DriveGetLabel( $drives[$ii] )
If $label == $szDriveLabel Then
return $drives[$ii]
EndIf
Next
EndIf
MsgBox(0, "Error", "MP4 not found!")
Exit
EndFunc
Func FindNotExistFile(const ByRef $szSourceFolder, const ByRef $szTargetFolder, ByRef $arrFileList)
$nFileCount = 0
$hSearch = FileFindFirstFile($szSourceFolder & "*.*")
; Check if the search was successful
If $hSearch = -1 Then
return $nFileCount
EndIf
If $DEBUG Then $str = ""
While 1
$file = FileFindNextFile($hSearch)
If @error Then ExitLoop
If $DEBUG Then $str &= "[" & $file & "]" & @TAB
$szSrcFile = $szSourceFolder & $file
$attrib = FileGetAttrib($szSrcFile)
If Not @error And StringInStr($attrib, "D") Then
$szSubSourceFolder = $szSourceFolder & $file & "\"
$szSubTargetFolder = $szTargetFolder & $file & "\"
$nFileCount += FindNotExistFile($szSubSourceFolder, $szSubTargetFolder, $arrFileList)
Else
$szDstFile = $szTargetFolder & $file
If IsMediaFile($file) And Not IsFilteredOut($szSrcFile) And Not FileExists($szDstFile) Then
$nFileCount += 1
If $nFileCount <= UBound($arrFileList) Then
$arrFileList[0] = $szSrcFile
Else
_ArrayAdd($arrFileList, $szSrcFile)
EndIf
$szMessage = "Synchronizing, " & $nFileCount & " file(s) in Total" & @CRLF & $szSrcFile
ControlSetText($g_szFullAppName, "", "Static1", $szMessage)
EndIf
EndIf
WEnd
If $DEBUG Then MsgBox(0, "Result", $str)
; Close the search handle
FileClose($hSearch)
return $nFileCount
EndFunc
Func IsMediaFile($file)
$bIsMedia = False
Dim $arMediaExt[2] = ["mp3", "wma"]
$nExtBegin = StringInStr($file, ".", 0, -1)
If $nExtBegin >= 1 Then
$file = StringTrimLeft($file, $nExtBegin)
For $ii = 0 To UBound($arMediaExt) - 1
If StringCompare ($arMediaExt[$ii], $file) = 0 Then
$bIsMedia = True
ExitLoop
EndIf
Next
EndIf
return $bIsMedia
EndFunc
Func IsFilteredOut($file)
If StringInStr($file, "_banzou") _
Or StringInStr($file, "funny") _
Or StringInStr($file, "搞笑") _
Or StringInStr($file, "伴奏") _
Then Return True
Return False
EndFunc
Func SyncFile(const $szSelectedIndices)
$Indices = StringSplit($szSelectedIndices, "|")
For $ii = 1 To $Indices[0]
$szFile = ControlListView($g_szFullAppName, "", "SysListView321", "GetText", $Indices[$ii], 0)
$szTargetFile = $g_szTargetFolder & StringRight($szFile, StringLen($szFile) - StringLen($g_szSourceFolder) )
$Ret = FileCopy ($szFile, $szTargetFile)
If Not $Ret Then MsgBox(0, "Error", "Failed to send file " & $szFile)
Next
MsgBox(0, $g_szFullAppName, "Done!")
EndFunc
Func UpdateListView()
GUICtrlSendMsg($g_hListView, $LVM_DELETEALLITEMS, 0, 0)
For $ii = 0 To UBound($g_arrFileList)-1
$item = GUICtrlCreateListViewItem($g_arrFileList[$ii], $g_hListView)
Next
GUICtrlSendMsg($g_hListView, $LVM_SETCOLUMNWIDTH, 0, $LVSCW_AUTOSIZE)
$nWidth = GUICtrlSendMsg($g_hListView, $LVM_GETCOLUMNWIDTH, 0, 0)
If $nWidth < $g_nListView Then GUICtrlSendMsg($g_hListView, $LVM_SETCOLUMNWIDTH, 0, $g_nListView - 20)
EndFunc
Func MainGUI()
Local $button, $msg
$g_hGUI = GUICreate($g_szFullAppName, 520, 400, 100, 200)
$g_hListView = GUICtrlCreateListView("File", 10, 10, $g_nListView, 350, $LVS_REPORT, $LVS_EX_GRIDLINES)
$button = GUICtrlCreateButton("&Send To MP4", 75, 370)
UpdateListView()
GUISetState()
ControlListView($g_szFullAppName, "", "SysListView321", "SelectAll")
Do
$msg = GUIGetMsg()
Select
Case $msg = $button
GUICtrlSetState($button, $GUI_DISABLE)
SyncFile( ControlListView($g_szFullAppName, "", "SysListView321", "GetSelected", 1) )
UpdateFileList()
UpdateListView()
ControlListView($g_szFullAppName, "", "SysListView321", "SelectAll")
GUICtrlSetState($button, $GUI_ENABLE)
EndSelect
Until $msg = $GUI_EVENT_CLOSE
Exit
EndFunc
Func UpdateFileList()
SplashTextOn($g_szFullAppName, "Synchronizing, 0 file in Total", 500, 100)
$g_nFileCount = FindNotExistFile($g_szSourceFolder, $g_szTargetFolder, $g_arrFileList)
SplashOff()
EndFunc
Func Main()
UpdateFileList()
MainGUI()
EndFunc
Main()