shuusei24178:server.logの保存フォルダを指定できるようにする(idea by 三菱A6M1)

diff --dos -ur 24177/constants.pas 24178/constants.pas
--- 24177/constants.pas	Sat Aug 09 04:45:06 2003
+++ 24178/constants.pas	Sun Aug 10 15:05:32 2003
@@ -27,8 +27,8 @@
  SLAVANAP_VERSION             = '2.4.1';
  SLAVANAP_BUILD               = '108';
  SLAVANAP_BUILD_DATE          = '24 January 2003';
- SLAVANAP_SHUUSEI             = '77';
- SLAVANAP_SHUUSEI_DATE        = '9 August 2003';
+ SLAVANAP_SHUUSEI             = '78';
+ SLAVANAP_SHUUSEI_DATE        = '10 August 2003';
  SLAVANAP_VERSION_SHORT       = SLAVANAP_TITLE+' '+SLAVANAP_VERSION;
  SLAVANAP_FULL                = SLAVANAP_TITLE+' '+SLAVANAP_VERSION+
                                 ' (build '+SLAVANAP_BUILD+
diff --dos -ur 24177/english.lng 24178/english.lng
--- 24177/english.lng	Fri Aug 08 13:04:18 2003
+++ 24178/english.lng	Sun Aug 10 17:43:32 2003
@@ -7,7 +7,7 @@
 Version=2.4.1
 Comments=Original file by SlavaNap development team
 BUILD=108
-SHUUSEI=76
+SHUUSEI=78
 
 [Log]
 SERVER_INIT=Starting $1
@@ -995,6 +995,7 @@
 S_SHOTHER4_CB_ALLOW_UTATANE                =Utatane
 S_SHOTHER4_CB_ALLOW_2GET                   =2get
 S_SHOTHER4_CB_ALLOW_OTHER                  =Other
+S_SHOTHER4_LABEL163                        =Log folder of server.log:
 
 [UserMode]
 CAPTION=Console User Mode
diff --dos -ur 24177/japanese.lng 24178/japanese.lng
--- 24177/japanese.lng	Fri Aug 08 12:59:22 2003
+++ 24178/japanese.lng	Sun Aug 10 17:43:32 2003
@@ -7,7 +7,7 @@
 Version=2.4.1.108
 Comments=Translated by usj12262@hotmail.com
 BUILD=108
-SHUUSEI=76
+SHUUSEI=78
 
 [Log]
 SERVER_INIT=$1を起動中…
@@ -995,6 +995,7 @@
 S_SHOTHER4_CB_ALLOW_UTATANE               =Utatane
 S_SHOTHER4_CB_ALLOW_2GET                  =2get
 S_SHOTHER4_CB_ALLOW_OTHER                 =ほか
+S_SHOTHER4_LABEL163                       =server.logの保存フォルダ:
 
 [UserMode]
 CAPTION=制御端末ユーザーの表示モード
diff --dos -ur 24177/lang.pas 24178/lang.pas
--- 24177/lang.pas	Fri Aug 08 13:01:30 2003
+++ 24178/lang.pas	Sun Aug 10 17:41:44 2003
@@ -1186,6 +1186,7 @@
  LNG_S_SHOTHER4_CB_ALLOW_UTATANE               = 1828;
  LNG_S_SHOTHER4_CB_ALLOW_2GET                  = 1829;
  LNG_S_SHOTHER4_CB_ALLOW_OTHER                 = 1830;
+ LNG_S_SHOTHER4_LABEL163                       = 1831;
  LNG_MAX                                       = 1862;//832;
 
  // strings that shouldn't be translated
@@ -2559,6 +2560,7 @@
   GetIni(ini,LNG_S_SHOTHER4_CB_ALLOW_UTATANE                ,'Settings','S_SHOTHER4_CB_ALLOW_UTATANE');
   GetIni(ini,LNG_S_SHOTHER4_CB_ALLOW_2GET                   ,'Settings','S_SHOTHER4_CB_ALLOW_2GET');
   GetIni(ini,LNG_S_SHOTHER4_CB_ALLOW_OTHER                  ,'Settings','S_SHOTHER4_CB_ALLOW_OTHER');
