OSDN Git Service

ローカルルール未取得時にAVが出る問題を修正
[gikonavigoeson/gikonavi.git] / Editor.pas
1 unit Editor;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
7         Dialogs, StdCtrls, ComCtrls, ExtCtrls, ToolWin, Menus, OleCtrls, Registry,
8 {$IF Defined(DELPRO) }
9         SHDocVw,
10         MSHTML,
11 {$ELSE}
12         SHDocVw_TLB,
13         MSHTML_TLB,
14 {$IFEND}
15         ActiveX, {HTTPApp,} YofUtils, Trip, IniFiles, StrUtils,
16         GikoSystem, GikoUtil, ImgList, Clipbrd, BoardGroup,
17         IdAntiFreezeBase,       IdAntiFreeze, IdBaseComponent, IdComponent,
18         IdTCPConnection, IdTCPClient, IdHTTP, ActnList, StdActns, IdIntercept,
19         IdLogBase, IdLogDebug, IdException, DateUtils, MojuUtils, bmRegExp,
20         GestureModel;
21
22 type
23 //      TSetLayeredWindowAttributes = function(wnd: HWND; crKey: DWORD; bAlpha: BYTE; dwFlag: DWORD): Boolean; stdcall;
24         //\8f\91\82«\8d\9e\82Ý\96ß\82è\92l\83^\83C\83v
25         TGikoResultType = (grtOK, grtCookie, grtCheck, grtError);
26
27         TEditorForm = class(TForm)
28                 MainMenu: TMainMenu;
29                 FileMenu: TMenuItem;
30                 PostMessage: TMenuItem;
31                 SaveMessage: TMenuItem;
32                 CloseMenu: TMenuItem;
33                 N01: TMenuItem;
34                 StatusBar: TStatusBar;
35         EditorPage: TPageControl;
36                 EditorTab: TTabSheet;
37                 PreviewTab: TTabSheet;
38                 Browser: TWebBrowser;
39                 EditMenu: TMenuItem;
40                 UndoMenu: TMenuItem;
41                 CutMenu: TMenuItem;
42                 CopyMenu: TMenuItem;
43                 PasteMenu: TMenuItem;
44                 N02: TMenuItem;
45                 ToolBarImageList: TImageList;
46                 HotToobarImageList: TImageList;
47                 BodyEdit: TMemo;
48                 NameBasePanel: TPanel;
49                 NameLabel: TLabel;
50                 MailLabel: TLabel;
51                 NameComboBox: TComboBox;
52                 MailComboBox: TComboBox;
53                 ToolBar: TToolBar;
54                 SendToolButton: TToolButton;
55                 OutBoxToolButton: TToolButton;
56                 ToolButton5: TToolButton;
57                 UndoToolButton: TToolButton;
58                 CutToolButton: TToolButton;
59                 CopyToolButton: TToolButton;
60                 PasteToolButton: TToolButton;
61                 ToolButton3: TToolButton;
62                 TransToolButton: TToolButton;
63                 TopToolButton: TToolButton;
64                 Indy: TIdHTTP;
65                 IdAntiFreeze: TIdAntiFreeze;
66                 ToolButton1: TToolButton;
67                 ToolButton2: TToolButton;
68                 ActionList: TActionList;
69                 SendAction: TAction;
70                 SaveAction: TAction;
71                 CloseAction: TAction;
72                 UndoAction: TAction;
73                 CutAction: TAction;
74                 CopyAction: TAction;
75                 PasteAction: TAction;
76                 AbortAction: TAction;
77                 TopAction: TAction;
78                 Show1: TMenuItem;
79                 T1: TMenuItem;
80                 N1: TMenuItem;
81                 S1: TMenuItem;
82                 SageCheckBox: TCheckBox;
83                 IdLogDebug: TIdLogDebug;
84                 TransAction: TAction;
85                 A1: TMenuItem;
86                 KotehanCheckBox: TCheckBox;
87                 TitlePanel: TPanel;
88                 Label1: TLabel;
89                 TitleEdit: TEdit;
90                 SelectAllAction: TAction;
91                 N2: TMenuItem;
92                 SelectAll1: TMenuItem;
93         Timer1: TTimer;
94         QuotePasteAction: TAction;
95         QuotePasteMenuItem: TMenuItem;
96         C1: TMenuItem;
97         SpaceToNBSPAction: TAction;
98         AmpToCharRefAction: TAction;
99         SpaceTabnbsp1: TMenuItem;
100         amp1: TMenuItem;
101         BoardInformationTab: TTabSheet;
102                                 BoardtopTab: TTabSheet;
103         TitlePictureBrowser: TWebBrowser;
104         BoardTop: TMenuItem;
105         BoardInformationMemo: TMemo;
106         GetSETTINGTXTAction: TAction;
107         N3: TMenuItem;
108         SETTINGTXT2: TMenuItem;
109         GetTitlePictureAction: TAction;
110         OP1: TMenuItem;
111     GetHeadTXTAction: TAction;
112     HeadTXT1: TMenuItem;
113     RocalRuleTab: TTabSheet;
114     WebBrowser1: TWebBrowser;
115     CalcCapasityAction: TAction;
116     N4: TMenuItem;
117     N5: TMenuItem;
118     LocalRule: TMenuItem;
119     LocalEdit: TMemo;
120
121                 procedure EditorPageChange(Sender: TObject);
122                 procedure FormCreate(Sender: TObject);
123                 procedure BrowserStatusTextChange(Sender: TObject;
124                         const Text: WideString);
125                 procedure FormClose(Sender: TObject; var Action: TCloseAction);
126                 procedure FormDestroy(Sender: TObject);
127                 procedure SendActionExecute(Sender: TObject);
128                 procedure SaveActionExecute(Sender: TObject);
129                 procedure AbortActionExecute(Sender: TObject);
130                 procedure CloseActionExecute(Sender: TObject);
131                 procedure UndoActionExecute(Sender: TObject);
132                 procedure CutActionExecute(Sender: TObject);
133                 procedure CopyActionExecute(Sender: TObject);
134                 procedure PasteActionExecute(Sender: TObject);
135                 procedure SendActionUpdate(Sender: TObject);
136                 procedure SaveActionUpdate(Sender: TObject);
137                 procedure CloseActionUpdate(Sender: TObject);
138                 procedure UndoActionUpdate(Sender: TObject);
139                 procedure CutActionUpdate(Sender: TObject);
140                 procedure CopyActionUpdate(Sender: TObject);
141                 procedure PasteActionUpdate(Sender: TObject);
142                 procedure TopActionExecute(Sender: TObject);
143                 procedure TopActionUpdate(Sender: TObject);
144                 procedure SageCheckBoxClick(Sender: TObject);
145                 procedure MailComboBoxChange(Sender: TObject);
146                 procedure TransActionExecute(Sender: TObject);
147                 procedure TransActionUpdate(Sender: TObject);
148                 procedure IdLogDebugReceive(ASender: TIdConnectionIntercept;
149                         AStream: TStream);
150                 procedure IdLogDebugSend(ASender: TIdConnectionIntercept;
151                         AStream: TStream);
152                 procedure SelectAllActionExecute(Sender: TObject);
153         procedure StatusBarResize(Sender: TObject);
154         procedure Timer1Timer(Sender: TObject);
155         procedure FormActivate(Sender: TObject);
156         procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
157                 procedure QuotePasteActionExecute(Sender: TObject);
158         procedure SpaceToNBSPActionExecute(Sender: TObject);
159         procedure AmpToCharRefActionExecute(Sender: TObject);
160         procedure BoardTopClick(Sender: TObject);
161         procedure GetSETTINGTXTActionExecute(Sender: TObject);
162         procedure GetTitlePictureActionUpdate(Sender: TObject);
163         procedure GetTitlePictureActionExecute(Sender: TObject);
164     procedure GetHeadTXTActionExecute(Sender: TObject);
165     procedure CalcCapasityActionExecute(Sender: TObject);
166     procedure LocalRuleClick(Sender: TObject);
167     procedure FormDeactivate(Sender: TObject);
168         private
169                 FThreadItem: TThreadItem;
170                 FBoard: TBoard;
171                 FNameComboEdit: THandle;
172                 FMailComboEdit: THandle;
173                 FAbort: Boolean;
174                 FWork: Boolean;
175                 FStatusCode: Integer;
176                 FDebugStrReceive: string;
177                 FDebugStrSend: string;
178                 FSambaTime: TDateTime;
179                 FHost: string;
180                 FNow: TDateTime;
181                 FGestures       : TGestureModel;
182                 procedure Preview;
183                 function RepHtml(s: string): string;
184                 function Check: Boolean;
185                 procedure SetNameList(sName, sMail: string);
186 //              procedure Send(SendType: TGikoSendType; SPID: string; PON: string; FirstWriting: Boolean);
187                 procedure Send(SPID: string; PON: string; FirstWriting: Boolean);
188
189                 function GetActiveControlHandle: THandle;
190 //              function GetSendData: string;
191 //              procedure GetSendData(Source: TStringStream);
192                 procedure GetSendData(Source: TStringStream);
193                 procedure SaveSendFile;
194                 procedure SetContent(Content: string; ABrowser: TWebBrowser);
195                 function GetSPID(CookieLine: string): string;
196                 function GetPON(CookieLine: string): string;
197                 function GetResultType(ResponseText: string): TGikoResultType;
198                 procedure ReadSambaTime(const AHost: string);
199                 procedure WriteSambaTime(const AHost: string; ATime: TDateTime);
200                 function ReadSettingTime(const AHost: string): Integer;
201                 function CheckSambaTime(const AHost: string; ATime: TDateTime): Boolean;
202                                 procedure SetSamba24(AURL: string);
203                 /// \88ø\97p\95\84\82Ì\8eæ\93¾
204                 function GetOEIndentChar : string;
205                 /// \96{\95\82Ì\8eæ\93¾
206                 function GetBody : string;
207                 //IdHttp\82Ì\8f\89\8aú\89»
208                 procedure InitIdHTTP(http: TIdHTTP);
209                 procedure ShowBoardInformation(ABoard: TBoard; AMemo: TMemo);
210                 function GetTitlePictureURL(body: TStringList; ABoard: TBoard): string;
211                 procedure ShowTitlePicture();
212                 function GetFusianaName(body: TStringList; ABoard: TBoard): String;
213                 //! \83}\83E\83X\83W\83F\83X\83`\83\83\81[\8aJ\8en
214                 procedure OnGestureStart(Sender: TObject);
215                 //! \83}\83E\83X\83W\83F\83X\83`\83\83\81[\92\86
216                 procedure OnGestureMove(Sender: TObject);
217                 //! \83}\83E\83X\83W\83F\83X\83`\83\83\81[\8fI\97¹
218                 procedure OnGestureEnd(Sender: TObject);
219                 //HEAD.TXT\8e©\93®\95\\8e¦
220                 procedure ShowBoardHead(ABoard: TBoard; AMemo: TMemo);
221         protected
222                 procedure CreateParams(var Params: TCreateParams); override;
223         public
224                                 FBBSID: String;
225                 procedure SetFont;
226                 procedure SetThreadItem(Item: TThreadItem);
227                 procedure SetBoard(Item: TBoard);
228                                 property BBSID: string read FBBSID write FBBSID;
229
230         end;
231
232 implementation
233
234 uses
235         Giko, ItemDownload, Gesture;
236 const
237         CAPTION_NAME_NEW: string = '\83M\83R\83i\83\83X\83\8c\97§\82Ä\83G\83f\83B\83^';
238         CAPTION_NAME_RES: string = '\83M\83R\83i\83\83\8c\83X\83G\83f\83B\83^';
239
240     // \83G\83f\83B\83b\83g\83E\83B\83\93\83h\83E\82ð\89E\89º\82É\82¸\82ç\82µ\82Ä\8aJ\82­\88Ú\93®\97Ê
241     WINDOWMOVE_H = 30;
242     WINDOWMOVE_V = 30;
243
244         //DAX\82³\82ñ±Ø¶ÞÄ!(\81L\81¤\81M)
245         READCGI_ERR                     = '-ERR';
246         READCGI_INCR            = '-INCR';
247         READCGI_OK                      = '+OK';
248         READCGI_PARTIAL = '+PARTIAL';
249         READCGI_ERR_FOUND_KAKO  = '-ERR \89ß\8b\8e\83\8d\83O\91q\8cÉ\82Å\94­\8c©';
250         READCGI_ERR_NOT_HTML            = '-ERR html\89»\91Ò\82¿';
251         READCGI_ERR_NOT_FOUND           = '-ERR \82»\82ñ\82È\94Âor\83X\83\8c\83b\83h\82È\82¢\82Å\82·\81B';
252         READCGI_ERR_ABONE                               = '-ERR \82Ç\82±\82©\82Å\82 \82Ú\81[\82ñ\82ª\82 \82Á\82½\82Ý\82½\82¢\82Å\82·\81B';
253         READCGI_ERR_TIMEOUT                     = '-ERR \8ew\92è\8e\9e\8aÔ\82ª\89ß\82¬\82Ü\82µ\82½\81B';
254         READCGI_ERR_CANTUSE                     = '-ERR \82à\82¤\81@\82Â\82©\82¦\82Ü\82¹\82ñ';
255         RES2CH_TRUE                             = '<!-- 2ch_X:true -->';
256         RES2CH_FALSE                    = '<!-- 2ch_X:false -->';
257         RES2CH_ERROR                    = '<!-- 2ch_X:error -->';
258         RES2CH_CHECK                    = '<!-- 2ch_X:check -->';
259         RES2CH_COOKIE                   = '<!-- 2ch_X:cookie -->';
260
261
262         BBS2CH_NAME:                                     string = '\82Q\82¿\82á\82ñ\82Ë\82é';
263         BBS2CH_LOG_FOLDER:               string = '2ch';
264         EXTERNAL_LOG_FOLDER:            string  = 'exboard';
265
266         FOLDER_INI_FILENAME:     string = 'Folder.ini';
267         FOLDER_INDEX_FILENAME: string   = 'Folder.idx';
268         SUBJECT_FILENAME:                       string  = 'subject.txt';
269         PATH_DELIM:                                             string  = '\';
270
271
272 type
273         TSelection = record
274                 StartPos, EndPos: Integer;
275         end;
276
277 {$R *.DFM}
278
279 {constructor TEditorForm.Create(AOwner: TComponent; Item: TBoard);
280 begin
281         inherited Create(AOwner);
282 end;}
283
284 procedure TEditorForm.CreateParams(var Params: TCreateParams);
285 begin
286         inherited;
287         if FormStyle in [fsNormal, fsStayOnTop] then
288                 if BorderStyle in [bsSingle, bsSizeable] then begin
289                         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
290                         Params.WndParent := 0;
291                 end;
292 end;
293
294 {procedure TEditorForm.CreateParams(var Params: TCreateParams);
295 begin
296         inherited CreateParams(Params);
297         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
298 end;}
299
300 procedure TEditorForm.FormCreate(Sender: TObject);
301 var
302         wp: TWindowPlacement;
303                 hUser32 : HINST;
304         ini: TIniFile;
305 begin
306         FWork := False;
307         Browser.Navigate('about:blank');
308         TitlePictureBrowser.Navigate('about:blank');
309         FBoard := nil;
310         FThreadItem := nil;
311
312         //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
313         wp.length := sizeof(wp);
314         wp.rcNormalPosition.Top := GikoSys.Setting.EditWindowTop;
315         wp.rcNormalPosition.Left := GikoSys.Setting.EditWindowLeft;
316
317         wp.rcNormalPosition.Bottom := GikoSys.Setting.EditWindowTop + GikoSys.Setting.EditWindowHeight;
318         wp.rcNormalPosition.Right := GikoSys.Setting.EditWindowLeft + GikoSys.Setting.EditWindowWidth;
319         wp.showCmd := SW_HIDE;
320         SetWindowPlacement(Handle, @wp);
321
322         if GikoSys.Setting.EditWindowMax then
323                 WindowState := wsMaximized;
324
325         //\83E\83B\83\93\83h\83E\82ª\89æ\96Ê\8aO\82È\82ç\89æ\96Ê\93à\82É\88Ú\93®\82·\82é
326         if (Left + Width) > Screen.Width then
327 //              Left := Screen.Width - Width;
328                 Left := 0;
329         if (Top + Height) > Screen.Height then
330 //              Top := Screen.Height - Height;
331                 Top := 0;
332         if Left < 0 then
333                 Left := 0;
334         if Top < 0 then
335                 Top := 0;
336
337     //\8c»\8dÝ\82Ì\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\82ð\95Û\91
338     GikoSys.Setting.EditWindowTop := Top  + WINDOWMOVE_V;   // \8e\9f\82É\8aJ\82­\83E\83B\83\93\83h\83E\82Í
339     GikoSys.Setting.EditWindowLeft := Left + WINDOWMOVE_H;  // \81@\81@\81@\89E\8eÎ\82ß\89º\82É\82¸\82ç\82·
340     //\83E\83B\83\93\83h\83E\82Ì\95\9d\82Æ\8d\82\82³\82ª\8f¬\82³\82·\82¬\82¢\82ê\82Î\8c³\82É\96ß\82·
341         if GikoSys.Setting.EditWindowHeight < 144 then
342                 Height := 400;
343         if GikoSys.Setting.EditWindowWidth < 144 then
344                 Width := 640;
345
346         EditorPage.ActivePage := EditorTab;
347         FNameComboEdit := GetWindow(NameComboBox.Handle, GW_CHILD);
348         FMailComboEdit := GetWindow(MailComboBox.Handle, GW_CHILD);
349         NameComboBox.Items.Assign(GikoSys.Setting.NameList);
350         MailComboBox.Items.Assign(GikoSys.Setting.MailList);
351         SetFont;
352         hUser32 := 0;
353         try
354                 try
355                         hUser32 := LoadLibrary('User32.dll');
356                         if hUser32 <> 0 then
357                                 TransAction.Enabled := true
358                         else
359                                 TransAction.Enabled := false;
360                 except
361                 TransAction.Enabled := false;
362                 end;
363         finally
364                 FreeLibrary(hUser32);
365         end;
366
367     // \83E\83B\83\93\83h\83E\82Ì\83X\83e\83C\8fó\91Ô
368         if GikoSys.Setting.EditWindowStay then begin    // \83X\83e\83C\8fó\91Ô
369                 SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
370                 TopAction.Checked := true;
371                 TopToolButton.Down := true;
372         end else begin                                  // \83X\83e\83C\82µ\82È\82¢
373                 SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
374                 TopAction.Checked := false;
375                 TopToolButton.Down := false;
376         end;
377
378     // \83E\83B\83\93\83h\83E\82Ì\94¼\93§\96¾\8fó\91Ô
379         if(GikoSys.Setting.EditWindowTranslucent) and (TransAction.Enabled) then begin // \94¼\93§\96¾\81i\83g\83\89\83\93\83X\83\8b\81[\83Z\83\93\83g\81j\8fó\91Ô
380         AlphaBlend := true;
381         TransAction.Checked := true;
382         TransToolButton.Down := true;
383     end else begin                                      // \95s\93§\96¾
384         AlphaBlend := false;
385         TransAction.Checked := false;
386         TransToolButton.Down := false;
387     end;
388         // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
389         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;
390
391         SpaceToNBSPAction.Checked               := GikoSys.Setting.SpaceToNBSP;
392         AmpToCharRefAction.Checked      := GikoSys.Setting.AmpToCharRef;
393
394                 ini := TIniFile.Create(GikoSys.Setting.GetFileName);
395
396                 try
397                         BoardtopTab.TabVisible := ini.Readbool('EditorForm', 'BoardTopTab', False);
398                         BoardTop.Checked := BoardtopTab.TabVisible;
399                         RocalRuleTab.TabVisible := ini.ReadBool('EditorForm', 'LocalRuleTab', False);
400                         LocalRule.Checked := RocalRuleTab.TabVisible;
401                 finally
402                         ini.Free;
403                 end;
404
405         // \83}\83E\83X\83W\83F\83X\83`\83\83\81[\82Ì\83C\83\93\83X\83g\81[\83\8b
406         if GikoSys.Setting.GestureEnabled then begin
407                 MouseGesture.UnHook;
408                 FGestures := TGestureModel.Create;
409                 FGestures.LoadGesture(
410                         GikoSys.Setting.GetGestureFileName, ActionList );
411                 MouseGesture.OnGestureStart := OnGestureStart;
412                 MouseGesture.OnGestureMove := OnGestureMove;
413                 MouseGesture.OnGestureEnd := OnGestureEnd;
414                 MouseGesture.SetHook( Handle );
415         end;
416
417 end;
418
419 procedure TEditorForm.SetBoard(Item: TBoard);
420 begin
421         FBoard := Item;
422         Caption := CAPTION_NAME_NEW + ' - [' + Item.Title + ']';
423         NameComboBox.Text := FBoard.KotehanName;
424         MailComboBox.Text := FBoard.KotehanMail;
425         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
426         TitlePanel.Visible := True;
427         SetSamba24(FBoard.URL);
428         ShowBoardInformation(FBoard, BoardInformationMemo);
429         ShowTitlePicture();
430 end;
431
432 procedure TEditorForm.SetThreadItem(Item: TThreadItem);
433 begin
434         FThreadItem := Item;
435         Caption := CAPTION_NAME_RES + ' - [' + FThreadItem.Title + ']';
436         NameComboBox.Text := FThreadItem.ParentBoard.KotehanName;
437         MailComboBox.Text := FThreadItem.ParentBoard.KotehanMail;
438         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
439         TitlePanel.Visible := False;
440         SetSamba24(FThreadItem.ParentBoard.URL);
441         ShowBoardInformation(FThreadItem.ParentBoard, BoardInformationMemo);
442         ShowTitlePicture();
443 end;
444
445 function TEditorForm.GetBody : string;
446 var
447         body, tmp               : string;
448         p, tail                 : PChar;
449         len                                     : Integer;
450 const
451         TAB_LENGTH      = 4;
452 begin
453
454         body := BodyEdit.Text;
455         if AmpToCharRefAction.Checked then
456                 // & \82Ì\92u\8a·\82Í\88ê\94Ô\8dÅ\8f\89\82É\82â\82é\82±\82Æ
457                 body := CustomStringReplace( body, '&', '&amp;' );
458         if SpaceToNBSPAction.Checked then begin
459                 p                       := PChar( body );
460                 tail    := p + Length( body );
461                 len             := 0;
462                 while p < tail do begin
463                         case p^ of
464                         #09:
465                                 begin
466                                         Inc( p );
467                                         repeat
468                                                 Inc( len );
469                                                 tmp := tmp + '&nbsp;';
470                                         until (len mod TAB_LENGTH) = 0;
471                                 end;
472
473                         #10, #13:
474                                 begin
475                                         tmp := tmp + p^;        Inc( p );
476                                         len     := 0;
477                                 end;
478
479                         ' ':
480                                 begin
481                                         tmp     := tmp + '&nbsp;';
482                                         Inc( p );
483                                         Inc( len );
484                                 end;
485                                 
486                         '&':
487                                 // \8eÀ\91Ì\8eQ\8fÆ\82Í 1 \95\8e\9a\95ª
488                                 begin
489                                         tmp := tmp + '&';
490                                         Inc( p );
491                                         Inc( len );
492                                         while p < tail do begin
493                                                 if p^ in ['a'..'z', 'A'..'Z', '0'..'9', '#'] then begin
494                                                         tmp := tmp + p^;
495                                                 end else if p^ = ';' then begin
496                                                         tmp := tmp + p^;
497                                                         Inc( p );
498                                                         Break;
499                                                 end else begin
500                                                         Break;
501                                                 end;
502                                                 Inc( p );
503                                         end;
504                                 end;
505
506                         else
507                                 if p^ in kYofKanji then begin
508                                         tmp := tmp + p^;        Inc( p );
509                                         tmp     := tmp + p^;    Inc( p );
510                                         len     := len + 2;
511                                 end else begin
512                                         tmp := tmp + p^;        Inc( p );
513                                         Inc( len );
514                                 end;
515                         end;
516                 end;
517                 body := tmp;
518         end;
519
520         Result  := body;
521
522 end;
523
524 procedure TEditorForm.SetFont;
525 begin
526         BodyEdit.Font.Name := GikoSys.Setting.EditorFontName;
527         BodyEdit.Font.Size := GikoSys.Setting.EditorFontSize;
528         BodyEdit.Font.Color := GikoSys.Setting.EditorFontColor;
529         BodyEdit.Color := GikoSys.Setting.EditorBackColor;
530 end;
531
532 procedure TEditorForm.Preview;
533 var
534         Title: string;
535         No: string;
536         Mail: string;
537         Namae: string;
538         DateTime: string;
539         Body: string;
540         s: string;
541
542                                 posTrip : Integer;
543                                 tripOrigin : string;
544 begin
545         if FThreadItem = nil then begin
546                 No := '1';
547                 Title := RepHtml(TitleEdit.Text);
548         end else begin
549                 No := IntToStr(FThreadItem.Count + 1);
550                 Title := RepHtml(FThreadItem.Title);
551         end;
552
553         body := GetBody;
554         Namae := RepHtml(NameComboBox.Text);
555         Mail := RepHtml(MailComboBox.Text);
556         Body := RepHtml(body);
557         Body := StringReplace(Body, #13#10, '<br>', [rfReplaceAll]);
558         DateTime := FormatDateTime('yyyy/mm/dd(aaa) hh:nn', now);
559
560         if Trim(Namae) = '' then
561                 Namae := '\96¼\96³\82µ\82³\82ñ';
562
563         s := '<HTML><HEAD>' + #13#10
564                         + '<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">' + #13#10
565                         + '<TITLE>' + title + '</TITLE>' + #13#10
566 //                      + '<STYLE><!--BODY{font-size : 9pt;font-family : "\82l\82\82o\83S\83V\83b\83N";}--></STYLE>' + #13#10
567                         + '</HEAD>' + #13#10
568                         + '<BODY text="#000000" bgcolor="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">' + #13#10
569                         + '<FONT COLOR="#FF0000">' + title + '</FONT>' + #13#10
570                         + '<DL>' + #13#10;
571                                 posTrip := AnsiPos( '#', Namae );
572                                 if posTrip > 0 then
573                                 begin
574                                                                 tripOrigin := Copy( Namae, posTrip + 1, Length( Namae ) );
575                                                                 Namae :=
576                                                                                                 Copy( Namae, 1, posTrip - 1 ) + '</B> \81\9f' +
577                                                                                                 get_2ch_trip( PChar( tripOrigin ) ) + '<B>';
578                                 end;
579         if Mail = '' then
580                 s := s + '<DT>' + No + ' \81F <FONT color="forestgreen"><B>' + Namae + '</B></FONT> \81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10
581         else
582                 s := s + '<DT>' + No + ' \81F <A href="mailto:' + Mail + '"><B>' + Namae + '</B></A> [' + Mail + ']\81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10;
583         s := s + '</BODY></HTML>';
584         SetContent(s, Browser);
585 end;
586
587 function TEditorForm.RepHtml(s: string): string;
588 begin
589 //      s := StringReplace(s, '&', '&amp;', [rfReplaceAll]);
590         s := StringReplace(s, '<', '&lt;', [rfReplaceAll]);
591         s := StringReplace(s, '>', '&gt;', [rfReplaceAll]);
592 //      s := StringReplace(s, ' ', '&nbsp;', [rfReplaceAll]);   //\8ed\97l\95Ï\8dX\82É\82æ\82è&nbsp;\8eg\97p\95s\89Â
593         s := StringReplace(s, '"', '&quot;', [rfReplaceAll]);
594         Result := s;
595 end;
596
597 procedure TEditorForm.EditorPageChange(Sender: TObject);
598 var
599         tmpBoard: TBoard;
600 begin
601         if FThreadItem = nil then
602                 tmpBoard := FBoard
603         else
604                 tmpBoard := FThreadItem.ParentBoard;
605
606         if tmpBoard = nil then Exit;
607
608         if EditorPage.ActivePage = PreviewTab then begin
609                 Preview;
610         end else if EditorPage.ActivePage = RocalRuleTab then begin
611                 if not FileExists(tmpBoard.GETHEADTXTFileName) then begin
612                         LocalEdit.Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\96¢\8eæ\93¾';
613                         Exit;
614                 end;
615                 ShowBoardHead(tmpBoard, LocalEdit);
616         end else begin
617                 Browser.Navigate('about:blank');
618         end;
619 end;
620
621 procedure TEditorForm.BrowserStatusTextChange(Sender: TObject;
622         const Text: WideString);
623 begin
624         if EditorPage.ActivePage = PreviewTab then begin
625                 StatusBar.Panels[0].Text := Text;
626         end else begin
627                 StatusBar.Panels[0].Text := '';
628         end;
629 end;
630
631 function TEditorForm.Check: Boolean;
632 var
633         Msg: string;
634         rc: Integer;
635         Board: TBoard;
636 begin
637         Result := True;
638         if FThreadItem = nil then
639                 Board := FBoard
640         else
641                 Board := FThreadItem.ParentBoard;
642
643         if (not GikoSys.Setting.UseMachineTime) and
644                  ((Board.LastGetTime = 0) or
645                         (Board.LastGetTime = ZERO_DATE)) then begin
646                 Msg := '\83T\81[\83o\82Ì\8e\9e\8d\8f\82ª\95ª\82©\82ç\82È\82¢\82½\82ß\81A\91\97\90M\8fo\97\88\82Ü\82¹\82ñ'#13#10
647                                  + '\83X\83\8c\83b\83h\82ð\8dX\90V\81i\8eæ\93¾\81j\8cã\81A15\95b\91Ò\82Á\82Ä\82©\82ç\91\97\90M\82µ\82Ä\82­\82¾\82³\82¢';
648                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
649                 Result := False;
650         end else if BodyEdit.Text = '' then begin
651                 Msg := '\96{\95\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
652                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
653                 Result := False;
654         end else if (FBoard <> nil) and (Trim(TitleEdit.Text) = '') then begin
655                 Msg := '\83^\83C\83g\83\8b\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
656                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
657                 Result := False;
658         end else begin
659                 if (not GikoSys.Dolib.Connected) and (AnsiPos('\81\9c', NameComboBox.Text) <> 0) then begin
660                         Msg := '\83\8d\83O\83C\83\93\82µ\82Ä\82¢\82È\82¢\82Ì\82Å\81\9c\82Ì\8b@\94\\82Í\97\98\97p\8fo\97\88\82Ü\82¹\82ñ\81B'#13#10
661                                          + '\82±\82Ì\82Ü\82Ü\91\97\90M\82µ\82Ä\82à\82æ\82ë\82µ\82¢\82Å\82·\82©\81H';
662                         rc := MsgBox(Handle, Msg, '\8am\94F', MB_YESNO or MB_ICONQUESTION);
663                         Result := (rc = IDYES);
664                 end;
665         end;
666 end;
667
668 procedure TEditorForm.FormClose(Sender: TObject; var Action: TCloseAction);
669 begin
670         Action := caFree;
671 end;
672
673 procedure TEditorForm.FormDestroy(Sender: TObject);
674 var
675         wp: TWindowPlacement;
676 begin
677         //\8dÅ\91å\89»\81E\83E\83B\83\93\83h\83E\88Ê\92u\95Û\91
678         wp.length := sizeof(wp);
679         GetWindowPlacement(Handle, @wp);
680
681         GikoSys.Setting.EditWindowTop := wp.rcNormalPosition.Top;
682         GikoSys.Setting.EditWindowLeft := wp.rcNormalPosition.Left;
683         GikoSys.Setting.EditWindowHeight := wp.rcNormalPosition.Bottom - wp.rcNormalPosition.Top;
684         GikoSys.Setting.EditWindowWidth := wp.rcNormalPosition.Right - wp.rcNormalPosition.Left;
685         GikoSys.Setting.EditWindowMax := WindowState = wsMaximized;
686         //GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;      // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
687         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;   // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
688
689         FGestures.Free;
690
691 end;
692
693 procedure TEditorForm.SetNameList(sName, sMail: string);
694 begin
695         if Trim(sName) <> '' then begin
696                 if GikoSys.Setting.NameList.IndexOf(sName) = -1 then
697                         GikoSys.Setting.NameList.Insert(0, sName);
698         end;
699         if Trim(sMail) <> '' then begin
700                 if GikoSys.Setting.MailList.IndexOf(sMail) = -1 then
701                         GikoSys.Setting.MailList.Insert(0, sMail);
702         end;
703 end;
704
705 function TEditorForm.GetActiveControlHandle: THandle;
706 begin
707         if EditorPage.ActivePage = EditorTab then begin
708                 if ActiveControl = NameComboBox then
709                         Result := FNameComboEdit
710                 else if ActiveControl = MailComboBox then
711                         Result := FMailComboEdit
712                 else if ActiveControl = BodyEdit then
713                         Result := BodyEdit.Handle
714                 else if ActiveControl = TitleEdit then
715                         Result := TitleEdit.Handle
716                 else
717                         Result := 0;
718         end else if Editorpage.ActivePage = BoardInformationTab then begin
719                 if ActiveControl = BoardInformationMemo then
720                         Result := BoardInformationMemo.Handle
721                 else
722                         Result := 0;
723         end else
724                 Result := 0;
725 end;
726
727 procedure TEditorForm.SetContent(Content: string; ABrowser: TWebBrowser);
728 var
729         doc: Variant;
730 begin
731         if ABrowser.Document <> nil then begin
732                 doc := Idispatch( olevariant(ABrowser.ControlInterface).Document) as IHTMLDocument2;
733                 doc.Clear;
734                 doc.open;
735                 doc.charset := 'Shift_JIS';
736                 doc.Write(Content);
737                 doc.Close;
738         end;
739 end;
740 procedure TEditorForm.InitIdHTTP(http: TIdHTTP);
741 begin
742         http.Request.Clear;
743         http.ProxyParams.BasicAuthentication := False;
744         if GikoSys.Setting.WriteProxy then begin
745                 http.ProxyParams.ProxyServer := GikoSys.Setting.WriteProxyAddress;
746                 http.ProxyParams.ProxyPort := GikoSys.Setting.WriteProxyPort;
747                 http.ProxyParams.ProxyUsername := GikoSys.Setting.WriteProxyUserID;
748                 http.ProxyParams.ProxyPassword := GikoSys.Setting.WriteProxyPassword;
749                 if GikoSys.Setting.ReadProxyUserID <> '' then
750                         http.ProxyParams.BasicAuthentication := True;
751         end else begin
752                 http.ProxyParams.ProxyServer := '';
753                 http.ProxyParams.ProxyPort := 80;
754                 http.ProxyParams.ProxyUsername := '';
755                 http.ProxyParams.ProxyPassword := '';
756         end;
757         Indy.Request.UserAgent := GikoSys.GetUserAgent;
758         Indy.Request.AcceptEncoding := '';
759 end;
760
761 procedure TEditorForm.Send(SPID: string; PON: string; FirstWriting: Boolean);
762 var
763         TextStream: TStringStream;
764         Source: TStringStream;
765         ResponseText: string;
766         URL: string;
767         RefURL: string;
768         State: TGikoDownloadState;
769         ResultType: TGikoResultType;
770         MsgResult: Integer;
771         Cookie: string;
772         Board: TBoard;
773         sysMenu : HMENU;
774         //fusianasan\83g\83\89\83b\83v by\92è\8aú\95Ö
775         Namae : String;
776         body : TStringList;
777         Remote : String;
778         ABoard : TBoard;
779 begin
780         FAbort := False;
781         State := gdsError;
782         Namae := RepHtml(NameComboBox.Text);
783         if FThreadItem = nil then
784                 Board := FBoard
785         else
786                 Board := FThreadItem.ParentBoard;
787
788
789         InitIdHTTP(Indy);
790         if FThreadItem = nil then begin
791                 URL := FBoard.GetSendURL;
792                 RefURL := GikoSys.UrlToServer(FBoard.URL) + 'test/bbs.cgi';
793         end else begin
794                 URL := FThreadItem.GetSendURL;
795                 RefURL := FThreadItem.URL;
796         end;
797 //      Indy.Request.UserAgent := GikoSys.GetUserAgent;
798         Indy.Request.Referer := RefURL;
799 //      Indy.Request.AcceptEncoding := '';
800
801         Cookie := '';
802         if SPID <> '' then
803                 Cookie := Cookie + 'SPID=' + SPID + '; ';
804         if PON <> '' then
805                 Cookie := Cookie + 'PON=' + PON + '; ';
806         Cookie := 'Cookie: ' + Cookie + 'NAME=' + NameComboBox.Text + '; MAIL=' + MailComboBox.Text;
807
808         sysMenu := GetSystemMenu( Handle, false );
809         EnableMenuItem( sysMenu, SC_CLOSE, MF_GRAYED );
810 {
811   EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
812   DrawMenuBar(Handle);
813 }
814         Indy.Request.CustomHeaders.Clear;
815 //      Indy.Request.CacheControl := 'no-cache';
816         Indy.Request.CustomHeaders.Add('Pragma: no-cache');
817         Indy.Request.AcceptLanguage := 'ja';
818         Indy.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*';
819         Indy.Request.ContentType := 'application/x-www-form-urlencoded';
820         Indy.Request.CustomHeaders.Add(Cookie);
821         TextStream := TStringStream.Create('');
822         Source := TStringStream.Create('');
823         try
824                 try
825                         FDebugStrReceive := '';
826                         FDebugStrSend := '';
827                         GetSendData(Source);
828                         Indy.Post(URL, Source, TextStream);
829                         ResponseText := TextStream.DataString;
830
831                         ResultType := GetResultType(ResponseText);
832
833                         //MsgResult\8f\89\8aú\89»
834                         MsgResult := IDNO;
835                         //\83t\83V\83A\83i\83g\83\89\83b\83v\8cx\8d\90(LocalMode) by \92è\8aú\95Ö
836                         if GikoSys.Setting.LocalTrapAtt then begin
837                                 if ((Namae = '\8eR\8dè\8fÂ') or (Namae = 'fusianasan')) then begin
838                                         MsgResult := MsgBox(
839                                                         Handle,
840                                                 '\83\8a\83\82\81[\83g\83z\83X\83g\82ð\95\\8e¦\82·\82é\8b@\94\\82ª\8eg\82í\82ê\82Ä\82¢\82Ü\82·' + #13#10 +
841                                                 '\82à\82µ\82à\8aÔ\88á\82Á\82Ä\82±\82Ì\95û\96@\82Å\83z\83X\83g\82ª\95\\8e¦\82³\82ê\82½\82Æ\82µ\82Ä\82à\81A\8e©\8cÈ\90Ó\94C\82È\82Ì\82Å\8dí\8f\9c\88Ë\97\8a\82É\82Í\89\9e\82\82Ü\82¹\82ñ\81B' + #13#10#13#10 +
842                                                 '\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
843                                                 '\8fî\95ñ',
844                                                 MB_YESNO or MB_ICONQUESTION);
845                                         if MsgResult = IDNO  then begin
846                                                 Board.SPID := '';
847                                                 Board.PON := '';
848                                                 FWork := false;
849                                                 EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
850                                                 DrawMenuBar(Handle);
851                                                 Exit;
852                                         end;
853                                 end;
854                         end;
855
856                         if GikoSys.Setting.RemoteTrapAtt then begin
857                                 if FThreadItem = nil then
858                                         ABoard := FBoard
859                                 else
860                                         ABoard := FThreadItem.ParentBoard;
861
862                                 if ABoard = nil then Exit;
863
864                                 if FileExists(ABoard.GetSETTINGTXTFileName)  then begin
865                                         body := TStringList.Create;
866                                         try
867                                                 body.LoadFromFile(ABoard.GetSETTINGTXTFileName);
868                                                 Remote := GetFusianaName(body, ABoard);
869                                         finally
870                                                 body.Free;
871                                         end;
872                                 end;
873                                 if Remote = 'fusianasan' then begin
874                                         MsgResult := MsgBox(
875                                                         Handle,
876                                                 '\83\8a\83\82\81[\83g\83z\83X\83g\82ð\95\\8e¦\82·\82é\8b@\94\\82ª\8eg\82í\82ê\82Ä\82¢\82Ü\82·' + #13#10 +
877                                                 '\82à\82µ\82à\8aÔ\88á\82Á\82Ä\82±\82Ì\95û\96@\82Å\83z\83X\83g\82ª\95\\8e¦\82³\82ê\82½\82Æ\82µ\82Ä\82à\81A\8e©\8cÈ\90Ó\94C\82È\82Ì\82Å\8dí\8f\9c\88Ë\97\8a\82É\82Í\89\9e\82\82Ü\82¹\82ñ\81B' + #13#10#13#10 +
878                                                 '\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
879                                                 '\8fî\95ñ',
880                                                 MB_YESNO or MB_ICONQUESTION);
881                                         if MsgResult = IDNO  then begin
882                                                 Board.SPID := '';
883                                                 Board.PON := '';
884                                                 FWork := false;
885                                                 EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
886                                                 DrawMenuBar(Handle);
887                                                 Exit;
888                                         end;
889                                 end;
890                         end;
891
892                         if ResultType = grtOK then begin
893                                 WriteSambaTime(FHost, Now());
894                                 State := gdsComplete;
895                         end else if ResultType = grtCookie then begin
896                                 //\83\8b\81[\83v\96h\8e~
897                                 if not FirstWriting then
898                                         raise Exception.Create('');
899                                 MsgResult := MsgBox(
900                                         Handle,
901                                         '\81E\93\8a\8de\82³\82ê\82½\93à\97e\82Í\83R\83s\81[\81A\95Û\91\81A\88ø\97p\81A\93]\8dÚ\93\99\82³\82ê\82é\8fê\8d\87\82ª\82 \82è\82Ü\82·\81B' + #13#10 +
902                                         '\81E\93\8a\8de\82É\8aÖ\82µ\82Ä\94­\90\82·\82é\90Ó\94C\82Í\91S\82Ä\93\8a\8de\8eÒ\82É\8bA\82µ\82Ü\82·\81B' + #13#10#13#10 +
903                                         '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
904                                         '\8fî\95ñ',
905                                         MB_YESNO or MB_ICONQUESTION);
906                                 if MsgResult = IDYES then begin
907                                         Board.SPID := GetSPID(Indy.Response.RawHeaders.Values['Set-Cookie']);
908                                         Board.PON := GetPON(Indy.Response.RawHeaders.Values['Set-Cookie']);
909                                         if (Board.SPID = '') and (Board.PON = '') then
910                                                 raise Exception.Create('');
911                                         //\82à\82¤\88ê\89ñ\82±\82Ì\83\81\83\\83b\83h
912                                         Send(Board.SPID, Board.PON, False);
913                                         Exit;
914                                 end else begin
915                                         Board.SPID := '';
916                                         Board.PON := '';
917                                         FWork := false;
918                                         EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
919                                         DrawMenuBar(Handle);
920                                         Exit;
921                                 end;
922                         end else if ResultType = grtCheck then begin
923                                 //
924                                 //\83\8b\81[\83v\96h\8e~
925                                 if not FirstWriting then
926                                         raise Exception.Create('');
927
928                                 MsgResult := MsgBox(
929                                         Handle,
930                                         '\8f\91\82«\8d\9e\82Ý\82É\8aÖ\82µ\82Ä\82Í\97l\81X\82È\83\8d\83O\8fî\95ñ\82ª\8bL\98^\82³\82ê\82Ä\82¢\82Ü\82·\81B' + #13#10 +
931                                         '\93\8a\8de\82É\8aÖ\82µ\82Ä\94­\90\82·\82é\90Ó\94C\82Í\91S\82Ä\93\8a\8de\8eÒ\82É\8bA\82µ\82Ü\82·\81B' + #13#10 +
932                                         '\8cö\8f\98\97Ç\91­\82É\94½\82µ\82½\82è\81A\91¼\90l\82É\96À\98f\82ð\82©\82¯\82é\8f\91\82«\8d\9e\82Ý\82Í\8dT\82¦\82Ä\89º\82³\82¢\81B' + #13#10 +
933                                         '\93\8a\8de\82³\82ê\82½\93à\97e\82Í\83R\83s\81[\81E\95Û\91\81E\88ø\97p\81E\93]\8dÚ\93\99\82³\82ê\82é\8fê\8d\87\82ª\82 \82è\82Ü\82·\81B' + #13#10 +
934                                         #13#10 +
935                                         '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
936                                         '\8am\94F',
937                                         MB_YESNO or MB_ICONQUESTION);
938
939                                 if MsgResult = IDYES then begin
940                                         Board.SPID := GetSPID(Indy.Response.RawHeaders.Values['Set-Cookie']);
941                                         Board.PON := GetPON(Indy.Response.RawHeaders.Values['Set-Cookie']);
942                                         if (Board.SPID = '') and (Board.PON = '') then
943                                                 raise Exception.Create('');
944                                         Send(Board.SPID, Board.PON, False);
945                                         Exit;
946                                 end else begin
947                                         EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
948                                         DrawMenuBar(Handle);
949                                         Board.SPID := '';
950                                         Board.PON := '';
951                                         FWork := false;
952                                         Exit;
953                                         end;
954                         end else begin
955                 WriteSambaTime(FHost, Now());
956                                 State := gdsError;
957                                 raise Exception.Create('');
958                         end;
959
960                 except
961                         on E: EIdConnectException do begin
962                                 State := gdsError;
963                                 ResponseText := '<html><body>'
964                                                                                         + '<div>\90Ú\91±\82ª\8e¸\94s\82µ\82Ü\82µ\82½<br>'
965                                                                                         + '\89ñ\90ü\82â\83v\83\8d\83L\83V\82Ì\8fó\91Ô\82ð\92²\82×\82Ä\82­\82¾\82³\82¢<br></div>'
966                                                                                         + '<br><br><div>' + E.Message + '</div>'
967                                                                                         + '</body></html>';
968                         end;
969                         on E: Exception do begin
970                                 State := gdsError;
971
972                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '<', '&lt;');
973                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '>', '&gt;');
974                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '<', '&lt;');
975                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '>', '&gt;');
976
977                                 ResponseText := '<html><body>' + TextStream.DataString;
978                                 ResponseText := AnsiReplaceText(ResponseText, '</body>', '');
979                                 ResponseText := AnsiReplaceText(ResponseText, '</html>', '');
980                                 ResponseText := ResponseText + '<hr><div align="left"><pre>';
981                                 ResponseText := ResponseText + '<b>\82±\82±\82©\82ç\83M\83R\83i\83r\82Ì\8fî\95ñ</b>'#13#10;
982                                 ResponseText := ResponseText + #13#10'\81\9c\91\97\90M'#13#10;
983                                 ResponseText := ResponseText + FDebugStrSend;
984                                 ResponseText := ResponseText + #13#10'\81\9c\8eó\90M'#13#10;
985                                 ResponseText := ResponseText + FDebugStrReceive;
986                                 ResponseText := ResponseText + '</pre></div></body></html>';
987                         end;
988                 end;
989                 FStatusCode := Indy.ResponseCode;
990                 if FAbort then
991                         State := gdsAbort;
992         finally
993                 Source.Free;
994                 TextStream.Free;
995                 //sysMenu := GetSystemMenu( Handle, true );
996                 EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
997                 DrawMenuBar(Handle);
998         end;
999         FWork := false;
1000         //\94ñ\8cö\8e®\83M\83R\83i\83r\94Â\82È\82Ç\82Ì\83X\83N\83\8a\83v\83g\97p
1001         //ResponceCode\82ª302Found\82Å\8f\91\82«\8d\9e\82Ý\8a®\97¹
1002         if FStatusCode = 302 then begin
1003                 GikoForm.PlaySound('ResEnd');
1004                 SaveSendFile;
1005                 if FThreadItem = nil then
1006                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK)
1007                 else
1008                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
1009                 Close;
1010                 Exit;
1011         end;
1012         if State = gdsComplete then begin
1013                 GikoForm.PlaySound('ResEnd');
1014                 SaveSendFile;
1015                 if FThreadItem = nil then
1016                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK)
1017                 else
1018                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
1019                 Close;
1020         end else if State = gdsError then begin
1021                 if FThreadItem = nil then
1022                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8e¸\94s]', nil, gmiNG)
1023                 else
1024                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8e¸\94s]', nil, gmiNG);
1025                 EditorPage.ActivePage := PreviewTab;
1026                 SetContent(ResponseText, Browser);
1027         end else if State = gdsAbort then begin
1028                 GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
1029         end;
1030 end;
1031
1032 function TEditorForm.GetResultType(ResponseText: string): TGikoResultType;
1033 begin
1034         if AnsiPos('\8f\91\82«\82±\82Ý\82ª\8fI\82í\82è\82Ü\82µ\82½', ResponseText) <> 0 then
1035                 Result := grtOK
1036         else if (AnsiPos('\83N\83b\83L\81[\82ª\82È\82¢\82©\8aú\8cÀ\90Ø\82ê\82Å\82·', ResponseText) > 0) or
1037                                         (AnsiPos('<title>\83N\83b\83L\81[\8am\94F\81I</title>', ResponseText) > 0)    or
1038                                         (AnsiPos('<title>\81¡\83N\83b\83L\81[\8am\94F\81I\81¡</title>', ResponseText) > 0)        or
1039                                         //(AnsiPos('\83N\83b\83L\81[\8am\94F', ResponseText) > 0) or
1040                                         (AnsiPos(RES2CH_COOKIE, ResponseText) > 0)      then
1041                 Result := grtCookie
1042         else if (AnsiPos('<font size=+2 color=#FF0000>\8f\91\82«\8d\9e\82Ý\83`\83F\83b\83N\81I </font>', ResponseText) > 0)   or
1043                                         (AnsiPos('<title>\81¡ \8f\91\82«\8d\9e\82Ý\8am\94F\82µ\82Ü\82· \81¡</title>', ResponseText) > 0)  or
1044                                         (AnsiPos('<title>\93\8a\8de\8am\94F</title>', ResponseText) > 0)  or
1045                                         (AnsiPos('<b>\8f\91\82«\82±\82Ý\8am\94F</b>', ResponseText) > 0)      or
1046                                         (AnsiPos('="../test/subbbs.cgi">', ResponseText) > 0)   or
1047                                         (AnsiPos(RES2CH_FALSE, ResponseText) > 0)       then
1048                 Result := grtCheck
1049         else
1050                 Result := grtError;
1051 end;
1052
1053
1054 procedure TEditorForm.GetSendData(Source: TStringStream);
1055 var
1056         SessionID: string;
1057         s: string;
1058         SendTime: Integer;
1059         Adjust: Integer;
1060         Board: TBoard;
1061         body            : string;
1062 begin
1063         if FThreadItem = nil then
1064                 Board := FBoard
1065         else
1066                 Board := FThreadItem.ParentBoard;
1067
1068         if GikoSys.Setting.UseMachineTime then begin
1069                 if GikoSys.Setting.TimeAdjust then
1070                         Adjust := Gikosys.Setting.TimeAdjustSec
1071                 else
1072                         Adjust := GikoSys.Setting.TimeAdjustSec * -1;
1073                 SendTime := GikoSys.DateTimeToInt(Now) - (9 * 60 * 60) + Adjust
1074         end else begin
1075                 if (Board.LastGetTime = 0) or (Board.LastGetTime = ZERO_DATE) then
1076                         SendTime := GikoSys.DateTimeToInt(Now)
1077                 else
1078                         SendTime := GikoSys.DateTimeToInt(Board.LastGetTime);
1079         end;
1080
1081         body := GetBody;
1082
1083         SessionID := GikoSys.Dolib.SessionID;
1084         if SessionID <> '' then
1085                 s := 'sid=' + HttpEncode(SessionID) + '&'
1086         else
1087                 s := '';
1088         s := s + 'subject=&'
1089                                  + 'FROM=' + HttpEncode(NameComboBox.Text) + '&'
1090                                  + 'mail=' + HttpEncode(MailComboBox.Text) + '&'
1091                                  + 'MESSAGE=' + HttpEncode(body) + '&'
1092                                  + 'bbs=' + Board.BBSID + '&'
1093                                  + 'time=' + IntToStr(SendTime) + '&';
1094         if FThreadItem = nil then begin
1095                 s := s + 'subject=' + HttpEncode(TitleEdit.Text) + '&';
1096                 s := s + 'submit=' + HttpEncode('\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Þ') + #13#10;
1097         end else begin
1098                 s := s + 'key=' + ChangeFileExt(FThreadItem.FileName, '') + '&';
1099                 s := s + 'submit=' + HttpEncode('\8f\91\82«\8d\9e\82Þ') + #13#10;
1100         end;
1101         Source.WriteString(s);
1102 end;
1103
1104 procedure TEditorForm.SaveSendFile;
1105 var
1106         sDate: string;
1107         ini: TMemIniFile;
1108 begin
1109         ini := TMemIniFile.Create(GikoSys.GetSentFileName);
1110         try
1111                 sDate := IntToStr(GikoSys.DateTimeToInt(Now));
1112
1113                 ini.WriteString(sDate, 'Name', NameComboBox.Text);
1114                 ini.WriteString(sDate, 'EMail', MailComboBox.Text);
1115                 ini.WriteString(sDate, 'Body', HttpEncode(BodyEdit.Text));
1116                 ini.WriteInteger(sDate, 'Status', FStatusCode);
1117                 ini.WriteDateTime(sDate, 'Date', Now);
1118                 if FThreadItem = nil then begin
1119                         ini.WriteString(sDate, 'Title', TitleEdit.Text);
1120                         ini.WriteString(sDate, 'BBS', FBoard.BBSID);
1121                         ini.WriteInteger(sDate, 'NewThread', 1);
1122                 end else begin
1123                         ini.WriteString(sDate, 'Title', FThreadItem.Title);
1124                         ini.WriteString(sDate, 'BBS', FThreadItem.ParentBoard.BBSID);
1125                         ini.WriteString(sDate, 'Key', ChangeFileExt(FThreadItem.FileName, ''));
1126                 end;
1127
1128                 ini.UpdateFile;
1129         finally
1130                 ini.Free;
1131         end;
1132 end;
1133
1134 procedure TEditorForm.SendActionExecute(Sender: TObject);
1135 var
1136         Board: TBoard;
1137         rc: Integer;
1138         state : TGikoDownloadState;
1139         body            : string;
1140 begin
1141         if FWork then
1142                 Exit;
1143         try
1144                 FWork := True;
1145                 SendAction.Enabled := False;
1146                 Application.ProcessMessages;
1147                 if not Check then Exit;
1148
1149                 if FThreadItem = nil then
1150                         Board := FBoard
1151                 else
1152                         Board := FThreadItem.ParentBoard;
1153
1154                 if FThreadItem = nil then begin
1155                         rc := GikoUtil.MsgBox(Handle,
1156                                                                                                         '\81u' + Board.Title + '\81v\94Â\82É\90V\82µ\82¢\83X\83\8c\83b\83h\97§\82Ä\82Ü\82·'#13#10#13#10
1157                                                                                                         + '\81E\94Â\82Ì\83\8b\81[\83\8b\82ð\8eç\82Á\82½\8f\91\82«\8d\9e\82Ý\82Å\82 \82é\82±\82Æ\82ð\8am\94F\82µ\82Ü\82µ\82½\82©\81H'#13#10
1158                                                                                                         + '\81E\91¼\82É\93¯\82\82æ\82¤\82È\83X\83\8c\83b\83h\82ª\96³\82©\82Á\82½\82±\82Æ\82ð\8am\94F\82µ\82Ü\82µ\82½\82©\81H'#13#10#13#10
1159                                                                                                         + '\81u\82Í\82¢\81v\82ð\89\9f\82·\82Æ\91\97\90M\82µ\82Ü\82·',
1160                                                                                                         '\8am\94F',
1161                                                                                                         MB_ICONQUESTION or MB_YESNO);
1162                         if rc <> ID_YES then
1163                                 Exit;
1164                 end;
1165
1166                 SetNameList(NameComboBox.Text, MailComboBox.Text);
1167                 if KotehanCheckBox.Checked then begin
1168                         Board.KotehanName := NameComboBox.Text;
1169                         Board.KotehanMail := MailComboBox.Text;
1170                 end;
1171
1172                 if Board.IsBoardPlugInAvailable then begin
1173                         body := GetBody;
1174
1175                         if FThreadItem = nil then begin
1176                                 // \83X\83\8c\97§\82Ä
1177                                 state := TGikoDownloadState( Board.BoardPlugIn.CreateThread(
1178                                         DWORD( Board ), TitleEdit.Text, NameComboBox.Text, MailComboBox.Text, body ) );
1179
1180                                 if state = gdsComplete then begin
1181                                         GikoForm.PlaySound('ResEnd');
1182                                         SaveSendFile;
1183                                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK);
1184                                         FWork := False;
1185                                         Close;
1186                                 end else if State = gdsError then begin
1187                                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8e¸\94s]', nil, gmiNG);
1188                                 end else if State = gdsAbort then begin
1189                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
1190                                 end;
1191                         end else begin
1192                                 // \83\8c\83X
1193                                 state := TGikoDownloadState( FThreadItem.BoardPlugIn.WriteThread(
1194                                         DWORD( FThreadItem ), NameComboBox.Text, MailComboBox.Text, body ) );
1195
1196                                 if state = gdsComplete then begin
1197                                         GikoForm.PlaySound('ResEnd');
1198                                         SaveSendFile;
1199                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
1200                     FWork := False;
1201                                         Close;
1202                                 end else if State = gdsError then begin
1203                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8e¸\94s]', nil, gmiNG);
1204                                 end else if State = gdsAbort then begin
1205                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
1206                                 end;
1207                         end;
1208                 end else begin
1209                         if not Timer1.Enabled then
1210                                 Send(Board.SPID, Board.PON, True)
1211                         else begin
1212                                 if not CheckSambaTime(FHost, Now()) then begin
1213                                         rc := GikoUtil.MsgBox(Handle,
1214                                                                 'Samba24\82Ì\8bK\92è\92l\96¢\96\9e\82Ì\95b\90\94\82µ\82©\8co\89ß\82µ\82Ä\82¢\82Ü\82¹\82ñ\81B'#13#10
1215                                                                 + '\91\97\90M\82ð\92\86\8e~\82µ\82Ü\82·\82©\81H' + #13#10
1216                                                                 + '(\81u\82¢\82¢\82¦\81v\82¾\82Æ\91\97\90M\82µ\82Ü\82·)', 'Samba24\8cx\8d\90',
1217                                                                 MB_YESNO or MB_ICONQUESTION);
1218                                         if rc = IDYES then begin
1219                                                 FWork := false;
1220                                                 Exit;
1221                                         end;
1222                                 end;
1223                                 Send(Board.SPID, Board.PON, True);
1224                         end;
1225                 end;
1226         finally
1227                 FWork := False;
1228                 if Timer1.Enabled then
1229                         ReadSambaTime(FHost);
1230         end;
1231 end;
1232
1233 procedure TEditorForm.SaveActionExecute(Sender: TObject);
1234 begin
1235 //
1236 end;
1237
1238 procedure TEditorForm.CloseActionExecute(Sender: TObject);
1239 begin
1240         Close;
1241 end;
1242
1243 procedure TEditorForm.UndoActionExecute(Sender: TObject);
1244 begin
1245         SendMessage(GetActiveControlHandle, WM_UNDO, 0, 0);
1246 end;
1247
1248 procedure TEditorForm.CutActionExecute(Sender: TObject);
1249 begin
1250         SendMessage(GetActiveControlHandle, WM_CUT, 0, 0);
1251 end;
1252
1253 procedure TEditorForm.CopyActionExecute(Sender: TObject);
1254 begin
1255         SendMessage(GetActiveControlHandle, WM_COPY, 0, 0);
1256 end;
1257
1258 procedure TEditorForm.PasteActionExecute(Sender: TObject);
1259 begin
1260         SendMessage(GetActiveControlHandle, WM_PASTE, 0, 0);
1261 end;
1262
1263 procedure TEditorForm.SelectAllActionExecute(Sender: TObject);
1264 begin
1265         SendMessage(GetActiveControlHandle, EM_SETSEL, 0, GetWindowTextLength(GetActiveControlHandle));
1266 end;
1267
1268 procedure TEditorForm.TopActionExecute(Sender: TObject);     // \83E\83B\83\93\83h\83E\8dÅ\91O\96Ê(Stay)\83{\83^\83\93\82Ì\8f\88\97\9d
1269 begin
1270         if not (fsShowing in Self.FormState) then begin
1271                 if TopAction.Checked then begin // \83X\83e\83C\8fó\91Ô\82É\90Ý\92è
1272                         SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
1273                         GikoSys.Setting.EditWindowStay := true;
1274                 end     else begin   // \83X\83e\83C\8fó\91Ô\89ð\8f\9c
1275                         SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
1276                         GikoSys.Setting.EditWindowStay := false;
1277                 end;
1278                 // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
1279                 //GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;
1280         end;
1281 end;
1282
1283 procedure TEditorForm.AbortActionExecute(Sender: TObject);
1284 begin
1285         FAbort := True;
1286 end;
1287
1288 procedure TEditorForm.SendActionUpdate(Sender: TObject);
1289 begin
1290         SendAction.Enabled := not FWork;
1291 end;
1292
1293 procedure TEditorForm.SaveActionUpdate(Sender: TObject);
1294 begin
1295         SaveAction.Enabled := False;
1296 end;
1297
1298 procedure TEditorForm.CloseActionUpdate(Sender: TObject);
1299 begin
1300         CloseAction.Enabled := not FWork;
1301 end;
1302
1303 procedure TEditorForm.UndoActionUpdate(Sender: TObject);
1304 begin
1305         UndoAction.Enabled := (GetActiveControlHandle <> 0)
1306                                                                                                 and (SendMessage(GetActiveControlHandle, EM_CANUNDO, 0, 0) <> 0)
1307                                                                                                 and (not FWork);
1308 end;
1309
1310 procedure TEditorForm.CutActionUpdate(Sender: TObject);
1311 var
1312         Selection: TSelection;
1313         AHandle: THandle;
1314 begin
1315         AHandle := GetActiveControlHandle;
1316         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
1317         CutAction.Enabled := (AHandle <> 0)
1318                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
1319                                                                                 and (not FWork);
1320 end;
1321
1322 procedure TEditorForm.CopyActionUpdate(Sender: TObject);
1323 var
1324         Selection: TSelection;
1325         AHandle: THandle;
1326 begin
1327         AHandle := GetActiveControlHandle;
1328         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
1329         CopyAction.Enabled := (AHandle <> 0)
1330                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
1331                                                                                 and (not FWork);
1332 end;
1333
1334 procedure TEditorForm.PasteActionUpdate(Sender: TObject);
1335 begin
1336         PasteAction.Enabled := (GetActiveControlHandle <> 0)
1337                                                                                         and (Clipboard.HasFormat(CF_TEXT))
1338                                                                                         and (not FWork);
1339 end;
1340
1341 procedure TEditorForm.TopActionUpdate(Sender: TObject);
1342 begin
1343         TopAction.Enabled := not FWork;
1344 end;
1345
1346 procedure TEditorForm.SageCheckBoxClick(Sender: TObject);
1347 begin
1348         if SageCheckBox.Checked then begin
1349                 if AnsiPos('sage', MailComboBox.Text) = 0 then
1350                         MailComboBox.Text := 'sage' + MailComboBox.Text;
1351         end else begin
1352                 if AnsiPos('sage', MailComboBox.Text) <> 0 then
1353                         MailComboBox.Text := StringReplace(MailComboBox.Text, 'sage', '', [rfReplaceAll]);
1354         end;
1355 end;
1356
1357 procedure TEditorForm.MailComboBoxChange(Sender: TObject);
1358 begin
1359         if AnsiPos('sage', MailComboBox.Text) = 0 then
1360                 SageCheckBox.Checked := False
1361         else
1362                 SageCheckBox.Checked := True;
1363 end;
1364
1365
1366 function TEditorForm.GetSPID(CookieLine: string): string;
1367 var
1368         s: string;
1369         i: Integer;
1370 begin
1371         Result := '';
1372         i := 0;
1373         while True do begin
1374                 s := Trim(GikoSys.GetTokenIndex(CookieLine, ';', i));
1375                 if s = '' then
1376                         Break
1377                 else begin
1378                         if Pos('SPID=', s) = 1 then begin
1379                                 Result := Trim(Copy(s, 6, Length(s)));
1380                                 Break;
1381                         end;
1382                 end;
1383                 inc(i);
1384         end;
1385 end;
1386
1387 function TEditorForm.GetPON(CookieLine: string): string;
1388 var
1389         s: string;
1390         i: Integer;
1391 begin
1392         Result := '';
1393         i := 0;
1394         while True do begin
1395                 s := Trim(GikoSys.GetTokenIndex(CookieLine, ';', i));
1396                 if s = '' then
1397                         Break
1398                 else begin
1399                         if Pos('PON=', s) = 1 then begin
1400                                 Result := Trim(Copy(s, 5, Length(s)));
1401                                 Break;
1402                         end;
1403                 end;
1404                 inc(i);
1405         end;
1406 end;
1407
1408 procedure TEditorForm.IdLogDebugReceive(ASender: TIdConnectionIntercept;
1409         AStream: TStream);
1410 var
1411         StringStream: TStringStream;
1412 begin
1413         StringStream := TStringStream.Create('');
1414         try
1415                 StringStream.CopyFrom(AStream, AStream.Size);
1416                 FDebugStrReceive := FDebugStrReceive + StringStream.DataString;
1417         finally
1418                 StringStream.Free;
1419         end;
1420 end;
1421
1422 procedure TEditorForm.IdLogDebugSend(ASender: TIdConnectionIntercept;
1423         AStream: TStream);
1424 var
1425         StringStream: TStringStream;
1426 begin
1427         StringStream := TStringStream.Create('');
1428         try
1429                 StringStream.CopyFrom(AStream, AStream.Size);
1430                 FDebugStrSend := FDebugStrSend + StringStream.DataString;
1431         finally
1432                 StringStream.Free;
1433         end;
1434 end;
1435
1436 procedure TEditorForm.TransActionExecute(Sender: TObject);
1437 begin
1438         AlphaBlend := TransAction.Checked;
1439         // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
1440         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;
1441 end;
1442
1443 procedure TEditorForm.TransActionUpdate(Sender: TObject);
1444 begin
1445         TransAction.Enabled := not FWork;
1446 end;
1447 //StatusBar\82ÌPanels[0]\82Ì\95\9d\82ð\89Â\95Ï\81B\8ec\82è\82ð\8cÅ\92è\82É\82·\82é
1448 procedure TEditorForm.StatusBarResize(Sender: TObject);
1449 begin
1450         StatusBar.Panels[0].Width := StatusBar.Width
1451                                                                         - StatusBar.Panels[1].Width - StatusBar.Panels[2].Width;
1452
1453 end;
1454
1455 procedure TEditorForm.Timer1Timer(Sender: TObject);
1456 begin
1457         if FSambaTime = ZERO_DATE then
1458                 StatusBar.Panels[1].Text := '\8f\89\8f\91'
1459         else begin
1460                 FNow := IncMilliSecond(FNow, 500);
1461                 StatusBar.Panels[1].Text := Format('%8.0f\95b\8co\89ß', [SecondSpan(FNow, FSambaTime)]);
1462         end;
1463
1464 end;
1465 //Samba.ini\82Ì\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1466 procedure TEditorForm.ReadSambaTime(const AHost: string);
1467 var
1468         ini :TMemIniFile;
1469         tmp: string;
1470 begin
1471         Timer1.Enabled := false; //\8co\89ß\95b\90\94\95\\8e¦Timer\82ðOff\82É\82·\82é\81i\82±\82ê\82ªON\82Ì\82Æ\82«Samba24\91Î\8dôOn\81j
1472         FNow := Now();   //\8c»\8dÝ\8e\9e\8aÔ\82ð\8eæ\93¾\81iTimer\95\\8e¦\97p\82Å\81ACheck\82·\82é\82Æ\82«\82Í\8dÄ\82ÑNow()\82ð\8cÄ\82Ô\81j
1473         Timer1.Enabled := true; //\8co\89ß\95b\90\94\95\\8e¦Timer\82ðOn\82É\82·\82é\81i\82±\82ê\82ªON\82Ì\82Æ\82«Samba24\91Î\8dôOn\81j
1474         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1475         try
1476                  //\95\8e\9a\97ñ\82Å\93Ç\82Ý\8eæ\82Á\82Ä\81A\95Ï\8a·\8aÖ\90\94\82ÅTDateTime\82Ö
1477                  tmp := ini.ReadString('Send', AHost, DateTimeToStr(ZERO_DATE));
1478                  FSambaTime := ConvertDateTimeString(tmp);
1479         finally
1480                 ini.Free;
1481         end;
1482 end;
1483 //Samba.ini\82É\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\8f\91\82«\8d\9e\82Þ
1484 procedure TEditorForm.WriteSambaTime(const AHost: string; ATime: TDateTime);
1485 var
1486         ini :TMemIniFile;
1487 begin
1488         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1489         try
1490                 ini.WriteDateTime('Send', AHost, ATime);
1491                 ini.UpdateFile;
1492         finally
1493                 ini.Free;
1494         end;
1495 end;
1496 //\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82Æ\8c»\8dÝ\8e\9e\82ð\94ä\8ar\82·\82é\81i\90^\81F\8bK\92è\92l\88È\8fã\81@\8bU\81F\8bK\92è\92l\96¢\96\9e\81j
1497 function TEditorForm.CheckSambaTime(const AHost: string; ATime: TDateTime): Boolean;
1498 var
1499         pastsec: double;
1500         SettingTime: Integer;
1501 begin
1502         SettingTime := ReadSettingTime(AHost);
1503         ReadSambaTime(AHost);
1504         pastsec := SecondSpan(ATime, FSambaTime);
1505         if pastsec > SettingTime then
1506                 Result := true
1507         else
1508                 Result := false;
1509 end;
1510 //AHost\81i\8eI\96¼\81j\82ÌSamba\82Ì\8bK\92è\92l\82ð\93Ç\82Ý\8d\9e\82Þ
1511 function TEditorForm.ReadSettingTime(const AHost: string): Integer;
1512 var
1513         ini :TMemIniFile;
1514 begin
1515         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1516         try
1517                 Result := ini.ReadInteger('Setting', AHost, 0);
1518                 //\8bK\92è\92l\82ª\82O\82Ì\82Æ\82«\81A\82à\82µ\82­\82Í\90Ý\92è\82³\82ê\82Ä\82¢\82È\82¢\82Æ\82«\82Í\81A\83t\83@\83C\83\8b\82É\8f\91\82«\82½\82·\81B
1519                 if Result = 0 then begin
1520                         ini.WriteInteger('Setting', AHost, 0);
1521                         ini.UpdateFile;
1522                 end;
1523         finally
1524                 ini.Free;
1525         end;
1526 end;
1527 //Form\82ªActive\82É\82È\82Á\82½\82ç\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1528 procedure TEditorForm.FormActivate(Sender: TObject);
1529 begin
1530         if ( Timer1.Enabled ) and ( FThreadItem <> nil )then
1531                 ReadSambaTime(FHost);
1532         if GikoSys.Setting.GestureEnabled then begin
1533                 MouseGesture.UnHook;
1534                 MouseGesture.OnGestureStart := OnGestureStart;
1535                 MouseGesture.OnGestureMove := OnGestureMove;
1536                 MouseGesture.OnGestureEnd := OnGestureEnd;
1537                 MouseGesture.SetHook( Handle );
1538         end;
1539 end;
1540 //Samba24\91Î\8dô\82ð\8eg\82¤\82©\82Ç\82¤\82©\8c\88\82ß\82é\8aÖ\90\94
1541 //ReadSambaTime \82ð\8cÄ\82Ñ\8fo\82·\82ÆTimer\82ªOn\82É\82È\82é
1542 procedure TEditorForm.SetSamba24(AURL: string);
1543 var
1544         Protocol, Host, Path, Document, Port, Bookmark : string;
1545 begin
1546         //Samba24\91Î\8dô\82ð\82µ\82È\82¢\82È\82ç\8fI\97¹
1547         if not GikoSys.Setting.UseSamba then
1548                 Exit;
1549         //Host\82ÌURL\82É'.2ch.'\82©'.bbspink.'\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82çSamba24\91Î\8dô\82ð\82·\82é
1550         GikoSys.ParseURI( AURL, Protocol,Host, Path, Document, Port, Bookmark );
1551         if GikoSys.Is2chHost(Host) then begin
1552                 Host := Copy(Host, 1, AnsiPos('.', Host) - 1);
1553                 FHost := Host;   //FHost=\8eI\96¼
1554                 ReadSambaTime(FHost); //\88È\91O\82Ì\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1555                 //StatusBar\82É\82±\82Ì\8eI\82Ì\8bK\92è\92l\82ð\95\\8e¦\82·\82é
1556                 StatusBar.Panels[2].Text := 'Samba24\8bK\92è\92l' + IntToStr(ReadSettingTime(FHost));
1557         end;
1558 end;
1559 procedure TEditorForm.FormCloseQuery(Sender: TObject;
1560   var CanClose: Boolean);
1561 begin
1562         CanClose := not FWork;
1563 end;
1564
1565 function TEditorForm.GetOEIndentChar : string;
1566 var
1567         regKey                  : TRegistry;
1568         Identities      : string;
1569         IndentChar      : DWORD;
1570 const
1571         DEFAULT_CHAR    = '> ';
1572         OE_MAIL_PATH    = '\Software\Microsoft\Outlook Express\5.0\Mail';
1573         INDENT_CHAR             = 'Indent Char';
1574 begin
1575
1576         Result  := DEFAULT_CHAR;
1577         regKey  := TRegistry.Create;
1578         try
1579                 try
1580                         regKey.RootKey  := HKEY_CURRENT_USER;
1581                         if not regKey.OpenKey( 'Identities', False ) then
1582                                 Exit;
1583                         Identities                      := regKey.ReadString( 'Default User ID' );
1584                         if Identities = '' then
1585                                 Exit;
1586                         if not regKey.OpenKey( Identities + OE_MAIL_PATH, False ) then
1587                                 Exit;
1588                         IndentChar := regKey.ReadInteger( INDENT_CHAR );
1589                         Result := Char( IndentChar ) + ' ';
1590                 except
1591                 end;
1592         finally
1593                 regKey.Free;
1594         end;
1595
1596 end;
1597
1598 procedure TEditorForm.QuotePasteActionExecute(Sender: TObject);
1599 var
1600         s                       : TStringList;
1601         i                       : Integer;
1602         quote   : string;
1603 begin
1604
1605         quote   := GetOEIndentChar;
1606         s                       := TStringList.Create;
1607         try
1608                 s.Text  := Clipboard.AsText;
1609
1610                 for i := s.Count - 1 downto 0 do
1611                         s[ i ]  := quote + s[ i ];
1612
1613                 BodyEdit.SelText        := s.Text;
1614         finally
1615                 s.Free;
1616         end;
1617
1618 end;
1619
1620 procedure TEditorForm.SpaceToNBSPActionExecute(Sender: TObject);
1621 begin
1622         GikoSys.Setting.SpaceToNBSP := SpaceToNBSPAction.Checked;
1623         if EditorPage.ActivePage = PreviewTab then
1624                 Preview;
1625 end;
1626
1627 procedure TEditorForm.AmpToCharRefActionExecute(Sender: TObject);
1628 begin
1629         GikoSys.Setting.AmpToCharRef := AmpToCharRefAction.Checked;
1630         if EditorPage.ActivePage = PreviewTab then
1631                 Preview;
1632 end;
1633
1634 procedure TEditorForm.BoardTopClick(Sender: TObject);
1635 var
1636         ini: TIniFile;
1637 begin
1638         ini := TIniFile.Create(GikoSys.Setting.GetFileName);
1639         try
1640                 BoardtopTab.TabVisible := BoardTop.Checked;
1641                 ini.WriteBool('EditorForm', 'BoardTopTab', BoardtopTab.TabVisible);
1642         finally
1643                 ini.Free;
1644         end;
1645 end;
1646
1647
1648 procedure TEditorForm.GetSETTINGTXTActionExecute(Sender: TObject);
1649 var
1650         URL, RefURL: string;
1651         settingBody: TStringList;
1652         tmpBoard: TBoard;
1653 begin
1654         InitIdHTTP(Indy);
1655         if FThreadItem = nil then
1656                 tmpBoard := FBoard
1657         else
1658                 tmpBoard := FThreadItem.ParentBoard;
1659
1660         if tmpBoard = nil then Exit;
1661
1662         RefURL  := tmpBoard.URL;
1663         if RefURL[Length(RefURL)] <> '/' then
1664                 URL     := RefURL + '/' + 'SETTING.TXT'
1665         else
1666                 URL     := RefURL + 'SETTING.TXT';
1667
1668         Indy.Request.LastModified := tmpBoard.SETTINGTXTTime;
1669         Indy.Request.Referer := RefURL;
1670         Screen.Cursor := crHourGlass;
1671         settingBody := TStringList.Create;
1672         try
1673                 StatusBar.Panels[0].Text := 'SETTING.TXT\83_\83E\83\93\83\8d\81[\83h\92\86';
1674                 try
1675                         settingBody.Text := Indy.Get(URL);
1676                         if( Indy.ResponseCode = 200 ) then begin
1677                                 settingBody.SaveToFile(tmpBoard.GetSETTINGTXTFileName);
1678                                 tmpBoard.SETTINGTXTTime := Indy.Response.LastModified;
1679                                 tmpBoard.IsSETTINGTXT := true;
1680                                 tmpBoard.TitlePictureURL := GetTitlePictureURL(settingBody, tmpBoard);
1681                                 tmpBoard.Modified := true;
1682                                 StatusBar.Panels[0].Text := 'SETTING.TXT\8eæ\93¾\8a®\97¹(' + IntToStr(Indy.ResponseCode) + ')';
1683                         end;
1684                 except
1685                         on E: EIdException do begin
1686                                 if( AnsiPos('304', E.Message) > 0 ) then
1687                                         StatusBar.Panels[0].Text := 'SETTING.TXT\8dX\90V\96³\82µ(' + IntToStr(Indy.ResponseCode) + ')'
1688                                 else
1689                                         StatusBar.Panels[0].Text := 'SETTING.TXT\8eæ\93¾\83G\83\89\81[(' + IntToStr(Indy.ResponseCode) + ')';
1690                         end;
1691                 end;
1692         finally
1693                 settingBody.Free;
1694                 Screen.Cursor := crDefault;
1695         end;
1696         ShowBoardInformation(tmpBoard, BoardInformationMemo);
1697 end;
1698
1699 procedure TEditorForm.ShowBoardInformation(ABoard: TBoard; AMemo: TMemo);
1700 var
1701         body: TStringList;
1702 begin
1703         AMemo.Clear;
1704         AMemo.Lines.Add('[SETTING.TXT]');
1705         if ABoard.IsSETTINGTXT then begin
1706                 if FileExists(ABoard.GetSETTINGTXTFileName)  then begin
1707                         AMemo.Lines.Add(DateTimeToStr(ABoard.SETTINGTXTTime) + ' \8dX\90V');
1708                         body := TStringList.Create;
1709                         try
1710                                 body.LoadFromFile(ABoard.GetSETTINGTXTFileName);
1711                                 AMemo.Lines.AddStrings(body);
1712                         finally
1713                                 body.Free;
1714                         end;
1715                 end else begin
1716                         ABoard.IsSETTINGTXT := false;
1717                         ABoard.SETTINGTXTTime := ZERO_DATE;
1718                         AMemo.Lines.Add('Local\82É\95Û\91\82³\82ê\82½SETTING.TXT\82ª\8c©\82Â\82©\82è\82Ü\82¹\82ñ');
1719                         AMemo.Lines.Add('\83\81\83j\83\85\81[\82æ\82è\8dÄ\8eæ\93¾\82µ\82Ä\82­\82¾\82³\82¢\81B');
1720                 end;
1721         end else begin
1722                 AMemo.Lines.Add('SETTING.TXT\82ð\8eæ\93¾\82µ\82Ä\82¢\82Ü\82¹\82ñ\81B');
1723                 AMemo.Lines.Add('\83\81\83j\83\85\81[\82æ\82è\8eæ\93¾\82µ\82Ä\82­\82¾\82³\82¢\81B');
1724         end;
1725 end;
1726 function TEditorForm.GetTitlePictureURL(body: TStringList; ABoard: TBoard): string;
1727 //BBS_TITLE_PICTURE=
1728 //BBS_FIGUREHEAD=
1729 var
1730         i: Integer;
1731         tmp: string;
1732 begin
1733         Result := '';
1734         for i := 0 to body.Count - 1 do begin
1735                 if (AnsiPos('BBS_TITLE_PICTURE=', body[i]) > 0) or
1736                    (AnsiPos('BBS_FIGUREHEAD=', body[i]) > 0) then begin
1737                         tmp := body[i];
1738                         Delete(tmp, 1, AnsiPos('=', tmp));
1739                         if AnsiPos('../', tmp) > 0 then begin
1740                                 tmp := CustomStringReplace(tmp, '../', GikoSys.UrlToServer(ABoard.URL));
1741                         end;
1742                         Result := tmp;
1743                         Exit;
1744                 end;
1745         end;
1746 end;
1747
1748 procedure TEditorForm.GetTitlePictureActionUpdate(Sender: TObject);
1749 begin
1750         if FThreadItem = nil then
1751                 GetTitlePictureAction.Enabled :=  FBoard.IsSETTINGTXT
1752         else
1753                 GetTitlePictureAction.Enabled :=  FThreadItem.ParentBoard.IsSETTINGTXT;
1754
1755 end;
1756
1757 procedure TEditorForm.GetTitlePictureActionExecute(Sender: TObject);
1758 var
1759         memStream: TMemoryStream;
1760         tmpBoard: TBoard;
1761 begin
1762         InitIdHTTP(Indy);
1763         memStream := TMemoryStream.Create;
1764         try
1765                 if FThreadItem = nil then
1766                         tmpBoard := FBoard
1767                 else
1768                         tmpBoard := FThreadItem.ParentBoard;
1769
1770                 Indy.Request.Referer := tmpBoard.URL;
1771                 if      tmpBoard.TitlePictureURL <> '' then begin
1772                         StatusBar.Panels[0].Text := '\94Â\83g\83b\83v\89æ\91\9c\83_\83E\83\93\83\8d\81[\83h\92\86';
1773                         Screen.Cursor := crHourGlass;
1774                         try
1775                                 Indy.Get(tmpBoard.TitlePictureURL, memStream);
1776                                 if Indy.ResponseCode = 200 then begin
1777                                         memStream.SaveToFile(tmpBoard.GetTitlePictureFileName);
1778                                         ShowTitlePicture();
1779                                         tmpBoard.Modified := true;
1780                                 end;
1781                         except
1782                         end;
1783                 end;
1784         finally
1785                 Screen.Cursor := crDefault;
1786                 StatusBar.Panels[0].Text := '\94Â\83g\83b\83v\89æ\91\9c (' + IntToStr(Indy.ResponseCode) + ')';
1787                 memStream.Free;
1788         end;
1789
1790 end;
1791 procedure TEditorForm.ShowTitlePicture();
1792 var
1793         tmpBoard: TBoard;
1794         s: String;
1795 begin
1796         if FThreadItem = nil then
1797                 tmpBoard := FBoard
1798         else
1799                 tmpBoard := FThreadItem.ParentBoard;
1800
1801         if FileExists(tmpBoard.GetTitlePictureFileName) then begin
1802                 TitlePictureBrowser.Navigate(tmpBoard.GetTitlePictureFileName);
1803         end else begin
1804                 s := '\94Â\83g\83b\83v\89æ\91\9c\96¢\8eæ\93¾\82Å\82·\81B<br>\83\81\83j\83\85\81[\82æ\82è\8eæ\93¾\82µ\82Ä\82­\82¾\82³\82¢\81B';
1805                 SetContent(s, TitlePictureBrowser);
1806         end;
1807 end;
1808
1809 function TEditorForm.GetFusianaName(body: TStringList; ABoard: TBoard): String;
1810 var
1811         i: Integer;
1812         tmp: string;
1813 begin
1814         for i := 0 to body.Count - 1 do begin
1815                 if (AnsiPos('BBS_NONAME_NAME=', body[i]) > 0) then begin
1816                         tmp := body[i];
1817                         Delete(tmp, 1, AnsiPos('=', tmp));
1818                         Result := tmp;
1819                         Exit;
1820                 end;
1821         end;
1822 end;
1823
1824 procedure TEditorForm.GetHeadTXTActionExecute(Sender: TObject);
1825 var
1826         URL, RefURL: string;
1827         settingBody: TStringList;
1828         tmpBoard: TBoard;
1829 begin
1830         InitIdHTTP(Indy);
1831         if FThreadItem = nil then
1832                 tmpBoard := FBoard
1833         else
1834                 tmpBoard := FThreadItem.ParentBoard;
1835
1836         if tmpBoard = nil then Exit;
1837
1838         RefURL  := tmpBoard.URL;
1839         if RefURL[Length(RefURL)] <> '/' then
1840                 URL     := RefURL + '/' + 'head.txt'
1841         else
1842                 URL     := RefURL + 'head.txt';
1843
1844         if FileExists(tmpBoard.GETHEADTXTFileName) then
1845                 Indy.Request.LastModified := tmpBoard.HEADTXTTime
1846         else
1847                 Indy.Request.LastModified := ZERO_DATE;
1848
1849         Indy.Request.Referer := RefURL;
1850         Screen.Cursor := crHourGlass;
1851         settingBody := TStringList.Create;
1852         try
1853                 StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b(head.txt)\83_\83E\83\93\83\8d\81[\83h\92\86';
1854                 try
1855                         settingBody.Text := Indy.Get(URL);
1856                         if( Indy.ResponseCode = 200 ) then begin
1857                                 settingBody.Insert(0, '<HTML lang="ja"><HEAD>');
1858                                 settingBody.Insert(1, '<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">');
1859                                 settingBody.Insert(2, '<TITLE>' + tmpBoard.Title + '</TITLE>');
1860                                 settingBody.Insert(3, '<base href="' + RefURL + '"></HEAD><BODY>');
1861                                 settingBody.Add('</BODY></HTML>');
1862                                 settingBody.SaveToFile(tmpBoard.GETHEADTXTFileName);
1863                                 tmpBoard.HEADTXTTime := Indy.Response.LastModified;
1864                                 tmpBoard.IsHEADTXT := true;
1865                                 tmpBoard.Modified := true;
1866                                 StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8eæ\93¾\8a®\97¹(' + IntToStr(Indy.ResponseCode) + ')';
1867                         end;
1868                 except
1869                         on E: EIdException do begin
1870                                 if( AnsiPos('304', E.Message) > 0 ) then
1871                                         StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8dX\90V\96³\82µ(' + IntToStr(Indy.ResponseCode) + ')'
1872                                 else
1873                                         StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8eæ\93¾\83G\83\89\81[(' + IntToStr(Indy.ResponseCode) + ')';
1874                         end;
1875                 end;
1876         finally
1877                 settingBody.Free;
1878                 Screen.Cursor := crDefault;
1879         end;
1880         if tmpBoard.IsHEADTXT then begin
1881                 ShowBoardHead(tmpboard, LocalEdit);
1882         end;
1883
1884 end;
1885
1886 procedure TEditorForm.CalcCapasityActionExecute(Sender: TObject);
1887 var
1888         body: String;
1889 begin
1890         body := GetBody;
1891         StatusBar.Panels[0].Text := '\97e\97Ê:' + IntToStr(Length(body)) + ' byte';
1892 end;
1893
1894 procedure TEditorForm.LocalRuleClick(Sender: TObject);
1895 var
1896   ini: TIniFile;
1897 begin
1898         ini := TIniFile.Create(GikoSys.Setting.GetFileName);
1899         try
1900                 RocalRuleTab.TabVisible := LocalRule.Checked;
1901                 ini.WriteBool('EditorForm', 'LocalRuleTab', RocalRuleTab.TabVisible);
1902         finally
1903                 ini.Free;
1904         end;
1905 end;
1906
1907 procedure TEditorForm.FormDeactivate(Sender: TObject);
1908 begin
1909         if GikoSys.Setting.GestureEnabled then begin
1910                 MouseGesture.UnHook;
1911                 MouseGesture.SetHook( GikoForm.Handle );
1912         end;
1913 end;
1914
1915 procedure TEditorForm.OnGestureStart(Sender: TObject);
1916 begin
1917 //
1918 end;
1919
1920 procedure TEditorForm.OnGestureMove(Sender: TObject);
1921 var
1922         s: string;
1923         Action: TAction;
1924         ActStr: string;
1925 begin
1926         s := MouseGesture.GetGestureStr;
1927         ActStr := '';
1928         Action := FGestures.GetGestureAction(s);
1929         if Action <> nil then
1930                 ActStr := '\81i' + Action.Caption + '\81j';
1931         s := '\83W\83F\83X\83`\83\83\81[: ' + s + ActStr;
1932         StatusBar.Panels[0].Text := s;
1933 end;
1934
1935 procedure TEditorForm.OnGestureEnd(Sender: TObject);
1936 var
1937         s: string;
1938         Action: TAction;
1939 begin
1940         s := MouseGesture.GetGestureStr;
1941         Action := FGestures.GetGestureAction(s);
1942         if Action <> nil then
1943                 Action.Execute;
1944         StatusBar.Panels[0].Text := '';
1945 end;
1946
1947 procedure TEditorForm.ShowBoardHead(ABoard: TBoard; AMemo: TMemo);
1948 var
1949         wDoc, WTex, le: OLEVariant;
1950 begin
1951                 //\8eQ\8dl\8c³
1952                 //http://www.campus.ne.jp/~ishigami/CREATION/TECHNIC/WEBAP-2.htm
1953                 WebBrowser1.Navigate(ABoard.GETHEADTXTFileName,le,le,le,le);
1954                 //\83\8c\83^\83\8a\83\93\83O\82ª\92x\82·\82¬\82ÄTXT\82É\88Ú\82¹\82È\82¢\81B\82Ê\82é\82Ûorz
1955                 //\89º\82Ì\82æ\82¤\82É\82¿\82á\82ñ\82Æ\93Ç\82Ý\8d\9e\82Ý\82ª\8fI\82í\82Á\82Ä\82¢\82é\82©\81A\83`\83F\83b\83N\82·\82ê\82Î\82¢\82¢\82ñ\82¾\82æ\81B
1956                 //\82±\82ê\82Å\82¢\82¯\82Ü\82µ\82½\81B\82 \82è\82ª\82Æ\82¤\82²\82´\82¢\82Ü\82µ\82½\81B
1957                 while (WebBrowser1.ReadyState <> READYSTATE_COMPLETE) and
1958                                 (WebBrowser1.ReadyState <> READYSTATE_INTERACTIVE) do begin
1959                         Application.ProcessMessages;
1960                 end;
1961                 wDoc := WebBrowser1.Document;
1962                 wTex := wDoc.body.createTextRange;
1963                 LocalEdit.Text := wTex.text;
1964 end;
1965
1966 end.