1+ property onData : Object
2+ property _Path; _workerpath : Text
3+ property _timeout : Integer
4+
15Class constructor ()
6+ var $path : Text
7+
28 This:C1470 .onData := New object:C1471 ("text" ; "" )
39 If (Is macOS:C1572)
410 This:C1470 ._return := Char:C90 (10 )
@@ -16,8 +22,13 @@ Class constructor()
1622 // uses https://github.com/prasmussen/gdrive
1723
1824 // MARK: FileTransfer
19- Function getDirectoryListing ($targetpath : Text; $ID : Text; $max : Integer)- > $success : Object
2025 // $ID prefered option, if missing trying to find via path
26+ Function getDirectoryListing ($targetpath : Text; $ID : Text; $max : Integer)- > $success : Object
27+ var $url ; $folder : Text
28+ var $pos : Integer
29+ var $answer : Object
30+ var $sublist : Collection
31+
2132 If ($max= 0)
2233 $max := 1000
2334 End if
@@ -82,11 +93,16 @@ Function upload($sourcepath : Text; $targetpath : Text)->$success : Object
8293 // ASSERT($targetpath#""; "target path must not be empty")
8394 $success := This:C1470 ._uploadSub ($sourcepath ; $targetpath )
8495
85- Function _uploadSub ($sourcepath : Text; $targetpath : Text; $mime : Text)- > $success : Object
8696 // need to find target file name (for --name parameter) and target folder (to find --parent ID)
97+ Function _uploadSub ($sourcepath : Text; $targetpath : Text; $mime : Text)- > $success : Object
98+ var $name ; $targetID ; $foldername ; $foldername2 ; $parentfoldername ; $url : Text
99+ var $pos ; $oldtimeout : Integer
100+ var $answer : Object
101+ var $sublist : Collection
102+
87103 $name := ""
88104 $targetID := ""
89- If ($targetpath# "" )
105+ If (Length :C16 ( $targetpath ) > 0 )
90106 If ($targetpath= "@/ ") // folder name
91107 $name := ""
92108 $foldername := Substring:C12 ($targetpath ; 1 ; Length:C16 ($targetpath )- 1 )
@@ -142,27 +158,31 @@ Function _uploadSub($sourcepath : Text; $targetpath : Text; $mime : Text)->$succ
142158 $success := This:C1470 ._runWorker ($url )
143159 This:C1470 ._timeout := $oldtimeout
144160
145- Function download ($sourcepath : Text; $targetpath : Text; $sourceID : Text; $sourceQuery : Text)- > $success : Object
146161 // $sourcepath just file name for local directory, else full path in POSIX syntax
147162 // targetpath is full remote path (starting with /, ending with file name) or just target folder, ending with /
148163 // Gdrive only (then pass "" for sourcepath:
149164 // sourceID = GDrive ID.
150165 // SourceQuery = query command, such as name = 'test' and modifiedTime > '2012-06-04T12:00:00' and (mimeType contains 'image/' or mimeType contains 'video/')
151166 // if the query returns two files with same name, the files will overwrite themself
152167 // always overwrite in targetpath file with given name, both original name and (if passed) renamed name
153- ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
154- $success := This:C1470 ._downloadSub ($sourcepath ; $targetpath ; $sourceID ; $sourceQuery )
168+ Function download ($sourcepath : Text; $targetpath : Text; $sourceID : Text; $sourceQuery : Text) : Object
169+ ASSERT:C1129 (Length:C16 ($targetpath )> 0 ; "target path must not be empty" )
170+ return This:C1470 ._downloadSub ($sourcepath ; $targetpath ; $sourceID ; $sourceQuery )
155171
156- Function export ($sourcepath : Text; $targetpath : Text; $sourceID : Text; $mime : Text)- > $success : Object
172+ Function export ($sourcepath : Text; $targetpath : Text; $sourceID : Text; $mime : Text) : Object
157173 // similar to download, just with forced MIME conversion
158- ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
174+ ASSERT:C1129 (Length :C16 ( $targetpath ) > 0 ; "target path must not be empty" )
159175 ASSERT:C1129 ($targetpath # "@/" ; "target path must be path to folder, not file" )
160176
161- ASSERT:C1129 ($mime # "" ; "mime must not be empty" )
177+ ASSERT:C1129 (Length :C16 ( $mime ) > 0 ; "mime must not be empty" )
162178 // no sourcequery for export
163- $success := This:C1470 ._downloadSub ($sourcepath ; $targetpath ; $sourceID ; "" ; $mime )
179+ return This:C1470 ._downloadSub ($sourcepath ; $targetpath ; $sourceID ; "" ; $mime )
164180
165181Function _downloadSub ($sourcepath : Text; $targetpath : Text; $sourceID : Text; $sourceQuery : Text; $mime : Text)- > $success : Object
182+ var $target ; $url ; $source ; $text ; $currentname ; $newname : Text
183+ var $pos ; $oldtimeout : Integer
184+ var $answer : Object
185+ var $sublist : Collection
166186
167187 $target := $targetpath
168188 If ($targetpath# "@/ ")
@@ -253,46 +273,52 @@ Function _downloadSub($sourcepath : Text; $targetpath : Text; $sourceID : Text;
253273 End if
254274
255275 // export / import similar to upload/download, but with document conversion. These commands are GDrive specific
256- Function import ($sourcepath : Text; $targetpath : Text; $mime : Text)- > $success : Object
276+ Function import ($sourcepath : Text; $targetpath : Text; $mime : Text) : Object
257277 // $sourcepath just file name for local directory, else full path in POSIX syntax
258278 // targetpath is full remote path (starting with /, ending with file name
259- ASSERT:C1129 ($sourcepath # "" ; "source path must not be empty" )
279+ ASSERT:C1129 (Length :C16 ( $sourcepath ) > 0 ; "source path must not be empty" )
260280 // ASSERT($targetpath#""; "target path must not be empty")
261- ASSERT:C1129 ($mime # "" ; "mime must not be empty" )
262- $success := This:C1470 ._uploadSub ($sourcepath ; $targetpath ; $mime )
281+ ASSERT:C1129 (Length :C16 ( $mime ) > 0 ; "mime must not be empty" )
282+ return This:C1470 ._uploadSub ($sourcepath ; $targetpath ; $mime )
263283
264- Function createDirectory ($targetpath : Text)- > $success : Object
265- ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
284+ Function createDirectory ($targetpath : Text) : Object
285+ var $url : Text
286+ ASSERT:C1129 (Length:C16 ($targetpath )> 0 ; "target path must not be empty" )
266287 $url := "mkdir " + $targetpath
267- $success := This:C1470 ._runWorker ($url )
288+ return This:C1470 ._runWorker ($url )
268289
269- Function deleteDirectory ($targetpath : Text; $force : Boolean)- > $success : Object
270- ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
290+ Function deleteDirectory ($targetpath : Text; $force : Boolean) : Object
291+ var $url : Text
292+ ASSERT:C1129 (Length:C16 ($targetpath )> 0 ; "target path must not be empty" )
271293 If ($force)
272294 $url := "rm -f " + $targetpath
273295 Else
274296 $url := "rm " + $targetpath
275297 End if
276- $success := This:C1470 ._runWorker ($url )
298+ return This:C1470 ._runWorker ($url )
277299
278- Function deleteFile ($targetpath : Text)- > $success : Object
279300 // same as deleteDirectory
280- ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
301+ Function deleteFile ($targetpath : Text) : Object
302+ var $url : Text
303+ ASSERT:C1129 (Length:C16 ($targetpath )> 0 ; "target path must not be empty" )
281304 $url := "rm " + $targetpath
282- $success := This:C1470 ._runWorker ($url )
305+ return This:C1470 ._runWorker ($url )
283306
284- Function renameFile ($sourcepath : Text; $targetpath : Text)- > $success : Object
285- ASSERT:C1129 ($sourcepath # "" ; "source path must not be empty" )
286- ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
307+ Function renameFile ($sourcepath : Text; $targetpath : Text) : Object
308+ var $url : Text
309+ ASSERT:C1129 (Length:C16 ($sourcepath )> 0 ; "source path must not be empty" )
310+ ASSERT:C1129 (Length:C16 ($targetpath )> 0 ; "target path must not be empty" )
287311 $url := "mv " + $sourcepath + " " + $targetpath
288- $success := This:C1470 ._runWorker ($url )
312+ return This:C1470 ._runWorker ($url )
289313
290314Function moveFile ($sourcepath : Text; $targetpath : Text)- > $success : Object
291315 $success := This:C1470 .renameFile ($sourcepath ; $targetpath )
292316
293317Function copyFile ($sourcepath : Text; $targetpath : Text)- > $success : Object
294- ASSERT:C1129 ($sourcepath # "" ; "source path must not be empty" )
295- ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
318+ var $url : Text
319+
320+ ASSERT:C1129 (Length:C16 ($sourcepath )> 0 ; "source path must not be empty" )
321+ ASSERT:C1129 (Length:C16 ($targetpath )> 0 ; "target path must not be empty" )
296322 $url := "cp " + $sourcepath + " " + $targetpath
297323 $success := This:C1470 ._runWorker ($url )
298324
@@ -348,6 +374,11 @@ Function _findLastPos($search : Integer; $string : Text)->$pos : Integer
348374 End while
349375
350376Function _parseDirListing ($success : Object)
377+ var $col : Collection
378+ var $diritem : Object
379+ var $posName ; $posType ; $posSize ; $posCreated : Integer
380+ var $line : Text
381+
351382 $col := Split string:C1554 (String:C10 ($success .data ); This:C1470 ._return ; sk ignore empty strings:K86:1 )
352383 If (($col .length > 0) && ($col[0 ]= "Id@"))
353384 $success .list := New collection:C1472
@@ -375,6 +406,11 @@ Function _parseDirListing($success : Object)
375406 End if
376407
377408Function _runWorker ($para : Text)- > $result : Object
409+ var $workerpara : cs:C1710 .SystemWorkerProperties
410+ var $path ; $command ; $old : Text
411+ var $worker : Object
412+ var $waittimeout : Integer
413+
378414 If (This:C1470 ._Callback # Null:C1517)
379415 $workerpara := cs:C1710 .SystemWorkerProperties .new ("gdrive" ; This:C1470 .onData; This:C1470 ._Callback; This:C1470 ._CallbackID; This:C1470 ._enableStopButton)
380416 Else
0 commit comments