// // Example location script for 2BrightSparks SyncBackPro: Browser Bookmarks. // // SBLang=Pascal // // http://www.2BrightSparks.com/ // November 2026 // // Browser Bookmarks is a read-only location that shows the bookmarks of your // web browsers as folders of .url files (internet shortcuts: double-click one // to open the page): // // \Chrome\Bookmarks bar\News\BBC News.url // \Edge - Work\Favorites bar\Intranet.url // \Firefox\Bookmarks Menu\Recipes\Pancakes.url // // Back it up and you have a copy of your bookmarks that any browser (or // Windows itself) can open, browser by browser and folder by folder. // // Browsers // -------- // It finds the bookmarks of Google Chrome, Microsoft Edge, Brave, Vivaldi // and Opera (from their Bookmarks files) and Mozilla Firefox (from its // places.sqlite, which it reads a copy of, so Firefox can stay open). A // browser with more than one profile has a folder per profile, e.g. // "Chrome - Work". Other bookmark files, e.g. of a portable browser, can be // added on the Browser Bookmarks page of the profile setup. // // Names // ----- // A bookmark's name can hold characters a file name cannot (\ / : * ? " < > // |): they become spaces. Two bookmarks with the same name in the same folder // get (2), (3) and so on. A name is cut at 100 characters. // // A .url file has the date the bookmark was added. When a bookmark's address // changes, its file gets the date & time the change was found, so the // profile copies it again. That is remembered in // %LOCALAPPDATA%\SyncBack Bookmarks\. // // Using it // -------- // Make a new Backup profile that copies FROM Browser Bookmarks, with the path // \, TO a folder such as D:\Bookmarks\. A location script is always the // destination of a profile, so SyncBack sets it up as "destination to source" // for you. Use Backup rather than Mirror if you want to keep the bookmarks // you delete. // // Insider Access // -------------- // This script needs SyncBackPro V12 with Insider Access. It uses these // Insider Access functions (they will be in every SyncBackPro V13): // // JSON.parse To read the bookmarks of Chrome, Edge and so on // SBSystem.SQLiteQuery To read the bookmarks of Firefox // SBSystem.HashString To name its index files // var gFSO, gIndex, gMade, gOutDirs, gOut, gUsed, gCacheLines, gCacheKeys, gNewCache; const READ_ONLY = 'Browser Bookmarks is read-only'; // // This is a location script with a page in the profile setup // function Description(var ScriptType): String; begin Result:='Browser Bookmarks'; ScriptType:=SCRIPTTYPE_LOCATION + SCRIPTTYPE_CONFIG; end; function Install(Interactive); begin Result:=''; end; procedure Uninstall; begin end; function FilesToExport(Interactive, Cnt); begin Result:=''; end; //----------------------------------------------------------------------------- // Helpers //----------------------------------------------------------------------------- procedure ForceDir(D); var P; begin D:=ExcludeTrailingPathDelimiter(D); if (D = '') or DirectoryExists(D) then Exit; P:=ExtractFilePath(D); if (P <> '') and (ExcludeTrailingPathDelimiter(P) <> D) then ForceDir(P); CreateDir(D); end; procedure ClearFolder(D); var Folder, FileItem, FilesEnum; begin if not gFSO.FolderExists(D) then Exit; Folder:=gFSO.GetFolder(D); FilesEnum:=TEnumVariant.Create(Folder.Files); try while FilesEnum.ForEach(FileItem) do gFSO.DeleteFile(FileItem.Path, TRUE); finally FilesEnum.Free; end; end; function ExpandEnv(s); var Shell; begin Shell:=CreateOleObject('WScript.Shell'); Result:=Shell.ExpandEnvironmentStrings(s); Shell:=Unassigned; end; function CleanPath(P); begin while (Pos('\\', P) > 0) do P:=ReplaceStr(P, '\\', '\'); Result:=P; end; function NormDir(P); begin P:=CleanPath(P); if (P = '') then P:='\'; if (Copy(P, 1, 1) <> '\') then P:='\' + P; Result:=IncludeTrailingPathDelimiter(P); end; function ParentDir(P); begin Result:=NormDir(ExtractFilePath(ExcludeTrailingPathDelimiter(CleanPath(P)))); end; function BaseName(P); begin Result:=ExtractFileName(ExcludeTrailingPathDelimiter(CleanPath(P))); end; function IsRoot(P); begin P:=CleanPath(P); Result:=(P = '') or (P = '\'); end; function DTToText(DT); begin if (DT <= 1.0) then Result:='' else Result:=SBSystem.UTCDateTimeToISO8601(SBSystem.LocalToGMT(DT), FALSE); end; function TextToDT(s); begin if (s = '') then Result:=1.0 else Result:=SBSystem.ISO8601ToLocalDateTime(s); end; // Field Idx (from 0) of a tab-separated line function Field(Line, Idx); var i, p, s; begin s:=Line; for i:=1 to Idx do begin p:=Pos(#9, s); if (p = 0) then begin Result:=''; Exit; end; s:=Copy(s, p + 1, Length(s)); end; p:=Pos(#9, s); if (p = 0) then Result:=s else Result:=Copy(s, 1, p - 1); end; function Pad(N, Len); begin Result:=IntToStr(N); while (Length(Result) < Len) do Result:='0' + Result; end; function IsDeviceName(N); var B; begin B:=UpperCase(N); if (Pos('.', B) > 0) then B:=Copy(B, 1, Pos('.', B) - 1); B:=Trim(B); Result:=(B = 'CON') or (B = 'PRN') or (B = 'AUX') or (B = 'NUL') or ((Length(B) = 4) and ((Copy(B, 1, 3) = 'COM') or (Copy(B, 1, 3) = 'LPT')) and (Copy(B, 4, 1) >= '0') and (Copy(B, 4, 1) <= '9')); end; // A bookmark or folder name as a file name function SafeName(s); var i, c, r; begin r:=''; for i:=1 to Length(s) do begin c:=Copy(s, i, 1); if (Pos(c, '\/:*?"<>|') > 0) or (Ord(c) < 32) then r:=r + ' ' else r:=r + c; end; while (Pos(' ', r) > 0) do r:=ReplaceStr(r, ' ', ' '); r:=Trim(r); if (Length(r) > 100) then r:=Trim(Copy(r, 1, 100)); while (r <> '') and ((Copy(r, Length(r), 1) = '.') or (Copy(r, Length(r), 1) = ' ')) do r:=Copy(r, 1, Length(r) - 1); if (r = '') then r:='Untitled'; if IsDeviceName(r) then r:=r + '_'; Result:=r; end; function HexByte(B); begin Result:='%' + IntToHex(B, 2); end; // A web address as plain ASCII (a .url file is not Unicode): anything else // is written as %XX of its UTF-8 bytes, the way browsers do function AsciiUrl(U); var i, o, o2, cp, r; begin r:=''; i:=1; while (i <= Length(U)) do begin o:=Ord(Copy(U, i, 1)); // No line breaks or tabs (below 32) if (o >= 32) and (o < 128) then r:=r + Copy(U, i, 1) else if (o >= 128) then begin cp:=o; if (o >= 55296) and (o <= 56319) and (i < Length(U)) then begin // A surrogate pair (e.g. an emoji) o2:=Ord(Copy(U, i + 1, 1)); if (o2 >= 56320) and (o2 <= 57343) then begin cp:=65536 + (o - 55296) * 1024 + (o2 - 56320); i:=i + 1; end; end; if (cp < 2048) then r:=r + HexByte(192 + cp div 64) + HexByte(128 + cp mod 64) else if (cp < 65536) then r:=r + HexByte(224 + cp div 4096) + HexByte(128 + (cp div 64) mod 64) + HexByte(128 + cp mod 64) else r:=r + HexByte(240 + cp div 262144) + HexByte(128 + (cp div 4096) mod 64) + HexByte(128 + (cp div 64) mod 64) + HexByte(128 + cp mod 64); end; i:=i + 1; end; Result:=r; end; function UrlFileText(Url); begin Result:='[InternetShortcut]' + #13#10 + 'URL=' + Url + #13#10; end; //----------------------------------------------------------------------------- // The index: a file per location folder in \dirs\, with a line per // sub-folder (D, name, date) and per bookmark (F, name, address, size, date) //----------------------------------------------------------------------------- function DirFile(VDir); begin Result:=gIndex + 'dirs\' + SBSystem.HashString(AnsiUpperCase(NormDir(VDir)), 'MD5') + '.txt'; end; function LoadDir(VDir, L); begin Result:=gFSO.FileExists(DirFile(VDir)); if Result then L.Text:=ReadStringFromFile(DirFile(VDir)); end; function FindEntry(L, Name); var i, U; begin Result:=-1; U:=AnsiUpperCase(Name); for i:=0 to L.Count - 1 do if (AnsiUpperCase(Field(L[i], 1)) = U) then begin Result:=i; Exit; end; end; // The index line of a location file (blank if there is none) function FileLine(P); var L, i; begin Result:=''; if IsRoot(P) or (Copy(P, Length(P), 1) = '\') then Exit; L:=TStringList.Create; try if LoadDir(ParentDir(P), L) then begin i:=FindEntry(L, BaseName(P)); if (i >= 0) and (Field(L[i], 0) = 'F') then Result:=L[i]; end; finally L.Free; end; end; function DirThere(P); begin Result:=IsRoot(P) or gFSO.FileExists(DirFile(P)); end; procedure IndexAdd(VDir, Line); var i; begin i:=gOutDirs.IndexOf(VDir); if (i < 0) then i:=gOutDirs.Add(VDir); gOut.Add(Pad(i, 7) + #9 + Line); end; // Write the index made with IndexAdd: a file per folder procedure IndexWrite; var i, Cur, Text, Written, Idx; begin ForceDir(gIndex + 'dirs\'); ClearFolder(gIndex + 'dirs\'); gOut.Sort; Written:=TStringList.Create; try Cur:=-1; Text:=''; for i:=0 to gOut.Count - 1 do begin Idx:=StrToInt(Copy(gOut[i], 1, 7)); if (Idx <> Cur) then begin if (Cur >= 0) then begin WriteStringToFile(DirFile(gOutDirs[Cur]), Text); Written.Add(IntToStr(Cur)); end; Cur:=Idx; Text:=''; end; Text:=Text + Copy(gOut[i], 9, Length(gOut[i])) + #13#10; end; if (Cur >= 0) then begin WriteStringToFile(DirFile(gOutDirs[Cur]), Text); Written.Add(IntToStr(Cur)); end; // Empty folders for i:=0 to gOutDirs.Count - 1 do if (Written.IndexOf(IntToStr(i)) < 0) then WriteStringToFile(DirFile(gOutDirs[i]), ''); finally Written.Free; end; end; // A name not yet used in location folder Parent function UniqueName(Parent, Base, Ext); var Cand, n; begin Cand:=Base + Ext; n:=1; while (gUsed.IndexOf(AnsiUpperCase(Parent + Cand)) >= 0) do begin n:=n + 1; Cand:=Base + ' (' + IntToStr(n) + ')' + Ext; end; gUsed.Add(AnsiUpperCase(Parent + Cand)); Result:=Cand; end; // Add a folder; returns its location path function AddFolder(Parent, Name, Added); var N; begin N:=UniqueName(Parent, SafeName(Name), ''); IndexAdd(Parent, 'D' + #9 + N + #9 + DTToText(Added)); Result:=Parent + N + '\'; if (gOutDirs.IndexOf(Result) < 0) then gOutDirs.Add(Result); end; // // The date of a .url file: the date the bookmark was added, unless its // address has changed since it was first seen, then when the change was // found. \dates.txt has a line per file: <32 hex: the path><32 hex: // the address> . Sorted, the keys (all the same length) are in // the same order as the lines, so a key's position is its line's. // function UrlDate(VPath, Url, Added); var Key, UrlKey, k, Line, When; begin Key:=SBSystem.HashString(AnsiUpperCase(VPath), 'MD5'); UrlKey:=SBSystem.HashString(Url, 'MD5'); When:=Added; k:=gCacheKeys.IndexOf(Key); if (k >= 0) then begin Line:=gCacheLines[k]; if (Copy(Line, 33, 32) = UrlKey) then When:=TextToDT(Copy(Line, 66, Length(Line))) else When:=Now; end; if (When <= 1.0) then When:=Now; gNewCache.Add(Key + UrlKey + #9 + DTToText(When)); Result:=When; end; procedure AddUrl(Parent, Title, Url, Added); var N, A; begin A:=AsciiUrl(Url); if (A = '') then Exit; N:=UniqueName(Parent, SafeName(Title), '.url'); IndexAdd(Parent, 'F' + #9 + N + #9 + A + #9 + IntToStr(Length(UrlFileText(A))) + #9 + DTToText(UrlDate(Parent + N, A, Added))); end; //----------------------------------------------------------------------------- // Reading the browsers //----------------------------------------------------------------------------- // Chrome & co: microseconds since 1 January 1601 (UTC) function ChromeTime(s); var us; begin // Digits only, so the decimal separator does not matter try us:=StrToFloat(Trim(s)); except us:=0; end; if (us <= 0) then Result:=1.0 else Result:=SBSystem.GMTToLocal(EncodeDate(1601, 1, 1) + us / 86400000000.0); end; // Firefox: microseconds since 1 January 1970 (UTC) function FirefoxTime(us); begin if (us <= 0) then Result:=1.0 else Result:=SBSystem.GMTToLocal(EncodeDate(1970, 1, 1) + us / 86400000000.0); end; procedure WalkChromium(V, Path, VDir); var i, C, T; begin i:=0; while V.Has(Path + '.children[' + IntToStr(i) + ']') do begin C:=Path + '.children[' + IntToStr(i) + ']'; T:=VarToStr(V.Get(C + '.type')); if (T = 'folder') then WalkChromium(V, C, AddFolder(VDir, VarToStr(V.Get(C + '.name')), ChromeTime(VarToStr(V.Get(C + '.date_added'))))) else if (T = 'url') then AddUrl(VDir, VarToStr(V.Get(C + '.name')), VarToStr(V.Get(C + '.url')), ChromeTime(VarToStr(V.Get(C + '.date_added')))); i:=i + 1; end; end; // The Bookmarks file of a Chromium browser (Chrome, Edge, Brave...) as // location folder VDir. Returns an error message, or blank. function ReadChromium(FileName, VDir); var V, Roots, i, R; begin Result:=''; try V:=JSON.parse(ReadStringFromFile(FileName)); except Result:='Browser Bookmarks: cannot read ' + FileName; Exit; end; try // bookmark_bar, other, synced (and any other roots there are) Roots:=V.GetObject('roots'); try for i:=0 to Roots.Count - 1 do begin R:='roots.' + Roots.Name(i); if V.Has(R + '.children') then WalkChromium(V, R, AddFolder(VDir, VarToStr(V.Get(R + '.name')), ChromeTime(VarToStr(V.Get(R + '.date_added'))))); end; finally Roots.Free; end; finally V.Free; end; end; // Firefox's places.sqlite as location folder VDir. Every bookmark and // folder comes back in one query, in tree order, with its depth. function ReadFirefox(FileName, VDir); var Err, Rows, V, i, n, Depth, Typ, Title, Guid, Stack, Parent, Sub, Added; begin Rows:=''; Err:=SBSystem.SQLiteQuery(FileName, 'WITH RECURSIVE t(id, type, title, url, added, depth, sortkey, guid) AS (' + ' SELECT b.id, b.type, b.title, NULL, b.dateAdded, 0, printf(''%06d'', b.position), b.guid' + ' FROM moz_bookmarks b WHERE b.parent = (SELECT id FROM moz_bookmarks WHERE guid = ''root________'')' + ' AND b.guid <> ''tags________''' + ' UNION ALL' + ' SELECT b.id, b.type, b.title, p.url, b.dateAdded, t.depth + 1, t.sortkey || ''.'' || printf(''%06d'', b.position), b.guid' + ' FROM moz_bookmarks b JOIN t ON b.parent = t.id LEFT JOIN moz_places p ON p.id = b.fk)' + ' SELECT type, title, url, added, depth, guid FROM t ORDER BY sortkey', Rows); if (Err <> '') then begin Result:='Browser Bookmarks: cannot read ' + FileName + ': ' + Err; Exit; end; Result:=''; V:=JSON.parse(Rows); Stack:=TStringList.Create; try n:=V.Count; for i:=0 to n - 1 do begin // JSON numbers are floating point: whole numbers for list positions Depth:=StrToIntDef(VarToStr(V.Get('[' + IntToStr(i) + '].depth')), 0); Typ:=StrToIntDef(VarToStr(V.Get('[' + IntToStr(i) + '].type')), 0); Title:=VarToStr(V.Get('[' + IntToStr(i) + '].title')); Added:=FirefoxTime(V.Get('[' + IntToStr(i) + '].added')); while (Stack.Count > Depth) do Stack.Delete(Stack.Count - 1); if (Depth = 0) then Parent:=VDir else if (Stack.Count = Depth) then Parent:=Stack[Depth - 1] else continue; // inside something that is not a folder if (Typ = 2) then begin if (Depth = 0) then begin // The names Firefox shows for its own folders Guid:=VarToStr(V.Get('[' + IntToStr(i) + '].guid')); if (Guid = 'menu________') then Title:='Bookmarks Menu' else if (Guid = 'toolbar_____') then Title:='Bookmarks Toolbar' else if (Guid = 'unfiled_____') then Title:='Other Bookmarks' else if (Guid = 'mobile______') then Title:='Mobile Bookmarks'; end; Sub:=AddFolder(Parent, Title, Added); Stack.Add(Sub); end else begin if (Typ = 1) then AddUrl(Parent, Title, VarToStr(V.Get('[' + IntToStr(i) + '].url')), Added); // Not a folder: anything "inside" it is skipped Stack.Add(''); end; end; finally Stack.Free; V.Free; end; end; // // The browsers' bookmark files: lines of // // procedure AddSource(Sources, Name, Kind, FileName); var i, N, k; begin // Each one a different name N:=SafeName(Name); k:=1; i:=0; while (i < Sources.Count) do begin if (AnsiUpperCase(Field(Sources[i], 0)) = AnsiUpperCase(N)) then begin k:=k + 1; N:=SafeName(Name) + ' (' + IntToStr(k) + ')'; i:=0; end else i:=i + 1; end; Sources.Add(N + #9 + Kind + #9 + FileName); end; // The profile name a Chromium browser shows, from its Local State file function ChromiumProfileName(UserData, Dir); var V; begin Result:=Dir; if not gFSO.FileExists(UserData + 'Local State') then Exit; try V:=JSON.parse(ReadStringFromFile(UserData + 'Local State')); try if V.Has('profile.info_cache.' + Dir + '.name') then Result:=VarToStr(V.Get('profile.info_cache.' + Dir + '.name')); finally V.Free; end; except Result:=Dir; end; end; procedure FindChromium(Sources, Browser, UserData); var Folder, Sub, SubEnum, Found; begin UserData:=IncludeTrailingPathDelimiter(ExpandEnv(UserData)); if not gFSO.FolderExists(UserData) then Exit; Found:=TStringList.Create; try // Opera keeps its Bookmarks file in the folder itself if gFSO.FileExists(UserData + 'Bookmarks') then Found.Add(''); Folder:=gFSO.GetFolder(UserData); SubEnum:=TEnumVariant.Create(Folder.SubFolders); try while SubEnum.ForEach(Sub) do if gFSO.FileExists(Sub.Path + '\Bookmarks') then Found.Add(Sub.Name); finally SubEnum.Free; end; Found.Sort; if (Found.Count = 1) then AddSource(Sources, Browser, 'C', UserData + Found[0] + '\Bookmarks') else for Sub:=0 to Found.Count - 1 do AddSource(Sources, Browser + ' - ' + ChromiumProfileName(UserData, Found[Sub]), 'C', UserData + Found[Sub] + '\Bookmarks'); finally Found.Free; end; end; procedure FindFirefox(Sources); var Dir, Folder, Sub, SubEnum, Found, i, N; begin Dir:=ExpandEnv('%APPDATA%\Mozilla\Firefox\Profiles\'); if not gFSO.FolderExists(Dir) then Exit; Found:=TStringList.Create; try Folder:=gFSO.GetFolder(Dir); SubEnum:=TEnumVariant.Create(Folder.SubFolders); try while SubEnum.ForEach(Sub) do if gFSO.FileExists(Sub.Path + '\places.sqlite') then Found.Add(Sub.Name); finally SubEnum.Free; end; Found.Sort; for i:=0 to Found.Count - 1 do begin if (Found.Count = 1) then N:='Firefox' else begin // abcd1234.default-release -> Firefox - default-release N:=Found[i]; if (Pos('.', N) > 0) then N:=Copy(N, Pos('.', N) + 1, Length(N)); N:='Firefox - ' + N; end; AddSource(Sources, N, 'F', Dir + Found[i] + '\places.sqlite'); end; finally Found.Free; end; end; procedure FindSources(Sources); var L, i, P, Name, F; begin if (UpperCase(SBVariables.GetProperty('BookmarksFind', 'Y', FALSE)) <> 'N') then begin FindChromium(Sources, 'Chrome', '%LOCALAPPDATA%\Google\Chrome\User Data'); FindChromium(Sources, 'Edge', '%LOCALAPPDATA%\Microsoft\Edge\User Data'); FindChromium(Sources, 'Brave', '%LOCALAPPDATA%\BraveSoftware\Brave-Browser\User Data'); FindChromium(Sources, 'Vivaldi', '%LOCALAPPDATA%\Vivaldi\User Data'); FindChromium(Sources, 'Opera', '%APPDATA%\Opera Software\Opera Stable'); FindFirefox(Sources); end; // Other files: Name=file;Name=file L:=TStringList.Create; try L.StrictDelimiter:=TRUE; L.Delimiter:=';'; L.DelimitedText:=SBVariables.GetProperty('BookmarksOther', '', FALSE); for i:=0 to L.Count - 1 do begin P:=Pos('=', L[i]); if (P = 0) then continue; Name:=Trim(Copy(L[i], 1, P - 1)); F:=ExpandEnv(Trim(Copy(L[i], P + 1, Length(L[i])))); if (Name = '') or (F = '') then continue; if (UpperCase(ExtractFileExt(F)) = '.SQLITE') then AddSource(Sources, Name, 'F', F) else AddSource(Sources, Name, 'C', F); end; finally L.Free; end; end; // // Read every browser's bookmarks into the index. A browser that cannot be // read stops the scan (otherwise a mirror would delete its bookmarks). // function BuildIndex; var Sources, i, VDir, Err, F; begin Result:=''; Sources:=TStringList.Create; gOutDirs:=TStringList.Create; gOut:=TStringList.Create; gUsed:=TStringList.Create; gCacheLines:=TStringList.Create; gCacheKeys:=TStringList.Create; gNewCache:=TStringList.Create; try gUsed.Sorted:=TRUE; if gFSO.FileExists(gIndex + 'dates.txt') then gCacheLines.Text:=ReadStringFromFile(gIndex + 'dates.txt'); gCacheLines.Sort; for i:=0 to gCacheLines.Count - 1 do gCacheKeys.Add(Copy(gCacheLines[i], 1, 32)); gCacheKeys.Sorted:=TRUE; SBSystem.UpdateFileStatus('Reading the bookmarks...'); FindSources(Sources); gOutDirs.Add('\'); for i:=0 to Sources.Count - 1 do begin F:=Field(Sources[i], 2); if not gFSO.FileExists(F) then begin Result:='Browser Bookmarks: the file ' + F + ' does not exist'; Exit; end; VDir:=AddFolder('\', Field(Sources[i], 0), gFSO.GetFile(F).DateCreated); if (Field(Sources[i], 1) = 'F') then Err:=ReadFirefox(F, VDir) else Err:=ReadChromium(F, VDir); if (Err <> '') then begin Result:=Err; Exit; end; end; IndexWrite; WriteStringToFile(gIndex + 'dates.txt', gNewCache.Text); finally gNewCache.Free; gCacheKeys.Free; gCacheLines.Free; gUsed.Free; gOut.Free; gOutDirs.Free; Sources.Free; end; end; //----------------------------------------------------------------------------- // Connecting //----------------------------------------------------------------------------- function LocConnect(MainThread); begin gFSO:=CreateOleObject('Scripting.FileSystemObject'); gMade:=FALSE; // One index per set of settings gIndex:=IncludeTrailingPathDelimiter(ExpandEnv('%LOCALAPPDATA%\SyncBack Bookmarks')) + SBSystem.HashString(UpperCase(SBVariables.GetProperty('BookmarksFind', 'Y', FALSE)) + '|' + SBVariables.GetProperty('BookmarksOther', '', FALSE), 'SHA1') + '\'; ForceDir(gIndex + 'dirs\'); if DirectoryExists(gIndex + 'dirs\') then Result:='' else Result:='Browser Bookmarks: cannot create its index folder ' + gIndex; end; function LocDisconnect; begin gFSO:=Unassigned; Result:=''; end; // // Called before SyncBack lists the location: read the bookmarks (once per // connection, so the Differences window does not do it again) // function LocScanPrepare; begin Result:=''; if not gMade then begin Result:=BuildIndex; gMade:=(Result = ''); end; end; function LocConnected; begin Result:=''; end; function LocReconnect; begin Result:=''; end; //----------------------------------------------------------------------------- // Reading //----------------------------------------------------------------------------- function LocDirExists(FullPath); begin if DirThere(FullPath) then Result:='' else Result:='Folder does not exist'; end; function LocFileExists(FullPath); begin if (FileLine(FullPath) <> '') then Result:='' else Result:='File does not exist'; end; function LocScanList(FullPath); var L, i, Line; begin Result:=''; L:=TStringList.Create; try if not LoadDir(NormDir(FullPath), L) then begin if not IsRoot(FullPath) then Result:='Folder does not exist'; Exit; end; for i:=0 to L.Count - 1 do begin Line:=L[i]; if (Field(Line, 0) = 'D') then begin if not SBLocation.AddDirEx2(Field(Line, 1), 16, TextToDT(Field(Line, 2)), TextToDT(Field(Line, 2)), '') then Exit; end else if (Field(Line, 0) = 'F') then begin if not SBLocation.AddFileEx(Field(Line, 1), '', StrToInt(Field(Line, 3)), 32, TextToDT(Field(Line, 4)), TextToDT(Field(Line, 4)), '') then Exit; end; end; finally L.Free; end; end; // // The .url file is written to a short temporary name first and then copied, // because CopyFile handles paths longer than 260 characters (deep bookmark // folders) and WriteStringToFile does not // function LocGet(fromFName, toFName); var Line, Temp, Err; begin Line:=FileLine(fromFName); if (Line = '') then begin Result:='File does not exist'; Exit; end; Temp:=gIndex + 'tmp' + SBSystem.UniqueID + '.url'; try WriteStringToFile(Temp, UrlFileText(Field(Line, 2))); except Result:='Cannot write ' + Temp; Exit; end; Err:=CopyFile(Temp, toFName); if gFSO.FileExists(Temp) then gFSO.DeleteFile(Temp, TRUE); if (Err = 0) then Result:='' else Result:=SysErrorMessage(Err); end; function LocGetAttributes(Filename; var Attrs); begin Result:=''; if (FileLine(Filename) <> '') then Attrs:=32 else if DirThere(Filename) then Attrs:=16 else Result:='File or folder does not exist'; end; function LocFreeSpace; begin Result:=-1; end; function LocAbilities; begin Result:=CAN_USEATTRIBUTES + CAN_HAVEEMPTYPATH; end; //----------------------------------------------------------------------------- // Writing: none of it is allowed //----------------------------------------------------------------------------- function LocMakeDir(FullPath); begin if DirThere(FullPath) then Result:='' else Result:=READ_ONLY; end; function LocRemoveDir(FullPath); begin Result:=READ_ONLY; end; function LocRenameDir(FromPath, ToPath); begin Result:=READ_ONLY; end; function LocRenameFile(FromName, ToName); begin Result:=READ_ONLY; end; function LocDeleteFile(FullPath; var DoesNotExist); begin DoesNotExist:=(FileLine(FullPath) = ''); if DoesNotExist then Result:='' else Result:=READ_ONLY; end; function LocSetModDateTime(FullPath, ModDateTime); begin Result:=READ_ONLY; end; function LocSetCreateDateTime(FullPath, CreateDateTime); begin Result:=READ_ONLY; end; function LocSetAttributes(Filename, Attrs); begin Result:=READ_ONLY; end; function LocPutEx(fromFName, toFName, fromAttrs, fromDateTime, fromCreateDateTime, fromFileSize, fromNTFSSec, DoSafeCopy; var SafeFName); begin SafeFName:=''; Result:=READ_ONLY; end; //----------------------------------------------------------------------------- // The Browser Bookmarks page in the profile setup //----------------------------------------------------------------------------- // Only in profiles that use Browser Bookmarks as their location function ConfigWantSetupNode(IsGroup); begin Result:=not IsGroup and SBProfile.UsesScript; end; function ConfigNodeCaption; begin Result:='Browser Bookmarks'; end; function ConfigCanRevert; begin Result:=TRUE; end; function ConfigCanClose; begin Result:=TRUE; end; procedure ConfigFactoryDefaults; begin SBVariables.DeleteProperty('BookmarksFind'); SBVariables.DeleteProperty('BookmarksOther'); end; procedure ConfigSetupDisplay; begin SBProfile.AddLabel('Your web browsers'' bookmarks as folders of .url files (internet shortcuts).', 20); SBProfile.AddCheckbox('Find the bookmarks of Chrome, Edge, Brave, Vivaldi, Opera and Firefox', 1); SBProfile.AddEdit('Other bookmark files, as Name=file;Name=file (a Bookmarks file, or a Firefox places.sqlite)', 4000, FALSE, FALSE, 2); end; function ConfigLoadSettings; begin Result:=''; SBProfile.SetCheckbox(UpperCase(SBVariables.GetProperty('BookmarksFind', 'Y', FALSE)) <> 'N', 1); SBProfile.SetEdit(SBVariables.GetProperty('BookmarksOther', '', FALSE), 2); end; // Store a setting in the profile. One that has never been set and is still // the default is left unset, so just looking at this page and pressing Cancel // does not count as a change to the profile. procedure SaveSetting(Name, Value, Default); begin if (SBVariables.GetProperty(Name, '!NOTSET!', FALSE) = '!NOTSET!') and (Value = Default) then Exit; SBVariables.SetProperty(Name, Value); end; function ConfigSaveSettings(Silent); var L, i, Find; begin Result:=''; L:=TStringList.Create; try L.StrictDelimiter:=TRUE; L.Delimiter:=';'; L.DelimitedText:=Trim(SBProfile.GetEdit(2)); for i:=0 to L.Count - 1 do if (Trim(L[i]) <> '') and (Pos('=', L[i]) < 2) then begin Result:='Browser Bookmarks: write each other bookmark file as Name=file, e.g. Portable Chrome=D:\Chrome\Data\Default\Bookmarks'; Exit; end; finally L.Free; end; if SBProfile.GetCheckbox(1) then Find:='Y' else Find:='N'; SaveSetting('BookmarksFind', Find, 'Y'); SaveSetting('BookmarksOther', Trim(SBProfile.GetEdit(2)), ''); end; procedure ConfigUpdateConditionals; begin end;