1+ Class constructor ($configname : Text)
2+ This:C1470 .onData := New object:C1471 ("text" ; "" )
3+ If (Is macOS:C1572)
4+ This:C1470 ._return := Char:C90 (10 )
5+ This:C1470 ._Path := "rclone"
6+ Else
7+ This:C1470 ._return := Char:C90 (10 ) // Char(13)+Char(10)
8+ This:C1470 ._Path := "rclone.exe"
9+ End if
10+ This:C1470 ._timeout := 0
11+ This:C1470 .config := $configname
12+
13+ // uses https://rclone.org
14+
15+ // MARK: FileTransfer
16+ Function getDirectoryListing ($targetpath : Text)- > $success : Object
17+ If ($targetpath= "")
18+ $targetpath := "/"
19+ End if
20+ // add +This.config+":/"
21+ $url := "lsjson " + This:C1470 .config + ":" + $targetpath
22+ $success := This:C1470 ._runWorker ($url )
23+ If ($success .success )
24+ If ($success .data = "[@")
25+ $json := JSON Parse:C1218 ($success .data )
26+ $success .list := $json
27+ Else
28+ $success .success := False:C215
29+ $success .error := $success .data
30+ End if
31+ End if
32+
33+ Function upload ($sourcepath : Text; $targetpath : Text)- > $success : Object
34+ // $sourcepath just file name for local directory, else full path in POSIX syntax
35+ // targetpath is full remote path (starting with /, ending with file name
36+ ASSERT:C1129 ($sourcepath # "" ; "source path must not be empty" )
37+ ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
38+ $url := "copyto " + $sourcepath + " " + This:C1470 .config + ":" + $targetpath
39+ $success := This:C1470 ._runWorker ($url )
40+ If ($success .data # "")
41+ $success .success := False:C215
42+ $success .error := $success .data
43+ End if
44+
45+ Function download ($sourcepath : Text; $targetpath : Text)- > $success : Object
46+ $success := This:C1470 .upload ($sourcepath ; $targetpath )
47+ ASSERT:C1129 ($sourcepath # "" ; "source path must not be empty" )
48+ ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
49+ $url := "copyto " + This:C1470 .config + ":" + $sourcepath + " " + $targetpath
50+ $success := This:C1470 ._runWorker ($url )
51+ If ($success .data # "")
52+ $success .success := False:C215
53+ $success .error := $success .data
54+ End if
55+
56+ Function createDirectory ($targetpath : Text)- > $success : Object
57+ ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
58+ $url := "mkdir " + $targetpath
59+ $success := This:C1470 ._runWorker ($url )
60+
61+ Function deleteDirectory ($targetpath : Text; $force : Boolean)- > $success : Object
62+ ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
63+ If ($force)
64+ $url := "rm -f " + $targetpath
65+ Else
66+ $url := "rm " + $targetpath
67+ End if
68+ $success := This:C1470 ._runWorker ($url )
69+
70+ Function deleteFile ($targetpath : Text)- > $success : Object
71+ // same as deleteDirectory
72+ ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
73+ $url := "rm " + $targetpath
74+ $success := This:C1470 ._runWorker ($url )
75+
76+ Function renameFile ($sourcepath : Text; $targetpath : Text)- > $success : Object
77+ ASSERT:C1129 ($sourcepath # "" ; "source path must not be empty" )
78+ ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
79+ $url := "mv " + $sourcepath + " " + $targetpath
80+ $success := This:C1470 ._runWorker ($url )
81+
82+ Function moveFile ($sourcepath : Text; $targetpath : Text)- > $success : Object
83+ $success := This:C1470 .renameFile ($sourcepath ; $targetpath )
84+
85+ Function copyFile ($sourcepath : Text; $targetpath : Text)- > $success : Object
86+ ASSERT:C1129 ($sourcepath # "" ; "source path must not be empty" )
87+ ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
88+ $url := "cp " + $sourcepath + " " + $targetpath
89+ $success := This:C1470 ._runWorker ($url )
90+
91+ Function executeCommand ($command : Text)- > $success : Object
92+ ASSERT:C1129 ($command # "" ; "command must not be empty" )
93+ $success := This:C1470 ._runWorker ($command )
94+
95+ // MARK: Settings
96+ Function validate ()- > $success : Object
97+ $success := This:C1470 ._runWorker ("about " + This:C1470 .config+ ":/" )
98+
99+ Function version ()- > $data : Object
100+ $data := This:C1470 ._runWorker ("version" )
101+
102+ Function setPath ($path : Text)
103+ This:C1470 ._Path := $path
104+
105+ Function useCallback ($callback : 4D:C1709 .Function ; $ID : Text)
106+ ASSERT:C1129 (Value type:C1509 ($callback )= Is object:K8:27 ; "Callback must be of type function" )
107+ ASSERT:C1129 (OB Instance of:C1731 ($callback ; 4D:C1709 .Function ); "Callback must be of type function" )
108+ ASSERT:C1129 ($ID # "" ; "Callback ID Method must not be empty" )
109+ This:C1470 ._Callback := $callback
110+ This:C1470 ._CallbackID := $ID
111+ This:C1470 ._noProgress := False:C215
112+
113+ Function setTimeout ($timeout : Integer)
114+ This:C1470 ._timeout := $timeout
115+
116+ Function setAsyncMode ($async : Boolean)
117+ This:C1470 ._async := $async
118+
119+ Function enableStopButton ($enable : Object)
120+ This:C1470 ._enableStopButton := $enable
121+
122+ Function stop ()
123+ If (This:C1470 ._worker # Null:C1517)
124+ This:C1470 ._worker .terminate ()
125+ End if
126+
127+ Function status ()- > $status : Object
128+ $status := New object:C1471
129+ $status .terminated := This:C1470 ._worker .terminated
130+ $status .response := This:C1470 ._worker .response
131+ $status .responseError := This:C1470 ._worker .responseError
132+ $status .exitCode := This:C1470 ._worker .exitCode
133+ $status .errors := This:C1470 ._worker .errors
134+
135+ Function wait ($max : Integer)
136+ This:C1470 ._worker .wait ($max )
137+
138+ // MARK: Internal helper calls
139+ Function _runWorker ($para : Text)- > $result : Object
140+ If (This:C1470 ._Callback # Null:C1517)
141+ $workerpara := cs:C1710 .SystemWorkerProperties .new ("rclone" ; This:C1470 .onData; This:C1470 ._Callback; This:C1470 ._CallbackID; This:C1470 ._enableStopButton)
142+ Else
143+ $workerpara := cs:C1710 .SystemWorkerProperties .new ("rclone" ; This:C1470 .onData)
144+ End if
145+
146+ If ((This:C1470 ._Path ) && (This:C1470 ._Path # ""))
147+ $path := This:C1470 ._Path
148+ Else
149+ $path := "rclone"
150+ End if
151+
152+ /*
153+
154+ If ((This._noProgress#Null) && (This._noProgress))
155+ $path+=" --no-progress-meter"
156+ End if
157+ If (This._connectTimeout#Null)
158+ $path+=" --connect-timeout "+String(This._connectTimeout)
159+ End if
160+ If (This._maxTime#Null)
161+ $path+=" --max-time "+String(This._maxTime)
162+ End if
163+ If (This._range#Null)
164+ $path+=" --range "+This._range
165+ End if
166+ If ((This._ActiveMode#Null) && (This._ActiveMode)) // default passive
167+ $path+=" --ftp-port "+This.ActiveModeIP
168+ End if
169+ If (This._prefix#Null)
170+ $path+=(" "+This._prefix)
171+ End if
172+
173+ */
174+
175+ $command := $path + " " + $para
176+ $old := Method called on error:C704
177+ ON ERR CALL:C155 (Formula:C1597 (ErrorHandler).source )
178+ This:C1470 ._worker := 4D:C1709 .SystemWorker .new ($command ; $workerpara )
179+ $worker := This:C1470 ._worker
180+
181+ If ($worker# Null:C1517)
182+ If ((This:C1470 ._async # Null:C1517) && (This:C1470 ._async ))
183+ $result := New object:C1471 ("data" ; "async" ; "success" ; True:C214 )
184+ Else
185+ $waittimeout := (This:C1470 ._timeout = 0) ? 60 : This:C1470 ._timeout
186+ $worker .wait ($waittimeout )
187+ If (($worker .responseError # Null:C1517) && ($worker .responseError # ""))
188+ $result := New object:C1471 ("responseError" ; $worker .responseError ; "success" ; False:C215 )
189+ $pos := Position:C15 ("Error:" ; $worker .responseError ; * )
190+ If ($pos> 0)
191+ $result .error := Replace string:C233 (Substring:C12 ($worker .responseError ; $pos + 6 ); Char:C90 (10 ); "" )
192+ Else
193+ If (($worker .response # Null:C1517) && ($worker .response # "")) // seems not to be an error, sometime curl set's process bar in error and result in response.
194+ $result := New object:C1471 ("data" ; $worker .response ; "success" ; True:C214 )
195+ Else
196+ $result := New object:C1471 ("data" ; $worker .responseError ; "success" ; True:C214 )
197+ End if
198+ End if
199+ Else
200+ $result := New object:C1471 ("data" ; $worker .response ; "success" ; True:C214 )
201+ End if
202+ End if
203+
204+ If (This:C1470 ._Callback # Null:C1517)
205+ This:C1470 ._worker .onTerminate (New object:C1471; New object:C1471)
206+ End if
207+ Else
208+ $result := New object:C1471 ("success" ; False:C215 ; "responseError" ; "rclone execution error" )
209+ End if
210+ ON ERR CALL:C155 ($old )
211+
212+ Function _trim ($text : Text)- > $result : Text
213+ $result := $text
214+ While (Substring:C12 ($result ; 1 ; 1 )= " ")
215+ $result := Substring:C12 ($result ; 2 )
216+ End while
217+ While (Substring:C12 ($result ; Length:C16 ($result ); 1 )= " ")
218+ $result := Substring:C12 ($result ; 1 ; Length:C16 ($result )- 1 )
219+ End while
220+
0 commit comments