Skip to content

Commit 626625c

Browse files
authored
Merge pull request #4 from heubachmedia/main
Changes v20
2 parents c7c9df7 + db9d160 commit 626625c

20 files changed

Lines changed: 530 additions & 360 deletions

Project/Sources/Classes/FileTransfer_Dropbox.4dm

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
property onData : Object
2+
property _return; _Path : Text
3+
property _timeout : Integer
4+
15
Class constructor()
26
This:C1470.onData:=New object:C1471("text"; "")
37
If (Is macOS:C1572)
@@ -13,7 +17,9 @@ Class constructor()
1317

1418
//MARK: FileTransfer
1519
Function getDirectoryListing($targetpath : Text)->$success : Object
16-
If ($targetpath="")
20+
var $url : Text
21+
22+
If (Length:C16($targetpath)=0)
1723
$targetpath:="/"
1824
End if
1925
$url:="ls -l "+$targetpath
@@ -23,11 +29,14 @@ Function getDirectoryListing($targetpath : Text)->$success : Object
2329
This:C1470._parseDirListing($success)
2430
End if
2531

26-
Function upload($sourcepath : Text; $targetpath : Text)->$success : Object
2732
//$sourcepath just file name for local directory, else full path in POSIX syntax
2833
// targetpath is full remote path (starting with /, ending with file name
29-
ASSERT:C1129($sourcepath#""; "source path must not be empty")
30-
ASSERT:C1129($targetpath#""; "target path must not be empty")
34+
Function upload($sourcepath : Text; $targetpath : Text)->$success : Object
35+
var $url : Text
36+
var $oldtimeout : Integer
37+
38+
ASSERT:C1129(Length:C16($sourcepath)>0; "source path must not be empty")
39+
ASSERT:C1129(Length:C16($targetpath)>0; "target path must not be empty")
3140

3241
$url:="put "+$sourcepath+" "+$targetpath
3342
$oldtimeout:=This:C1470._timeout
@@ -37,11 +46,14 @@ Function upload($sourcepath : Text; $targetpath : Text)->$success : Object
3746
$success:=This:C1470._runWorker($url)
3847
This:C1470._timeout:=$oldtimeout
3948

40-
Function download($sourcepath : Text; $targetpath : Text)->$success : Object
4149
//$sourcepath just file name for local directory, else full path in POSIX syntax
4250
// targetpath is full remote path (starting with /, ending with file name
43-
ASSERT:C1129($sourcepath#""; "source path must not be empty")
44-
ASSERT:C1129($targetpath#""; "target path must not be empty")
51+
Function download($sourcepath : Text; $targetpath : Text)->$success : Object
52+
var $url : Text
53+
var $oldtimeout : Integer
54+
55+
ASSERT:C1129(Length:C16($sourcepath)>0; "source path must not be empty")
56+
ASSERT:C1129(Length:C16($targetpath)>0; "target path must not be empty")
4557

4658
$url:="get "+$sourcepath+" "+$targetpath
4759
$oldtimeout:=This:C1470._timeout
@@ -51,43 +63,47 @@ Function download($sourcepath : Text; $targetpath : Text)->$success : Object
5163
$success:=This:C1470._runWorker($url)
5264
This:C1470._timeout:=$oldtimeout
5365

54-
Function createDirectory($targetpath : Text)->$success : Object
55-
ASSERT:C1129($targetpath#""; "target path must not be empty")
56-
$url:="mkdir "+$targetpath
57-
$success:=This:C1470._runWorker($url)
66+
Function createDirectory($targetpath : Text) : Object
67+
ASSERT:C1129(Length:C16($targetpath)>0; "target path must not be empty")
68+
return This:C1470._runWorker("mkdir "+$targetpath)
69+
70+
Function deleteDirectory($targetpath : Text; $force : Boolean) : Object
71+
var $url : Text
5872

59-
Function deleteDirectory($targetpath : Text; $force : Boolean)->$success : Object
60-
ASSERT:C1129($targetpath#""; "target path must not be empty")
73+
ASSERT:C1129(Length:C16($targetpath)>0; "target path must not be empty")
6174
If ($force)
6275
$url:="rm -f "+$targetpath
6376
Else
6477
$url:="rm "+$targetpath
6578
End if
66-
$success:=This:C1470._runWorker($url)
79+
return This:C1470._runWorker($url)
6780

68-
Function deleteFile($targetpath : Text)->$success : Object
81+
Function deleteFile($targetpath : Text) : Object
6982
// same as deleteDirectory
70-
ASSERT:C1129($targetpath#""; "target path must not be empty")
71-
$url:="rm "+$targetpath
72-
$success:=This:C1470._runWorker($url)
83+
ASSERT:C1129(Length:C16($targetpath)>0; "target path must not be empty")
84+
return This:C1470._runWorker("rm "+$targetpath)
7385

74-
Function renameFile($sourcepath : Text; $targetpath : Text)->$success : Object
75-
ASSERT:C1129($sourcepath#""; "source path must not be empty")
76-
ASSERT:C1129($targetpath#""; "target path must not be empty")
86+
Function renameFile($sourcepath : Text; $targetpath : Text) : Object
87+
var $url : Text
88+
89+
ASSERT:C1129(Length:C16($sourcepath)>0; "source path must not be empty")
90+
ASSERT:C1129(Length:C16($targetpath)>0; "target path must not be empty")
7791
$url:="mv "+$sourcepath+" "+$targetpath
78-
$success:=This:C1470._runWorker($url)
92+
return This:C1470._runWorker($url)
7993

80-
Function moveFile($sourcepath : Text; $targetpath : Text)->$success : Object
81-
$success:=This:C1470.renameFile($sourcepath; $targetpath)
94+
Function moveFile($sourcepath : Text; $targetpath : Text) : Object
95+
return This:C1470.renameFile($sourcepath; $targetpath)
8296

83-
Function copyFile($sourcepath : Text; $targetpath : Text)->$success : Object
84-
ASSERT:C1129($sourcepath#""; "source path must not be empty")
85-
ASSERT:C1129($targetpath#""; "target path must not be empty")
97+
Function copyFile($sourcepath : Text; $targetpath : Text) : Object
98+
var $url : Text
99+
100+
ASSERT:C1129(Length:C16($sourcepath)>0; "source path must not be empty")
101+
ASSERT:C1129(Length:C16($targetpath)>0; "target path must not be empty")
86102
$url:="cp "+$sourcepath+" "+$targetpath
87-
$success:=This:C1470._runWorker($url)
103+
return This:C1470._runWorker($url)
88104

89105
Function executeCommand($command : Text)->$success : Object
90-
ASSERT:C1129($command#""; "command must not be empty")
106+
ASSERT:C1129(Length:C16($command)>0; "command must not be empty")
91107
$success:=This:C1470._runWorker($command)
92108

93109
//MARK: Settings
@@ -132,6 +148,11 @@ Function wait($max : Integer)
132148

133149
// MARK: Internal helper calls
134150
Function _parseDirListing($success : Object)
151+
var $col : Collection
152+
var $posSize; $posLast; $posPath : Integer
153+
var $line : Text
154+
var $diritem : Object
155+
135156
$col:=Split string:C1554(String:C10($success.data); This:C1470._return; sk ignore empty strings:K86:1)
136157
If (($col.length>0) && ($col[0]="Revision@"))
137158
$success.list:=New collection:C1472
@@ -157,6 +178,11 @@ Function _parseDirListing($success : Object)
157178
End if
158179

159180
Function _runWorker($para : Text)->$result : Object
181+
var $workerpara : cs:C1710.SystemWorkerProperties
182+
var $path; $command; $old : Text
183+
var $worker : Object
184+
var $waittimeout; $pos : Integer
185+
160186
If (This:C1470._Callback#Null:C1517)
161187
$workerpara:=cs:C1710.SystemWorkerProperties.new("dropbox"; This:C1470.onData; This:C1470._Callback; This:C1470._CallbackID; This:C1470._enableStopButton)
162188
Else

Project/Sources/Classes/FileTransfer_GDrive.4dm

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
property onData : Object
2+
property _Path; _workerpath : Text
3+
property _timeout : Integer
4+
15
Class 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

165181
Function _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

290314
Function moveFile($sourcepath : Text; $targetpath : Text)->$success : Object
291315
$success:=This:C1470.renameFile($sourcepath; $targetpath)
292316

293317
Function 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

350376
Function _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

377408
Function _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

Comments
 (0)