Skip to content

Commit

Permalink
Add option Group box and can change chunk_size.
Browse files Browse the repository at this point in the history
  • Loading branch information
rasberryrabbit committed Apr 9, 2017
1 parent 6a8e2eb commit a7979f7
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 41 deletions.
2 changes: 1 addition & 1 deletion nginxtool.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<AutoIncrementBuild Value="True"/>
<MinorVersionNr Value="1"/>
<RevisionNr Value="1"/>
<BuildNr Value="9"/>
<BuildNr Value="15"/>
<StringTable ProductVersion="0.0.0.0"/>
</VersionInfo>
<BuildModes Count="2">
Expand Down
Binary file modified nginxtool.res
Binary file not shown.
99 changes: 67 additions & 32 deletions nginxtool_main.lfm
Original file line number Diff line number Diff line change
@@ -1,70 +1,105 @@
object FormNginxtool: TFormNginxtool
Left = 276
Height = 330
Left = 281
Height = 340
Top = 140
Width = 562
Width = 557
BorderIcons = [biSystemMenu, biMinimize]
Caption = 'nginx rtmp tool'
ClientHeight = 330
ClientWidth = 562
ClientHeight = 340
ClientWidth = 557
OnCreate = FormCreate
OnDestroy = FormDestroy
OnShow = FormShow
LCLVersion = '1.7'
object Panel1: TPanel
Left = 16
Height = 261
Top = 56
Width = 532
Height = 199
Top = 128
Width = 527
Anchors = [akTop, akLeft, akRight, akBottom]
BevelOuter = bvLowered
TabOrder = 2
TabOrder = 3
OnClick = Panel1Click
end
object Button1: TButton
Left = 16
Height = 25
Top = 24
Top = 96
Width = 112
Caption = '&Start'
OnClick = Button1Click
TabOrder = 0
TabOrder = 1
end
object Button2: TButton
Left = 184
Left = 160
Height = 25
Top = 24
Top = 96
Width = 123
Caption = 'Sto&p'
OnClick = Button2Click
TabOrder = 1
end
object CheckBox1: TCheckBox
Left = 16
Height = 19
Top = 0
Width = 140
Caption = 'Above Normal Priority'
TabOrder = 3
TabOrder = 2
end
object CheckBoxModConf: TCheckBox
Left = 184
Height = 19
object GroupBox1: TGroupBox
Left = 8
Height = 81
Top = 0
Width = 120
Caption = 'Modify Config File'
TabOrder = 4
Width = 536
Anchors = [akTop, akLeft, akRight]
Caption = ' Option '
ClientHeight = 64
ClientWidth = 532
TabOrder = 0
object CheckBoxModConf: TCheckBox
Left = 178
Height = 19
Top = 4
Width = 120
Caption = 'Modify Config File'
TabOrder = 0
end
object CheckBox1: TCheckBox
Left = 10
Height = 19
Top = 4
Width = 140
Caption = 'Above Normal Priority'
TabOrder = 1
end
object Label1: TLabel
Left = 10
Height = 12
Top = 35
Width = 73
Caption = 'Chunk Size :'
ParentColor = False
end
object ComboBoxChunk: TComboBox
Left = 92
Height = 23
Top = 30
Width = 68
ItemHeight = 15
ItemIndex = 1
Items.Strings = (
'4096'
'8192'
)
OnCloseUp = ComboBoxChunkCloseUp
OnKeyPress = ComboBoxChunkKeyPress
TabOrder = 2
Text = '8192'
end
end
object UniqueInstance1: TUniqueInstance
Enabled = True
Left = 372
Top = 20
Left = 328
Top = 88
end
object Timer1: TTimer
Enabled = False
Interval = 500
OnTimer = Timer1Timer
Left = 432
Top = 22
Left = 376
Top = 88
end
end
49 changes: 41 additions & 8 deletions nginxtool_main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ TFormNginxtool = class(TForm)
Button2: TButton;
CheckBox1: TCheckBox;
CheckBoxModConf: TCheckBox;
ComboBoxChunk: TComboBox;
GroupBox1: TGroupBox;
Label1: TLabel;
Panel1: TPanel;
Timer1: TTimer;
UniqueInstance1: TUniqueInstance;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure CheckBoxModConfClick(Sender: TObject);
procedure ComboBoxChunkCloseUp(Sender: TObject);
procedure ComboBoxChunkKeyPress(Sender: TObject; var Key: char);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
Expand Down Expand Up @@ -201,7 +206,7 @@ procedure TFormNginxtool.Timer1Timer(Sender: TObject);