+  GetIni(ini,LNG_S_SHOTHER4_LABEL163                        ,'Settings','S_SHOTHER4_LABEL163');
   GetIni(ini,LNG_FONT_CHARSET                               ,'Font','FONT_CHARSET');
   GetIni(ini,LNG_FONT_SIZE                                  ,'Font','FONT_SIZE');
   GetIni(ini,LNG_FONT_NAME                                  ,'Font','FONT_NAME');
diff --dos -ur 24177/mainform.pas 24178/mainform.pas
--- 24177/mainform.pas	Fri Aug 08 12:04:28 2003
+++ 24178/mainform.pas	Sun Aug 10 17:42:52 2003
@@ -695,9 +695,14 @@
  i: Integer;
  r: TRect;
  logfilename: String;
+ ini: TIniFile;
 begin
+ ini:=TIniFile.Create(ApplicationDir+'config');
+ log_folder:=ini.ReadString('Other2','LogFolder',ApplicationDir);
+ ini.Free;
  ShortDateFormat := 'yyyymmdd';
- logfilename:=ApplicationDir+'server-'+DateToStr(now)+'.log';
+ //logfilename:=ApplicationDir+'server-'+DateToStr(now)+'.log';
+ logfilename:=log_folder+'server-'+DateToStr(now)+'.log';
  ShortDateFormat := 'yyyy/mm/dd';
  if not FileExists(logfilename) then
    try
@@ -1502,7 +1507,7 @@
   listall_for_users:=ini.ReadBool('Other2','ListAllForUsers',true);
   block_weird_xnapfile:=ini.ReadBool('Other2','BlockWeirdXNapFile',false);
   suggest_dbrowse:=ini.ReadBool('Other2','SuggestDirectBrowse',false);
-
+  log_folder:=ini.ReadString('Other2','LogFolder',ApplicationDir);
   // set up console
   LogStartup('mainform::loadconfig: setting up console user');
   cons_channels:=TMyList.Create;
@@ -1985,6 +1990,7 @@
   ini.WriteBool('Other2','ListAllForUsers',listall_for_users);
   ini.WriteBool('Other2','BlockWeirdXNapFile',block_weird_xnapfile);
   ini.WriteBool('Other2','SuggestDirectBrowse',suggest_dbrowse);
+  ini.WriteString('Other2','LogFolder',log_folder);
   finally
   ini.Free;
  end;
diff --dos -ur 24177/settings.dfm 24178/settings.dfm
--- 24177/settings.dfm	Fri Aug 08 12:02:52 2003
+++ 24178/settings.dfm	Sun Aug 10 17:44:38 2003
@@ -1,6 +1,6 @@
 object SlavaNapSettings: TSlavaNapSettings
-  Left = 270
-  Top = 147
+  Left = 255
+  Top = 184
   BorderIcons = [biSystemMenu, biMinimize]
   BorderStyle = bsSingle
   Caption = 'SlavaNapの設定'
@@ -285,7 +285,7 @@
       Top = 38
       Width = 365
       Height = 392
-      ActivePage = sh_other3
+      ActivePage = sh_other4
       Align = alClient
       MultiLine = True
       OwnerDraw = True
@@ -1922,7 +1922,7 @@
           Width = 156
           Height = 20
           Style = csDropDownList
-          ItemHeight = 0
+          ItemHeight = 12
           TabOrder = 9
         end
       end
@@ -2435,7 +2435,7 @@
           Width = 111
           Height = 20
           Style = csDropDownList
-          ItemHeight = 0
+          ItemHeight = 12
           TabOrder = 1
         end
         object Edit_cons_autojoin1: TEdit
@@ -5504,7 +5504,7 @@
           Width = 156
           Height = 20
           Style = csDropDownList
-          ItemHeight = 0
+          ItemHeight = 12
           TabOrder = 9
         end
       end
@@ -5860,7 +5860,7 @@
             Width = 73
             Height = 20
             Style = csDropDownList
