Added new function allowing automatic system shutdown after rendering completion.

This commit is contained in:
utak3r 2005-04-29 23:06:36 +00:00
parent d8bd40db89
commit ed5d08220c
4 changed files with 89 additions and 15 deletions

View File

@ -1,10 +1,10 @@
object RenderForm: TRenderForm object RenderForm: TRenderForm
Left = 280 Left = 286
Top = 279 Top = 251
BorderIcons = [biSystemMenu, biMinimize] BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle BorderStyle = bsSingle
Caption = 'RenderForm' Caption = 'RenderForm'
ClientHeight = 400 ClientHeight = 405
ClientWidth = 424 ClientWidth = 424
Color = clBtnFace Color = clBtnFace
Font.Charset = DEFAULT_CHARSET Font.Charset = DEFAULT_CHARSET
@ -297,9 +297,9 @@ object RenderForm: TRenderForm
object lblPhysical: TLabel object lblPhysical: TLabel
Left = 202 Left = 202
Top = 20 Top = 20
Width = 121 Width = 126
Height = 13 Height = 13
Caption = 'Available phycial memory:' Caption = 'Available physical memory:'
end end
object Label9: TLabel object Label9: TLabel
Left = 8 Left = 8
@ -346,7 +346,7 @@ object RenderForm: TRenderForm
end end
object chkSave: TCheckBox object chkSave: TCheckBox
Left = 8 Left = 8
Top = 354 Top = 346
Width = 113 Width = 113
Height = 17 Height = 17
Caption = 'Save parameters' Caption = 'Save parameters'
@ -408,7 +408,7 @@ object RenderForm: TRenderForm
end end
object StatusBar: TStatusBar object StatusBar: TStatusBar
Left = 0 Left = 0
Top = 381 Top = 386
Width = 424 Width = 424
Height = 19 Height = 19
Panels = < Panels = <
@ -422,6 +422,14 @@ object RenderForm: TRenderForm
Width = 50 Width = 50
end> end>
end end
object chkShutdown: TCheckBox
Left = 8
Top = 368
Width = 137
Height = 17
Caption = 'Shutdown on complete'
TabOrder = 11
end
object SaveDialog: TSaveDialog object SaveDialog: TSaveDialog
Left = 368 Left = 368
Top = 256 Top = 256

View File

@ -66,6 +66,7 @@ type
cbWidth: TComboBox; cbWidth: TComboBox;
cbHeight: TComboBox; cbHeight: TComboBox;
StatusBar: TStatusBar; StatusBar: TStatusBar;
chkShutdown: TCheckBox;
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject); procedure FormDestroy(Sender: TObject);
procedure btnRenderClick(Sender: TObject); procedure btnRenderClick(Sender: TObject);
@ -96,6 +97,7 @@ type
procedure HandleThreadTermination(var Message: TMessage); procedure HandleThreadTermination(var Message: TMessage);
message WM_THREAD_TERMINATE; message WM_THREAD_TERMINATE;
procedure ListPresets; procedure ListPresets;
function WindowsExit(RebootParam: Longword = EWX_POWEROFF or EWX_FORCE): Boolean;
public public
Renderer: TRenderThread; Renderer: TRenderThread;
PhysicalMemory, ApproxMemory: int64; PhysicalMemory, ApproxMemory: int64;
@ -170,6 +172,8 @@ begin
Renderer.Free; Renderer.Free;
Renderer := nil; Renderer := nil;
ResetControls; ResetControls;
if chkShutdown.Checked then
WindowsExit;
finally finally
Free; Free;
end; end;
@ -667,5 +671,44 @@ begin
Ratio := ImageWidth / ImageHeight; Ratio := ImageWidth / ImageHeight;
end; end;
function TRenderForm.WindowsExit(RebootParam: Longword = EWX_POWEROFF or EWX_FORCE): Boolean;
var
TTokenHd: THandle;
TTokenPvg: TTokenPrivileges;
cbtpPrevious: DWORD;
rTTokenPvg: TTokenPrivileges;
pcbtpPreviousRequired: DWORD;
tpResult: Boolean;
const
SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
begin
if ((GetWinVersion = wvWinNT) or
(GetWinVersion = wvWin2000) or
(GetWinVersion = wvWinXP)) then
begin
tpResult := OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
TTokenHd);
if tpResult then
begin
tpResult := LookupPrivilegeValue(nil,
SE_SHUTDOWN_NAME,
TTokenPvg.Privileges[0].Luid);
TTokenPvg.PrivilegeCount := 1;
TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
cbtpPrevious := SizeOf(rTTokenPvg);
pcbtpPreviousRequired := 0;
if tpResult then
Windows.AdjustTokenPrivileges(TTokenHd,
False,
TTokenPvg,
cbtpPrevious,
rTTokenPvg,
pcbtpPreviousRequired);
end;
end;
Result := ExitWindowsEx(RebootParam, 0);
end;
end. end.

