Skip to content

Commit

Permalink
Added FsRenMovFileW plugin method
Browse files Browse the repository at this point in the history
Added method to copy/move Dropbox files
Added copy and move DropboxClient methods
  • Loading branch information
peleccom committed Sep 28, 2013
1 parent f338835 commit 595b508
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
46 changes: 46 additions & 0 deletions DropboxAPI/DropboxClient.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ TDropboxClient = class
function metaData(path: string; list: boolean;file_limit: integer = 10000; hash:boolean=False;revision:string='';include_deleted:boolean=False):TJsonObject;
// Return True if path refers to an existing path
function exists(path: string): boolean;
// Copies a file or folder to a new location
function copy(fromPath: string; toPath: string): TJSONObject;
// Moves a file or folder to a new location
function move(fromPath: string; toPath: string): TJSONObject;
// Return True if path is existsting file
function isFile(path: string): boolean;
// Return True if path is existsting directory
Expand Down Expand Up @@ -106,6 +110,27 @@ function TDropboxClient.accountInfo(): TJsonObject;
Result := FrestClient.GET_JSON(url);
end;

function TDropboxClient.copy(fromPath, toPath: string): TJSONObject;
var
params, requestparams, requestheaders: TStringList;
url: string;
begin
try
params := TStringList.Create;
requestparams := TStringList.Create;
requestheaders := TStringList.Create;
params.Values['root'] := FSession.Root;
params.Values['from_path'] := fromPath;
params.Values['to_path'] := toPath;
url := request('/fileops/copy',requestparams,requestheaders,params,'POST');
Result := FRestClient.POST_JSON(url, requestparams);
finally
params.Free;
requestparams.Free;
requestheaders.Free;
end;
end;

constructor TDropboxClient.Create(session: TDropboxSession);
begin
FSession := session;
Expand Down Expand Up @@ -278,6 +303,27 @@ function TDropboxClient.metaData(path: string; list: boolean;file_limit: integer
end;


function TDropboxClient.move(fromPath, toPath: string): TJSONObject;
var
params, requestparams, requestheaders: TStringList;
url: string;
begin
try
params := TStringList.Create;
requestparams := TStringList.Create;
requestheaders := TStringList.Create;
params.Values['root'] := FSession.Root;
params.Values['from_path'] := fromPath;
params.Values['to_path'] := toPath;
url := request('/fileops/move',requestparams,requestheaders,params,'POST');
Result := FRestClient.POST_JSON(url, requestparams);
finally
params.Free;
requestparams.Free;
requestheaders.Free;
end;
end;

function TDropboxClient.parseDate(dateStr: string): TDateTime;
const
_ShortMonthNames : array[1..12] of string = ('Jan','Feb','Mar','Apr','May','Jun',
Expand Down
49 changes: 48 additions & 1 deletion TCBox.dpr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library TCBox;
library TCBox;

uses
Windows,
Expand Down Expand Up @@ -590,6 +590,52 @@ begin
end;
end;

function FsRenMovFileW(OldName, NewName: pwidechar; Move, OverWrite: bool;
RemoteInfo: pRemoteInfo): Integer; stdcall;
var
oldFileName, newFileName: string;
newFileExists: boolean;
json: TJSONObject;
begin
oldFileName := normalizeDropboxPath(OldName);
newFileName := normalizeDropboxPath(NewName);
newFileExists := DropboxClient.exists(newFileName);
if not OverWrite and newFileExists then
begin
Result := FS_FILE_EXISTS;
exit;
end;
if OverWrite and newFileExists then
try
DropboxClient.delete(newFileName);
except
Result := FS_FILE_NOTSUPPORTED;
exit;
end;
try
if Move then
begin
// move object
json := DropboxClient.Move(oldFileName, newFileName);
json.Free;
end
else
begin
// copy objects
json := DropboxClient.copy(oldFileName, newFileName);
json.Free;
end;
Result := FS_FILE_OK;
except
on E: Exception do
begin
Log('Exception in FsRenMovFileW ' + E.ClassName + ' ' + E.Message);
Result := FS_FILE_WRITEERROR;
exit;
end;
end;
end;

procedure FsGetDefRootName(DefRootName: PAnsiChar; maxlen: Integer); stdcall;
const
rootName: String = 'Dropbox';
Expand All @@ -610,6 +656,7 @@ exports
FsGetFileW,
FsMkDirW,
FsRemoveDirW,
FsRenMovFileW,
FsDeleteFileW,
FsPutFileW,
FsGetDefRootName,
Expand Down

0 comments on commit 595b508

Please sign in to comment.