-            ItemHeight = 0
+            ItemHeight = 12
             TabOrder = 4
             Visible = False
           end
@@ -5915,7 +5915,7 @@
             Width = 73
             Height = 20
             Style = csDropDownList
-            ItemHeight = 0
+            ItemHeight = 12
             TabOrder = 4
             Visible = False
           end
@@ -6258,6 +6258,13 @@
         TabFontColor = clBlack
         BevelInner = bvNone
         BevelOuter = bvNone
+        object Label163: TLabel
+          Left = 8
+          Top = 82
+          Width = 134
+          Height = 12
+          Caption = 'server.logの保存フォルダ:'
+        end
         object cb_regsoft_only: TCheckBox
           Left = 8
           Top = 0
@@ -6333,7 +6340,7 @@
         end
         object edit_allow_sign0: TEdit
           Left = 24
-          Top = 56
+          Top = 54
           Width = 57
           Height = 20
           TabOrder = 9
@@ -6342,7 +6349,7 @@
         end
         object edit_allow_sign1: TEdit
           Left = 88
-          Top = 56
+          Top = 54
           Width = 57
           Height = 20
           TabOrder = 10
@@ -6351,7 +6358,7 @@
         end
         object edit_allow_sign2: TEdit
           Left = 152
-          Top = 56
+          Top = 54
           Width = 57
           Height = 20
           TabOrder = 11
@@ -6360,7 +6367,7 @@
         end
         object edit_allow_sign3: TEdit
           Left = 216
-          Top = 56
+          Top = 54
           Width = 57
           Height = 20
           TabOrder = 12
@@ -6369,7 +6376,7 @@
         end
         object edit_allow_sign4: TEdit
           Left = 280
-          Top = 56
+          Top = 54
           Width = 57
           Height = 20
           TabOrder = 13
@@ -6383,6 +6390,23 @@
           Height = 17
           Caption = 'TekNap'
           TabOrder = 14
+        end
+        object edit_log_folder: TEdit
+          Left = 152
+          Top = 78
+          Width = 189
+          Height = 20
+          TabOrder = 15
+          Text = 'edit_log_folder'
+        end
+        object btn_log_folder: TButton
+          Left = 341
+          Top = 78
+          Width = 12
+          Height = 20
+          Caption = '...'
+          TabOrder = 16
+          OnClick = btn_log_folderClick
         end
       end
     end
diff --dos -ur 24177/settings.pas 24178/settings.pas
--- 24177/settings.pas	Fri Aug 08 12:54:22 2003
+++ 24178/settings.pas	Sun Aug 10 19:09:12 2003
@@ -23,7 +23,7 @@
   Windows, Messages, SysUtils, Classes2, Graphics, Controls, Forms, Dialogs,
   ExtCtrls, OfficePanel, ComCtrls, StdCtrls, inifiles, registry,
   SpectrumCombo, ShellApi, Buttons, Spin, basecombo, Pages, Classes,
-  DFWPages;
+  DFWPages, ActiveX, ShlObj;
 
 type
   TSlavaNapSettings = class(TForm)
@@ -623,6 +623,9 @@
     Label161: TLabel;
     Label162: TLabel;
     cb_suggest_dbrowse: TCheckBox;
+    edit_log_folder: TEdit;
+    btn_log_folder: TButton;
+    Label163: TLabel;
     procedure Panel3Resize(Sender: TObject);
     procedure headerPaint(Sender: TObject);
     procedure SetTopText(str: String);
@@ -710,6 +713,7 @@
     procedure cb_allow_otherClick(Sender: TObject);
     procedure sh_other4Show(Sender: TObject);
     procedure cb_kill_idleuserClick(Sender: TObject);
+    procedure btn_log_folderClick(Sender: TObject);
   private
     { Private declarations }
     procedure SetBanItems(control: TComboBox);
@@ -722,8 +726,11 @@
     procedure ChangeInterface;
   end;
 
+function BrowseCallbackProc(hWnd: HWND; uMsg: UINT; lParam, lpData: lParam): Integer stdCall;
+
 var
   SlavaNapSettings: TSlavaNapSettings;
