2003-04-16 15:49:59 +00:00
|
|
|
#include <xvt.h>
|
|
|
|
|
1998-02-13 13:46:18 +00:00
|
|
|
#include <dongle.h>
|
1994-11-11 18:04:29 +00:00
|
|
|
#include <execp.h>
|
1995-03-22 09:07:04 +00:00
|
|
|
#include <prefix.h>
|
1998-12-10 16:25:48 +00:00
|
|
|
#include <recarray.h>
|
2008-10-02 15:57:06 +00:00
|
|
|
#include <user.h>
|
1997-06-06 09:00:01 +00:00
|
|
|
|
2008-07-11 11:16:52 +00:00
|
|
|
static bool is_outlook_menu_chain()
|
2008-04-04 16:04:15 +00:00
|
|
|
{
|
2009-12-24 11:36:31 +00:00
|
|
|
const TFilename n = __argv[0];
|
|
|
|
const TString& app = n.name_only();
|
2008-07-11 11:16:52 +00:00
|
|
|
if (app.match("*ba[0,1]*", true))
|
|
|
|
return false;
|
2009-12-24 11:36:31 +00:00
|
|
|
return ini_get_int(CONFIG_GUI, "Colors", "TreeView") == 3;
|
2008-04-04 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1995-05-26 10:16:03 +00:00
|
|
|
// @mfunc Esegue il processo
|
1996-02-05 19:00:53 +00:00
|
|
|
//
|
2003-04-16 15:49:59 +00:00
|
|
|
// @rdesc Ritorna il codice di uscita del processo (0 in caso di errore).
|
|
|
|
long TExternal_app::run(
|
1997-10-30 16:14:49 +00:00
|
|
|
bool async, // @parm Per eseguire il processo in parallelo
|
1998-03-05 13:54:51 +00:00
|
|
|
byte utente, // @parm Permette di inserire il nome dell'utente nella riga di comando
|
2003-04-16 15:49:59 +00:00
|
|
|
bool iconize) // @parm Iconizza il programma chiamante
|
1995-05-26 10:16:03 +00:00
|
|
|
|
|
|
|
// @comm Se <p asyn> e' FALSE aspetta che termini il processo in esecuzione prima di iniziare il nuovo
|
1994-09-22 07:48:15 +00:00
|
|
|
|
|
|
|
{
|
1997-12-17 15:10:38 +00:00
|
|
|
TFilename path(_path);
|
1997-08-18 14:11:37 +00:00
|
|
|
|
1997-12-17 15:10:38 +00:00
|
|
|
TFilename comm_name(_path);
|
2009-09-23 12:04:06 +00:00
|
|
|
int p = comm_name.find(" -"); //c'e' un - nella stringa?
|
|
|
|
if (p > 0) //se c'e' tronca il nome allo spazio
|
|
|
|
comm_name.cut(p);
|
|
|
|
p = comm_name.find(" /"); //c'e' un / nella stringa?
|
2006-12-13 16:22:33 +00:00
|
|
|
if (p > 0) //se c'e' tronca il nome allo spazio
|
1997-12-17 15:10:38 +00:00
|
|
|
comm_name.cut(p);
|
2006-12-13 16:22:33 +00:00
|
|
|
|
|
|
|
if (*comm_name.ext() == '\0') //se non c'e' estensione ci mette .exe (sono programmi)
|
|
|
|
comm_name.ext("exe");
|
|
|
|
|
|
|
|
const bool found = comm_name.custom_path(); //cerca il file in custom o in locale
|
1997-12-17 15:10:38 +00:00
|
|
|
|
|
|
|
TString name(comm_name.name());
|
2003-03-27 12:14:51 +00:00
|
|
|
if (utente == 1) // utente puo' essere 0 = No, 1 = Si, 3 = Forzatura
|
1997-08-18 14:11:37 +00:00
|
|
|
{
|
|
|
|
bool our_app = name.len() > 2;
|
|
|
|
if (our_app && atoi(name) < 70)
|
|
|
|
{
|
|
|
|
our_app = isalpha(name[0]) && isalpha(name[1]) && isdigit(name[2]);
|
|
|
|
}
|
|
|
|
if (!our_app)
|
2006-12-13 16:22:33 +00:00
|
|
|
utente = false;
|
1997-08-18 14:11:37 +00:00
|
|
|
}
|
2005-05-16 23:44:23 +00:00
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
if (found && p > 0)
|
2005-05-16 23:44:23 +00:00
|
|
|
{
|
|
|
|
path = comm_name;
|
|
|
|
path << _path.mid(p);
|
|
|
|
}
|
|
|
|
|
1995-03-22 09:07:04 +00:00
|
|
|
if (utente)
|
1995-03-27 14:36:11 +00:00
|
|
|
path << " /u" << user();
|
1994-11-30 09:04:03 +00:00
|
|
|
|
1994-09-22 07:48:15 +00:00
|
|
|
// save cwd
|
2002-02-26 16:20:19 +00:00
|
|
|
DIRECTORY oldir;
|
|
|
|
xvt_fsys_get_dir(&oldir);
|
1994-09-22 07:48:15 +00:00
|
|
|
|
2005-05-16 23:44:23 +00:00
|
|
|
if (!utente) // cambio directory se eseguo un programma estero
|
1997-06-06 09:00:01 +00:00
|
|
|
{
|
2009-09-23 12:04:06 +00:00
|
|
|
TFilename dir(comm_name.path());
|
|
|
|
dir.lower();
|
|
|
|
if (dir.full() && dir.find("custom") < 0)
|
2005-05-16 23:44:23 +00:00
|
|
|
{
|
|
|
|
DIRECTORY d;
|
2008-10-02 15:57:06 +00:00
|
|
|
if (xvt_fsys_convert_str_to_dir(dir, &d))
|
2005-05-16 23:44:23 +00:00
|
|
|
xvt_fsys_set_dir(&d);
|
|
|
|
}
|
|
|
|
}
|
1997-08-18 14:11:37 +00:00
|
|
|
|
2008-07-11 11:16:52 +00:00
|
|
|
TString256 old_title; // Vecchio titolo della finestra principale
|
|
|
|
bool close_all = false; // Chiudi tutti i file in caso di manutenzione
|
|
|
|
|
1998-03-30 13:39:21 +00:00
|
|
|
if (!async)
|
2003-04-16 15:49:59 +00:00
|
|
|
{
|
2008-07-11 11:16:52 +00:00
|
|
|
close_all = _path.starts_with("ba1 -0") && prefix_valid();
|
2007-09-17 15:33:04 +00:00
|
|
|
if (close_all) //se lancia la gestione archivi forza la chiusura dei files e pure dei tracciati!
|
|
|
|
prefix().set("");
|
|
|
|
else
|
|
|
|
safely_close_closeable_isamfiles();
|
|
|
|
|
2003-04-16 15:49:59 +00:00
|
|
|
if (dongle().local())
|
|
|
|
dongle().logout();
|
2008-04-04 16:04:15 +00:00
|
|
|
|
2008-07-11 11:16:52 +00:00
|
|
|
// Programma normale (non menu) che chiama "collega"
|
|
|
|
if (utente && iconize && is_outlook_menu_chain())
|
2008-04-04 16:04:15 +00:00
|
|
|
{
|
|
|
|
xvt_vobj_get_title(TASK_WIN, old_title.get_buffer(), old_title.size());
|
|
|
|
xvt_vobj_set_title(TASK_WIN, __MAGIC_CAPTION__);
|
|
|
|
iconize = false;
|
|
|
|
}
|
2003-04-16 15:49:59 +00:00
|
|
|
}
|
1998-03-30 13:39:21 +00:00
|
|
|
|
2003-04-16 15:49:59 +00:00
|
|
|
_exitcode = xvt_sys_execute(path, !async, iconize);
|
2008-04-04 16:04:15 +00:00
|
|
|
|
|
|
|
if (old_title.full()) // Rimetto le cose a posto
|
|
|
|
xvt_vobj_set_title(TASK_WIN, old_title);
|
2002-02-26 16:20:19 +00:00
|
|
|
|
1994-09-22 07:48:15 +00:00
|
|
|
// restore cwd
|
2002-02-26 16:20:19 +00:00
|
|
|
xvt_fsys_set_dir(&oldir);
|
1994-09-22 07:48:15 +00:00
|
|
|
|
1996-05-31 13:05:55 +00:00
|
|
|
// Ignora volutamente il return code da HL_LOGIN(). Se va bene riprende il posto
|
|
|
|
// altrimenti fa lo stesso. Infatti puo' capitare con una chiave di rete, che
|
|
|
|
// nel lasso di tempo trascorso dalla HL_LOGOUT() dell'applicazione chiamata,
|
|
|
|
// a questa HL_LOGIN() [approssimativamente qualche decimo di secondo], qualche altro
|
|
|
|
// programma si inserisca, occupando magari anche l'ultimo posto disponibile.
|
|
|
|
// Quindi se si verificasse tale sfigatissima condizione, sicuramente
|
|
|
|
// non ci saranno piu' posti liberi nell'HL_server: il programma comunque non
|
|
|
|
// puo' interrompersi a meta'; ecco perche il valore di ritorno di HL_LOGIN viene
|
|
|
|
// ignorato.
|
2007-09-17 15:33:04 +00:00
|
|
|
if (!async)
|
|
|
|
{
|
|
|
|
if (dongle().local())
|
|
|
|
dongle().login();
|
|
|
|
|
|
|
|
if (close_all) //se lancia la gestione archivi forza la riapertura dei files e pure dei tracciati!
|
|
|
|
prefix().set("DEF"); //..li aveva chiusi qualche riga sopra
|
|
|
|
}
|
1998-02-24 10:37:28 +00:00
|
|
|
|
1994-09-22 07:48:15 +00:00
|
|
|
return _exitcode;
|
|
|
|
}
|
|
|
|
|
1998-12-10 16:25:48 +00:00
|
|
|
bool TExternal_app::can_run() const
|
1999-05-24 13:34:11 +00:00
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
if (*prefix().name() <= '.')
|
1999-05-24 13:34:11 +00:00
|
|
|
return TRUE;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
const TLocalisamfile test(LF_USER);
|
2008-10-02 15:57:06 +00:00
|
|
|
if (test.curr().exist(USR_PERMISSION))
|
1998-12-10 16:25:48 +00:00
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
TRecord_cache utonti(LF_USER); // Non uso cache() per problemi durante conversioni
|
|
|
|
TToken_string perm(4096, '\n'), row(80,SAFE_PIPE_CHR);
|
2008-10-02 15:57:06 +00:00
|
|
|
for (TString16 u = user(); u.not_empty(); u = utonti.get(u, USR_GROUPNAME))
|
1998-12-10 16:25:48 +00:00
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
if (utonti.already_loaded(u))
|
|
|
|
{
|
|
|
|
NFCHECK("L'utente %s ha dei permessi ricorsivi", (const char*)u);
|
|
|
|
break;
|
|
|
|
}
|
2008-10-02 15:57:06 +00:00
|
|
|
perm = utonti.get(u, USR_PERMISSION);
|
1999-10-22 10:00:18 +00:00
|
|
|
if (!perm.blank())
|
1998-12-10 16:25:48 +00:00
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
FOR_EACH_TOKEN(perm, tok)
|
1998-12-10 16:25:48 +00:00
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
row = tok;
|
|
|
|
if (_path == row.get(0)) // Il nome corrisponde
|
|
|
|
{
|
|
|
|
if (*row.get(1) == 'N')
|
|
|
|
return FALSE;
|
|
|
|
}
|
1998-12-10 16:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
1999-10-22 10:00:18 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-10 16:25:48 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1994-09-22 07:48:15 +00:00
|
|
|
TExternal_app::TExternal_app(const char* p)
|
1998-03-13 10:25:37 +00:00
|
|
|
: _path(p), _exitcode(0)
|
1994-09-22 07:48:15 +00:00
|
|
|
{
|
|
|
|
}
|
1997-09-19 08:47:46 +00:00
|
|
|
|