; Simese bundled with a media package script ; Copyright (C) 2005/8 Mattic BV ; ; This program is free software; you can redistribute it and/or ; modify it under the terms of the GNU General Public License ; as published by the Free Software Foundation; either version 2 ; of the License, or (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ; ; ;#define OSC ;#define Oxyl ;#define SwissCenter #define Simese #dim VersionInfo[4]; #define MyAppVersionNo ParseVersion("M:\Tools\Utils\Simese\Simese.exe", VersionInfo[0], VersionInfo[1], VersionInfo[2], VersionInfo[3]) #define APP_VERSION Str(VersionInfo[0]) + "." + Str(VersionInfo[1])+ "." + Str(VersionInfo[2]) [Setup] AppName=Simple Media Server #ifdef Simese AppVerName=Simese {#APP_VERSION} #endif #ifdef OSC AppVerName=Simese {#APP_VERSION} (OpenShowCenter) #endif #ifdef Oxyl AppVerName=Simese {#APP_VERSION} (Oxyl~Box) #endif #ifdef SwissCenter AppVerName=Simese {#APP_VERSION} (SwissCenter) #endif AppPublisher=Mattic Software AppPublisherURL=http://www.matdev.com/simese.html AppSupportURL=http://www.matdev.com/simese.html AppUpdatesURL=http://www.matdev.com/simese.html DefaultDirName={pf}\Simese DefaultGroupName=Simple Media Server AllowNoIcons=true VersionInfoVersion={# MyAppVersionNo} OutputDir=M:\Tools\Utils\Simese\Install #ifdef Simese OutputBaseFilename=Simese-{# APP_VERSION} #endif #ifdef OSC OutputBaseFilename=Simese_OSC-{# APP_VERSION} #endif #ifdef Oxyl OutputBaseFilename=Simese_Oxyl-{# APP_VERSION} #endif #ifdef SwissCenter OutputBaseFilename=Simese_SwissCenter-{# APP_VERSION} #endif AppID={{FD525209-216F-4C25-A9E3-8122273CB42A}} ShowLanguageDialog=yes InternalCompressLevel=normal AppMutex=SimeseServer Compression=lzma SolidCompression=true [Tasks] Name: InstallService; Description: Start Simese on computer startup (running as a service); GroupDescription: Startup; MinVersion: 0,4.0.1381; Flags: exclusive Name: AddToStartup; Description: Start Simese after logging in (running as a program); GroupDescription: Startup; Flags: exclusive unchecked Name: StartManual; Description: Start Simese manually; GroupDescription: Startup; Flags: exclusive unchecked [Files] Source: ..\Simese.exe; DestDir: {app}; Flags: ignoreversion #ifndef Simese Source: M:\Tools\Utils\Simese\Install Files\Php\*.*; DestDir: {commonappdata}\Simese\Php; Flags: ignoreversion recursesubdirs Source: M:\Tools\Utils\Simese\Install\Readme Media Packages.txt; DestDir: {app}; Flags: ignoreversion #endif Source: M:\Tools\Utils\Simese\Install\Readme Simese.txt; DestDir: {app}; Flags: ignoreversion Source: M:\Tools\\Utils\Simese\Install\History.txt; DestDir: {app}; Flags: ignoreversion #ifdef Simese Source: ..\Install files\Simese\Simese.ini; DestDir: {commonappdata}\Simese #endif #ifdef OSC Source: ..\Install files\OpenShowCenter\Simese.ini; DestDir: {commonappdata}\Simese Source: ..\Install files\OpenShowCenter\Data\*.*; DestDir: {commonappdata}\Simese\Data; Flags: ignoreversion recursesubdirs #endif #ifdef Oxyl Source: ..\Install files\Oxylbox\Simese.ini; DestDir: {commonappdata}\Simese Source: ..\Install files\oxylbox\Data\*.*; DestDir: {commonappdata}\Simese\Data; Flags: ignoreversion recursesubdirs #endif #ifdef SwissCenter Source: ..\Install files\SwissCenter\Simese.ini; DestDir: {commonappdata}\Simese Source: ..\Install files\SwissCenter\Data\*.*; DestDir: {commonappdata}\Simese\Data; Flags: ignoreversion recursesubdirs Source: ..\Install files\SwissCenter\MySQL\Bin\*.*; DestDir: {app}\MySQL; Flags: ignoreversion recursesubdirs Source: ..\Install files\SwissCenter\MySQL\Data\*.*; DestDir: {commonappdata}\Simese\MySQL; Flags: ignoreversion recursesubdirs #endif [Dirs] Name: {commonappdata}\Simese\Data #ifdef Simese #endif #ifdef OSC #endif #ifdef Oxyl #endif #ifdef SwissCenter Name: {commonappdata}\Simese\Data\log #endif [Icons] Name: {group}\Simple Media Server; Filename: {app}\Simese.exe; IconIndex: 0 Name: {group}\ReadMe; Filename: {app}\Readme Simese.txt #ifndef Simese Name: {group}\ReadMe Media Package; Filename: {app}\Readme Media Packages.txt #endif Name: {group}\Uninstall Simple Media Server; Filename: {uninstallexe} Name: {commonstartup}\Simple Media Server; Filename: {app}\Simese.exe; IconIndex: 0; Tasks: AddToStartup; Parameters: /minimize [Run] Filename: {app}\Simese.exe; Flags: postinstall nowait; Description: Start the Simple Media Server; Tasks: Filename: {app}\Simese.exe; Parameters: /install /silent; Description: Install Simese as a service; StatusMsg: Please wait while the Simese Service is installed; Tasks: InstallService [_ISTool] Use7zip=false OutputExeFilename=M:\Utils\Simese\Install\Simese_OSC.exe EnableISX=true [UninstallDelete] Name: {commonappdata}\Simese\Data\*.*; Type: filesandordirs Name: {commonappdata}\Simese\Php; Type: filesandordirs Name: {commonappdata}\Simese\MySQL\*.*; Type: filesandordirs [Code] type SERVICE_STATUS = record dwServiceType : cardinal; dwCurrentState : cardinal; dwControlsAccepted : cardinal; dwWin32ExitCode : cardinal; dwServiceSpecificExitCode : cardinal; dwCheckPoint : cardinal; dwWaitHint : cardinal; end; HANDLE = cardinal; const SERVICE_QUERY_CONFIG = $1; SERVICE_CHANGE_CONFIG = $2; SERVICE_QUERY_STATUS = $4; SERVICE_START = $10; SERVICE_STOP = $20; SERVICE_ALL_ACCESS = $f01ff; SC_MANAGER_ALL_ACCESS = $f003f; SERVICE_WIN32_OWN_PROCESS = $10; SERVICE_WIN32_SHARE_PROCESS = $20; SERVICE_WIN32 = $30; SERVICE_INTERACTIVE_PROCESS = $100; SERVICE_BOOT_START = $0; SERVICE_SYSTEM_START = $1; SERVICE_AUTO_START = $2; SERVICE_DEMAND_START = $3; SERVICE_DISABLED = $4; SERVICE_DELETE = $10000; SERVICE_CONTROL_STOP = $1; SERVICE_CONTROL_PAUSE = $2; SERVICE_CONTROL_CONTINUE = $3; SERVICE_CONTROL_INTERROGATE = $4; SERVICE_STOPPED = $1; SERVICE_START_PENDING = $2; SERVICE_STOP_PENDING = $3; SERVICE_RUNNING = $4; SERVICE_CONTINUE_PENDING = $5; SERVICE_PAUSE_PENDING = $6; SERVICE_PAUSED = $7; // ####################################################################################### // nt based service utilities // ####################################################################################### function OpenSCManager(lpMachineName, lpDatabaseName: string; dwDesiredAccess :cardinal): HANDLE; external 'OpenSCManagerA@advapi32.dll stdcall'; function OpenService(hSCManager :HANDLE;lpServiceName: string; dwDesiredAccess :cardinal): HANDLE; external 'OpenServiceA@advapi32.dll stdcall'; function CloseServiceHandle(hSCObject :HANDLE): boolean; external 'CloseServiceHandle@advapi32.dll stdcall'; function CreateService(hSCManager :HANDLE;lpServiceName, lpDisplayName: string;dwDesiredAccess,dwServiceType,dwStartType,dwErrorControl: cardinal;lpBinaryPathName,lpLoadOrderGroup: String; lpdwTagId : cardinal;lpDependencies,lpServiceStartName,lpPassword :string): cardinal; external 'CreateServiceA@advapi32.dll stdcall'; function DeleteService(hService :HANDLE): boolean; external 'DeleteService@advapi32.dll stdcall'; function StartNTService(hService :HANDLE;dwNumServiceArgs : cardinal;lpServiceArgVectors : cardinal) : boolean; external 'StartServiceA@advapi32.dll stdcall'; function ControlService(hService :HANDLE; dwControl :cardinal;var ServiceStatus :SERVICE_STATUS) : boolean; external 'ControlService@advapi32.dll stdcall'; function QueryServiceStatus(hService :HANDLE;var ServiceStatus :SERVICE_STATUS) : boolean; external 'QueryServiceStatus@advapi32.dll stdcall'; function QueryServiceStatusEx(hService :HANDLE;ServiceStatus :SERVICE_STATUS) : boolean; external 'QueryServiceStatus@advapi32.dll stdcall'; function OpenServiceManager() : HANDLE; begin if UsingWinNT() = true then begin Result := OpenSCManager('','ServicesActive',SC_MANAGER_ALL_ACCESS); if Result = 0 then MsgBox('the servicemanager is not available', mbError, MB_OK) end else begin MsgBox('only nt based systems support services', mbError, MB_OK) Result := 0; end end; function IsServiceInstalled(ServiceName: string) : boolean; var hSCM : HANDLE; hService: HANDLE; begin hSCM := OpenServiceManager(); Result := false; if hSCM <> 0 then begin hService := OpenService(hSCM,ServiceName,SERVICE_QUERY_CONFIG); if hService <> 0 then begin Result := true; CloseServiceHandle(hService) end; CloseServiceHandle(hSCM) end end; function InstallService(FileName, ServiceName, DisplayName, Description : string;ServiceType,StartType :cardinal) : boolean; var hSCM : HANDLE; hService: HANDLE; begin hSCM := OpenServiceManager(); Result := false; if hSCM <> 0 then begin hService := CreateService(hSCM,ServiceName,DisplayName,SERVICE_ALL_ACCESS,ServiceType,StartType,0,FileName,'',0,'','',''); if hService <> 0 then begin Result := true; // Win2K & WinXP supports aditional description text for services if Description<> '' then RegWriteStringValue(HKLM,'System\CurrentControlSet\Services\' + ServiceName,'Description',Description); CloseServiceHandle(hService) end; CloseServiceHandle(hSCM) end end; function RemoveService(ServiceName: string) : boolean; var hSCM : HANDLE; hService: HANDLE; begin hSCM := OpenServiceManager(); Result := false; if hSCM <> 0 then begin hService := OpenService(hSCM,ServiceName,SERVICE_DELETE); if hService <> 0 then begin Result := DeleteService(hService); CloseServiceHandle(hService) end; CloseServiceHandle(hSCM) end end; function StartService(ServiceName: string) : boolean; var hSCM : HANDLE; hService: HANDLE; begin hSCM := OpenServiceManager(); Result := false; if hSCM <> 0 then begin hService := OpenService(hSCM,ServiceName,SERVICE_START); if hService <> 0 then begin Result := StartNTService(hService,0,0); CloseServiceHandle(hService) end; CloseServiceHandle(hSCM) end; end; function StopService(ServiceName: string) : boolean; var hSCM : HANDLE; hService: HANDLE; Status : SERVICE_STATUS; begin hSCM := OpenServiceManager(); Result := false; if hSCM <> 0 then begin hService := OpenService(hSCM,ServiceName,SERVICE_STOP); if hService <> 0 then begin Result := ControlService(hService,SERVICE_CONTROL_STOP,Status); CloseServiceHandle(hService) end; CloseServiceHandle(hSCM) end; end; function IsServiceRunning(ServiceName: string) : boolean; var hSCM : HANDLE; hService: HANDLE; Status : SERVICE_STATUS; begin hSCM := OpenServiceManager(); Result := false; if hSCM <> 0 then begin hService := OpenService(hSCM,ServiceName,SERVICE_QUERY_STATUS); if hService <> 0 then begin if QueryServiceStatus(hService,Status) then begin Result :=(Status.dwCurrentState = SERVICE_RUNNING) end; CloseServiceHandle(hService) end; CloseServiceHandle(hSCM) end end; // ####################################################################################### // create an entry in the services file // ####################################################################################### function SetupService(service, port, comment: string) : boolean; var filename : string; s : string; lines : TArrayOfString; n : longint; i : longint; errcode : integer; servnamlen : integer; error : boolean; begin if UsingWinNT() = true then filename := ExpandConstant('{sys}\drivers\etc\services') else filename := ExpandConstant('{win}\services'); if LoadStringsFromFile(filename,lines) = true then begin Result := true; n := GetArrayLength(lines) - 1; servnamlen := Length(service); error := false; for i:=0 to n do begin if Copy(lines[i],1,1) <> '#' then begin s := Copy(lines[i],1,servnamlen); if CompareText(s,service) = 0 then exit; // found service-entry if Pos(port,lines[i]) > 0 then begin error := true; lines[i] := '#' + lines[i] + ' # disabled because collision with ' + service + ' service'; end; end else if CompareText(Copy(lines[i],2,servnamlen),service) = 0 then begin // service-entry was disabled Delete(lines[i],1,1); Result := SaveStringsToFile(filename,lines,false); exit; end; end; if error = true then begin // save disabled entries if SaveStringsToFile(filename,lines,false) = false then begin Result := false; exit; end; end; // create new service entry s := service + ' ' + port + ' # ' + comment + #13#10; if SaveStringToFile(filename,s,true) = false then begin Result := false; exit; end; if error = true then begin MsgBox('the ' + service + ' port was already used. The old service is disabled now. You should check the services file manually now.',mbInformation,MB_OK); Exec('notepad.exe',filename,GetCurrentDir(),SW_SHOWNORMAL,ewWaitUntilTerminated,errcode); end; end else Result := false; end; // ####################################################################################### // version functions // ####################################################################################### function CheckVersion(Filename : string;hh,hl,lh,ll : integer) : boolean; var VersionMS : cardinal; VersionLS : cardinal; CheckMS : cardinal; CheckLS : cardinal; begin if GetVersionNumbers(Filename,VersionMS,VersionLS) = false then Result := false else begin CheckMS := (hh shl $10) or hl; CheckLS := (lh shl $10) or ll; Result := (VersionMS > CheckMS) or ((VersionMS = CheckMS) and (VersionLS >= CheckLS)); end; end; // Some examples for version checking function NeedShellFolderUpdate() : boolean; begin Result := CheckVersion('ShFolder.dll',5,50,4027,300) = false; end; function NeedVCRedistUpdate() : boolean; begin Result := (CheckVersion('mfc42.dll',6,0,8665,0) = false) or (CheckVersion('msvcrt.dll',6,0,8797,0) = false) or (CheckVersion('comctl32.dll',5,80,2614,3600) = false); end; function NeedHTMLHelpUpdate() : boolean; begin Result := CheckVersion('hh.exe',4,72,0,0) = false; end; function NeedWinsockUpdate() : boolean; begin Result := (UsingWinNT() = false) and (CheckVersion('mswsock.dll',4,10,0,1656) = false); end; function NeedDCOMUpdate() : boolean; begin Result := (UsingWinNT() = false) and (CheckVersion('oleaut32.dll',2,30,0,0) = false); end; // function IsServiceInstalled(ServiceName: string) : boolean; // function IsServiceRunning(ServiceName: string) : boolean; // function InstallService(FileName, ServiceName, DisplayName, Description : string;ServiceType,StartType :cardinal) : boolean; // function RemoveService(ServiceName: string) : boolean; // function StartService(ServiceName: string) : boolean; // function StopService(ServiceName: string) : boolean; // function SetupService(service, port, comment: string) : boolean; // function CheckVersion(Filename : string;hh,hl,lh,ll : integer) : boolean; PROCEDURE CurUninstallStepChanged(CurUninstallStep: TUninstallStep); BEGIN // Always remove the service, it is stopped due to the mutex check IF CurUninstallStep = usUninstall THEN BEGIN IF IsServiceInstalled('SimeseServer') THEN RemoveService('SimeseServer'); END; END;