Skip to content
Permalink
Browse files

#4 0813 有點混亂,但這樣應該是可以吧

  • Loading branch information...
pulipulichen committed Aug 13, 2019
1 parent 2d8d2dc commit d122bbf1969e31af7810d35a5215db6d4cf496fe
Showing with 187 additions and 185 deletions.
  1. BIN archive-util-zip.exe
  2. +121 −118 libs/add-archive.au3
  3. +5 −5 libs/archive-method-entry.au3
  4. +1 −1 libs/file-helper.au3
  5. +2 −2 libs/lock-helper.au3
  6. +58 −59 libs/unarchive.au3
BIN +0 Bytes (100%) archive-util-zip.exe
Binary file not shown.
@@ -1,119 +1,122 @@
Func addArchive($archiveFormat)

; ----------------------------------

Local $path7z = @ScriptDir & '\7-zip\7z.exe'

;MsgBox($MB_SYSTEMMODAL, "", $fileList)

MsgBox($MB_SYSTEMMODAL, "", $path7z)

; ----------------------------------

If $CmdLine[0] > 0 Then
FileChangeDir(GetDir($CmdLine[1]))
EndIf
Local $workingDir = @WorkingDir

; ----------------------------------

Local $archiveFilename

; 如果檔案只有一個,那就以該檔案為名字
; 如果檔案有很多個,那就取上層目錄為檔案名字
If $CmdLine[0] = 0 Then
;MsgBox($MB_SYSTEMMODAL, "", "no file")
Exit
ElseIf $CmdLine[0] = 1 Then
;Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""
;Local $aPathSplit = _PathSplit($CmdLine[1], $sDrive, $sDir, $sFileName, $sExtension)
;MsgBox($MB_SYSTEMMODAL, "", $sFileName)
If StringInStr(FileGetAttrib($CmdLine[1]), "D") Then
$archiveFilename = GetFileNameNoExt($CmdLine[1])
Else
$archiveFilename = GetFileName($CmdLine[1])
EndIf
Else
;MsgBox($MB_SYSTEMMODAL, "", "many files")
;Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""
;Local $aPathSplit = _PathSplit($CmdLine[1], $sDrive, $sDir, $sFileName, $sExtension)
;$sDir = StringTrimRight($sDir, 1)
;MsgBox($MB_SYSTEMMODAL, "", $sDir)
$archiveFilename = GetDir($CmdLine[1])
EndIf

; ------------------------------------

;MsgBox($MB_SYSTEMMODAL, "", $workingDir)

If $CmdLine[0] = 1 And StringInStr(FileGetAttrib($CmdLine[1]), "D") Then
uniqueDir(GetFileName($CmdLine[1]))
EndIf

; ----------------------------------
; 建立列表

;MsgBox($MB_SYSTEMMODAL, "", StringInStr(FileGetAttrib($CmdLine[1]), "D"))

Local $fileList = ""
If $CmdLine[0] = 1 And StringInStr(FileGetAttrib($CmdLine[1]), "D") Then
Local $trimLength = StringLen($CmdLine[1]) + 1
$archiveFilename = '../' & $archiveFilename

Local $subFileList = _FileListToArray($CmdLine[1])
FileChangeDir($CmdLine[1])
;MsgBox($MB_SYSTEMMODAL, "", $CmdLine[1])
;MsgBox($MB_SYSTEMMODAL, "", @WorkingDir)
If $subFileList[0] = 0 Then
MsgBox($MB_SYSTEMMODAL, @WorkingDir, "$subFileList[0] = 0")
unlock()
Exit
EndIf

For $i = 1 To $subFileList[0]
;MsgBox($MB_SYSTEMMODAL, "", $CmdLine[1])
MsgBox($MB_SYSTEMMODAL, "", $subFileList[$i])

If FileExists($subFileList[$i]) Then
Local $f = $subFileList[$i]
$fileList = $fileList & ' "' & $f & '"'
EndIf
Next

