When integrating the use of DropBox in your application, you'd first need to be able to find the path to the DropBox directory.
Dropbox documented this well (see this link), and a JSON file is available in the user's home directory:
~/.dropbox/info.json
This file contains the needed info an is formatted as such (if you have only a personal, or only a business DropBox account, then obviously the other one does not exist):
{
"business": {
"host": 123456789,
"path": "/Users/<USERNAME>/Dropbox (<BUSINESS_NAME>)"
},
"personal": {
"host": 123456789,
"path": "/Users/<USERNAME>/Dropbox (Personal)"
}
}
- business/personal: The type of account.
- host: An identifier that uniquely specifies a particular user account and computer pair.
- path: The path to this Dropbox folder.
To read this DropBox configuration file, we will need a JSON parser (see
Lazarus Wiki).
A simple example on how to retrieve the DropBox path:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, fpjson, jsonparser;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
jData : TJSONData;
jObject : TJSONObject;
jArray : TJSONArray;
jText : TStringList;
DropBoxPath : string;
begin
if FileExists(ExpandFileName('~/.dropbox/info.json')) then
begin
jText:=TStringList.Create;
jText.LoadFromFile(ExpandFileName('~/.dropbox/info.json'));
jData := GetJSON(jText.Text);
jObject := TJSONObject(jData);
DropBoxPath:='';
try
DropBoxPath:=jData.FindPath('personal.path').AsString;
except
// Do nothing
end;
if DropBoxPath='' then
try
DropBoxPath:=jData.FindPath('business.path').AsString;
except
// Do Nothing
end;
if DropBoxPath<>'' then
Label1.Caption:=DropBoxPath;
else
Label1.Caption:='Not found';
jText.Free;
jObject.Free;
jData.Free;
end;
end;
end.