unit uconf;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  Tform_conf = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    e_arqmodelo: TEdit;
    e_autor: TEdit;
    Ok: TButton;
    Cancelar: TButton;
    Label6: TLabel;
    e_email: TEdit;
    Label7: TLabel;
    e_logotipo: TEdit;
    l_dirAtual: TLabel;
    procedure CancelarClick(Sender: TObject);
    procedure OkClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

procedure carregaConfigs;
procedure salvaConfigs;

var
  form_conf: Tform_conf;

implementation

uses intercapPrinc, uvars;

{$R *.dfm}

procedure carregaConfigs;
var valor, def, arqConfLocal: array [0..255] of char;
begin
    strPCopy (arqConfLocal, dirAtual+'\intercap.ini');

    GetPrivateProfileString ('INTERCAP', 'ARQMODELO', '', valor, 255, arqConfLocal);
    if strPas(valor) = '' then
        begin
            strPcopy (def, 'modelo.mdl');
            GetPrivateProfileString ('INTERCAP', 'ARQMODELO', def, valor, 255, 'intercap.ini');
        end;
    nomeModeloDefault := strPas (valor);

    GetPrivateProfileString ('INTERCAP', 'AUTOR', '', valor, 255, arqConfLocal);
    if strPas(valor) = '' then
        begin
            strPCopy (def, 'Fulano de Tal');
            getPrivateProfileString('INTERCAP', 'AUTOR', def, valor, 255, 'intercap.ini');
        end;
    nomeAutor := strPas (valor);

    GetPrivateProfileString ('INTERCAP', 'EMAIL', '', valor, 255, arqConfLocal);
    if strPas(valor) = '' then
        begin
            strPCopy (def, 'fulano@gmail.com');
            getPrivateProfileString('INTERCAP', 'EMAIL', def, valor, 255, 'intercap.ini');
        end;
    emailAutor := strPas (valor);

    GetPrivateProfileString ('INTERCAP', 'LOGOTIPO', '', valor, 255, arqConfLocal);
    if strPas(valor) = '' then
        begin
            strPCopy (def, 'logotipo.gif');
            getPrivateProfileString('INTERCAP', 'LOGOTIPO', def, valor, 255, 'intercap.ini');
        end;
    logotipoPadrao := strPas (valor);

    GetPrivateProfileString ('INTERCAP', 'DIRREMOTO', '', valor, 255, 'intercap.ini');
    dirRemoto := strPas (valor);
end;

procedure salvaConfigs;
var p, arqConfLocal: array [0..255] of char;
begin
    strPCopy (p, dirAtual);
    WritePrivateProfileString('INTERCAP', 'PASTAPADRAO', p, 'intercap.ini');

    StrPCopy(arqConfLocal, dirAtual + '\intercap.ini');

    strPCopy (p, nomeModeloDefault);
    WritePrivateProfileString('INTERCAP', 'ARQMODELO', p, 'intercap.ini');
    WritePrivateProfileString('INTERCAP', 'ARQMODELO', p, arqConfLocal);

    strPCopy (p, nomeAutor);
    WritePrivateProfileString('INTERCAP', 'AUTOR', p, 'intercap.ini');
    WritePrivateProfileString('INTERCAP', 'AUTOR', p, arqConfLocal);

    strPCopy (p, emailAutor);
    WritePrivateProfileString('INTERCAP', 'EMAIL', p, 'intercap.ini');
    WritePrivateProfileString('INTERCAP', 'EMAIL', p, arqConfLocal);

    strPCopy (p, logotipoPadrao);
    WritePrivateProfileString('INTERCAP', 'LOGOTIPO', p, 'intercap.ini');
    WritePrivateProfileString('INTERCAP', 'LOGOTIPO', p, arqConfLocal);
end;

procedure Tform_conf.FormActivate(Sender: TObject);
begin
    l_dirAtual.Caption := dirAtual;
    e_arqmodelo.text := nomeModeloDefault;
    e_autor.text := nomeAutor;
    e_email.text := emailAutor;
    e_logotipo.text := logotipoPadrao;
end;

procedure Tform_conf.OkClick(Sender: TObject);
begin
    nomeModeloDefault := e_arqmodelo.text;
    nomeAutor := e_autor.text;
    emailAutor := e_email.text;
    logotipoPadrao := e_logotipo.text;

    salvaConfigs;
    close;
end;

procedure Tform_conf.CancelarClick(Sender: TObject);
begin
    close;
end;

end.