MsgBox($MB_SYSTEMMODAL, "fileList", $fileList)
Else
MsgBox($MB_SYSTEMMODAL, "not dir", @WorkingDir)
For $i = 1 To $CmdLine[0]
;MsgBox($MB_SYSTEMMODAL, FileExists(GetFileName($CmdLine[$i])), GetFileName($CmdLine[$i]))
If FileExists(GetFileName($CmdLine[$i])) Then
$fileList = $fileList & ' "' & GetFileName($CmdLine[$i]) & '"'
EndIf
Next

EndIf

; ------------------------------------

Local $cmd = '"' & $path7z & '" a -t' & $archiveFormat & ' -mx=9 "' & $archiveFilename & '.' & $archiveFormat & '"' & $fileList

MsgBox($MB_SYSTEMMODAL, @WorkingDir, $cmd)
;MsgBox($MB_SYSTEMMODAL, "", $CmdLine[1])
;Exit

;Sleep(10000)

If StringLen($fileList) > 0 Then
RunWait($cmd, '', @SW_MINIMIZE)
EndIf

; ------------------------------------

FileChangeDir($workingDir)
For $i = 1 To $CmdLine[0]
Local $file = GetFileName($CmdLine[$i])
FileRecycle($file)
Next

unlock()

Func addArchive($archiveFormat)

; ----------------------------------

Local $path7z = @ScriptDir & '\7-zip\7z.exe'

;MsgBox($MB_SYSTEMMODAL, "", $fileList)

;MsgBox($MB_SYSTEMMODAL, "", $path7z)

; ----------------------------------

If $CmdLine[0] = 1 And isDir($CmdLine[1]) Then
; 這裡也要清理
FileChangeDir(GetDir($CmdLine[1]))
ElseIf $CmdLine[0] > 0 Then
FileChangeDir(GetDir($CmdLine[1]))
EndIf
Local $workingDir = @WorkingDir

; ----------------------------------

Local $archiveFilename

; 如果檔案只有一個,那就以該檔案為名字
; 如果檔案有很多個,那就取上層目錄為檔案名字
If $CmdLine[0] = 0 Then
;MsgBox($MB_SYSTEMMODAL, "", "no file")
Exit
ElseIf $CmdLine[0] = 1 Then
;Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""
;Local $aPathSplit = _PathSplit($CmdLine[1], $sDrive, $sDir, $sFileName, $sExtension)
;MsgBox($MB_SYSTEMMODAL, "", $sFileName)
If StringInStr(FileGetAttrib($CmdLine[1]), "D") Then
$archiveFilename = GetFileNameNoExt($CmdLine[1])
Else
$archiveFilename = GetFileName($CmdLine[1])
EndIf
Else
;MsgBox($MB_SYSTEMMODAL, "", "many files")
;Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""
;Local $aPathSplit = _PathSplit($CmdLine[1], $sDrive, $sDir, $sFileName, $sExtension)
;$sDir = StringTrimRight($sDir, 1)
;MsgBox($MB_SYSTEMMODAL, "", $sDir)
$archiveFilename = GetDir($CmdLine[1])
EndIf

; ------------------------------------

;MsgBox($MB_SYSTEMMODAL, "", $workingDir)

If $CmdLine[0] = 1 And StringInStr(FileGetAttrib($CmdLine[1]), "D") Then
uniqueDir(GetFileName($CmdLine[1]))
EndIf

; ----------------------------------
; 建立列表

;MsgBox($MB_SYSTEMMODAL, "", StringInStr(FileGetAttrib($CmdLine[1]), "D"))

Local $fileList = ""
If $CmdLine[0] = 1 And StringInStr(FileGetAttrib($CmdLine[1]), "D") Then
Local $trimLength = StringLen($CmdLine[1]) + 1
$archiveFilename = '../' & $archiveFilename

