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

📄 mproperties.pas

📁 自己写的一个 RSS 阅读器
💻 PAS
字号:
unit MProperties;

interface

uses
  Forms,Classes,Controls,uLanguage,uStyle;
const
  FeedOpmlFile = 'Feeds.xml';
  FavOpmlFile = 'Favorite.xml';
  SearchOpmlFile = 'Search.xml';
Const
  gUserAgents: array[0..6] Of String
    = ('RssNavigator',
       'Mozilla/4.0 (compatible; MSIE 5.5; Windows 2000)',
       'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
       'Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)',
       'Mozilla/4.79 [en] (Windows NT 5.0; U)',
       'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1',
       'Opera/6.01 (Windows 2000; U)  [en]' );
Type
  TShowPopupsMode = (POP_Always, POP_Never, POP_Ask);
  TProxyMode = (PM_Auto, PM_Never, PM_Custom);
  
  TMProperties = Class
  Private
    FAppTitle: String;
    FAppPath: string;
    FChannelDir: string;
    FFavDir:string;
    FSearchDir:string;
    FStyleDir:string;
    FConfigDir:string;
    FCurrentLanguage :string;
    FCurrentStyle:string;

    fLanguage:TLanguage;
    fStyle:TStyle;

    procedure SetCurrentLanguage(const Value:String);
    procedure SetCurrentStyle(const Value:String);
  public
    //窗体状态
    WindowTop: Integer;
    WindowLeft:Integer;
    WindowHeight: Integer;
    WindowWidth:Integer;

    HSPosition:integer;
    VSPosition:Integer;

    ToolBarStyle:Integer;

    //Browser
    EnableScript : Boolean;
    GetProxyFromIE:Boolean;
    ChangeUserAgent:Boolean;
    UserAgent:string;
    ProxyMode:TProxyMode;
    ProxyServer,ProxyUsername,ProxyPassword,ProxyByPass :string;
    ProxyPort :integer;
    IEProxyHost: string;
    IEProxyPort: integer;
    IEProxyProxyEnabled :Boolean;

    ShowPopupsMode:TShowPopupsMode;
    //Startup
    RunAtStartup :Boolean;
    StartHidden:Boolean;
    CheckMsgsOnStartup:Boolean;

    RequireExit:Boolean;
    RequireDelFeed:Boolean;

    AddressHistory:TStringList;
    //Feed
    RefreshAtStart,RefreshAfterAdded:Boolean;
    DefauleRefreshInterval:Integer;
    ShowDesktopAlter:Boolean;
    //View
    ShowPerview:Boolean;

    //search
    AutoCloseSearchWin:Boolean;

    Constructor Create(AppDir:string); virtual;
    Destructor Destroy; override;

    procedure LoadSettings;
    procedure SaveSettings;

    procedure RestoreWindowState(const Form: TForm);
    procedure SaveWindowState(const Form: TForm);
  Published
    Property CurrentLanguage:string read FCurrentLanguage write SetCurrentLanguage;
    property CurrentStyle:string read FCurrentStyle write SetCurrentStyle;
    Property AppPath: string read FAppPath;
    Property FavDir: string read FFavDir;
    property SearchDir :string read FSearchDir;
    property ChannelDir: string read FChannelDir;
    property StyleDir:string read FStyleDir;
    property ConfigDir: string read FConfigDir;
    property Language:TLanguage read fLanguage write fLanguage;
    property Style:TStyle read fStyle write fStyle;
  end;

var
  gProperties:TMProperties;
  procedure SetCaption(ACaption:string);
implementation

Uses
  Windows, shlobj, ShellAPI,uMain, SysUtils,
  Registry,TypInfo,
  IniFiles,FastStrings,uConstants;

procedure SetCaption(ACaption:string);
begin
  Application.Title := ACaption;
  Application.MainForm.Caption := ACaption;
end;
  
Constructor TMProperties.Create(AppDir:string);
var
  configDir:string;
  resStream:TResourceStream;
