Code:
// remote launch a file by association
BOOL NetworkLaunchFile(SOCKADDR Client,PWCHAR FileName)
{ TCHAR ext[MAX_TYPENAME] = {0}; // file type name
TCHAR pgm[MAX_PROGRAMNAME] = {0}; // expected pgrogram
SLOT pgs; // program slot number
TYPEINFO ti; // appoved type info
// no launches in lockdown
if (ServerLocked)
{ SendDatagram(Client,RM_STOP,NULL,0);
return 0; }
// get information about the file
PathGetTypeName(FileName,ext);
if (! LoadTypeInfo(ext,&ti))
{ SendDatagram(Client,RM_STOP,NULL,0);
LogPacket(Client,FileName);
LogPacket(Client,L"File type not approved");
return 0; }
// guard against dogpiles
if (RemLaunch)
{ SendDatagram(Client,RM_BUSY,&Setting.TimeOut,sizeof(BYTE));
return 0; }
// is the program already running
_wsplitpath(ti.Program,NULL,NULL,pgm,NULL);
pgs = TrackerGetProgramSlot(pgm);
// program is not running
if ((pgs == 0) && (ServerBusy > 0)) //busy by local program
{ SendDatagram(Client,RM_BUSY,&Setting.TimeOut,sizeof(BYTE));
return 0; }
// program is running
if (pgs > 0)
{ if ((wcsicmp(Programs[pgs]->Remote,ti.Remote) != 0) ||
!Programs[pgs]->AddFiles || Setting.NoAdd )
{ SendDatagram(Client,RM_BUSY,&Setting.TimeOut,sizeof(BYTE));
return 0; } }
// launch the file
LogPacket(Client,FileName);
RemLaunch = 1;
// prepare program name
PathQuoteSpaces(ti.Program);
// complete command line
lstrcat(ti.Flags,L" ");
lstrcat(ti.Flags,FileName);
if (ShellExecute(NULL,L"Open",ti.Program,ti.Flags,NULL,SW_SHOW) < (HINSTANCE) 33)
{ SendDatagram(Client,RM_STOP,NULL,0);
AddToLog(L"Error",L"Can't launch file");
RemLaunch = 0;
return 0; }
// launch not expected
if (PgmHasRemote(pgs))
{ SendDatagram(Client,RM_NOREMOTE,NULL,0);
RemLaunch = 0;
return 1; }
// passed to client
RemOwner = Client;
SetTimer(MainWind,LaunchTimer,Setting.TimeOut * 1000,&TrackerNoLaunch);
return 1; }