View File

@ -1,6 +1,6 @@
object MainForm: TMainForm object MainForm: TMainForm
Left = 316 Left = 411
Top = 424 Top = 128
Width = 574 Width = 574
Height = 575 Height = 575
Caption = 'Apophysis' Caption = 'Apophysis'
@ -27,7 +27,7 @@ object MainForm: TMainForm
Left = 160 Left = 160
Top = 28 Top = 28
Width = 4 Width = 4
Height = 494 Height = 482
end end
object ToolBar: TToolBar object ToolBar: TToolBar
Left = 0 Left = 0
@ -251,7 +251,7 @@ object MainForm: TMainForm
Left = 0 Left = 0
Top = 28 Top = 28
Width = 160 Width = 160
Height = 494 Height = 482
Align = alLeft Align = alLeft
Columns = < Columns = <
item item
@ -270,7 +270,7 @@ object MainForm: TMainForm
Left = 164 Left = 164
Top = 28 Top = 28
Width = 402 Width = 402
Height = 494 Height = 482
Align = alClient Align = alClient
BevelInner = bvLowered BevelInner = bvLowered
BevelOuter = bvNone BevelOuter = bvNone
@ -281,7 +281,7 @@ object MainForm: TMainForm
Left = 1 Left = 1
Top = 1 Top = 1
Width = 400 Width = 400
Height = 472 Height = 480
Align = alClient Align = alClient
AutoSize = True AutoSize = True
PopupMenu = DisplayPopup PopupMenu = DisplayPopup
@ -293,7 +293,7 @@ object MainForm: TMainForm
end end
object StatusBar: TStatusBar object StatusBar: TStatusBar
Left = 0 Left = 0
Top = 522 Top = 510
Width = 566 Width = 566
Height = 19 Height = 19
Panels = < Panels = <
@ -2919,8 +2919,9 @@ object MainForm: TMainForm
end end
object HTTP: TIdHTTP object HTTP: TIdHTTP
OnStatus = HTTPStatus OnStatus = HTTPStatus
MaxLineAction = maException
ReadTimeout = 0
AuthRetries = 0 AuthRetries = 0
AuthProxyRetries = 0
AllowCookies = True AllowCookies = True
ProxyParams.BasicAuthentication = False ProxyParams.BasicAuthentication = False
ProxyParams.ProxyPort = 0 ProxyParams.ProxyPort = 0

View File

@ -41,6 +41,8 @@ const
type type
TMouseMoveState = (msUsual, msZoomWindow, msZoomWindowMove, msDrag, msDragMove, msRotate, msRotateMove); TMouseMoveState = (msUsual, msZoomWindow, msZoomWindowMove, msDrag, msDragMove, msRotate, msRotateMove);
type
TWin32Version = (wvUnknown, wvWin95, wvWin98, wvWinNT, wvWin2000, wvWinXP);
type type
pRGBTripleArray = ^TRGBTripleArray; pRGBTripleArray = ^TRGBTripleArray;
@ -344,6 +346,7 @@ procedure ListFlames(FileName: string; sel: integer);
procedure ListIFS(FileName: string; sel: integer); procedure ListIFS(FileName: string; sel: integer);
procedure AdjustScale(var cp1: TControlPoint; width, height: integer); procedure AdjustScale(var cp1: TControlPoint; width, height: integer);
procedure NormalizeVariations(var cp1: TControlPoint); procedure NormalizeVariations(var cp1: TControlPoint);
function GetWinVersion: TWin32Version;
var var
MainForm: TMainForm; MainForm: TMainForm;
@ -497,6 +500,25 @@ begin
Variations[i] := boolean(v shr i and 1); Variations[i] := boolean(v shr i and 1);
end; end;
function GetWinVersion: TWin32Version;
{ Returns current version of a host Win32 platform }
begin
Result := wvUnknown;
if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
if (Win32MajorVersion > 4) or
((Win32MajorVersion = 4) and
(Win32MinorVersion > 0)) then
Result := wvWin98
else
Result := wvWin95
else
if Win32MajorVersion <= 4 then
Result := wvWinNT
else
if Win32MajorVersion = 5 then
Result := wvWin2000
end;
{ ************************************* Help ********************************* } { ************************************* Help ********************************* }
procedure ShowHelp(Pt: TPoint; ContextId: Integer); procedure ShowHelp(Pt: TPoint; ContextId: Integer);