Skip to content

Commit 24252df

Browse files
committed
Update stdShell.cls
CopyAsync work
1 parent 58bf87f commit 24252df

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

src/WIP/stdShell.cls

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ Attribute VB_PredeclaredId = True
99
Attribute VB_Exposed = False
1010

1111
'Issues:
12-
' WIN32 MIGRATION
13-
' - [x] On windows, migrate to Win32 API rather than native calls.
14-
' - [x] File hashing uses Win32 CryptoAPI for significantly better performance than .NET COM classes.
15-
' - [ ] ReadText uses ANSI encoding, no UTF-8/UTF-16 handling.
1612
'FILE ENUMERATION
1713
' - [ ] No binary read/write methods; no large-file chunking helpers.
1814
'GENERAL
@@ -2023,6 +2019,64 @@ EH:
20232019
Delete = False
20242020
End Function
20252021

2022+
'Starts a non-blocking copy operation and returns immediately
2023+
'@param path - Path to copy the file/folder to
2024+
'@returns - Boolean indicating if the copy was started successfully
2025+
'@remark This function returns immediately after starting the copy. The OS handles the copy operation in the background.
2026+
'@example ```vb
2027+
'Call stdShell.Create("C:\my\files\song.mp3").CopyToAsync("C:\my\files\song2.mp3")
2028+
''... do other work while copy happens in background ...
2029+
'```
2030+
Public Function CopyToAsync(ByVal path As String) As Boolean
2031+
On Error GoTo EH
2032+
If Not Exists Then
2033+
CopyToAsync = False
2034+
Exit Function
2035+
End If
2036+
2037+
'Use shell command to copy - this is truly non-blocking
2038+
#If Mac Then
2039+
CopyToAsync = false
2040+
#Else
2041+
'On Windows, use xcopy or robocopy for truly async copy
2042+
Dim cmd As String
2043+
If This.kind = EShellFileTypeFolder Then
2044+
cmd = "xcopy /E /I /Y """ & This.path & """ """ & path & """"
2045+
Else
2046+
cmd = "copy /Y """ & This.path & """ """ & path & """"
2047+
End If
2048+
Call Shell(Environ("COMSPEC") & "/c " & cmd, vbHidden)
2049+
CopyToAsync = True
2050+
#End If
2051+
Exit Function
2052+
EH:
2053+
CopyToAsync = False
2054+
End Function
2055+
2056+
'Checks if the copy operation is complete
2057+
'@param path - Path to check if the copy operation is complete
2058+
'@returns - True if the copy operation is complete, false otherwise
2059+
'@example ```vb
2060+
'Dim file as stdShell: set file = stdShell.Create("C:\my\files\song.mp3")
2061+
'Dim copyTo as string: copyTo = "C:\my\files\song2.mp3"
2062+
'Call file.CopyToAsync(copyTo)
2063+
'While not file.CopyToAsyncHasCompleted(copyTo)
2064+
' DoEvents
2065+
'Wend
2066+
'```
2067+
Public Function CopyToAsyncHasCompleted(ByVal path as String) As Boolean
2068+
On Error GoTo EH
2069+
CopyToAsyncHasCompleted = false
2070+
static cacheSize as Long: if cacheSize = 0 then cacheSize = size
2071+
static cacheHash as string: if cacheHash = "" then cacheHash = hash
2072+
Dim dest as stdShell: set dest = stdShell.Create(path)
2073+
if not dest.exists then Exit Function
2074+
if dest.size <> cacheSize then Exit Function
2075+
if dest.hash <> cacheHash then Exit Function
2076+
CopyToAsyncHasCompleted = true
2077+
EH:
2078+
End Function
2079+
20262080
'Copies the file/folder to a new path
20272081
'@param path - Path to copy the file/folder to
20282082
'@returns - Success flag

0 commit comments

Comments
 (0)