+  BrowseInfo: TBrowseInfo;
 
 implementation
 
@@ -1627,6 +1634,7 @@
  edit_allow_sign2.Visible:=cb_allow_other.Checked;
  edit_allow_sign3.Visible:=cb_allow_other.Checked;
  edit_allow_sign4.Visible:=cb_allow_other.Checked;
+ edit_log_folder.Text:=log_folder;
 end;
 
 procedure TSlavaNapSettings.sh_reportShow(Sender: TObject);
@@ -1706,6 +1714,7 @@
  ini: TIniFile;
  reg: TRegistry;
  i: Integer;
+ logfilename: String;
 begin
  if pages.ActivePage=sh_main then
  try
@@ -2222,6 +2231,29 @@
    allowed_custom[2]:=edit_allow_sign2.Text;
    allowed_custom[3]:=edit_allow_sign3.Text;
    allowed_custom[4]:=edit_allow_sign4.Text;
+   if log_folder<>edit_log_folder.Text then
+   begin
+     log_file.Free;
+     ShortDateFormat := 'yyyymmdd';
+     //logfilename:=ApplicationDir+'server-'+DateToStr(now)+'.log';
+     logfilename:=edit_log_folder.Text+'server-'+DateToStr(now)+'.log';
+     ShortDateFormat := 'yyyy/mm/dd';
+     if not FileExists(logfilename) then
+       try
+        log_file:=TFileStream.Create(logfilename,fmCreate);
+        log_file.Free;
+        except
+       end;
+     try
+       log_file:=TFileStream.Create(logfilename,fmOpenWrite or fmShareDenyWrite);
+       log_file.Seek(0,soFromEnd);
+      except
+       log_file:=nil;
+       LogStartup('settings::btn_changeClick: cannot open "'+logfilename+'" !!!');
+       DebugLog('Error: cannot open file '+logfilename);
+     end;
+   end;
+   log_folder:=edit_log_folder.Text;
   except
  end;
  btn_restoreClick(nil);
@@ -3088,6 +3120,7 @@
   cb_allow_utatane.Caption             :=GetLangI(LNG_S_SHOTHER4_CB_ALLOW_UTATANE);
   cb_allow_winmx.Caption               :=GetLangI(LNG_S_SHOTHER4_CB_ALLOW_WINMX);
   cb_allow_xnap.Caption                :=GetLangI(LNG_S_SHOTHER4_CB_ALLOW_XNAP);
+  Label163.Caption                     :=GetLangI(LNG_S_SHOTHER4_LABEL163);
 end;
 
 procedure TSlavaNapSettings.cb_allow_otherClick(Sender: TObject);
@@ -3104,6 +3137,49 @@
   Label161.Visible:=cb_kill_idleuser.Checked;
   Label162.Visible:=cb_kill_idleuser.Checked;
   edit_kill_idleuser_time.Visible:=cb_kill_idleuser.Checked;
+end;
+
+procedure TSlavaNapSettings.btn_log_folderClick(Sender: TObject);
+var
+  Memory: IMalloc;
+  Buffer: PChar;
+  Ret, Root: PItemIDList;
+begin
+  SHGetMalloc(Memory);
+  Buffer:= Memory.Alloc(MAX_PATH);
+  SHGetSpecialFolderLocation(SlavaNapSettings.Handle, CSIDL_DRIVES, Root);
+  with BrowseInfo do
+  begin
+    hwndOwner:= SlavaNapSettings.Handle;
+    pidlRoot:= Root;
+    ulFlags:= BIF_STATUSTEXT ;
+    lpszTitle:= 'ログフォルダを指定してください。';
+    pszDisplayName:= Buffer;
+    lpfn:= BrowseCallbackProc;
+  end;
+  Ret := SHBrowseForFolder(BrowseInfo);
+  if SHGetPathFromIDList(Ret, Buffer) then
+    edit_log_folder.Text := Buffer;
+  if edit_log_folder.Text[Length(edit_log_folder.Text)]<>'\' then
+    edit_log_folder.Text := Buffer + '\';
+  Memory.Free(Ret);
+  Memory.Free(Root);
+  Memory.Free(Buffer);
+end;
+
+function BrowseCallbackProc(hWnd: HWND; uMsg: UINT; lParam, lpData: lParam): Integer;
+var
+ Path: array[0..65536] of Char;
+begin
+  if BrowseInfo.ulFlags=BIF_STATUSTEXT then
+  begin
+    if uMsg = BFFM_SELCHANGED then
+    begin
+      SHGetPathFromIDList(PItemIDList(lParam), Path);
+      SendMessage(hWnd, BFFM_SETSTATUSTEXT, 0, LongInt(String(Path)));
+    end;
+  end;
+  Result:= 0;
 end;
 
 end.
