OSDN Git Service

[YCへマージ]
[winbottle/winbottle.git] / bottleclient / BottleDef.pas
1 unit BottleDef;
2
3 (*
4   \83A\83v\83\8a\83P\81[\83V\83\87\83\93\91S\91Ì\82Å\8eg\82¤\82³\82Ü\82´\82Ü\82È\83f\81[\83^\82ð\92è\8b`
5 *)
6
7 interface
8
9 uses Windows, IniFiles, BRegExp, Graphics, SysUtils, Forms, Dialogs, Classes,
10   ComCtrls, Contnrs, SsPlayTime, StrReplace;
11
12 type
13   TReturnKeyFunction = (kfYenN, kfReturn, kfYenNReturn, kfConstText);
14   TSoundArrived = (saFalse, saTrue, saParent);
15   TLogWindowPreviewStyle = (psConversation, psImageConversation,
16     psScript, psScriptWithLineBreak);
17   TLogListPreviewStyle = (psNoColor, psNormal, psTagStripped);
18   TSurfacePreviewOnScriptPointPosition = (spspMainWindowLeft, spspMainWindowRight);
19
20   //SSTP Bottle\82Ì\90Ý\92è
21   TBottlePrefs = class(TObject)
22   private
23     FIni: TIniFile;
24     FIni2: TIniFile;
25     //
26     FIgnoreTimeCritical: boolean;
27     FStayOnTop: boolean;
28     FShowConstBar: boolean;
29     FNoConfirm: boolean;
30     FDblClkInsert: boolean;
31     FShowToolBar: boolean;
32     FDefaultScript: TStringList;
33     FTalkColorH: TColor;
34     FMetaWordColor: TColor;
35     FTalkColorU: TColor;
36     FMarkErrorColor: TColor;
37     FMarkUpColor: TColor;
38     FAutoStart: boolean;
39     FCgiName: string;
40     FHomePage: string;
41     FWhenCtrlReturn: TReturnKeyFunction;
42     FWhenShiftReturn: TReturnKeyFunction;
43     FWhenReturn: TReturnKeyFunction;
44     FNoTranslate: boolean;
45     FNoDescript: boolean;
46     FBgColor: TColor;
47     FTextColor: TColor;
48     FServerPort: integer;
49     FSilentWhenHidden: boolean;
50     FLUID: String;
51     FSenderWindowPosition: TRect;
52     FTabPosition: TTabPosition;
53     FLogWindowPosition: TRect;
54     FNoTransUrl: boolean;
55     FIgnoreFrequentYenS: boolean;
56     FWaitScriptEnd: integer;
57     FCgiNameGhost: String;
58     FGLogPage: String;
59     FVotePage: String;
60     FLogWindowDividerPos: integer;
61     FHelpPage: String;
62     FUseHttpProxy: boolean;
63     FAskUseHttpProxy: boolean;
64     FProxyPort: integer;
65     FProxyAddress: String;
66     FConfirmOnExit: boolean;
67     FFixMessySurface: boolean;
68     FResetIfGhostAfterSend: boolean;
69     FGhostDropDownCount: integer;
70     FLogWindowPreviewStyle: TLogWindowPreviewStyle;
71     FCgiFetchLog: String;
72     FTalkColorS: TColor;
73     FLogWindowColumnWidth: String;
74     FClearAfterSend: boolean;
75     FAutoJoinChannels: TStrings;
76     FFMOName: TStrings;
77     FHUTagTo01Tag: boolean;
78     FWarnYenTNotExist: boolean;
79     FWarnScopeChangeInSynchronize: boolean;
80     FNeedConfirmBeforeSend: boolean;
81     FShowRuler: boolean;
82     FHideGhosts: boolean;
83     FVisibleGhostsList: TStringList;
84     FSurfacePreviewOnHint: boolean;
85     FSurfacePreviewOnScriptPoint: boolean;
86     FSurfacePreviewOnScriptPointPosition: TSurfacePreviewOnScriptPointPosition;
87     FNoExtraSSTPHeaders: boolean;
88     FLogListPreviewStyle: TLogListPreviewStyle;
89     FEditorPreviewWindowPosition: TRect;
90     FAutoClip: boolean;
91     FConfirmOnTabClose: boolean;
92     FReconnectWait: integer;
93     FPartialConfirmFormat: String;
94     FAutoPartialConfirm: boolean;
95     FPlayTimeParams: TSsPlayTimeParams;
96     FBottleServerPort: integer;
97     FBottleServer: String;
98     FTabWidth: integer;
99     FBrowserExeName: string;
100     FReplacePresets: TReplacePresets;
101     FNotWarnGhostIsntExists: Boolean;
102     //\82â\82³\82®\82ê\95ª
103     FSendAction: boolean;
104     FNotSSTP: boolean;
105     FScriptBackup: boolean;
106     FScriptBackupTime: integer;
107     FErrScript: boolean;
108     FGhostCh: boolean;
109     FGhostChList: TStringList;
110     FNotShowLog: boolean;
111     FNotCheckClear: boolean;
112     FNotYenETrans: boolean;
113     FNotScriptTime: boolean;
114     FScriptBackupMode: boolean;
115     FLogDir: String;
116     FTextDir: String;
117     FNoDeleteBackupFile: boolean;
118
119     procedure SetDblClkInsert(const Value: boolean);
120     procedure SetDefaultScript(const Value: String);
121     procedure SetIgnoreTimeCritical(const Value: boolean);
122     procedure SetMarkErrorColor(const Value: TColor);
123     procedure SetMarkUpColor(const Value: TColor);
124     procedure SetMetaWordColor(const Value: TColor);
125     procedure SetTextColor(const Value: TColor);
126     procedure SetNoConfirm(const Value: boolean);
127     procedure SetShowConstBar(const Value: boolean);
128     procedure SetShowToolBar(const Value: boolean);
129     procedure SetStayOnTop(const Value: boolean);
130     procedure SetTalkColorH(const Value: TColor);
131     procedure SetTalkColorU(const Value: TColor);
132     procedure SetAutoStart(const Value: boolean);
133     procedure SetWhenCtrlReturn(const Value: TReturnKeyFunction);
134     procedure SetWhenReturn(const Value: TReturnKeyFunction);
135     procedure SetWhenShiftReturn(const Value: TReturnKeyFunction);
136     procedure SetNoTranslate(const Value: boolean);
137     procedure SetNoDescript(const Value: boolean);
138     procedure SetBgColor(const Value: TColor);
139     procedure SetServerPort(const Value: integer);
140     procedure SetSilentWhenHidden(const Value: boolean);
141     procedure SetLUID(const Value: String);
142     procedure SetSenderWindowPosition(const Value: TRect);
143     procedure SetTabPosition(const Value: TTabPosition);
144     procedure SetLogWindowPosition(const Value: TRect);
145     procedure SetIgnoreFrequentYenS(const Value: boolean);
146     procedure SetNoTransUrl(const Value: boolean);
147     procedure SetWaitScriptEnd(const Value: integer);
148     procedure SetLogWindowDividerPos(const Value: integer);
149     procedure SetProxyAddress(const Value: String);
150     procedure SetProxyPort(const Value: integer);
151     procedure SetUseHttpProxy(const Value: boolean);
152     procedure SetAskUseHttpProxy(const Value: boolean);
153     procedure SetConfirmOnExit(const Value: boolean);
154     procedure SetFixMessySurface(const Value: boolean);
155     procedure SetResetIfGhostAfterSend(const Value: boolean);
156     procedure SetGhostDropDownCount(const Value: integer);
157     procedure SetLogWindowPreviewStyle(const Value: TLogWindowPreviewStyle);
158     procedure SetTalkColorS(const Value: TColor);
159     procedure SetLogWindowColumnWidth(const Value: String);
160     procedure SetClearAfterSend(const Value: boolean);
161     procedure SetAutoJoinChannels(const Value: TStrings);
162     procedure SetFMOName(const Value: TStrings);
163     function GetDefaultScript: String;
164     procedure SetHUTagTo01Tag(const Value: boolean);
165     procedure SetWarnScopeChangeInSynchronize(const Value: boolean);
166     procedure SetWarnYenTNotExist(const Value: boolean);
167     procedure SetNeedConfirmBeforeSend(const Value: boolean);
168     procedure SetShowRuler(const Value: boolean);
169     procedure SetHideGhosts(const Value: boolean);
170     procedure SetVisibleGhostsList(const Value: TStringList);
171     procedure SetSurfacePreviewOnHint(const Value: boolean);
172     procedure SetSurfacePreviewOnScriptPoint(const Value: boolean);
173     procedure SetSurfacePreviewOnScriptPointPosition(
174       const Value: TSurfacePreviewOnScriptPointPosition);
175     procedure SetNoExtraSSTPHeaders(const Value: boolean);
176     procedure SetLogListPreviewStyle(const Value: TLogListPreviewStyle);
177     procedure SetEditorPreviewWindowPosition(const Value: TRect);
178     procedure SetAutoClip(const Value: boolean);
179     procedure SetConfirmOnTabClose(const Value: boolean);
180     procedure SetReconnectWait(const Value: integer);
181     procedure SetPartialConfirmFormat(const Value: String);
182     procedure SetAutoPartialConfirm(const Value: boolean);
183     procedure SetPlayTimeParams(const Value: TSsPlayTimeParams);
184     procedure SetTabWidth(const Value: integer);
185     procedure SetBrowserExeName(const Value: string);
186     procedure SetNotWarnGhostIsntExists(const Value: Boolean);
187     //\82â\82³\82®\82ê\95ª
188     procedure SetSendAction(const Value: boolean);
189     procedure SetNotSSTP(const Value: boolean);
190     procedure SetScriptBackup(const Value: boolean);
191     procedure SetScriptBackupTime(const Value: integer);
192     procedure SetErrScript(const Value: boolean);
193     procedure SetGhostCh(const Value: boolean);
194     procedure SetGhostChList(const Value: TStringList);
195     procedure SetNotShowLog(const Value: boolean);
196     procedure SetNotCheckClear(const Value: boolean);
197     procedure SetNotYenETrans(const Value: boolean);
198     procedure SetNotScriptTime(const Value: boolean);
199     procedure SetScriptBackupMode(const Value: boolean);
200     procedure SetLogDir(const Value: String);
201     procedure SetTextDir(const Value: String);
202     procedure SetNoDeleteBackupFile(const Value: boolean);
203   protected
204     function InScreen(ARect: TRect): boolean;
205   public
206     property BottleServer: String read FBottleServer;
207     property BottleServerPort: integer read FBottleServerPort;
208     property PartialConfirmFormat: String read FPartialConfirmFormat write SetPartialConfirmFormat;
209     property AutoPartialConfirm: boolean read FAutoPartialConfirm write SetAutoPartialConfirm;
210     property ConfirmOnExit: boolean read FConfirmOnExit write SetConfirmOnExit;
211     property ConfirmOnTabClose: boolean read FConfirmOnTabClose write SetConfirmOnTabClose;
212     property AutoClip: boolean read FAutoClip write SetAutoClip;
213     property AutoStart: boolean read FAutoStart write SetAutoStart;
214     property TabPosition: TTabPosition read FTabPosition write SetTabPosition;
215     property TabWidth: integer read FTabWidth write SetTabWidth;
216     property GhostDropDownCount: integer read FGhostDropDownCount write SetGhostDropDownCount;
217     property NoTranslate: boolean read FNoTranslate write SetNoTranslate;
218     property NoDescript: boolean read FNoDescript write SetNoDescript;
219     property NoTransUrl: boolean read FNoTransUrl write SetNoTransUrl;
220     property SilentWhenHidden: boolean read FSilentWhenHidden write SetSilentWhenHidden;
221     property FixMessySurface: boolean read FFixMessySurface write SetFixMessySurface;
222     property HUTagTo01Tag: boolean read FHUTagTo01Tag write SetHUTagTo01Tag;
223     property ResetIfGhostAfterSend: boolean read FResetIfGhostAfterSend write SetResetIfGhostAfterSend;
224     property ClearAfterSend: boolean read FClearAfterSend write SetClearAfterSend;
225     property NeedConfirmBeforeSend: boolean read FNeedConfirmBeforeSend write SetNeedConfirmBeforeSend;
226     property IgnoreFrequentYenS: boolean read FIgnoreFrequentYenS write SetIgnoreFrequentYenS;
227     property WarnYenTNotExist: boolean read FWarnYenTNotExist write SetWarnYenTNotExist;
228     property WarnScopeChangeInSynchronize: boolean read FWarnScopeChangeInSynchronize write SetWarnScopeChangeInSynchronize;
229     property WaitScriptEnd: integer read FWaitScriptEnd write SetWaitScriptEnd;
230     property StayOnTop: boolean read FStayOnTop write SetStayOnTop;
231     property IgnoreTimeCritical: boolean read FIgnoreTimeCritical write SetIgnoreTimeCritical;
232     property TalkColorH: TColor read FTalkColorH write SetTalkColorH;
233     property TalkColorU: TColor read FTalkColorU write SetTalkColorU;
234     property TalkColorS: TColor read FTalkColorS write SetTalkColorS;
235     property MarkUpColor: TColor read FMarkUpColor write SetMarkUpColor;
236     property MetaWordColor: TColor read FMetaWordColor write SetMetaWordColor;
237     property MarkErrorColor: TColor read FMarkErrorColor write SetMarkErrorColor;
238     property BgColor: TColor read FBgColor write SetBgColor;
239     property TextColor: TColor read FTextColor write SetTextColor;
240     property DefaultScript: String read GetDefaultScript write SetDefaultScript;
241     property ShowRuler: boolean read FShowRuler write SetShowRuler;
242     property DblClkInsert: boolean read FDblClkInsert write SetDblClkInsert;
243     property ShowToolBar: boolean read FShowToolBar write SetShowToolBar;
244     property ShowConstBar: boolean read FShowConstBar write SetShowConstBar;
245     property NoConfirm: boolean read FNoConfirm write SetNoConfirm;
246     property HomePage: string read FHomePage;
247     property WhenReturn: TReturnKeyFunction read FWhenReturn write SetWhenReturn;
248     property WhenShiftReturn: TReturnKeyFunction read FWhenShiftReturn write SetWhenShiftReturn;
249     property WhenCtrlReturn: TReturnKeyFunction read FWhenCtrlReturn write SetWhenCtrlReturn;
250     property ServerPort: integer read FServerPort write SetServerPort;
251     //URL\8aÖ\8cW
252     property CgiName: string read FCgiName;
253     property CgiNameGhost: String read FCgiNameGhost;
254     property CgiFetchLog: String read FCgiFetchLog;
255     property GLogPage: String read FGLogPage;
256     property VotePage: String read FVotePage;
257     property HelpPage: String read FHelpPage;
258
259     //\83`\83\83\83\93\83l\83\8b\8aÖ\8cW
260     property AutoJoinChannels: TStrings read FAutoJoinChannels write SetAutoJoinChannels;
261
262     property LUID: String read FLUID write SetLUID;
263
264     //\83E\83B\83\93\83h\83E\88Ê\92u
265     property SenderWindowPosition: TRect
266       read FSenderWindowPosition write SetSenderWindowPosition;
267     property LogWindowPosition: TRect read FLogWindowPosition write SetLogWindowPosition;
268     property LogWindowDividerPos: integer
269       read FLogWindowDividerPos write SetLogWindowDividerPos;
270     property LogWindowColumnWidth: String
271       read FLogWindowColumnWidth write SetLogWindowColumnWidth;
272     property EditorPreviewWindowPosition: TRect read FEditorPreviewWindowPosition write SetEditorPreviewWindowPosition;
273     //\83v\83\8d\83L\83V\8aÖ\8cW
274     property UseHttpProxy: boolean read FUseHttpProxy write SetUseHttpProxy;
275     property AskUseHttpProxy: boolean read FAskUseHttpProxy write SetAskUseHttpProxy;
276     property ProxyAddress: String read FProxyAddress write SetProxyAddress;
277     property ProxyPort: integer read FProxyPort write SetProxyPort;
278     //\8dÄ\90Ú\91±
279     property ReconnectWait: integer read FReconnectWait write SetReconnectWait;
280     //\83\8d\83O\83E\83B\83\93\83h\83E\8aÖ\8cW
281     property LogWindowPreviewStyle: TLogWindowPreviewStyle
282       read FLogWindowPreviewStyle write SetLogWindowPreviewStyle;
283     property LogListPreviewStyle: TLogListPreviewStyle
284       read FLogListPreviewStyle write SetLogListPreviewStyle;
285     //\8fÚ\8d×\90Ý\92è
286     property FMOName: TStrings read FFMOName write SetFMOName;
287     property HideGhosts: boolean read FHideGhosts write SetHideGhosts;
288     property VisibleGhostsList: TStringList read FVisibleGhostsList write SetVisibleGhostsList;
289     property NoExtraSSTPHeaders: boolean read FNoExtraSSTPHeaders write SetNoExtraSSTPHeaders;
290     //\83T\81[\83t\83B\83X\83v\83\8c\83r\83\85\81[
291     property SurfacePreviewOnHint: boolean
292       read FSurfacePreviewOnHint write SetSurfacePreviewOnHint;
293     property SurfacePreviewOnScriptPoint: boolean
294       read FSurfacePreviewOnScriptPoint write SetSurfacePreviewOnScriptPoint;
295     property SurfacePreviewOnScriptPointPosition: TSurfacePreviewOnScriptPointPosition
296       read FSurfacePreviewOnScriptPointPosition write SetSurfacePreviewOnScriptPointPosition;
297     //\8dÄ\90\8e\9e\8aÔ\97\\91ª
298     property PlayTimeParams: TSsPlayTimeParams read FPlayTimeParams write SetPlayTimeParams;
299     //URL\83I\81[\83v\83\93\8e\9e\82É\8eg\82¤\83u\83\89\83E\83U\82Ì\8eÀ\8ds\83t\83@\83C\83\8b\96¼
300     property BrowserExeName: string read FBrowserExeName write SetBrowserExeName;
301     //\8e©\93®\92u\8a·\83v\83\8a\83Z\83b\83g
302     property ReplacePresets: TReplacePresets read FReplacePresets;
303     //SSTP\83T\81[\83o\94ñ\91\8dÝ\8cx\8d\90\82Ì\83J\83b\83g\82ð\82·\82é\82©
304     property NotWarnGhostIsntExists: Boolean
305       read FNotWarnGhostIsntExists write SetNotWarnGhostIsntExists;
306     //\82â\82³\82®\82ê\95ª
307     property SendAction: boolean read FSendAction write SetSendACtion;
308     property NotSSTP: boolean read FNotSSTP write SetNotSSTP;
309     property ScriptBackup: boolean read FScriptBackup write SetScriptBackup;
310     property ScriptBackupTime: Integer read FScriptBackupTime write SetScriptBackupTime;
311     property ErrScript: boolean read FErrScript write SetErrScript;
312     property GhostCh: boolean read FGhostCh write SetGhostCh;
313     property GhostChList: TStringList read FGhostChList write SetGhostChList;
314     property NotShowLog: boolean read FNotShowLog write SetNotShowLog;
315     property NotCheckClear: boolean read FNotCheckClear write SetNotCheckClear;
316     property NotYenETrans: boolean read FNotYenETrans write SetNotYenETrans;
317     property NotScriptTime: boolean read FNotScriptTime write SetNotScriptTime;
318     property ScriptBackupMode: boolean read FScriptBackupMode write SetScriptBackupMode;
319     property LogDir: String read FLogDir write SetLogDir;
320     property TextDir: String read FTextDir write SetTextDir;
321     property NoDeleteBackupFile: boolean read FNoDeleteBackupFile write SetNoDeleteBackupFile;
322
323     //\83R\83\93\83X\83g\83\89\83N\83^\81E\83f\83X\83g\83\89\83N\83^\81E\95Û\91
324     constructor Create;
325     destructor Destroy; override;
326     procedure SaveSettings;
327   end;
328
329   TChannelListItem = class(TObject)
330   private
331     FMembers: integer;
332     FGhost: String;
333     FInfo: String;
334     FName: String;
335     FNoPost: boolean;
336     FWarnPost: boolean;
337     procedure SetGhost(const Value: String);
338     procedure SetInfo(const Value: String);
339     procedure SetMembers(const Value: integer);
340     procedure SetName(const Value: String);
341     procedure SetNoPost(const Value: boolean);
342     procedure SetWarnPost(const Value: boolean);
343   public
344     property Name: String read FName write SetName;
345     property Info: String read FInfo write SetInfo;
346     property Ghost: String read FGhost write SetGhost;
347     property Members: integer read FMembers write SetMembers;
348     property NoPost: boolean read FNoPost write SetNoPost;
349     property WarnPost: boolean read FWarnPost write SetWarnPost;
350   end;
351
352   TChannelList = class(TList)
353   private
354     function GetChannel(Name: String): TChannelListItem;
355     function GetChannelItem(Index: integer): TChannelListItem;
356   public
357     procedure Clear; override;
358     property Channel[Name: String]: TChannelListItem read GetChannel;
359     property ChannelItem[Index: integer]: TChannelListItem read GetChannelItem;
360   end;
361
362   TScriptTransOption = (
363     toIgnoreTimeCritical,
364     toConvertURL,
365     toNoChoice,
366     toIgnoreFrequentYenS,
367     toWaitScriptEnd,
368     toFixMessySurface,
369     toWarnMessySurface,
370     toHUTagTo01Tag,
371     toWarnCheck
372   );
373
374   TScriptTransOptions = set of TScriptTransOption;
375
376 var
377   Pref: TBottlePrefs;
378   ChannelList: TChannelList; //\83`\83\83\83\93\83l\83\8b\83\8a\83X\83g\82ð\95Û\8e\9d\82·\82é
379   //JoinChannels: TStringList; // \8c»\8dÝ\8eQ\89Á\82µ\82Ä\82¢\82é\83`\83\83\83\93\83l\83\8b
380
381 const
382   DefaultBottleServer    = 'bottle.mikage.to';
383   DefaultBottleServerPort = 9871;
384   DefaultCGI      = '/bottle2.cgi';
385   DefaultCGIGhost = '/glog/bottleglog.cgi';
386   DefaultCGIFetchLog = '/fetchlog.cgi';
387
388
389   DefaultHomePage = 'http://bottle.mikage.to/';
390   DefaultGLogPage = 'http://bottle.mikage.to/glog/glogview.cgi';
391   DefaultVotePage = 'http://bottle.mikage.to/viewvotes.cgi';
392   DefaultHelpPage = 'http://bottle.mikage.to/clihelp/index.html';
393
394   Version = '1.02'; //2.69\82©\82ç\95ª\8aò
395
396   {$IFDEF NOMUTEX}
397   VersionString = 'SSTP Bottle Client ver ' + Version + 'a NO MUTEX VERSION';
398   {$ELSE}
399   VersionString = 'Yasagure Client ver ' + Version;
400   {$ENDIF}
401
402   SentLogFile     = 'sent.log';
403
404   BottleDisclaimer = '(C)2001-2004 WinBottle Project'#13#10 +
405     'naru, C.Ponapalt, Yune Kotomi, yese, Mikage Sawatari, E01'#13#10 +
406     DefaultHomePage;
407
408   ChannelDefault = '(CH\90\84\8f§)';
409   ClipChannel    = '(\83N\83\8a\83b\83v)';
410
411 function ParamsEncode(const ASrc: string): string;
412 function XMLEntity(From: String): String;
413 function SafeFileName(From: String; ChangePathDelimiters: boolean = true): String;
414 function ComponentToString(Component: TComponent): string;
415 function StringToComponent(Value: string): TComponent;
416
417 function ReplacePresetFileName: string;
418
419 procedure BuildShortCutList(Target: TStrings);
420
421 implementation
422
423 function ParamsEncode(const ASrc: string): string;
424 var
425   i: Integer;
426 const
427   UnsafeChars = ['*', '#', '%', '<', '>', ' ', '[', ']', '+'];
428 begin
429   Result := '';    {Do not Localize}
430   for i := 1 to Length(ASrc) do
431   begin
432     if (ASrc[i] in UnsafeChars) or (not (ord(ASrc[i])in [33..128])) then
433     begin {do not localize}
434       Result := Result + '%' + IntToHex(Ord(ASrc[i]), 2);  {do not localize}
435     end
436     else
437     begin
438       Result := Result + ASrc[i];
439     end;
440   end;
441 end;
442
443 // XML\8eÀ\91Ì\8eQ\8fÆ\82É\92u\82«\8a·\82¦\82é
444 function XMLEntity(From: String): String;
445 var
446   i: integer;
447   InLead: boolean;
448 begin
449   InLead := false;
450   Result := '';
451   for i := 1 to Length(From) do
452   begin
453     if InLead then
454     begin
455       InLead := false;
456       Result := Result + From[i];
457     end else if From[i] in LeadBytes then
458     begin
459       InLead := true;
460       Result := Result + From[i];
461     end else
462     begin
463       case Ord(From[i]) of
464         60: Result := Result + '&lt;'; // Less than
465         62: Result := Result + '&gt;'; // Greater than
466         38: Result := Result + '&amp;'; // Ampersand
467         39: Result := Result + '&#39;'; // Single quote
468         34: Result := Result + '&quot;'; // Double quote
469         else
470           Result := Result + From[i];
471       end;
472     end;
473   end;
474 end;
475
476 // Escape characters which can not be used as a filename
477 function SafeFileName(From: String; ChangePathDelimiters: boolean = true): String;
478 begin
479   Result := StringReplace(From, '*', '\81\96', [rfReplaceAll]);
480   Result := StringReplace(Result, '|', '\81b', [rfReplaceAll]);
481   Result := StringReplace(Result, '"', '''''', [rfReplaceAll]);
482   Result := StringReplace(Result, '<', '\81\83', [rfReplaceAll]);
483   Result := StringReplace(Result, '>', '\81\84', [rfReplaceAll]);
484   Result := StringReplace(Result, '?', '\81H', [rfReplaceAll]);
485   if ChangePathDelimiters then
486   begin
487     Result := StringReplace(Result, '\', '\81\8f', [rfReplaceAll]);
488     Result := StringReplace(Result, ':', '\81F', [rfReplaceAll]);
489     Result := StringReplace(Result, '/', '\81^', [rfReplaceAll]);
490   end;
491 end;
492
493 function ComponentToString(Component: TComponent): string;
494 var
495   BinStream:TMemoryStream;
496   StrStream: TStringStream;
497   s: string;
498 begin
499   BinStream := TMemoryStream.Create;
500   try
501     StrStream := TStringStream.Create(s);
502     try
503       BinStream.WriteComponent(Component);
504       BinStream.Seek(0, soFromBeginning);
505       ObjectBinaryToText(BinStream, StrStream);
506       StrStream.Seek(0, soFromBeginning);
507       Result:= StrStream.DataString;
508     finally
509       StrStream.Free;
510     end;
511   finally
512     BinStream.Free
513   end;
514 end;
515
516 function StringToComponent(Value: string): TComponent;
517 var
518   StrStream:TStringStream;
519   BinStream: TMemoryStream;
520 begin
521   StrStream := TStringStream.Create(Value);
522   try
523     BinStream := TMemoryStream.Create;
524     try
525       ObjectTextToBinary(StrStream, BinStream);
526       BinStream.Seek(0, soFromBeginning);
527       Result := BinStream.ReadComponent(nil);
528     finally
529       BinStream.Free;
530     end;
531   finally
532     StrStream.Free;
533   end;
534 end;
535
536 function ReplacePresetFileName: string;
537 begin
538   Result := ExtractFilePath(Application.ExeName) + 'replace.txt';
539 end;
540
541 procedure BuildShortCutList(Target: TStrings);
542 var
543   c: Char;
544   i: Integer;
545 begin
546   // \83V\83\87\81[\83g\83J\83b\83g\83\8a\83X\83g\82Ì\91I\91ð\8e\88\82ð\8dì\90¬
547   with Target do
548   begin
549     BeginUpdate;
550     try
551       for c := 'A' to 'Z' do
552         Add('Ctrl+' + c);
553       for c := 'A' to 'Z' do
554         Add('Shift+Ctrl+' + c);
555       for c := 'A' to 'Z' do
556         Add('Alt+Ctrl+' + c);
557       for i := 1 to 12 do
558         Add('F' + IntToStr(i));
559       for i := 1 to 12 do
560         Add('Shift+F' + IntToStr(i));
561     finally
562       EndUpdate;
563     end;
564   end;
565 end;
566
567 { TBottlePrefs }
568
569 constructor TBottlePrefs.Create;
570 var ARect: TRect;
571     Strs: TStringList;
572 begin
573   FAutoJoinChannels := TStringList.Create;
574   FDefaultScript := TStringList.Create;
575   FFMOName := TStringList.Create;
576   FVisibleGhostsList := TStringList.Create;
577   FGhostChList := TStringList.Create;
578   try
579     FIni := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
580     FIni2 := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'YC.ini');
581     //
582     PartialConfirmFormat := FIni.ReadString('System', 'PartialConfirmFormat', '\t|\e');
583     AutoPartialConfirm := FIni.ReadBool('System', 'AutoPartialConfirm', false);
584     ConfirmOnExit := FIni.ReadBool('System', 'ConfirmOnExit', false);
585     ConfirmOnExit := FIni.ReadBool('System', 'ConfirmOnExit', false);
586     ConfirmOnTabClose := FIni.ReadBool('System', 'ConfirmOnTabClose', false);
587     AutoClip := FIni.ReadBool('System', 'AutoClip', false);
588     AutoStart := FIni.ReadBool('System', 'AutoStart', false);
589     TabPosition := TTabPosition(FIni.ReadInteger('System', 'TabPosition', 0));
590     TabWidth := FIni.ReadInteger('System', 'TabWidth', 0);
591     GhostDropDownCount := FIni.ReadInteger('System', 'GhostDropDownCount', 30);
592
593     NoTranslate := FIni.ReadBool('System', 'NoTranslate', true);
594     NoDescript := FIni.ReadBool('System', 'NoDescript', false);
595     NoTransUrl := FIni.ReadBool('System', 'NoTransUrl', false);
596     SilentWhenHidden:= FIni.ReadBool('System', 'SilentWhenHidden', true);
597     FixMessySurface := FIni.ReadBool('System', 'FixMessySurface', false);
598     HUTagTo01Tag := FIni.ReadBool('System', 'HUTagTo01Tag', false);
599     ResetIfGhostAfterSend := FIni.ReadBool('System', 'ResetIfGhostAfterSend', false);
600     ClearAfterSend := FIni.ReadBool('System', 'ClearAfterSend', true);
601     NeedConfirmBeforeSend := FIni.ReadBool('System', 'NeedConfirmBeforeSend', true);
602     WarnYenTNotExist := FIni.ReadBool('System', 'WarnYenTNotExist', false);
603     WarnScopeChangeInSynchronize := FIni.ReadBool('System', 'WarnScopeChangeInSynchronize', false);
604
605     IgnoreFrequentYenS := FIni.ReadBool('System', 'IgnoreFrequentYenS', false);
606     WaitScriptEnd := FIni.ReadInteger('System', 'WaitScriptEnd', 0);
607     StayOnTop := FIni.ReadBool('System', 'StayOnTop', false);
608     ShowConstBar := FIni.ReadBool('System', 'ShowConstBar', true);
609     ShowToolBar := FIni.ReadBool('System', 'ShowToolBar', true);
610     NoConfirm := FIni.ReadBool('System', 'NoConfirm', false);
611     IgnoreTimeCritical := FIni.ReadBool('System', 'IgnoreTimeCritical', false);
612     FDefaultScript.CommaText := FIni.ReadString('System', 'DefaultScript', '\t\u\s[10]\h\s[0]|\e');
613     ShowRuler := FIni.ReadBool('System', 'ShowRuler', false);
614     //
615     try
616       TalkColorH := StringToColor(FIni.ReadString('System', 'TalkColorH', 'clBlack'));
617       TalkColorU := StringToColor(FIni.ReadString('System', 'TalkColorU', 'clMaroon'));
618       TalkColorS := StringToColor(FIni.ReadString('System', 'TalkColorS', 'clPurple'));
619       MarkUpColor := StringToColor(FIni.ReadString('System', 'MarkUpColor', 'clGreen'));
620       MetaWordColor := StringToColor(FIni.ReadString('System', 'MetaWordColor', 'clBlue'));
621       MarkErrorColor := StringToColor(FIni.ReadString('System', 'MarkErrorColor', 'clRed'));
622       TextColor := StringToColor(FIni.ReadString('System', 'TextColor', ColorToString(TalkColorH)));
623       BgColor := StringToColor(FIni.ReadString('System', 'BgColor', 'clWhite'));
624     except
625       on EConvertError do begin
626         ShowMessage('\83J\83\89\81[\82Ì\90Ý\92è\93Ç\82Ý\8d\9e\82Ý\83G\83\89\81[');
627         FTalkColorH := clBlack;
628         FTalkColorU := clMaroon;
629         FMarkUpColor := clGreen;
630         FMetaWordColor := clBlue;
631         FMarkErrorColor := clRed;
632         FTextColor := clBlack;
633       end;
634     end;
635
636     try
637       if FIni.ReadString('System', 'PlayTimeParams', '') = '' then
638       begin
639         FPlayTimeParams := TSsPlayTimeParams.Create(nil);
640         FPlayTimeParams.ProfileName := '\83f\83t\83H\83\8b\83g';
641       end else
642       begin
643         Strs := TStringList.Create;
644         try
645           Strs.CommaText := FIni.ReadString('System', 'PlayTimeParams', '');
646           FPlayTimeParams := StringToComponent(Strs.Text) as TSsPlayTimeParams;
647         finally
648           Strs.Free;
649         end;
650       end;
651     except
652       on E: Exception do
653       begin
654         ShowMessage('\8dÄ\90\8e\9e\8aÔ\97\\91ª\90Ý\92è\82Ì\93Ç\82Ý\8d\9e\82Ý\83G\83\89\81[' + E.Message);
655         if FPlayTimeParams = nil then
656           FPlayTimeParams := TSsPlayTimeParams.Create(nil);
657       end;
658     end;
659
660     WhenReturn      := TReturnKeyFunction(FIni.ReadInteger('System', 'WhenReturn', 0));
661     WhenShiftReturn := TReturnKeyFunction(FIni.ReadInteger('System', 'WhenShiftReturn', 0));
662     WhenCtrlReturn  := TReturnKeyFunction(FIni.ReadInteger('System', 'WhenCtrlReturn', 0));
663     //\83\\83P\83b\83g\82ð\83{\83g\83\8b\94z\91\97\82ÌSSTP\92Ê\90M\82É\8eg\97p\82·\82é\8fê\8d\87\82Ì\90Ý\92è
664     ServerPort      := FIni.ReadInteger('System', 'ServerPort', 11000);
665
666     FBottleServer := FIni.ReadString('System', 'BottleServer', DefaultBottleServer);
667     FBottleServerPort := FIni.ReadInteger('System', 'BottleServerPort', DefaultBottleServerPort);
668     FCgiName  := FIni.ReadString('System', 'CgiName', DefaultCGI);
669     FCgiFetchLog := FIni.ReadString('System', 'CgiFetchLog', DefaultCGIFetchLog);
670     FHomePage := FIni.ReadString('System', 'HomePage', DefaultHomePage);
671     FGLogPage := FIni.ReadString('System', 'GLogPage', DefaultGLogPage);
672     FVotePage := FIni.ReadString('System', 'VotePage', DefaultVotePage);
673     FHelpPage := FIni.ReadString('System', 'HelpPage', DefaultHelpPage);
674     FCgiNameGhost := FIni.ReadString('System', 'GHOST', DefaultCGIGhost);
675     FLUID     := FIni.ReadString('System', 'LUID', '');
676     FAutoJoinChannels.CommaText := FIni.ReadString('System', 'AutoJoinChannels', '');
677     //
678     ARect.Top    := FIni.ReadInteger('System', 'SenderWindowPositionTop', 100);
679     ARect.Left   := FIni.ReadInteger('System', 'SenderWindowPositionLeft', 100);
680     ARect.Bottom := FIni.ReadInteger('System', 'SenderWindowPositionBottom', 500);
681     ARect.Right  := FIni.ReadInteger('System', 'SenderWindowPositionRight', 500);
682     if not InScreen(ARect) then
683       ARect := Rect(100, 100, 500, 500);
684     SenderWindowPosition := ARect;
685     ARect.Top    := FIni.ReadInteger('System', 'LogWindowPositionTop', 200);
686     ARect.Left   := FIni.ReadInteger('System', 'LogWindowPositionLeft', 200);
687     ARect.Bottom := FIni.ReadInteger('System', 'LogWindowPositionBottom', 600);
688     ARect.Right  := FIni.ReadInteger('System', 'LogWindowPositionRight', 400);
689     LogWindowDividerPos := FIni.ReadInteger('System', 'LogWindowDividerPos', 150);
690     LogWindowColumnWidth := FIni.ReadString('System', 'LogWindowColumnWidth', '');
691     if not InScreen(ARect) then begin
692       ARect := Rect(200, 200, 600, 400);
693       LogWindowDividerPos := 150;
694     end;
695     LogWindowPosition := ARect;
696     Strs := TStringList.Create;
697     try
698       Strs.CommaText := FIni.ReadString('System', 'EditorPreviewWindowPosition', '500,100,800,500');
699       try
700         ARect.Left   := StrToInt(Strs[0]);
701         ARect.Top    := StrToInt(Strs[1]);
702         ARect.Right  := StrToInt(Strs[2]);
703         ARect.Bottom := StrToInt(Strs[3]);
704       except
705         ARect := Rect(500, 100, 800, 500);
706       end;
707       EditorPreviewWindowPosition := ARect;
708     finally
709       Strs.Free;
710     end;
711     //
712     UseHttpProxy := FIni.ReadBool('System', 'UseHttpProxy', false);
713     AskUseHttpProxy := FIni.ReadBool('System', 'AskUseHttpProxy', false);
714     ProxyAddress := FIni.ReadString('System', 'ProxyAddress', '');
715     ProxyPort    := FIni.ReadInteger('System', 'ProxyPort', 0);
716     //
717     ReconnectWait := FIni.ReadInteger('System', 'ReconnectWait', 6);
718     //\83\8d\83O\83E\83B\83\93\83h\83E\8aÖ\8cW
719     LogWindowPreviewStyle := TLogWindowPreviewStyle(
720       FIni.ReadInteger('System', 'LogWindowPreviewStyle', 0));
721     LogListPreviewStyle := TLogListPreviewStyle(
722       FIni.ReadInteger('System', 'LogListPreviewStyle', 0));
723     //\8fÚ\8d×
724     FMOName.CommaText := FIni.ReadString('System', 'FMOName', 'Sakura');
725     HideGhosts := FIni.ReadBool('System', 'HideGhosts', false);
726     VisibleGhostsList.CommaText := FIni.ReadString('System', 'VisibleGhostsList', '');
727     NoExtraSSTPHeaders := FIni.ReadBool('System', 'NoExtraSSTPHeaders', false);
728     //\83T\81[\83t\83B\83X\83v\83\8c\83r\83\85\81[
729     SurfacePreviewOnHint := FIni.ReadBool('System', 'SurfacePreviewOnHint', false);
730     SurfacePreviewOnScriptPoint := FIni.ReadBool('System', 'SurfacePreviewOnScriptPoint', false);
731     SurfacePreviewOnScriptPointPosition :=
732       TSurfacePreviewOnScriptPointPosition(FIni.ReadInteger('System', 'SurfacePreviewOnScriptPointPosition', 0));
733
734     //URL\82ð\8aJ\82­\83u\83\89\83E\83U
735     BrowserExeName:= FIni.ReadString('System', 'BrowserExeName', '');
736     NotWarnGhostIsntExists := FIni.ReadBool('System', 'NotWarnGhostIsntExists', False);
737
738     //\8e©\93®\92u\8a·\83v\83\8a\83Z\83b\83g
739     if FileExists(ReplacePresetFileName) then
740     begin
741       try
742         Strs := TStringList.Create;
743         try
744           Strs.LoadFromFile(ReplacePresetFileName);
745           FReplacePresets := StringToComponent(Strs.Text) as TReplacePresets;
746         finally
747           Strs.Free;
748         end;
749       except
750         ShowMessage('Replace.txt\93Ç\82Ý\8d\9e\82Ý\92\86\82Ì\83G\83\89\81[\81B'#13#10+
751           '\83t\83@\83C\83\8b\82ª\94j\91¹\82µ\82Ä\82¢\82é\8fê\8d\87\82Í\81A\82±\82Ì\83t\83@\83C\83\8b\82ð\8dí\8f\9c\82µ\82Ä\8dÄ\8bN\93®\82µ\82Ä\82­\82¾\82³\82¢');
752         raise;
753       end;
754     end else
755       FReplacePresets := TReplacePresets.Create(nil);
756     //\82â\82³\82®\82ê\95ª
757     SendAction := FIni2.ReadBool('System', 'SendAction', false);
758     NotSSTP := FIni2.ReadBool('System', 'NotSSTP', false);
759     ScriptBackup := FIni2.ReadBool('System', 'ScriptBackup', false);
760     ScriptBackupTime := FIni2.ReadInteger('System', 'ScriptBackupTime', 3);
761     ErrScript := FIni2.ReadBool('System', 'ErrScript', false);
762     GhostCh := FIni2.ReadBool('System', 'GhostCh', false);
763     GhostChList.CommaText := FIni2.ReadString('System', 'GhostChList', '');
764     NotShowLog := FIni2.ReadBool('System', 'NotShowLog', false);
765     NotCheckClear := FIni2.ReadBool('System', 'NotCheckClear', false);
766     NotYenETrans := FIni2.ReadBool('System', 'NotYenETrans', false);
767     NotScriptTime := FIni2.ReadBool('System', 'NotScriptTime', true);
768     ScriptBackupMode := FIni2.ReadBool('System', 'ScriptBackupMode', false);
769     LogDir := FIni2.ReadString('System', 'LogDir', '');
770     TextDir := FIni2.ReadString('System', 'TextDir', '');
771     NoDeleteBackupFile := FIni2.ReadBool('System', 'NoDeleteBackupFile', false);
772
773   except
774     on E: Exception do
775     begin
776       ShowMessage('\90Ý\92è\93Ç\82Ý\8d\9e\82Ý\83G\83\89\81['#13#10 + E.Message);
777       Application.Terminate;
778     end;
779   end;
780 end;
781
782 destructor TBottlePrefs.Destroy;
783 begin
784   inherited;
785   SaveSettings;
786   if FReplacePresets <> nil then
787     FReplacePresets.Free;
788   if FIni <> nil then
789     FIni.Free;
790   if FIni2 <> nil then
791     FIni2.Free;
792   if FAutoJoinChannels <> nil then
793     FAutoJoinChannels.Free;
794   if FDefaultScript <> nil then
795     FDefaultScript.Free;
796   if FFMOName <> nil then
797     FFMOName.Free;
798   if FVisibleGhostsList <> nil then
799     FVisibleGhostsList.Free;
800   if FGhostChList <> nil then
801     FGhostChList.Free;
802   if FPlayTimeParams <> nil then
803     FPlayTimeParams.Free;
804 end;
805
806 procedure TBottlePrefs.SetAutoStart(const Value: boolean);
807 begin
808   FAutoStart := Value;
809 end;
810
811 procedure TBottlePrefs.SetBgColor(const Value: TColor);
812 begin
813   FBgColor := Value;
814 end;
815
816 procedure TBottlePrefs.SetConfirmOnExit(const Value: boolean);
817 begin
818   FConfirmOnExit := Value;
819 end;
820
821 procedure TBottlePrefs.SetDblClkInsert(const Value: boolean);
822 begin
823   FDblClkInsert := Value;
824 end;
825
826 procedure TBottlePrefs.SetDefaultScript(const Value: String);
827 begin
828   FDefaultScript.Text := Value;
829 end;
830
831 procedure TBottlePrefs.SetFixMessySurface(const Value: boolean);
832 begin
833   FFixMessySurface := Value;
834 end;
835
836 procedure TBottlePrefs.SetGhostDropDownCount(const Value: integer);
837 begin
838   FGhostDropDownCount := Value;
839 end;
840
841 procedure TBottlePrefs.SetIgnoreFrequentYenS(const Value: boolean);
842 begin
843   FIgnoreFrequentYenS := Value;
844 end;
845
846 procedure TBottlePrefs.SetIgnoreTimeCritical(const Value: boolean);
847 begin
848   FIgnoreTimeCritical := Value;
849 end;
850
851 procedure TBottlePrefs.SetLogWindowDividerPos(const Value: integer);
852 begin
853   FLogWindowDividerPos := Value;
854 end;
855
856 procedure TBottlePrefs.SetLogWindowPosition(const Value: TRect);
857 begin
858   FLogWindowPosition := Value;
859 end;
860
861 procedure TBottlePrefs.SetLUID(const Value: String);
862 begin
863   FLUID := Value;
864 end;
865
866 procedure TBottlePrefs.SetMarkErrorColor(const Value: TColor);
867 begin
868   FMarkErrorColor := Value;
869 end;
870
871 procedure TBottlePrefs.SetTextColor(const Value: TColor);
872 begin
873   FTextColor := Value;
874 end;
875
876 procedure TBottlePrefs.SetMarkUpColor(const Value: TColor);
877 begin
878   FMarkUpColor := Value;
879 end;
880
881 procedure TBottlePrefs.SetMetaWordColor(const Value: TColor);
882 begin
883   FMetaWordColor := Value;
884 end;
885
886 procedure TBottlePrefs.SetNoConfirm(const Value: boolean);
887 begin
888   FNoConfirm := Value;
889 end;
890
891 procedure TBottlePrefs.SetNoDescript(const Value: boolean);
892 begin
893   FNoDescript := Value;
894 end;
895
896 procedure TBottlePrefs.SetNoTranslate(const Value: boolean);
897 begin
898   FNoTranslate := Value;
899 end;
900
901 procedure TBottlePrefs.SetNoTransUrl(const Value: boolean);
902 begin
903   FNoTransUrl := Value;
904 end;
905
906 procedure TBottlePrefs.SetLogWindowPreviewStyle(
907   const Value: TLogWindowPreviewStyle);
908 begin
909   FLogWindowPreviewStyle := Value;
910 end;
911
912 procedure TBottlePrefs.SetProxyAddress(const Value: String);
913 begin
914   FProxyAddress := Value;
915 end;
916
917 procedure TBottlePrefs.SetProxyPort(const Value: integer);
918 begin
919   FProxyPort := Value;
920 end;
921
922 procedure TBottlePrefs.SetResetIfGhostAfterSend(const Value: boolean);
923 begin
924   FResetIfGhostAfterSend := Value;
925 end;
926
927 procedure TBottlePrefs.SetSenderWindowPosition(const Value: TRect);
928 begin
929   FSenderWindowPosition := Value;
930 end;
931
932 procedure TBottlePrefs.SetServerPort(const Value: integer);
933 begin
934   if Value > 0 then FServerPort := Value;
935 end;
936
937 procedure TBottlePrefs.SetShowConstBar(const Value: boolean);
938 begin
939   FShowConstBar := Value;
940 end;
941
942 procedure TBottlePrefs.SetShowToolBar(const Value: boolean);
943 begin
944   FShowToolBar := Value;
945 end;
946
947 procedure TBottlePrefs.SetSilentWhenHidden(const Value: boolean);
948 begin
949   FSilentWhenHidden := Value;
950 end;
951
952 procedure TBottlePrefs.SetStayOnTop(const Value: boolean);
953 begin
954   FStayOnTop := Value;
955 end;
956
957 procedure TBottlePrefs.SetTabPosition(const Value: TTabPosition);
958 begin
959   FTabPosition := Value;
960 end;
961
962 procedure TBottlePrefs.SetTalkColorH(const Value: TColor);
963 begin
964   FTalkColorH := Value;
965 end;
966
967 procedure TBottlePrefs.SetTalkColorU(const Value: TColor);
968 begin
969   FTalkColorU := Value;
970 end;
971
972 procedure TBottlePrefs.SetUseHttpProxy(const Value: boolean);
973 begin
974   FUseHttpProxy := Value;
975 end;
976
977 procedure TBottlePrefs.SetAskUseHttpProxy(const Value: boolean);
978 begin
979   FAskUseHttpProxy := Value;
980 end;
981
982 procedure TBottlePrefs.SetWaitScriptEnd(const Value: integer);
983 begin
984   if Value > 0 then FWaitScriptEnd := Value;
985 end;
986
987 procedure TBottlePrefs.SetWhenCtrlReturn(const Value: TReturnKeyFunction);
988 begin
989   FWhenCtrlReturn := Value;
990 end;
991
992 procedure TBottlePrefs.SetWhenReturn(const Value: TReturnKeyFunction);
993 begin
994   FWhenReturn := Value;
995 end;
996
997 procedure TBottlePrefs.SetWhenShiftReturn(const Value: TReturnKeyFunction);
998 begin
999   FWhenShiftReturn := Value;
1000 end;
1001
1002 procedure TBottlePrefs.SetTalkColorS(const Value: TColor);
1003 begin
1004   FTalkColorS := Value;
1005 end;
1006
1007 procedure TBottlePrefs.SetLogWindowColumnWidth(const Value: String);
1008 begin
1009   FLogWindowColumnWidth := Value;
1010 end;
1011
1012 procedure TBottlePrefs.SetClearAfterSend(const Value: boolean);
1013 begin
1014   FClearAfterSend := Value;
1015 end;
1016
1017 procedure TBottlePrefs.SetAutoJoinChannels(const Value: TStrings);
1018 begin
1019   FAutoJoinChannels.Assign(Value);
1020 end;
1021
1022 procedure TBottlePrefs.SetFMOName(const Value: TStrings);
1023 begin
1024   FFMOName.Assign(Value);
1025 end;
1026
1027 procedure TBottlePrefs.SaveSettings;
1028 var
1029   Strs: TStringList;
1030 begin
1031   FIni.WriteString('System', 'PartialConfirmFormat', PartialConfirmFormat);
1032   FIni.WriteBool('System', 'AutoPartialConfirm', AutoPartialConfirm);
1033   FIni.WriteBool('System', 'ConfirmOnExit', ConfirmOnExit);
1034   FIni.WriteBool('System', 'ConfirmOnTabClose', ConfirmOnTabClose);
1035   FIni.WriteBool('System', 'AutoClip', AutoClip);
1036   FIni.WriteBool('System', 'AutoStart', AutoStart);
1037   FIni.WriteInteger('System', 'TabPosition', Ord(TabPosition));
1038   FIni.WriteInteger('System', 'TabWidth', TabWidth);
1039   FIni.WriteInteger('System', 'GhostDropDownCount', GhostDropDownCount);
1040
1041   FIni.WriteBool('System', 'NoTranslate', NoTranslate);
1042   FIni.WriteBool('System', 'NoDescript', NoDescript);
1043   FIni.WriteBool('System', 'NoTransUrl', NoTransUrl);
1044   FIni.WriteBool('System', 'SilentWhenHidden', SilentWhenHidden);
1045   FIni.WriteBool('System', 'FixMessySurface', FixMessySurface);
1046   FIni.WriteBool('System', 'HUTagTo01Tag', HUTagTo01Tag);
1047   FIni.WriteBool('System', 'ResetIfGhostAfterSend', ResetIfGhostAfterSend);
1048   FIni.WriteBool('System', 'ClearAfterSend', ClearAfterSend);
1049   FIni.WriteBool('System', 'NeedConfirmBeforeSend', NeedConfirmBeforeSend);
1050   FIni.WriteBool('System', 'WarnYenTNotExist', WarnYenTNotExist);
1051   FIni.WriteBool('System', 'WarnScopeChangeInSynchronize', WarnScopeChangeInSynchronize);
1052
1053   FIni.WriteBool('System', 'IgnoreFrequentYenS', IgnoreFrequentYenS);
1054   FIni.WriteInteger('System', 'WaitScriptEnd', WaitScriptEnd);
1055   FIni.WriteBool('System', 'StayOnTop', StayOnTop);
1056   FIni.WriteBool('System', 'NoConfirm', NoConfirm);
1057   FIni.WriteBool('System', 'IgnoreTimeCritical', IgnoreTimeCritical);
1058   FIni.WriteString('System', 'TalkColorH',     ColorToString(TalkColorH));
1059   FIni.WriteString('System', 'TalkColorU',     ColorToString(TalkColorU));
1060   FIni.WriteString('System', 'TalkColorS',     ColorToString(TalkColorS));
1061   FIni.WriteString('System', 'MarkUpColor',    ColorToString(MarkUpColor));
1062   FIni.WriteString('System', 'MetaWordColor',  ColorToString(MetaWordColor));
1063   FIni.WriteString('System', 'MarkErrorColor', ColorToString(MarkErrorColor));
1064   FIni.WriteString('System', 'TextColor', ColorToString(TextColor));
1065
1066   Strs := TStringList.Create;
1067   try
1068     Strs.Text := ComponentToString(FPlayTimeParams);
1069     FIni.WriteString('System', 'PlayTimeParams', Strs.CommaText);
1070   finally
1071     Strs.Free;
1072   end;
1073
1074   FIni.WriteString('System', 'BgColor', ColorToString(BgColor));
1075   FIni.WriteBool('System', 'ShowToolBar', ShowToolBar);
1076   FIni.WriteBool('System', 'ShowConstBar', ShowConstBar);
1077   FIni.WriteString('System', 'DefaultScript', FDefaultScript.CommaText);
1078   FIni.WriteBool('System', 'ShowRuler', ShowRuler);
1079   FIni.WriteInteger('System', 'WhenReturn', Ord(WhenReturn));
1080   FIni.WriteInteger('System', 'WhenShiftReturn', Ord(WhenShiftReturn));
1081   FIni.WriteInteger('System', 'WhenCtrlReturn', Ord(WhenCtrlReturn));
1082   FIni.WriteInteger('System', 'ServerPort', ServerPort);
1083   FIni.WriteString('System', 'LUID', LUID);
1084   FIni.WriteString('System', 'AutoJoinChannels', FAutoJoinChannels.CommaText);
1085   //
1086   FIni.WriteInteger('System', 'SenderWindowPositionLeft', SenderWindowPosition.Left);
1087   FIni.WriteInteger('System', 'SenderWindowPositionTop', SenderWindowPosition.Top);
1088   FIni.WriteInteger('System', 'SenderWindowPositionRight', SenderWindowPosition.Right);
1089   FIni.WriteInteger('System', 'SenderWindowPositionBottom', SenderWindowPosition.Bottom);
1090   FIni.WriteInteger('System', 'LogWindowPositionLeft', LogWindowPosition.Left);
1091   FIni.WriteInteger('System', 'LogWindowPositionTop', LogWindowPosition.Top);
1092   FIni.WriteInteger('System', 'LogWindowPositionRight', LogWindowPosition.Right);
1093   FIni.WriteInteger('System', 'LogWindowPositionBottom', LogWindowPosition.Bottom);
1094   FIni.WriteInteger('System', 'LogWindowDividerPos', LogWindowDividerPos);
1095   FIni.WriteString('System', 'LogWindowColumnWidth', LogWindowColumnWidth);
1096   with EditorPreviewWindowPosition do
1097     FIni.WriteString('System', 'EditorPreviewWindowPosition',
1098       Format('%d,%d,%d,%d', [Left, Top, Right, Bottom]));
1099   //
1100   FIni.WriteBool('System', 'UseHttpProxy', UseHttpProxy);
1101   FIni.WriteBool('System', 'AskUseHttpProxy', AskUseHttpProxy);
1102   FIni.WriteString('System', 'ProxyAddress', ProxyAddress);
1103   FIni.WriteInteger('System', 'ProxyPort', ProxyPort);
1104   //
1105   FIni.WriteInteger('System', 'ReconnectWait', ReconnectWait);
1106   //
1107   FIni.WriteInteger('System', 'LogWindowPreviewStyle', Ord(LogWindowPreviewStyle));
1108   FIni.WriteInteger('System', 'LogListPreviewStyle', Ord(LogListPreviewStyle));
1109   FIni.WriteString('System', 'FMOName', FFMOName.CommaText);
1110   FIni.WriteBool('System', 'HideGhosts', HideGhosts);
1111   FIni.WriteString('System', 'VisibleGhostsList', VisibleGhostsList.CommaText);
1112   FIni.WriteBool('System', 'NoExtraSSTPHeaders', NoExtraSSTPHeaders);
1113   //
1114   FIni.WriteBool('System', 'SurfacePreviewOnHint', SurfacePreviewOnHint);
1115   FIni.WriteBool('System', 'SurfacePreviewOnScriptPoint', SurfacePreviewOnScriptPoint);
1116   FIni.WriteInteger('System', 'SurfacePreviewOnScriptPointPosition', Ord(SurfacePreviewOnScriptPointPosition));
1117
1118   FIni.WriteString('System', 'BrowserExeName', BrowserExeName);
1119   FIni.WriteBool('System', 'NotWarnGhostIsntExists', NotWarnGhostIsntExists);
1120
1121   Strs := TStringList.Create;
1122   try
1123     Strs.Text := ComponentToString(FReplacePresets);
1124     Strs.SaveToFile(ReplacePresetFileName);
1125   finally
1126     Strs.Free;
1127   end;
1128
1129   //\82â\82³\82®\82ê\95ª
1130   FIni2.WriteBool('System', 'SendAction', SendAction);
1131   FIni2.WriteBool('System', 'NotSSTP', NotSSTP);
1132   FIni2.WriteBool('System', 'ScriptBackup', ScriptBackup);
1133   FIni2.WriteInteger('System', 'ScriptBackupTime', ScriptBackupTime);
1134   FIni2.WriteBool('System', 'ErrScript', ErrScript);
1135   FIni2.WriteBool('System', 'GhostCh', GhostCh);
1136   FIni2.WriteString('System', 'GhostChList', GhostChList.CommaText);
1137   FIni2.WriteBool('System', 'NotShowLog', NotShowLog);
1138   FIni2.WriteBool('System', 'NotCheckClear', NotCheckClear);
1139   FIni2.WriteBool('System', 'NotYenETrans', NotYenETrans);
1140   FIni2.WriteBool('System', 'NotScriptTime', NotScriptTime);
1141   FIni2.WriteBool('System', 'ScriptBackupMode', ScriptBackupMode);
1142   FIni2.WriteString('System', 'LogDir', LogDir);
1143   FIni2.WriteString('System', 'TextDir', TextDir);
1144   FIni2.WriteBool('System', 'NoDeleteBackupFile', NoDeleteBackupFile);
1145 end;
1146
1147 function TBottlePrefs.GetDefaultScript: String;
1148 begin
1149   Result := FDefaultScript.Text;
1150 end;
1151
1152 procedure TBottlePrefs.SetHUTagTo01Tag(const Value: boolean);
1153 begin
1154   FHUTagTo01Tag := Value;
1155 end;
1156
1157 procedure TBottlePrefs.SetWarnScopeChangeInSynchronize(
1158   const Value: boolean);
1159 begin
1160   FWarnScopeChangeInSynchronize := Value;
1161 end;
1162
1163 procedure TBottlePrefs.SetWarnYenTNotExist(const Value: boolean);
1164 begin
1165   FWarnYenTNotExist := Value;
1166 end;
1167
1168 procedure TBottlePrefs.SetNeedConfirmBeforeSend(const Value: boolean);
1169 begin
1170   FNeedConfirmBeforeSend := Value;
1171 end;
1172
1173 procedure TBottlePrefs.SetShowRuler(const Value: boolean);
1174 begin
1175   FShowRuler := Value;
1176 end;
1177
1178 procedure TBottlePrefs.SetHideGhosts(const Value: boolean);
1179 begin
1180   FHideGhosts := Value;
1181 end;
1182
1183 procedure TBottlePrefs.SetVisibleGhostsList(const Value: TStringList);
1184 begin
1185   FVisibleGhostsList.Assign(Value);
1186 end;
1187
1188 procedure TBottlePrefs.SetSurfacePreviewOnHint(const Value: boolean);
1189 begin
1190   FSurfacePreviewOnHint := Value;
1191 end;
1192
1193 procedure TBottlePrefs.SetSurfacePreviewOnScriptPoint(
1194   const Value: boolean);
1195 begin
1196   FSurfacePreviewOnScriptPoint := Value;
1197 end;
1198
1199 procedure TBottlePrefs.SetSurfacePreviewOnScriptPointPosition(
1200   const Value: TSurfacePreviewOnScriptPointPosition);
1201 begin
1202   FSurfacePreviewOnScriptPointPosition := Value;
1203 end;
1204
1205 procedure TBottlePrefs.SetNoExtraSSTPHeaders(const Value: boolean);
1206 begin
1207   FNoExtraSSTPHeaders := Value;
1208 end;
1209
1210 procedure TBottlePrefs.SetLogListPreviewStyle(
1211   const Value: TLogListPreviewStyle);
1212 begin
1213   FLogListPreviewStyle := Value;
1214 end;
1215
1216 procedure TBottlePrefs.SetEditorPreviewWindowPosition(const Value: TRect);
1217 begin
1218   FEditorPreviewWindowPosition := Value;
1219 end;
1220
1221 function TBottlePrefs.InScreen(ARect: TRect): boolean;
1222 var i: integer;
1223     dum: TRect;
1224 begin
1225   Result := false;
1226   for i := 0 to Screen.MonitorCount-1 do
1227   begin
1228     if IntersectRect(dum, ARect, Screen.Monitors[i].WorkareaRect) then
1229     begin
1230       Result := true;
1231       Exit;
1232     end;
1233   end;
1234 end;
1235
1236 procedure TBottlePrefs.SetAutoClip(const Value: boolean);
1237 begin
1238   FAutoClip := Value;
1239 end;
1240
1241 procedure TBottlePrefs.SetConfirmOnTabClose(const Value: boolean);
1242 begin
1243   FConfirmOnTabClose := Value;
1244 end;
1245
1246 procedure TBottlePrefs.SetReconnectWait(const Value: integer);
1247 begin
1248   FReconnectWait := Value;
1249   if Value < 6 then
1250     raise Exception.Create('Reconnect wait must be >=6');
1251 end;
1252
1253 procedure TBottlePrefs.SetPartialConfirmFormat(const Value: String);
1254 begin
1255   FPartialConfirmFormat := Value;
1256 end;
1257
1258 procedure TBottlePrefs.SetAutoPartialConfirm(const Value: boolean);
1259 begin
1260   FAutoPartialConfirm := Value;
1261 end;
1262
1263 procedure TBottlePrefs.SetPlayTimeParams(const Value: TSsPlayTimeParams);
1264 begin
1265   FPlayTimeParams.Assign(Value);
1266 end;
1267
1268 procedure TBottlePrefs.SetTabWidth(const Value: integer);
1269 begin
1270   FTabWidth := Value;
1271 end;
1272
1273 procedure TBottlePrefs.SetBrowserExeName(const Value: string);
1274 begin
1275   FBrowserExeName := Value;
1276 end;
1277
1278 procedure TBottlePrefs.SetNotWarnGhostIsntExists(const Value: boolean);
1279 begin
1280   FNotWarnGhostIsntExists := Value;
1281 end;
1282
1283 { TChannelListItem }
1284
1285 procedure TChannelListItem.SetGhost(const Value: String);
1286 begin
1287   FGhost := Value;
1288 end;
1289
1290 procedure TChannelListItem.SetInfo(const Value: String);
1291 begin
1292   FInfo := Value;
1293 end;
1294
1295 procedure TChannelListItem.SetMembers(const Value: integer);
1296 begin
1297   FMembers := Value;
1298 end;
1299
1300 procedure TChannelListItem.SetName(const Value: String);
1301 begin
1302   FName := Value;
1303 end;
1304
1305 procedure TChannelListItem.SetNoPost(const Value: boolean);
1306 begin
1307   FNoPost := Value;
1308 end;
1309
1310 procedure TChannelListItem.SetWarnPost(const Value: boolean);
1311 begin
1312   FWarnPost := Value;
1313 end;
1314
1315 { TChannelList }
1316
1317 procedure TChannelList.Clear;
1318 var i: integer;
1319 begin
1320   for i := Self.Count-1 downto 0 do begin
1321     TChannelListItem(Self[i]).Free;
1322   end;
1323   inherited;
1324 end;
1325
1326 function TChannelList.GetChannel(Name: String): TChannelListItem;
1327 var i: integer;
1328 begin
1329   Result := nil;
1330   for i := 0 to Count-1 do
1331     if TChannelListItem(Self[i]).Name = Name then begin
1332       Result := TChannelListItem(Self[i]);
1333       Exit;
1334     end;
1335 end;
1336
1337 function TChannelList.GetChannelItem(Index: integer): TChannelListItem;
1338 begin
1339   Result := TChannelListItem(Self[Index]);
1340 end;
1341
1342 //\82â\82³\82®\82ê\95ª
1343 procedure TBottlePrefs.SetSendAction(const Value: boolean);
1344 begin
1345   FSendAction := Value;
1346 end;
1347
1348 procedure TBottlePrefs.SetNotSSTP(const Value: boolean);
1349 begin
1350   FNotSSTP := Value;
1351 end;
1352
1353 procedure TBottlePrefs.SetScriptBackup(const Value: boolean);
1354 begin
1355   FScriptBackup := Value;
1356 end;
1357
1358 procedure TBottlePrefs.SetScriptBackupTime(const Value: Integer);
1359 begin
1360   FScriptBackupTime := Value;
1361 end;
1362
1363 procedure TBottlePrefs.SetErrScript(const Value: boolean);
1364 begin
1365   FErrScript := Value;
1366 end;
1367
1368 procedure TBottlePrefs.SetGhostCh(const Value: boolean);
1369 begin
1370   FGhostCh := Value;
1371 end;
1372
1373 procedure TBottlePrefs.SetGhostChList(const Value: TStringList);
1374 begin
1375   FGhostChList.Assign(Value);
1376 end;
1377
1378 procedure TBottlePrefs.SetNotShowLog(const Value: boolean);
1379 begin
1380   FNotShowLog := Value;
1381 end;
1382
1383 procedure TBottlePrefs.SetNotCheckClear(const Value: boolean);
1384 begin
1385   FNotCheckClear := Value;
1386 end;
1387
1388 procedure TBottlePrefs.SetNotYenETrans(const Value: boolean);
1389 begin
1390   FNotYenETrans := Value;
1391 end;
1392
1393 procedure TBottlePrefs.SetNotScriptTime(const Value: boolean);
1394 begin
1395   FNotScriptTime := Value;
1396 end;
1397
1398 procedure TBottlePrefs.SetScriptBackupMode(const Value: boolean);
1399 begin
1400   FScriptBackupMode := Value;
1401 end;
1402
1403 procedure TBottlePrefs.SetLogDir(const Value: String);
1404 begin
1405   FLogDir := Value;
1406 end;
1407
1408 procedure TBottlePrefs.SetTextDir(const Value: String);
1409 begin
1410   FTextDir := Value;
1411 end;
1412
1413 procedure TBottlePrefs.SetNoDeleteBackupFile(const Value: boolean);
1414 begin
1415   FNoDeleteBackupFile := Value;
1416 end;
1417
1418 initialization
1419
1420 Classes.RegisterClass(TSsPlayTimeParams);
1421
1422 Pref := TBottlePrefs.Create;
1423 ChannelList := TChannelList.Create;
1424 //JoinChannels := TStringList.Create;
1425
1426 finalization
1427
1428 Pref.Free;
1429 ChannelList.Clear;
1430 //JoinChannels.Free;
1431 ChannelList.Free;
1432
1433 end.