{
===============================================================================
  Copyright (©) 2005. Rodax Software.
===============================================================================
  Los contenidos de este fichero son propiedad de Rodax Software titular del
  copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
  en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
  acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
  bajo el que se suministra.
  -----------------------------------------------------------------------------
  Web:  www.rodax-software.com
===============================================================================
  Fecha primera versión: 17-05-2005
  Versión actual: 1.0.0
  Fecha versión actual: 17-05-2005
===============================================================================
  Modificaciones:

    Fecha         Comentarios
    ---------------------------------------------------------------------------
===============================================================================
}

unit Actualizacion;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, JvComponent, JvAppStorage,
  JvProgramVersionCheck, JvPropertyStore, JvBaseDlg, JvBrowseFolder,
  ActnList, JvFormPlacement, JvComponentBase, JvAppRegistryStorage, Buttons,
  InfoProject;

type
  TfConfiguracion = class(TForm)
    Panel2: TPanel;
    OKBtn: TButton;
    CancelBtn: TButton;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    edUsuario: TEdit;
    Label3: TLabel;
    edPassword: TEdit;
    Label4: TLabel;
    JvAppRegistryStorage1: TJvAppRegistryStorage;
    JvFormStorage1: TJvFormStorage;
    edRutaLan: TEdit;
    bDirectorio: TSpeedButton;
    rbInternet: TRadioButton;
    rbLan: TRadioButton;
    ActionList1: TActionList;
    Action1: TAction;
    Action2: TAction;
    TabSheet2: TTabSheet;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    Label5: TLabel;
    edFicheroConfig: TEdit;
    JvBrowseForFolderDialog1: TJvBrowseForFolderDialog;
    JvProgramVersionCheck1: TJvProgramVersionCheck;
    JvProgramVersionNetworkLocation1: TJvProgramVersionNetworkLocation;
    JvProgramVersionHTTPLocationIndy1: TJvProgramVersionHTTPLocationIndy;
    procedure bDirectorioClick(Sender: TObject);
    procedure Action1Update(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure OKBtnClick(Sender: TObject);
    procedure JvFormStorage1StoredValues0Save(Sender: TJvStoredValue;
      var AValue: Variant);
  private
    InfoProject : TInfoProject;
  public
    { Public declarations }
    procedure Actualizar;
    function darVersion: String;
  end;

var
  fConfiguracion: TfConfiguracion;

implementation

{$R *.dfm}

uses
  JclFileUtils;

procedure TfConfiguracion.bDirectorioClick(Sender: TObject);
begin
  if Length(edRutaLan.Text) > 0 then
    JvBrowseForFolderDialog1.Directory := edRutaLan.Text;
  JvBrowseForFolderDialog1.Execute;
  if DirectoryExists(JvBrowseForFolderDialog1.Directory) then
    edRutaLan.Text := JvBrowseForFolderDialog1.Directory + '\'
  else begin
    ShowMessage('Directorio no válido');
    bDirectorio.Click;
  end;
end;

procedure TfConfiguracion.Action1Update(Sender: TObject);
begin
  edRutaLan.Enabled := rbLan.Checked;
  bDirectorio.Enabled := rbLan.Checked;
  edUsuario.Enabled := rbInternet.Checked;
  edPassword.Enabled := rbInternet.Checked;
end;

procedure TfConfiguracion.FormActivate(Sender: TObject);
begin
  JvFormStorage1.RestoreFormPlacement;
  PageControl1.TabIndex := 0;
end;

procedure TfConfiguracion.OKBtnClick(Sender: TObject);
begin
  JvFormStorage1.SaveFormPlacement;
end;

procedure TfConfiguracion.Actualizar;
begin
  JvFormStorage1.RestoreFormPlacement;
  if rbLan.Checked then
  begin
    JvProgramVersionCheck1.LocationType := pvltNetwork;
    with JvProgramVersionNetworkLocation1 do
    begin
      VersionInfoLocationPathList.Clear;
      VersionInfoLocationPathList.Add(edRutaLan.Text);
      VersionInfoFileName := edFicheroConfig.Text;
    end;
  end
  else begin
    JvProgramVersionCheck1.LocationType := pvltHTTP;
    with JvProgramVersionHTTPLocationIndy1 do
    begin
      VersionInfoFileName := edFicheroConfig.Text;
      VersionInfoLocationPathList.Clear;
      VersionInfoLocationPathList.Add('http://www.rodax-software.com/miguelo/');
      UserName := edUsuario.Text;
      Password := edPassword.Text;
    end;
  end;

  JvProgramVersionCheck1.LocalVersionInfoFileName := 'versionlocal.ini';//edFicheroConfig.Text;
  JvProgramVersionCheck1.Execute;
end;

procedure TfConfiguracion.JvFormStorage1StoredValues0Save(
  Sender: TJvStoredValue; var AValue: Variant);
begin
  if rbInternet.Checked then
    AValue := 'INTERNET'
  else
    AValue := 'LAN';
end;

function TfConfiguracion.darVersion: String;
begin
    InfoProject := TInfoProject.Create(Self);
    Result := InfoProject.FileVersion;
    FreeAndNil(InfoProject);
end;

end.