diff --dos -ur 24177/stypes.pas 24178/stypes.pas
--- 24177/stypes.pas	Fri Aug 08 00:08:00 2003
+++ 24178/stypes.pas	Sun Aug 10 18:00:52 2003
@@ -1611,7 +1611,8 @@
    if not log_to_file then exit;
    cmd:=cmd+#13#10;
    ShortDateFormat := 'yyyymmdd';
-   logfilename:=ApplicationDir+'server-'+DateToStr(now)+'.log';
+   //logfilename:=ApplicationDir+'server-'+DateToStr(now)+'.log';
+   logfilename:=log_folder+'server-'+DateToStr(now)+'.log';
    ShortDateFormat := 'yyyy/mm/dd';
    if not FileExists(logfilename) then begin
     try
@@ -1658,7 +1659,8 @@
    cmd:=GetLogTime+'Console: '+cmd+#13#10;
    if log_to_file then begin
     ShortDateFormat := 'yyyymmdd';
-    logfilename:=ApplicationDir+'server-'+DateToStr(now)+'.log';
+    //logfilename:=ApplicationDir+'server-'+DateToStr(now)+'.log';
+    logfilename:=log_folder+'server-'+DateToStr(now)+'.log';
     ShortDateFormat := 'yyyy/mm/dd';
     if not FileExists(logfilename) then begin
      try
diff --dos -ur 24177/thread.pas 24178/thread.pas
--- 24177/thread.pas	Fri Aug 08 00:50:32 2003
+++ 24178/thread.pas	Sun Aug 10 19:18:58 2003
@@ -472,7 +472,7 @@
    SlavaNapWindow.LogMain(slError,GetLangT(LNG_INVALIDLNGFILE,language+'.lng'));
   if GetLangT(LNG_MSGFILE_VERSION)<>SLAVANAP_BUILD then
    SlavaNapWindow.LogMain(slError,GetLangT(LNG_INVALIDLNGFILE,'slavanap.msg'));
-  if cons_autojoin3<>'' then 
+  if cons_autojoin3<>'' then
    cmd_list.AddDoubleCmd(MSG_CLIENT_JOIN,0,cons_autojoin3,'');
   if cons_autojoin2<>'' then 
    cmd_list.AddDoubleCmd(MSG_CLIENT_JOIN,0,cons_autojoin2,'');
@@ -642,7 +642,8 @@
    MSG_CMD_RESETLOG: begin
                        tmp_pos:=1499;
                        ShortDateFormat := 'yyyymmdd';
-                       logfilename:=ApplicationDir+'server-'+DateToStr(now)+'.log';
+                       //logfilename:=ApplicationDir+'server-'+DateToStr(now)+'.log';
+                       logfilename:=log_folder+'server-'+DateToStr(now)+'.log';
                        ShortDateFormat := 'yyyy/mm/dd';
                        try
                          if log_file<>nil then
diff --dos -ur 24177/vars.pas 24178/vars.pas
--- 24177/vars.pas	Fri Aug 08 12:03:10 2003
+++ 24178/vars.pas	Sun Aug 10 17:39:16 2003
@@ -345,6 +345,7 @@
  listall_for_users: Boolean;
  block_weird_xnapfile: Boolean;
  suggest_dbrowse: Boolean;
+ log_folder: String;
 implementation
 
 procedure CheckWindows;