1994-09-19 09:50:07 +00:00
|
|
|
|
#ifndef __CONFIG_H
|
1995-01-02 09:33:00 +00:00
|
|
|
|
#define __CONFIG_H
|
|
|
|
|
|
1994-09-19 09:50:07 +00:00
|
|
|
|
#ifndef __ASSOC_H
|
|
|
|
|
#include <assoc.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
1998-11-03 10:27:35 +00:00
|
|
|
|
class TConfig;
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
2009-05-20 15:36:38 +00:00
|
|
|
|
// file lista moduli installati (install.ini)
|
1994-09-27 10:07:50 +00:00
|
|
|
|
#define CONFIG_GENERAL 0
|
2005-03-03 15:42:04 +00:00
|
|
|
|
// file campo.ini
|
1998-01-09 09:53:03 +00:00
|
|
|
|
#define CONFIG_INSTALL 1
|
1994-09-19 09:50:07 +00:00
|
|
|
|
// file parametri studio (uno per studio, per ora e' il principale)
|
1998-01-09 09:53:03 +00:00
|
|
|
|
#define CONFIG_STUDIO 2
|
1994-09-19 09:50:07 +00:00
|
|
|
|
// file parametri ditta (uno per ditta)
|
1998-01-09 09:53:03 +00:00
|
|
|
|
#define CONFIG_DITTA 3
|
1994-09-27 10:07:50 +00:00
|
|
|
|
// file conversioni archivi
|
1998-01-09 09:53:03 +00:00
|
|
|
|
#define CONFIG_FCONV 4
|
1995-02-28 10:25:02 +00:00
|
|
|
|
// file parametri utente
|
1998-01-09 09:53:03 +00:00
|
|
|
|
#define CONFIG_USER 5
|
1995-05-12 09:24:47 +00:00
|
|
|
|
// file parametri stampe
|
1998-01-09 09:53:03 +00:00
|
|
|
|
#define CONFIG_STAMPE 6
|
2003-10-14 13:42:54 +00:00
|
|
|
|
// file parametri GUI (nel senso di Graphic User Interface)
|
|
|
|
|
#define CONFIG_GUI 7
|
2006-12-13 16:22:33 +00:00
|
|
|
|
// file parametri workstation
|
|
|
|
|
#define CONFIG_WST 8
|
2009-01-12 15:24:09 +00:00
|
|
|
|
// file parametri OEM (setup/oem.ini)
|
|
|
|
|
#define CONFIG_OEM 9
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
1998-11-04 18:04:26 +00:00
|
|
|
|
// Callback per for_each_paragraph
|
1998-11-03 10:27:35 +00:00
|
|
|
|
typedef int (*CONFIG_CALLBACK)(TConfig& cfg, void* jolly);
|
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
|
// @doc EXTERNAL
|
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @class TConfig | Classe per la gestione dei file di configurazione in formato
|
|
|
|
|
// Windows
|
|
|
|
|
//
|
|
|
|
|
// @base public | TObject
|
1994-09-19 09:50:07 +00:00
|
|
|
|
class TConfig : public TObject
|
1996-02-05 19:00:53 +00:00
|
|
|
|
|
|
|
|
|
// @author:(INTERNAL) Villa
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @comm Sono definite alcune costanti per l'individuazione immediata di
|
|
|
|
|
// alcuni file particolari e di frequente uso. Tali file sono:
|
|
|
|
|
//
|
|
|
|
|
// @flag CONFIG_GENERAL | Questo sara' il principale, per ora non c'e'
|
|
|
|
|
// @flag CONFIG_STUDIO | File parametri studio (uno per studio, per ora e'
|
|
|
|
|
// il principale)
|
|
|
|
|
// @flag CONFIG_DITTA | File parametri ditta (uno per ditta)
|
|
|
|
|
// @flag CONFIG_FCONV | File conversioni archivi
|
|
|
|
|
// @flag CONFIG_USER | File parametri utente
|
|
|
|
|
// @flag CONFIG_STAMPE | File parametri stampe
|
|
|
|
|
// @flag CONFIG_GOLEM | File parametri golem
|
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
|
// @access:(INTERNAL) Private Member
|
|
|
|
|
{
|
|
|
|
|
// @cmember:(INTERNAL) Contenuto del paragrafo
|
1995-05-26 10:16:03 +00:00
|
|
|
|
TAssoc_array _data;
|
1996-02-05 19:00:53 +00:00
|
|
|
|
// @cmember:(INTERNAL) Nome del file di configurazione
|
1995-05-26 10:16:03 +00:00
|
|
|
|
TFilename _file;
|
1996-02-05 19:00:53 +00:00
|
|
|
|
// @cmember:(INTERNAL) Indica se il paragrafo e' stato modificato (TRUE se esiste)
|
1995-05-26 10:16:03 +00:00
|
|
|
|
bool _dirty;
|
1998-01-26 10:29:26 +00:00
|
|
|
|
// @cmember:(INTERNAL) Indica se proteggere il TConfig da scrittura
|
|
|
|
|
bool _write_protected;
|
1996-02-05 19:00:53 +00:00
|
|
|
|
// @cmember:(INTERNAL) Indica se il paragrafo e' presente (TRUE se esiste)
|
1995-05-26 10:16:03 +00:00
|
|
|
|
bool _ispresent;
|
1996-02-05 19:00:53 +00:00
|
|
|
|
// @cmember:(INTERNAL) Nome del paragrafo attivo
|
1995-05-26 10:16:03 +00:00
|
|
|
|
TString _paragraph;
|
|
|
|
|
|
|
|
|
|
// @access Protected Member
|
1995-05-16 09:35:12 +00:00
|
|
|
|
protected:
|
1998-11-04 18:04:26 +00:00
|
|
|
|
// @cmember Legge una riga del paragrafo
|
|
|
|
|
bool add_line(const TString& line);
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Legge i dati del paragrafo
|
1994-09-19 09:50:07 +00:00
|
|
|
|
bool _read_paragraph();
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Scrive i dati del paragrafo
|
1994-09-19 09:50:07 +00:00
|
|
|
|
void _write_paragraph(ofstream&);
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Scrive il file di configurazione
|
1994-09-19 09:50:07 +00:00
|
|
|
|
void _write_file();
|
1996-09-05 09:54:52 +00:00
|
|
|
|
// @cmember Inizializza il paragrafo leggendo dal file di nome <p fn > i dati
|
2003-10-17 08:20:13 +00:00
|
|
|
|
void init(const char *fn, const char* pa);
|
2004-02-03 14:20:36 +00:00
|
|
|
|
|
|
|
|
|
const char* get_varkey(const char* var, int index) const;
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @access Public Memeber
|
1994-09-22 16:47:50 +00:00
|
|
|
|
public:
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Ritorna il valore della variabile nella sezione corrente o in
|
|
|
|
|
// quella specificata
|
2005-03-16 13:15:10 +00:00
|
|
|
|
virtual const TString& get(const char* var, const char* section = NULL, int index = -1, const char* def = "");
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Ritorna il valore della variabile nella sezione corrente o in
|
|
|
|
|
// quella specificata (se la variabile contiene un long)
|
1995-01-02 09:33:00 +00:00
|
|
|
|
long get_long(const char* var, const char* section = NULL, int index = -1, long def = 0L);
|
1995-01-24 08:52:49 +00:00
|
|
|
|
|
1995-11-22 13:40:15 +00:00
|
|
|
|
// @cmember Ritorna il valore della variabile nella sezione corrente o in
|
|
|
|
|
// quella specificata (se la variabile contiene un long)
|
|
|
|
|
char get_char(const char* var, const char* section = NULL, int index = -1, char def = ' ' );
|
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Ritorna il valore della variabile nella sezione corrente o in
|
|
|
|
|
// quella specificata (se la variabile contiene un int)
|
1995-01-24 08:52:49 +00:00
|
|
|
|
int get_int(const char* var, const char* section = NULL, int index = -1, int def = 0);
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Ritorna il valore della variabile nella sezione corrente o in
|
|
|
|
|
// quella specificata (se la variabile contiene un bool)
|
1995-01-02 09:33:00 +00:00
|
|
|
|
bool get_bool(const char* var, const char* section = NULL, int index = -1, bool def = FALSE);
|
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Ritorna il valore del colore settato nella variabile nella
|
1998-01-28 08:21:11 +00:00
|
|
|
|
// sezione corrente o in quella specificata (COLOR = unsigned long)
|
|
|
|
|
unsigned long get_color(const char* var, const char* section = NULL, int index = -1, unsigned long def = 0);
|
1996-11-12 14:53:09 +00:00
|
|
|
|
|
|
|
|
|
// @cmember Setta il colore nella sezione corrente o specificata
|
1998-01-28 08:21:11 +00:00
|
|
|
|
bool set_color(const char* var, unsigned long col, const char* section = NULL, bool force = TRUE, int index = -1);
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Setta la variabile nella sezione corrente o specificata
|
|
|
|
|
bool set(const char* var, const char* value, const char* section = NULL, bool force = TRUE, int index = -1);
|
|
|
|
|
// @cmember Setta la variabile nella sezione corrente o specificata
|
|
|
|
|
bool set(const char* var, long value, const char* section = NULL, bool force = TRUE, int index = -1);
|
1994-10-26 12:23:12 +00:00
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Controlla se esite una variabile nel paragrafo attivo
|
1994-10-26 12:23:12 +00:00
|
|
|
|
bool exist(const char* var, int index = -1);
|
2010-10-10 22:40:02 +00:00
|
|
|
|
// @cmember Controlla se esite una variabile nel paragrafo section
|
|
|
|
|
bool exist(const char* var, const char * section, int index = -1);
|
1996-11-12 14:53:09 +00:00
|
|
|
|
|
|
|
|
|
// @cmember Elimina una variabile nel paragrafo attivo
|
|
|
|
|
bool remove(const char* var, int index = -1);
|
1997-11-10 13:46:38 +00:00
|
|
|
|
|
|
|
|
|
// @cmember Elimina tutte le variabili nel paragrafo attivo
|
|
|
|
|
void remove_all();
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Controlla se il paragrafo corrente e' nuovo (TRUE se nuovo)
|
2002-09-13 14:06:05 +00:00
|
|
|
|
bool new_paragraph() const
|
1995-05-26 10:16:03 +00:00
|
|
|
|
{ return !_ispresent; }
|
1994-09-19 09:50:07 +00:00
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Ritorna quanti elementi dell'array nominato sono presenti nella
|
|
|
|
|
// sezione indicata.
|
1994-09-19 09:50:07 +00:00
|
|
|
|
word items(const char* var, const char* section);
|
1997-03-28 12:07:58 +00:00
|
|
|
|
|
|
|
|
|
// @cmember Ritorna il nome del paragrafo attivo
|
|
|
|
|
const TString& get_paragraph() const { return _paragraph; }
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Setta il paragrafo passato come quello attivo
|
1997-03-28 12:07:58 +00:00
|
|
|
|
bool set_paragraph(const char* par);
|
1995-05-16 09:35:12 +00:00
|
|
|
|
|
1995-06-28 16:35:30 +00:00
|
|
|
|
// @cmember Riempie pl con la lista dei paragrafi
|
|
|
|
|
int list_paragraphs(TString_array& pl);
|
1995-11-14 10:28:24 +00:00
|
|
|
|
|
1995-12-29 12:09:48 +00:00
|
|
|
|
// @cmember Riempie <p vl> con la lista dei nomi delle variabili
|
1995-11-14 10:28:24 +00:00
|
|
|
|
// nella sezione corrente o in quella indicata; se
|
1995-12-29 12:09:48 +00:00
|
|
|
|
// add_value e' TRUE ci mette "variabile<pipe>valore"
|
1998-04-30 15:31:34 +00:00
|
|
|
|
// se sort=TRUE, l'array <20> ordinato per nomevar(i), altrimenti <20> in ordine HASH
|
|
|
|
|
int list_variables(TString_array& vl, bool add_value = FALSE, const char* section = NULL, const bool sort=FALSE);
|
1998-11-03 10:27:35 +00:00
|
|
|
|
|
1996-06-18 13:33:27 +00:00
|
|
|
|
// @cmember Ritorna l'intero array delle variabili della sezione
|
|
|
|
|
// eventualmente specificata da <p section>
|
1997-12-17 10:40:18 +00:00
|
|
|
|
TAssoc_array& list_variables(const char* section = NULL);
|
1995-11-14 10:28:24 +00:00
|
|
|
|
|
2001-06-25 10:41:20 +00:00
|
|
|
|
// @cmember Chiama cfgcb per ogni paragrafo
|
1998-11-04 18:04:26 +00:00
|
|
|
|
int for_each_paragraph(CONFIG_CALLBACK cfgcb, void* jolly);
|
|
|
|
|
|
1996-08-21 10:38:27 +00:00
|
|
|
|
// @cmember Ritorna il nome del file di configurazione
|
1996-09-12 13:06:32 +00:00
|
|
|
|
const TFilename& name() const { return _file; }
|
1998-01-26 10:29:26 +00:00
|
|
|
|
|
|
|
|
|
// @cmember Setta il valore del flag di protezione da scrittura
|
|
|
|
|
void write_protect(const bool b = TRUE) { _write_protected = b; }
|
|
|
|
|
|
|
|
|
|
// @cmember Ritorna il valore del flag di protezione da scrittura
|
|
|
|
|
const bool is_write_protected() const { return _write_protected; }
|
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Costruttore (il paragrafo iniziale e' il modulo corrente
|
|
|
|
|
// salvo diversa indicazione)
|
2009-05-20 15:36:38 +00:00
|
|
|
|
TConfig(int which_config, const char* paragraph = NULL);
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @cmember Costruttore (il paragrafo iniziale e' il modulo corrente
|
|
|
|
|
// salvo diversa indicazione)
|
1994-09-22 16:47:50 +00:00
|
|
|
|
TConfig(const char* file, const char* paragraph = NULL);
|
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
|
// @ cmember Distruttore. Riscrive il file con le modifiche se necessrio,
|
1994-09-19 09:50:07 +00:00
|
|
|
|
virtual ~TConfig();
|
|
|
|
|
};
|
|
|
|
|
|
2009-03-17 11:02:30 +00:00
|
|
|
|
// Low level utilities
|
2009-05-15 09:19:11 +00:00
|
|
|
|
bool ini_get_bool (const char* file, const char* para, const char* name, bool defval = false, int idx = -1);
|
2009-03-17 11:02:30 +00:00
|
|
|
|
int ini_get_int (const char* file, const char* para, const char* name, int defval = 0, int idx = -1);
|
|
|
|
|
const TString& ini_get_string(const char* file, const char* para, const char* name, const char* defval = "", int idx = -1);
|
2009-07-15 15:10:28 +00:00
|
|
|
|
bool ini_set_bool (const char* file, const char* para, const char* name, bool val, int idx = -1);
|
2009-03-17 11:02:30 +00:00
|
|
|
|
bool ini_set_int (const char* file, const char* para, const char* name, int val, int idx = -1);
|
|
|
|
|
bool ini_set_string(const char* file, const char* para, const char* name, const char* val, int idx = -1);
|
|
|
|
|
|
|
|
|
|
// High level utilities
|
2009-05-15 09:19:11 +00:00
|
|
|
|
bool ini_get_bool (int cfg, const char* para, const char* name, bool defval = false, int idx = -1);
|
2009-03-17 11:02:30 +00:00
|
|
|
|
int ini_get_int (int cfg, const char* para, const char* name, int defval = 0, int idx = -1);
|
|
|
|
|
const TString& ini_get_string(int cfg, const char* para, const char* name, const char* defval = "", int idx = -1);
|
2009-07-15 15:10:28 +00:00
|
|
|
|
bool ini_set_bool (int cfg, const char* para, const char* name, bool val, int idx = -1);
|
2009-03-17 11:02:30 +00:00
|
|
|
|
bool ini_set_int (int cfg, const char* para, const char* name, int val, int idx = -1);
|
|
|
|
|
bool ini_set_string(int cfg, const char* para, const char* name, const char* val, int idx = -1);
|
|
|
|
|
|
2010-03-02 11:23:20 +00:00
|
|
|
|
const TString& get_oem_info(const char* varname, const char* defval = ""); // ini_get_string(CONFIG_OEM, "OEM_?", varname, defval);
|
2009-10-20 15:22:22 +00:00
|
|
|
|
bool is_aga_version(bool power_user_only = false);
|
2009-01-19 17:47:32 +00:00
|
|
|
|
|
1994-09-19 09:50:07 +00:00
|
|
|
|
#endif
|