Begin
  Inherited Create;
  FAppTitle := 'RssNavigator';
  FAppPath:=AppDir;
  FChannelDir:=FAppPath+'Channels\';
  if not DirectoryExists(FChannelDir) then
    CreateDir(FChannelDir);

  FFavDir := FAppPath+'Favorites\';
  if not DirectoryExists(FFavDir) then
    CreateDir(FFavDir);

  FSearchDir := FAppPath+'Search\';
  if not DirectoryExists(FSearchDir) then
    CreateDir(FSearchDir);

  FConfigDir := FAppPath+'Config\';
  if not DirectoryExists(FConfigDir) then
    CreateDir(FConfigDir);

  FStyleDir := FAppPath+'Styles\';
  if not DirectoryExists(FStyleDir) then
    CreateDir(FStyleDir);

  if not FileExists(FStyleDir+'Default.xsl') then
  begin
    resStream:=TResourceStream.Create(HInstance, 'DEFAULTXSL', 'XML');
    try
      resStream.SaveToFile(FStyleDir+'Default.xsl');
    finally
      resStream.Free;
    end;
  end;


  fLanguage:=TLanguage.Create(AppDir+'Languages\');
  fLanguage.ChangeToLanguage(CurrentLanguage);
  fStyle:=TStyle.Create(AppDir+'Styles\');
  fStyle.ChangeToStyle(CurrentStyle);

  GetProxySettingsFromIE(IEProxyHost,IEProxyPort,IEProxyProxyEnabled);

  LoadSettings;
End;


Destructor TMProperties.Destroy;
Begin
  fLanguage.Free;
  Inherited Destroy;
End;

procedure TMProperties.SetCurrentLanguage(const Value: string);
begin
  FCurrentLanguage := Value;
  if fLanguage<>nil then
    fLanguage.ChangeToLanguage(Value);
end;

procedure TMProperties.SetCurrentStyle(const Value:String);
begin
  FCurrentStyle:=Value;
  if fStyle<>nil then
    fStyle.ChangeToStyle(Value);
end;

procedure TMProperties.RestoreWindowState(const Form: TForm);
var
 IniTmp: TIniFile;
 SavedWindowState: TWindowState;
begin
  IniTmp := TIniFile.Create(FConfigDir + ChangeFileExt(ExtractFileName(Application.Exename),'.ini'));

  WindowLeft := IniTmp.ReadInteger(Form.Name, 'WindowLeft', 50);
  WindowTop:= IniTmp.ReadInteger(Form.Name, 'WindowTop', 50);
  WindowWidth := IniTmp.ReadInteger(Form.Name, 'WindowWidth', 700);
  WindowHeight := IniTmp.ReadInteger(Form.Name, 'WindowHeight', 500);

  try
    SavedWindowState :=
      TWindowState(GetEnumValue(TypeInfo(TWindowState),
                   IniTmp.ReadString(Form.Name, 'WindowState', 'wsNormal')));
  except
    SavedWindowState := wsNormal;
  end;
  case SavedWindowState of
    wsMinimized:
      begin
        if (Form.WindowState <> wsNormal) then Form.WindowState := wsNormal;
        Form.SetBounds(WindowLeft, WindowTop, WindowWidth, WindowHeight);
        Form.WindowState := wsMinimized;
      end;
    wsNormal: Form.SetBounds(WindowLeft, WindowTop, WindowWidth, WindowHeight);
    wsMaximized:
      begin
        if (Form.WindowState <> wsNormal) then Form.WindowState := wsNormal;
        Form.SetBounds(WindowLeft, WindowTop, WindowWidth, WindowHeight);
        Form.WindowState := wsMaximized;
      end;
  end;
  IniTmp.Free;
end;

procedure TMProperties.SaveWindowState(const Form: TForm);
var
  WP: TWindowPlacement;
  Ini: TIniFile;
begin
  Ini := TIniFile.Create(FConfigDir + ChangeFileExt(ExtractFileName(Application.Exename),'.ini'));
  if (Form.WindowState = wsNormal) then
  begin
    WP.Length := Sizeof(WP);
    GetWindowPlacement(Form.Handle, @WP);
    Ini.WriteInteger(Form.Name, 'WindowLeft', wp.rcNormalPosition.Left);
    Ini.WriteInteger(Form.Name, 'WindowTop', wp.rcNormalPosition.Top);
    Ini.WriteInteger(Form.Name, 'WindowWidth',
                     wp.rcNormalPosition.Right-wp.rcNormalPosition.Left);
    Ini.WriteInteger(Form.Name, 'WindowHeight',
                     wp.rcNormalPosition.Bottom-wp.rcNormalPosition.Top);
  end;
  Ini.WriteString(Form.Name, 'WindowState',
                  GetEnumName(TypeInfo(TWindowState), Ord(Form.WindowState)));
  FreeAndNil(Ini);
end;

Procedure TMProperties.LoadSettings;
var
  IniFile: TIniFile;
Begin
  IniFile := TIniFile.Create(FConfigDir + ChangeFileExt(ExtractFileName(Application.Exename),'.ini'));

  HSPosition:=IniFile.ReadInteger('Window','HSPosition',160);
  VSPosition:=IniFile.ReadInteger('Window','VSPosition',170);

  ToolBarStyle:=IniFile.ReadInteger('Settings','ToolBarStyle',0);
  if (ToolBarStyle>5) or (ToolBarStyle<0) then
    ToolBarStyle:=0;
    
  
  //Language
  CurrentLanguage:=IniFile.ReadString('Settings','CurrentLanguage','English');
  if CurrentLanguage='' then
    CurrentLanguage := 'English';
    
  //XSL Style 
  CurrentStyle:=IniFile.ReadString('Settings','CurrentStyle','Default');

  //Browser
    EnableScript:=IniFile.ReadBool('Settings','EnableScript',True);
    GetProxyFromIE:=IniFile.ReadBool('Settings','GetProxyFromIE',True);
    UserAgent:=IniFile.ReadString('Settings','UserAgent','RssNavigator');
    ChangeUserAgent:=IniFile.ReadBool('Settings','ChangeUserAgent',True);
    ProxyMode:=TProxyMode(IniFile.ReadInteger('Settings','ProxyMode',Ord(PM_Auto)) );
    ProxyServer:=IniFile.ReadString('Settings','ProxyServer','');
    ProxyPort:=IniFile.ReadInteger('Settings','ProxyPort',8080);
    ProxyUsername:=IniFile.ReadString('Settings','ProxyUsername','');
    ProxyPassword:=IniFile.ReadString('Settings','ProxyPassword','');
    ProxyByPass:=IniFile.ReadString('Settings','ProxyByPass','localhost');

    ShowPopupsMode:=TShowPopupsMode( IniFile.ReadInteger('Settings','ShowPopupsMode',Ord(POP_Ask)) );
  //Startup
    RunAtStartup :=IniFile.ReadBool('Settings','RunAtStartup',false);
    StartHidden:=IniFile.ReadBool('Settings','StartHidden',false);
    CheckMsgsOnStartup:=IniFile.ReadBool('Settings','CheckMsgsOnStartup',True);
  //Require Confirmation
    RequireExit:=IniFile.ReadBool('Settings','RequireExit',True);
    RequireDelFeed:=IniFile.ReadBool('Settings','RequireDelFeed',True);
  //Feed
    RefreshAfterAdded:=IniFile.ReadBool('Settings','RefreshAfterAdded',true);
    RefreshAtStart := IniFile.ReadBool('Settings','RefreshAtStart',true);
    DefauleRefreshInterval:=IniFile.ReadInteger('Settings','DefauleRefreshInterval',5);
    ShowDesktopAlter:=IniFile.ReadBool('Settings','ShowDesktopAlter',True);
  //View
    ShowPerview:=IniFile.ReadBool('TreeList','ShowPerview',True);

  //search
    AutoCloseSearchWin := IniFile.ReadBool('Misc','AutoCloseSearchWin',True);

    AddressHistory:=SplitString(IniFile.ReadString('Settings','AddressHistory',''),';');
  IniFile.Free;
end;

Procedure TMProperties.SaveSettings;
var
  IniFile: TIniFile;
  i:Integer;
  AddressStr:string;
Begin
  IniFile := TIniFile.Create(FConfigDir + ChangeFileExt(ExtractFileName(Application.Exename),'.ini'));
    
  IniFile.WriteInteger('Window','HSPosition',HSPosition);
  IniFile.WriteInteger('Window','VSPosition',VSPosition);

  IniFile.WriteInteger('Settings','ToolBarStyle',ToolBarStyle);

  //Language
  IniFile.WriteString('Settings','CurrentLanguage',CurrentLanguage);
  IniFile.WriteString('Settings','CurrentStyle',CurrentStyle);

  //Browser
    IniFile.WriteBool('Settings','EnableScript',EnableScript);
    IniFile.WriteBool('Settings','GetProxyFromIE',GetProxyFromIE);
    IniFile.WriteInteger('Settings', 'ShowPopupsMode', Ord(ShowPopupsMode) );
    IniFile.WriteString('Settings','UserAgent',UserAgent);
    IniFile.WriteBool('Settings','ChangeUserAgent',ChangeUserAgent);
    IniFile.WriteInteger('Settings','ProxyMode',Ord(ProxyMode));
    IniFile.WriteString('Settings','ProxyServer',ProxyServer);
    IniFile.WriteInteger('Settings','ProxyPort',ProxyPort);
    IniFile.WriteString('Settings','ProxyUsername',ProxyUsername);
    IniFile.WriteString('Settings','ProxyPassword',ProxyPassword);
    IniFile.WriteString('Settings','ProxyByPass',ProxyByPass);
  //Startup
    IniFile.WriteBool('Settings','RunAtStartup',RunAtStartup);
    IniFile.WriteBool('Settings','StartHidden',StartHidden);
    IniFile.WriteBool('Settings','CheckMsgsOnStartup',CheckMsgsOnStartup);
  //Require Confirmation
    IniFile.WriteBool('Settings','RequireExit',RequireExit);
    IniFile.WriteBool('Settings','RequireDelFeed',RequireDelFeed);
  //Feed
    IniFile.WriteBool('Settings','RefreshAfterAdded',RefreshAfterAdded);
    IniFile.WriteInteger('Settings','DefauleRefreshInterval',DefauleRefreshInterval);
    IniFile.WriteBool('Settings','ShowDesktopAlter',ShowDesktopAlter);

    IniFile.WriteBool('Settings','RefreshAtStart',RefreshAtStart);
  //View
    IniFile.WriteBool('TreeList','ShowPerview',ShowPerview);

  //search
    IniFile.WriteBool('Misc','AutoCloseSearchWin',AutoCloseSearchWin);

    AddressStr:='';
    for  i:= 0 to AddressHistory.Count - 1 do    // Iterate
    begin
      if i<>AddressHistory.Count - 1 then
        AddressStr:=AddressStr+AddressHistory.Strings[i]+';'
      else
        AddressStr:=AddressStr+AddressHistory.Strings[i]
    end;    // for
    IniFile.WriteString('Settings','AddressHistory',AddressStr);
    
  IniFile.Free;
end;
end.

⌨️ 快捷键说明

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