# Get local Dropbox path with Delphi XE7

I've put together a function in Delphi XE7 which returns the Dropbox directory path on my machine, as this path can be customized by the user.

This function currently works on my computer, but it could have many defects preventing it to work for other users on different machines. So I would be very grateful if anybody could point to these defects.

uses
System.IOUtils, System.JSON, System.NetEncoding, JclSysInfo, JclStrings

function GetDropboxPath: string;
var
tempstr: string;
function ParseJsonStr(jStr, jPar1, jPar2: string): string;
var
jObj: TJSONObject;
jVal: TJSONValue;
begin
Result:= '';
jObj := TJSONObject.ParseJSONValue(jStr) as TJSONObject;
try
jVal:= jObj.Get(jPar1).JsonValue;
Result:= TJSONObject(jVal).Get(jPar2).JsonValue.Value;
finally
jObj.Free;
end;
end;
begin
Result := '';
tempstr := IncludeTrailingBackslash(JclSysInfo.GetAppdataFolder) + 'Dropbox\';
if DirectoryExists(tempstr) then
begin
if FileExists(tempstr + 'info.json') then // try with info.json
begin
tempstr := tempstr + 'info.json';
try
tempstr := ParseJsonStr(tempstr, 'personal', 'path');
except
// Todo: log this error
EXIT;
end;
Result := Trim(tempstr);
end
else if FileExists(tempstr + 'host.db') then // else try with host.db
begin
tempstr := tempstr + 'host.db';

• The result of the subroutine ParseJsonStrcould be an empty string. In this case the host.db file should be checked, which currently is not the case because of the if-else structure. So instead of the if-else structure at the end of the info.json check, the result should be evaluated. Only in the case (and only then) it is empty, the second check of the host-db file should be executed. What do you think? – user1580348 Feb 23 '15 at 15:49
• Also, in the except section, there should be no EXIT but instead it should continue to the host.db check. What do you think? – user1580348 Feb 23 '15 at 15:57
• Personally, I would be reading that path from the registry. Any user can install DropBox wherever he wants to. I doubt that you can rely on JclSysInfo.GetAppdataFolder (and, even if it works for DropBox, because they hard code some stuff, instead of following MS rules & allowing a choice, it is not guaranteed to work for all (read "properly coded") apps). – Mawg Apr 13 '15 at 14:19
• Google is your friend (or you could even just fire up Regedit & search for DropBox). See forensicartifacts.com/2011/07/dropbox-config-files-windows or forensicfocus.com/Content/pid=429/page=2 or any of the other numerous results of googling for dropbox registry keys – Mawg Apr 15 '15 at 12:38