⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exportfavorites.pas

📁 Delphi VCL Component Pack
💻 PAS
📖 第 1 页 / 共 2 页
字号:
//***********************************************************
//                      TExportFavorites                    *
//                                                          *
//               For Delphi 5,6, 7 , 2005, 2006             *
//                     Freeware Component                   *
//                            by                            *
//                     Eran Bodankin (bsalsa)               *
//                     bsalsa@bsalsa.com                    *
//                                                          *
//           Based on idea's by:  Troels Jakobsen           *
//                                                          *
//     Documentation and updated versions:                  *
//               http://www.bsalsa.com                      *
//***********************************************************

{*******************************************************************************}
{LICENSE:
THIS SOFTWARE IS PROVIDED TO YOU "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESSED OR IMPLIED INCLUDING BUT NOT LIMITED TO THE APPLIED
WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
YOU ASSUME THE ENTIRE RISK AS TO THE ACCURACY AND THE USE OF THE SOFTWARE
AND ALL OTHER RISK ARISING OUT OF THE USE OR PERFORMANCE OF THIS SOFTWARE
AND DOCUMENTATION. [YOUR NAME] DOES NOT WARRANT THAT THE SOFTWARE IS ERROR-FREE
OR WILL OPERATE WITHOUT INTERRUPTION. THE SOFTWARE IS NOT DESIGNED, INTENDED
OR LICENSED FOR USE IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE CONTROLS,
INCLUDING WITHOUT LIMITATION, THE DESIGN, CONSTRUCTION, MAINTENANCE OR
OPERATION OF NUCLEAR FACILITIES, AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS,
AIR TRAFFIC CONTROL, AND LIFE SUPPORT OR WEAPONS SYSTEMS. VSOFT SPECIFICALLY
DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR SUCH PURPOSE.

You may use, change or modify the component under 3 conditions:
1. In your website, add a link to "http://www.bsalsa.com"
2. In your application, add credits to "Embedded Web Browser"
3. Mail me  (bsalsa@bsalsa.com) any code change in the unit
   for the benefit of the other users.
4. You may consider donation in our web site!
{*******************************************************************************}

unit ExportFavorites;
{$I EWB.inc}
interface

{$IFDEF DELPHI_6_UP}
{$WARN UNIT_PLATFORM OFF}
{$ENDIF}

uses
   Classes, dialogs, IniFiles, ShellApi, SHDocVw_EWB, ComCtrls, EmbeddedWB;

type
   PUrlRec = ^TUrlRec;
   TUrlRec = record
      Rep: string;
      UrlName: string;
      UrlPath: string;
      Level: Integer;
   end;

type
   TExportFavorite = class(TComponent)
   private
      BmkList: TStringList;
      fAbout: string;
      FavFolder: string;
      FavList: TList;
      fEnabled: Boolean;
      fExploreFavFileFolder: Boolean;
      fFavoritesPath: string;
      fNavigateOnComplete: Boolean;
      fShowSuccessMessage: Boolean;
      fStatusBar: TStatusBar;
      fSuccessMessage: TStrings;
      fTargetFileName: string;
      fTargetPath: string;
      fWebBrowser: TEmbeddedWB;
      procedure GetFavoritesFolder;
      procedure MakeBookmarkFile;
      procedure SearchURL(Folder: string; Level: Integer);
      procedure SetAbout(Value: string);
      procedure SetSuccessMessage(Value: TStrings);
      procedure TraverseFavList(Idx, PrevIdx: Integer);

   protected
      procedure MakeBookmark(UrlRec: PUrlRec);
      procedure MakeDocumentBottom;
      procedure MakeDocumentTop;
      procedure MakeHeaderBottom(UrlRec: PUrlRec);
      procedure MakeHeaderTop(UrlRec: PUrlRec);
      procedure ExportFavoritesToIni;
   public
      SuccessFlag: Boolean;
      NavigatePath: string;
      constructor Create(AOwner: TComponent); override;
      destructor Destroy; override;
      procedure ExportFavorites;

   published
      property About: string read fAbout write SetAbout;
      property Enabled: boolean read fEnabled write fEnabled default True;
      property ExploreFavFileOnComplete: Boolean read fExploreFavFileFolder write fExploreFavFileFolder default False;
      property FavoritesPath: string read fFavoritesPath write fFavoritesPath;
      property NarigateOnComplete: Boolean read fNavigateOnComplete write fNavigateOnComplete default False;
      property ShowSuccessMessage: Boolean read fShowSuccessMessage write fShowSuccessMessage default True;
      property StatusBar: TStatusBar read fStatusBar write fStatusBar;
      property SuccessMessage: TStrings read fSuccessMessage write SetSuccessMessage;
      property TargetFileName: string read FTargetFileName write fTargetFileName;
      property TargetPath: string read fTargetPath write fTargetPath;
      property WebBrowser: TEmbeddedWB read fWebBrowser write fWebBrowser;
   end;

implementation

uses
   Windows, SysUtils, Registry, Forms, IEConst;

constructor TExportFavorite.Create;
begin
   fFavoritesPath := 'Auto';
   fTargetPath := 'C:\';
   fTargetFileName := 'newbook.htm';
   fSuccessMessage := TStringList.Create;
   fSuccessMessage.Add('Your favorites have been exported successfully!');
   fSuccessMessage.Text := 'Your favorites have been exported to successfully!';
   fShowSuccessMessage := true;
   fAbout := 'TExportFavorites by bsalsa. ' + WEB_SITE;
   SuccessFlag := false;
   fEnabled := true;
   fExploreFavFileFolder := false;
   fNavigateOnComplete := false;
   inherited;
end;

destructor TExportFavorite.Destroy;
begin
   fSuccessMessage.Free;
   inherited Destroy;
end;

procedure TExportFavorite.SetSuccessMessage(Value: TStrings);
begin
   fSuccessMessage.Assign(Value)
end;

procedure TExportFavorite.GetFavoritesFolder;
var
   Registry: TRegistry;
begin
   Registry := TRegistry.Create;
   Registry.RootKey := HKEY_CURRENT_USER;
   Registry.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', False);
   FavFolder := Registry.ReadString('Favorites');
   Registry.Free;
end;

procedure TExportFavorite.SearchURL(Folder: string; Level: Integer);
var
   Found: Integer;
   SearchRec: TSearchRec;
   UrlFile: TIniFile;
   UrlRec: PUrlRec;
begin
   Found := FindFirst(Folder + '\*.*', faAnyFile, SearchRec);
   while Found = 0 do
      begin
         if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
            if (SearchRec.Attr and faDirectory > 0) then
               begin
                 {$WARNINGS OFF}
                  if not (SearchRec.Attr and faSysFile > 0) then
                     begin
                        UrlRec := New(PUrlRec);
                        UrlRec.Rep := Copy(Folder + '\' + SearchRec.Name, Length(FavFolder) + 2, Length(Folder + '\' + SearchRec.Name));
                        UrlRec.UrlName := '';
                        UrlRec.UrlPath := '';
                        UrlRec.Level := Level;
                        FavList.Add(UrlRec);
                     end;
                  SearchURL(Folder + '\' + SearchRec.Name, Level + 1); // Recursion
                {$WARNINGS ON}
               end
            else
               begin
                  if UpperCase(ExtractFileExt(SearchRec.Name)) = '.URL' then
                     begin
                        UrlRec := New(PUrlRec);
                        UrlRec.Rep := Copy(Folder, Length(FavFolder) + 2, Length(Folder));
                        UrlRec.UrlName := Copy(SearchRec.Name, 0, Length(SearchRec.Name) - 3);
                        UrlFile := TIniFile.Create(Folder + '\' + SearchRec.Name);
                        UrlRec.UrlPath := UrlFile.ReadString('InternetShortcut', 'URL', 'no path');
                        UrlRec.Level := Level;
                        UrlFile.Free;
                        FavList.Add(UrlRec);
                     end;
               end;
         Found := FindNext(SearchRec);
      end;

end;

procedure TExportFavorite.SetAbout(Value: string);
begin
   Exit;
end;

procedure TExportFavorite.TraverseFavList(Idx, PrevIdx: Integer);
var
   UrlRec, PrevUrlRec: PUrlRec;
   X: Integer;
begin
   if Idx < FavList.Count then
      begin
         UrlRec := FavList[Idx];
         if PrevIdx = -1 then
            PrevUrlRec := nil
         else
            PrevUrlRec := FavList[PrevIdx];
         if UrlRec.UrlName = '' then
            begin
               if PrevUrlRec <> nil then
                  begin
                     X := PrevUrlRec.Level;
                     while UrlRec.Level <= X do
                        begin
                           MakeHeaderBottom(PrevUrlRec);
                           Dec(PrevUrlRec.Level);
                           Dec(X);
                        end;
                  end;
               MakeHeaderTop(UrlRec);
               PrevIdx := Idx;
            end
         else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -