diff --git a/nginxtool.lpi b/nginxtool.lpi index 0f9a7c8..6580763 100644 --- a/nginxtool.lpi +++ b/nginxtool.lpi @@ -14,8 +14,8 @@ - - + + diff --git a/nginxtool.res b/nginxtool.res index 128fc2d..9198b86 100644 Binary files a/nginxtool.res and b/nginxtool.res differ diff --git a/nginxtool_main.lfm b/nginxtool_main.lfm index 252074e..ef26507 100644 --- a/nginxtool_main.lfm +++ b/nginxtool_main.lfm @@ -10,11 +10,11 @@ object FormNginxtool: TFormNginxtool OnCreate = FormCreate OnDestroy = FormDestroy OnShow = FormShow - LCLVersion = '1.7' + LCLVersion = '1.9.0.0' object Panel1: TPanel Left = 16 - Height = 199 - Top = 128 + Height = 167 + Top = 160 Width = 527 Anchors = [akTop, akLeft, akRight, akBottom] BevelOuter = bvLowered @@ -24,16 +24,16 @@ object FormNginxtool: TFormNginxtool object Button1: TButton Left = 16 Height = 25 - Top = 96 + Top = 120 Width = 112 Caption = '&Start' OnClick = Button1Click TabOrder = 1 end object Button2: TButton - Left = 160 + Left = 152 Height = 25 - Top = 96 + Top = 120 Width = 123 Caption = 'Sto&p' OnClick = Button2Click @@ -41,12 +41,12 @@ object FormNginxtool: TFormNginxtool end object GroupBox1: TGroupBox Left = 8 - Height = 81 + Height = 113 Top = 0 Width = 536 Anchors = [akTop, akLeft, akRight] Caption = ' Option ' - ClientHeight = 64 + ClientHeight = 96 ClientWidth = 532 TabOrder = 0 object CheckBoxModConf: TCheckBox @@ -57,7 +57,7 @@ object FormNginxtool: TFormNginxtool Caption = 'Modify Config File' TabOrder = 0 end - object CheckBox1: TCheckBox + object CheckBox_priority: TCheckBox Left = 10 Height = 19 Top = 4 @@ -89,17 +89,96 @@ object FormNginxtool: TFormNginxtool TabOrder = 2 Text = '8192' end + object ComboBox_meta: TComboBox + Left = 56 + Height = 23 + Top = 64 + Width = 60 + ItemHeight = 15 + ItemIndex = 2 + Items.Strings = ( + 'off' + 'on' + 'copy' + ) + OnCloseUp = ComboBox_metaCloseUp + Style = csDropDownList + TabOrder = 3 + Text = 'copy' + end + object Label2: TLabel + Left = 10 + Height = 12 + Top = 68 + Width = 36 + Caption = 'meta :' + ParentColor = False + end + object Label3: TLabel + Left = 144 + Height = 12 + Top = 68 + Width = 67 + Caption = 'wait_video :' + ParentColor = False + end + object Label4: TLabel + Left = 315 + Height = 12 + Top = 69 + Width = 49 + Caption = 'wait_key' + ParentColor = False + end + end + object ComboBox_waitvideo: TComboBox + Left = 228 + Height = 23 + Top = 79 + Width = 60 + ItemHeight = 15 + ItemIndex = 0 + Items.Strings = ( + 'on' + 'off' + ) + OnCloseUp = ComboBox_waitvideoCloseUp + Style = csDropDownList + TabOrder = 4 + Text = 'on' + end + object ComboBox_waitkey: TComboBox + Left = 392 + Height = 23 + Top = 79 + Width = 60 + ItemHeight = 15 + ItemIndex = 0 + Items.Strings = ( + 'on' + 'off' + ) + OnCloseUp = ComboBox_waitvideoCloseUp + Style = csDropDownList + TabOrder = 5 + Text = 'on' end object UniqueInstance1: TUniqueInstance Enabled = True - Left = 328 - Top = 88 + Left = 312 + Top = 112 end object Timer1: TTimer Enabled = False Interval = 500 OnTimer = Timer1Timer Left = 376 - Top = 88 + Top = 112 + end + object JSONPropStorage1: TJSONPropStorage + StoredValues = <> + Formatted = True + Left = 464 + Top = 112 end end diff --git a/nginxtool_main.pas b/nginxtool_main.pas index 4580287..7c5594e 100644 --- a/nginxtool_main.pas +++ b/nginxtool_main.pas @@ -6,7 +6,7 @@ interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, - StdCtrls, UniqueInstance; + StdCtrls, JSONPropStorage, UniqueInstance; type @@ -15,11 +15,18 @@ interface TFormNginxtool = class(TForm) Button1: TButton; Button2: TButton; - CheckBox1: TCheckBox; + CheckBox_priority: TCheckBox; CheckBoxModConf: TCheckBox; + ComboBox_meta: TComboBox; ComboBoxChunk: TComboBox; + ComboBox_waitvideo: TComboBox; + ComboBox_waitkey: TComboBox; GroupBox1: TGroupBox; + JSONPropStorage1: TJSONPropStorage; Label1: TLabel; + Label2: TLabel; + Label3: TLabel; + Label4: TLabel; Panel1: TPanel; Timer1: TTimer; UniqueInstance1: TUniqueInstance; @@ -28,6 +35,8 @@ TFormNginxtool = class(TForm) procedure CheckBoxModConfClick(Sender: TObject); procedure ComboBoxChunkCloseUp(Sender: TObject); procedure ComboBoxChunkKeyPress(Sender: TObject; var Key: char); + procedure ComboBox_metaCloseUp(Sender: TObject); + procedure ComboBox_waitvideoCloseUp(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure FormShow(Sender: TObject); @@ -197,24 +206,48 @@ procedure TFormNginxtool.Panel1Click(Sender: TObject); procedure TFormNginxtool.Timer1Timer(Sender: TObject); begin {$ifdef WINDOWS} - if CheckBox1.Checked then + if CheckBox_priority.Checked then ProcessPriority('nginx.exe',ppval); {$endif} if nginx_process_find>0 then Timer1.Enabled:=False; end; + +function checkConfigComment(const s:string):Boolean; +var + i,len:Integer; +begin + Result:=False; + i:=1; + len:=Length(s); + while i<=len do begin + if s[i]>#32 then + break; + Inc(i); + end; + while i<=len do begin + if s[i]='#' then begin + Result:=True; + break; + end; + Inc(i); + end; +end; + procedure TFormNginxtool.VerboseNginxConfig; var - buf, bufrtmp, schunksize : string; + buf, bufrtmp, schunksize, sRtmpMeta : string; fs : TFileStream; - bufsize, bufloc, bufpos, bufopen : Integer; + bufsize, bufloc, bufpos, bufopen, rtmpidx, ii, ij : Integer; rx, rxrtmp : TRegExpr; templist : TStringList; workercount, chunksize : Integer; has_autopush, chunk_modified : Boolean; + IPBuf:array[0..254] of char; begin chunk_modified:=False; + loglist.AddLog('----- nginx config -----'); schunksize:=Trim(ComboBoxChunk.Text); if StrToIntDef(schunksize,0)=0 then begin schunksize:='4096'; @@ -306,6 +339,72 @@ procedure TFormNginxtool.VerboseNginxConfig; finally rx.Free; end; + // insert meta copy + rx := TRegExpr.Create('meta\s+[^;]+;'); + try + rx.ModifierI:=True; + if rx.Exec(buf) then begin + buf:=rx.Replace(buf,'meta '+ComboBox_meta.Text+';',False); + chunk_modified:=True; + end else begin + rxrtmp:=TRegExpr.Create('rtmp\s+\{[^\{]+server\s+\{\s+[^\{]+application\s+(\S+)\s+\{'); + try + if rxrtmp.Exec(buf) then begin + buf:=Copy(buf,1,rxrtmp.MatchPos[0]+rxrtmp.MatchLen[0]-1)+#10#9#9#9'meta '+ComboBox_meta.Text+';'#10+ + Copy(buf,rxrtmp.MatchPos[0]+rxrtmp.MatchLen[0]); + chunk_modified:=True; + end; + finally + rxrtmp.Free; + end; + end; + finally + rx.Free; + end; + // wait_video + rx := TRegExpr.Create('wait_video\s+[^;]+;'); + try + rx.ModifierI:=True; + if rx.Exec(buf) then begin + buf:=rx.Replace(buf,'wait_video '+ComboBox_waitvideo.Text+';',False); + chunk_modified:=True; + end else begin + rxrtmp:=TRegExpr.Create('rtmp\s+\{[^\{]+server\s+\{\s+[^\{]+application\s+(\S+)\s+\{'); + try + if rxrtmp.Exec(buf) then begin + buf:=Copy(buf,1,rxrtmp.MatchPos[0]+rxrtmp.MatchLen[0]-1)+#10#9#9#9'wait_video '+ComboBox_waitvideo.Text+';'#10+ + Copy(buf,rxrtmp.MatchPos[0]+rxrtmp.MatchLen[0]); + chunk_modified:=True; + end; + finally + rxrtmp.Free; + end; + end; + finally + rx.Free; + end; + // wait_key + rx := TRegExpr.Create('wait_key\s+[^;]+;'); + try + rx.ModifierI:=True; + if rx.Exec(buf) then begin + buf:=rx.Replace(buf,'wait_key '+ComboBox_waitkey.Text+';',False); + chunk_modified:=True; + end else begin + rxrtmp:=TRegExpr.Create('rtmp\s+\{[^\{]+server\s+\{\s+[^\{]+application\s+(\S+)\s+\{'); + try + if rxrtmp.Exec(buf) then begin + buf:=Copy(buf,1,rxrtmp.MatchPos[0]+rxrtmp.MatchLen[0]-1)+#10#9#9#9'wait_key '+ComboBox_waitkey.Text+';'#10+ + Copy(buf,rxrtmp.MatchPos[0]+rxrtmp.MatchLen[0]); + chunk_modified:=True; + end; + finally + rxrtmp.Free; + end; + end; + finally + rx.Free; + end; (* // add 'rtmp_auto_push on' if (workercount<>1) and (not has_autopush) then begin @@ -362,6 +461,8 @@ procedure TFormNginxtool.VerboseNginxConfig; finally rx.Free; end; + GetIPAddr(IPBuf,sizeof(IPBuf)); + loglist.AddLog(Format('> IP Address: %s',[IPBuf])); end; procedure TFormNginxtool.FormCreate(Sender: TObject); @@ -376,27 +477,16 @@ procedure TFormNginxtool.FormCreate(Sender: TObject); end; procedure TFormNginxtool.FormDestroy(Sender: TObject); -var - fs : TFileStream; - 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); - try - fs.Write(s[1],Length(s)); - finally - fs.Free; - end; - except - end; + JSONPropStorage1.WriteBoolean('priority',CheckBox_priority.Checked); + JSONPropStorage1.WriteBoolean('modify',CheckBoxModConf.Checked); + JSONPropStorage1.WriteString('chunk_size',ComboBoxChunk.Text); + JSONPropStorage1.WriteInteger('meta',ComboBox_meta.ItemIndex); + JSONPropStorage1.WriteInteger('wait_video',ComboBox_waitvideo.ItemIndex); + JSONPropStorage1.WriteInteger('wait_key',ComboBox_waitkey.ItemIndex); + try + JSONPropStorage1.Save; + except end; end; @@ -420,7 +510,7 @@ procedure TFormNginxtool.Button1Click(Sender: TObject); myprocess.Environment.Add(GetEnvironmentString(i)); myprocess.Executable:='nginx'; {$ifdef WINDOWS} - if CheckBox1.Checked then + if CheckBox_priority.Checked then if UseAboveNormalProcess then begin myprocess.Priority:=ppAboveNormal; ppval:=ABOVE_NORMAL_PRIORITY_CLASS; @@ -496,48 +586,29 @@ procedure TFormNginxtool.ComboBoxChunkKeyPress(Sender: TObject; var Key: char); end; end; -function ReadINIFile(idx:Integer):Boolean; -var - fs : TFileStream; - s : string; - bsize : Integer; +procedure TFormNginxtool.ComboBox_metaCloseUp(Sender: TObject); begin - 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:='018192'; - end; - checkflag:=s; - end; - if idx<3 then - Result:=checkflag[idx]='1' - else - Result:=False; + CheckBoxModConfClick(nil); end; +procedure TFormNginxtool.ComboBox_waitvideoCloseUp(Sender: TObject); +begin + CheckBoxModConfClick(nil); +end; procedure TFormNginxtool.FormShow(Sender: TObject); -var - IPBuf:array[0..254] of char; begin - GetIPAddr(IPBuf,sizeof(IPBuf)); - loglist.AddLog(Format('> IP Address: %s',[IPBuf])); - CheckBox1.Checked:=ReadINIFile(1); - CheckBoxModConf.Checked:=ReadINIFile(2); - ComboBoxChunk.Text:=Copy(checkflag,3); + try + JSONPropStorage1.Restore; + CheckBox_priority.Checked:=JSONPropStorage1.ReadBoolean('priority',False); + CheckBoxModConf.Checked:=JSONPropStorage1.ReadBoolean('modify',True); + ComboBoxChunk.Text:=JSONPropStorage1.ReadString('chunk_size',ComboBoxChunk.Text); + ComboBox_meta.ItemIndex:=JSONPropStorage1.ReadInteger('meta',ComboBox_meta.ItemIndex); + ComboBox_waitvideo.ItemIndex:=JSONPropStorage1.ReadInteger('wait_video',ComboBox_waitvideo.ItemIndex); + ComboBox_waitkey.ItemIndex:=JSONPropStorage1.ReadInteger('wait_key',ComboBox_waitkey.ItemIndex); + except + end; + CheckBoxModConf.OnClick:=@CheckBoxModConfClick; VerboseNginxConfig; end;