procedure TFormNginxtool.VerboseNginxConfig;
var
buf, bufrtmp : string;
buf, bufrtmp, schunksize : string;
fs : TFileStream;
bufsize, bufloc, bufpos, bufopen : Integer;
rx, rxrtmp : TRegExpr;
Expand All @@ -210,6 +215,11 @@ procedure TFormNginxtool.VerboseNginxConfig;
has_autopush, chunk_modified : Boolean;
begin
chunk_modified:=False;
schunksize:=Trim(ComboBoxChunk.Text);
if StrToIntDef(schunksize,0)=0 then begin
schunksize:='4096';
ComboBoxChunk.Text:=schunksize;
end;
try
// read config file
fs := TFileStream.Create('conf/nginx.conf',fmOpenRead or fmShareDenyNone);
Expand Down Expand Up @@ -276,16 +286,16 @@ procedure TFormNginxtool.VerboseNginxConfig;
try
rx.ModifierI:=True;
if rx.Exec(buf) then begin
if StrToIntDef(rx.Match[1],0)<8192 then begin
buf:=Copy(buf,1,rx.MatchPos[1]-1)+'8192'+Copy(buf,rx.MatchPos[1]+rx.MatchLen[1]);
if StrToIntDef(rx.Match[1],0)<>0 then begin
buf:=Copy(buf,1,rx.MatchPos[1]-1)+schunksize+Copy(buf,rx.MatchPos[1]+rx.MatchLen[1]);
chunk_modified:=True;
end;
end else begin
rxrtmp:=TRegExpr.Create('rtmp\s+\{[^\{]+server\s+\{\s+[^;]+;');
try
rxrtmp.ModifierI:=True;
if rxrtmp.Exec(buf) then begin
buf:=Copy(buf,1,rxrtmp.MatchPos[0]+rxrtmp.MatchLen[0]-1)+#10#9#9'chunk_size 8192;'#10+
buf:=Copy(buf,1,rxrtmp.MatchPos[0]+rxrtmp.MatchLen[0]-1)+#10#9#9'chunk_size '+schunksize+';'#10+
Copy(buf,rxrtmp.MatchPos[0]+rxrtmp.MatchLen[0]);
chunk_modified:=True;
end;
Expand Down Expand Up @@ -368,14 +378,15 @@ procedure TFormNginxtool.FormCreate(Sender: TObject);
procedure TFormNginxtool.FormDestroy(Sender: TObject);
var
fs : TFileStream;
s : string;
s,schunk : string;
i : Integer;
begin
s:='00';
if CheckBox1.Checked then
s[1]:='1';
if CheckBoxModConf.Checked then
s[2]:='1';
s:=s+ComboBoxChunk.Text;
if checkflag<>s then begin
try
fs:=TFileStream.Create('nginxtool.ini',fmOpenWrite or fmCreate or fmShareDenyNone);
Expand Down Expand Up @@ -472,28 +483,49 @@ procedure TFormNginxtool.CheckBoxModConfClick(Sender: TObject);
VerboseNginxConfig;
end;

procedure TFormNginxtool.ComboBoxChunkCloseUp(Sender: TObject);
begin
CheckBoxModConfClick(nil);
end;

procedure TFormNginxtool.ComboBoxChunkKeyPress(Sender: TObject; var Key: char);
begin
if Key=#13 then begin
Key:=#0;
CheckBoxModConfClick(nil);
end;
end;

function ReadINIFile(idx:Integer):Boolean;
var
fs : TFileStream;
s : string;
bsize : Integer;
begin
s:='01';
s:='018192';
if idx>Length(s) then
idx:=Length(s);
if checkflag='' then begin
try
fs:=TFileStream.Create('nginxtool.ini',fmOpenRead or fmShareDenyNone);
try
bsize:=fs.Size;
if bsize>8 then
bsize:=8;
SetLength(s,bsize);
fs.Read(s[1],Length(s));
finally
fs.Free;
end;
except
s:='01';
s:='018192';
end;
checkflag:=s;
end;
Result:=checkflag[idx]='1';
if idx<3 then
Result:=checkflag[idx]='1'
else
Result:=False;
end;


Expand All @@ -505,6 +537,7 @@ procedure TFormNginxtool.FormShow(Sender: TObject);
loglist.AddLog(Format('> IP Address: %s',[IPBuf]));
CheckBox1.Checked:=ReadINIFile(1);
CheckBoxModConf.Checked:=ReadINIFile(2);
ComboBoxChunk.Text:=Copy(checkflag,3);
CheckBoxModConf.OnClick:=@CheckBoxModConfClick;
VerboseNginxConfig;
end;
Expand Down

0 comments on commit a7979f7

Please sign in to comment.