Local $subFileList = _FileListToArray($CmdLine[1])
FileChangeDir($CmdLine[1])
;MsgBox($MB_SYSTEMMODAL, "", $CmdLine[1])
;MsgBox($MB_SYSTEMMODAL, "", @WorkingDir)
If $subFileList[0] = 0 Then
MsgBox($MB_SYSTEMMODAL, @WorkingDir, "$subFileList[0] = 0")
unlock()
Exit
EndIf

For $i = 1 To $subFileList[0]
;MsgBox($MB_SYSTEMMODAL, "", $CmdLine[1])
MsgBox($MB_SYSTEMMODAL, "", $subFileList[$i])

If FileExists($subFileList[$i]) Then
Local $f = $subFileList[$i]
$fileList = $fileList & ' "' & $f & '"'
EndIf
Next

;MsgBox($MB_SYSTEMMODAL, "fileList", $fileList)
Else
;MsgBox($MB_SYSTEMMODAL, "not dir", @WorkingDir)
For $i = 1 To $CmdLine[0]
;MsgBox($MB_SYSTEMMODAL, FileExists(GetFileName($CmdLine[$i])), GetFileName($CmdLine[$i]))
If FileExists(GetFileName($CmdLine[$i])) Then
$fileList = $fileList & ' "' & GetFileName($CmdLine[$i]) & '"'
EndIf
Next

EndIf

; ------------------------------------

Local $cmd = '"' & $path7z & '" a -t' & $archiveFormat & ' -mx=9 "' & $archiveFilename & '.' & $archiveFormat & '"' & $fileList

;MsgBox($MB_SYSTEMMODAL, @WorkingDir, $cmd)
;MsgBox($MB_SYSTEMMODAL, "", $CmdLine[1])
;Exit

;Sleep(10000)

If StringLen($fileList) > 0 Then
RunWait($cmd, '', @SW_MINIMIZE)
EndIf

; ------------------------------------

FileChangeDir($workingDir)
For $i = 1 To $CmdLine[0]
Local $file = GetFileName($CmdLine[$i])
FileRecycle($file)
Next

unlock()

EndFunc
@@ -32,13 +32,13 @@ Func archiveMethodEntry($archiveFormat)

If $CmdLine[0] = 1 Then
If (StringRight($CmdLine[1], 4) = '.zip' Or StringRight($CmdLine[1], 3) = '.7z') Then
unarchive()
unarchiveUnique()
unarchive(True)
unlock()
Return
ElseIf StringRight($CmdLine[1], 4) = '.rar' Then
unarchive()
;Exit
ElseIf StringRight($CmdLine[1], 4) = '.rar' Then
unarchive(False)
; 這裡就要清理完
Exit
$CmdLine[1] = StringMid($CmdLine[1], 1, StringLen($CmdLine[1]) - 4)
;MsgBox($MB_SYSTEMMODAL, @WorkingDir, $CmdLine[1])
;Exit
@@ -40,5 +40,5 @@ Func StripExt($FileName)
EndFunc

Func isDir($path)
Return StringInStr(FileGetAttrib($sFilePath), "D") = True
Return StringInStr(FileGetAttrib($path), "D") = True
EndFunc
@@ -2,15 +2,15 @@ Func lock()
Local $lockFile = @ScriptDir & '\lock.tmp'
If FileExists($lockFile) Then
Sleep(3000)
Return addArchive($archiveFormat)
Return archiveMethodEntry($archiveFormat)
EndIf

Local $content = ""
If $CmdLine[0] > 0 Then
$content = $CmdLine[1]
EndIf

FileWrite($lockFile, "Archive is going now. Please wait." & @CRLF & $content)
;FileWrite($lockFile, "Archive is going now. Please wait." & @CRLF & $content)
EndFunc

Func unlock()

0 comments on commit d122bbf

Please sign in to comment.
You can’t perform that action at this time.