OSDN Git Service

[YCへマージ]
[winbottle/winbottle.git] / bottleclient / MainForm.pas
index e98499f..e4ace7d 100755 (executable)
@@ -290,7 +290,7 @@ type
 //    FConnecting: boolean;
 //    FAdded: boolean;
     FBooted: boolean; //\8f\89\89ñ\8bN\93®\92Ê\90M\97p
-    FEndSession: Boolean; // Windows\8fI\97¹\82ð\8c\9f\92m\82µ\82Ätrue\82É\82È\82é
+//    FEndSession: Boolean; // Windows\8fI\97¹\82ð\8c\9f\92m\82µ\82Ätrue\82É\82È\82é
     FOriginalCaption: String;
 //    FAutoAddAfterGetChannel: boolean; //\83`\83\83\83\93\83l\83\8b\8eæ\93¾\8cã\82É\83_\83C\83A\83\8d\83O\82È\82µ\82É
                                       //\83`\83\83\83\93\83l\83\8b\82É\8eQ\89Á\82·\82é\82©\82Ç\82¤\82©
@@ -388,7 +388,7 @@ type
     //\92P\91Ì\83t\83@\83C\83\8b\93ü\8fo\97Í\8aÖ\8cW
     procedure PerformFileOpen(const AFileName: string);
     procedure PerformFileSave(const AFileName: string);
-    procedure SetFileName(const FileName: string; Value: boolean);
+    procedure SetFileName(const FileName: string; Reset, SetNewFile: boolean);
     function CheckFileModified(Sender: TObject): integer;
     function FileSave(Sender: TObject): integer;
     function FileSaveAs(Sender: TObject): integer;
@@ -399,11 +399,8 @@ type
 
   protected
     procedure WndProc(var Message: TMessage); override;
-    procedure WMQueryEndSession(var msg: TWMQueryEndSession);
-      message WM_QUERYENDSESSION;
-{$IFDEF PASS}
-    procedure CopyDataMessage(var WMCopyData: TWMCopyData); message WM_COPYDATA;
-{$ENDIF}
+//    procedure WMQueryEndSession(var msg: TWMQueryEndSession);
+//      message WM_QUERYENDSESSION;
   public
     function DoTrans(var Script: String;
       Options: TScriptTransOptions): String; overload;
@@ -442,9 +439,10 @@ const
   PanelStatus     = 4;  //SSTP Bottle\83T\81[\83o\82É\93o\98^\82³\82ê\82Ä\82¢\82Ü\82·\81c\82È\82Ç
 
   IconConnected    = 17;
-  IconDisconnected = 47;  //\8b\8c18  \8e¸\94s\8fó\91Ô\82ð\8fí\82É\8eg\97p
+  IconDisconnected = 18;
   IconSleep        = 19;
-  IconSleepDisconnected = 47; //\8b\8c20
+  IconSleepDisconnected = 20;
+  IconYC                = 47;
 
   WarningColor = clRed;
 
@@ -1017,11 +1015,8 @@ begin
   ShowHintLabel('SSTP Bottle\83T\81[\83o\82É\82Í\90Ú\91±\82Å\82«\82Ü\82¹\82ñ', WarningColor);
 {
   // \8b­\90§\8dÄ\90Ú\91±\82ð\8ds\82¤
-  IdSlpp20.OnDisconnect := nil;
-  if IdSlpp20.Connected then IdSlpp20.Disconnect;
-  FAutoAddAfterGetChannel := true;
-  BeginConnect;
-  IdSlpp20.OnDisconnect := Slpp20Disconnect;
+  FBeginConnectFailCount := 0; // \8e©\93®\8dÄ\90Ú\91±\83J\83E\83\93\83^\83\8a\83Z\83b\83g
+  RetryBeginConnect;
 }
 end;
 
@@ -1091,16 +1086,13 @@ var
 begin
   // \83X\83e\81[\83^\83X\95Ï\8dX
   // \93à\97e\82ª\83h\83\89\83b\83O\82³\82ê\82½\82Æ\82«\82à\8cÄ\82Ñ\8fo\82³\82ê\82é
-  Script := GetScriptText;
+  Script := StringReplace(GetScriptText, #13#10, '', [rfReplaceAll]);
   if Pref.NotScriptTime then
-    // \91\8d\83o\83C\83g\90\94\82¾\82¯\95\\8e¦
+    // \83o\83C\83g\90\94\82¾\82¯\95\\8e¦
     Text := Format('%d\83o\83C\83g', [Length(Script)])
   else
-  begin
     // \83o\83C\83g\90\94\81{\97\\91ª\8e\9e\8aÔ\95\\8e¦
-    Script := StringReplace(Script, #13#10, '', [rfReplaceAll]);
-    Text := Format('%d\83o\83C\83g/%d\95b', [Length(Script), SsPlayTime.PlayTime(Script) div 1000])
-  end;
+    Text := Format('%d\83o\83C\83g/%d\95b', [Length(Script), SsPlayTime.PlayTime(Script) div 1000]);
   StatusBar.Panels[PanelBytes].Text := Text;
 //  FScriptModified := true;
   EditorPreview;
@@ -1191,7 +1183,7 @@ end;
 
 procedure TfrmSender.ChangeTaskIcon;
 var Ico: TIcon;
-    IcoNum: integer;
+//    IcoNum: integer;
 begin
 {
   if Added then begin
@@ -1201,13 +1193,10 @@ begin
     else IcoNum := IconDisconnected;
   end;
 }
-  //\83^\83X\83N\83A\83C\83R\83\93\82Ì\8fó\91Ô\81i\8e¸\94s\8fó\91Ô\8eg\97p\81j
-  if Sleeping then IcoNum := IconSleepDisconnected
-    else IcoNum := IconDisconnected;
   try
     Ico := TIcon.Create;
     try
-      imgIcon.GetIcon(IcoNum, Ico);
+      imgIcon.GetIcon(IconYC, Ico);  // IconNum
       TaskTray.Icon := Ico;
       TaskTray.Registered := true;
     finally
@@ -1668,7 +1657,7 @@ begin
 
   // \83o\83b\83N\83A\83b\83v\83\82\81[\83h\82ª\95Ï\8dX\82³\82ê\82½\82Æ\82«FScriptBackupFile\82à\95Ï\8dX\82·\82é
   if FTBackupMode <> Pref.ScriptBackupMode then
-    SetFileName(FFileName, false);
+    SetFileName(FFileName, false, false);
 end;
 
 procedure TfrmSender.memScriptKeyPress(Sender: TObject; var Key: Char);
@@ -1914,13 +1903,13 @@ begin
   ReplaceHash := THeadValue.Create;
   ReplaceHash['%channel%'] := SafeFileName(Dat['Channel']);
   ReplaceHash['%ghost%'] := SafeFileName(Dat['IfGhost']);
-  ReplaceHash['%date%'] := FormatDateTime('yy-mm-dd', Now());
-  ReplaceHash['%year%'] := FormatDateTime('yyyy', Now());
-  ReplaceHash['%yy%'] := FormatDateTime('yy', Now());
-  ReplaceHash['%month%'] := FormatDateTime('mm', Now());
-  ReplaceHash['%day%'] := FormatDateTime('dd', Now());
-  ReplaceHash['%hour%'] := FormatDateTime('hh', Now());
-  ReplaceHash['%minute%'] := FormatDateTime('nn', Now());
+  ReplaceHash['%date%'] := FormatDateTime('yy-mm-dd', LogTime);
+  ReplaceHash['%year%'] := FormatDateTime('yyyy', LogTime);
+  ReplaceHash['%yy%'] := FormatDateTime('yy', LogTime);
+  ReplaceHash['%month%'] := FormatDateTime('mm', LogTime);
+  ReplaceHash['%day%'] := FormatDateTime('dd', LogTime);
+  ReplaceHash['%hour%'] := FormatDateTime('hh', LogTime);
+  ReplaceHash['%minute%'] := FormatDateTime('nn', LogTime);
 
   Event := TBottleChainBottleEvent.Create;
   try
@@ -1985,7 +1974,7 @@ begin
           if Action is TBottleChainSaveTextLogAction then
             AppendTextLog(StringReplaceEx((Action as TBottleChainSaveTextLogAction).FileName, ReplaceHash),
               Format('%s,%s,%s,%s', [Dat['Channel'], Dat['IfGhost'],
-                FormatDateTime('yy/mm/dd hh:nn:ss', Now), Dat['Script']]), true);
+                FormatDateTime('yy/mm/dd hh:nn:ss', LogTime), Dat['Script']]), true);
           if Action is TBottleChainSaveXMLLogAction then
             AppendXMLLog(StringReplaceEx((Action as TBottleChainSaveXMLLogAction).FileName, ReplaceHash),
               Dat);
@@ -2004,7 +1993,7 @@ begin
         end else begin
           Ghost := Dat['TargetGhost']; // \83I\81[\83o\81[\83\89\83C\83h\82³\82ê\82Ä\82¢\82é\89Â\94\\90«\82ª\82 \82é
           CueItem := TLogItem.Create(ltBottle, Dat['MID'], Dat['Channel'],
-            Script, Ghost, Now());
+            Script, Ghost, LogTime);
           try
             FBottleSstp.Push(CueItem);
           except
@@ -2013,16 +2002,16 @@ begin
         end;
       end;
 
-{$IFDEF PASS}
+{
       if Dat['DialogMessage'] <> '' then begin
         Beep;
         frmMessageBox.ShowMessage(
-          DateTimeToStr(Now) + #13#10 +
+          DateTimeToStr(LogTime) + #13#10 +
           'SSTP Bottle\83T\81[\83o\82©\82ç\82¨\92m\82ç\82¹'#13#10+Dat['DialogMessage']);
         for i := 0 to LogNameList.Count-1 do
           frmLog.AddCurrentSystemLog(LogNameList[i], Dat['DialogMessage']);
       end;
-{$ENDIF}
+}
 
       //\89¹\82Ì\8dÄ\90
       if (Sound <> '') then PlaySound(Sound);
@@ -2363,6 +2352,20 @@ end;
 procedure TfrmSender.FormCloseQuery(Sender: TObject;
   var CanClose: Boolean);
 begin
+{
+  if (not Pref.ConfirmOnExit) or FEndSession then
+  begin
+    Exit;
+  end;
+}
+  if Pref.ConfirmOnExit then
+    if MessageDlg('Yasagure Client\82ð\8fI\97¹\82µ\82Ü\82·', mtConfirmation,
+                mbOkCancel, 0) = mrCancel then
+    begin
+      CanClose := false;
+      exit;
+    end;
+
   //\83t\83@\83C\83\8b\82Ì\8dX\90V\83`\83F\83b\83N\81i\83G\83f\83B\83^\95\94\81j
   if CheckFileModified(Self) = idCancel then
   begin
@@ -2375,17 +2378,6 @@ begin
     CanClose := false;
     exit;
   end;
-  if (not Pref.ConfirmOnExit) or FEndSession then
-  begin
-    DeleteBackupFile(FScriptBackupFile); // \88ê\8e\9e\83t\83@\83C\83\8b\8dí\8f\9c\82Ö
-    Exit;
-  end;
-  if MessageDlg('Yasagure Client\82ð\8fI\97¹\82µ\82Ü\82·', mtConfirmation,
-                mbOkCancel, 0) = mrCancel then
-    begin
-      CanClose := false;
-      exit;
-    end;
   DeleteBackupFile(FScriptBackupFile);   // \88ê\8e\9e\83t\83@\83C\83\8b\8dí\8f\9c\82Ö
 end;
 
@@ -2514,8 +2506,11 @@ procedure TfrmSender.RetryBeginConnect;
 begin
   if FBeginConnectFailCount < 3 then begin
     // \90Ø\92f\82³\82ê\82Ä\82¢\82ê\82Î\8dÄ\90Ú\91±
+    IdSlpp20.OnDisconnect := nil;
+    if IdSlpp20.Connected then IdSlpp20.Disconnect;
     FAutoAddAfterGetChannel := true;
     BeginConnect;
+    IdSlpp20.OnDisconnect := Slpp20Disconnect;
   end else if FBeginConnectFailCount = 3 then begin
     frmLog.AddCurrentSystemLog('SYSTEM', '\8dÄ\90Ú\91±\8e©\93®\83\8a\83g\83\89\83C\82ð\92\86\8e~\82µ\82Ü\82·');
     frmMessageBox.ShowMessage(
@@ -2790,8 +2785,11 @@ begin
     try
       //\83A\83N\83V\83\87\83\93\82ª\97L\8cø\82Å\82 \82ê\82Î\83X\83N\83\8a\83v\83g\82Ì\95Ï\8a·\82µ\82È\82¢
       if TestAction then
-        BottleCnv(InsertItem) // \8c^\95Ï\8a·\82Æ\8eó\90M
-      else
+      begin
+        BottleCnv(InsertItem); // \8c^\95Ï\8a·\82Æ\8eó\90M
+        frmLog.StatusBar.Panels[1].Text := Format('\8ec\82è%d\8c\8f', [i]);
+        frmLog.StatusBar.Update;
+      end else
       begin
         InsertItem.Script := ScriptTransForSSTP(InsertItem.Script, ErrorMes);
         if ErrorMes <> '' then
@@ -2821,6 +2819,8 @@ begin
       Inc(errCount);
     end;
   end;
+  if TestAction then
+    frmLog.StatusBar.Panels[1].Text := '\8a®\97¹';
   if errCount > 0 then
     ShowMessage(Format('%d\8c\8f\82Ì\83{\83g\83\8b\82É\96â\91è\82ª\82 \82Á\82½\82½\82ß\8dÄ\90\82Å\82«\82Ü\82¹\82ñ\81B', [errCount]));
   FBottleSSTP.OnResendCountChange := BottleSstpResendCountChange;
@@ -3223,9 +3223,7 @@ begin
   frmSender.actClear.Execute; // \8c»\8dÝ\82Ì\83X\83N\83\8a\83v\83g\82ð\83N\83\8a\83b\83v\82·\82é(\90Ý\92è\82É\82æ\82Á\82Ä)
   memScript.Lines.Clear;
   memScript.Lines.Add(Log.Script);
-  SetFileName(Log.MID, false);    //\83^\83C\83g\83\8b\82¾\82¯\95Ï\8dX
-  SetFileModified(false);         //\95Ï\8dX\96³\82µ\82É
-  FScriptBackupModified := false; //\8e©\93®\95Û\91\88ê\8e\9e\92â\8e~
+  SetFileName(Log.MID, true, false);  // \81ª\82Å\93à\97e\82ª\8dX\90V\82³\82ê\82é\82Ì\82Å\8dÄ\93x\90V\8bK\82É
   Ghost := Log.Ghost;
   //\83`\83\83\83\93\83l\83\8b\83S\81[\83X\83g\91Î\8dô
   if Ghost = '' then
@@ -3298,11 +3296,8 @@ begin
   if Visible then memScript.SetFocus;
 //  FScriptModified := false;
 
-  DeleteBackupFile(FScriptBackupFile);  // \88ê\8e\9e\83t\83@\83C\83\8b\8dí\8f\9c\82Ö
-  FScriptBackupModified := false;     // \8e©\93®\95Û\91\88ê\8e\9e\92â\8e~
-  SetFileName(NewFileTitle, true);    // \83t\83@\83C\83\8b\82ð\90V\8bK\88µ\82¢\82É\82·\82é
-  SetFileModified(false);             // \95Ï\8dX\96³\82µ
-  EditerStatusChange;                 // \83X\83e\81[\83^\83X\8dX\90V
+  SetFileName(NewFileTitle, true, true);    // \83t\83@\83C\83\8b\82ð\90V\8bK\88µ\82¢\82É\82·\82é
+  EditerStatusChange;                       // \83X\83e\81[\83^\83X\8dX\90V
 end;
 
 procedure TfrmSender.AppendTextLog(const FileName, Line: String; FAppend: boolean);
@@ -3488,12 +3483,14 @@ begin
   end;
 end;
 
+{
 procedure TfrmSender.WMQueryEndSession(var msg: TWMQueryEndSession);
 begin
   // Windows\82ª\8fI\97¹\82µ\82æ\82¤\82Æ\82µ\82Ä\82¢\82é\82Ì\82ð\8a´\92m\82·\82é
   FEndSession := true;
   inherited;
 end;
+}
 
 {
 procedure TfrmSender.IdSLPP20ConnectFailed(Sender: TObject);
@@ -3659,14 +3656,13 @@ begin
   Screen.Cursor := crHourGlass;
   try
     memScript.Lines.LoadFromFile(AFileName);
-    SetFileModified(false);
-    SetFileName(AFileName, true);
+    SetFileName(AFileName, true, true);
     Pref.TextDir := ExtractFileDir(AFileName);
   except
     on E: Exception do
     begin
       ShowMessage('\83G\83\89\81[:'#13#10#13#10 + E.Message);
-      SetFileName(NewFileTitle, true);  // \8e¸\94s\82µ\82½\8e\9e\82Í\83^\83C\83g\83\8b\8f\89\8aú\89»\81B
+      SetFileName(NewFileTitle, true, true);  // \8e¸\94s\82µ\82½\8e\9e\82Í\83^\83C\83g\83\8b\8f\89\8aú\89»\81B
     end;
   end;
   Screen.Cursor := crDefault;
@@ -3699,14 +3695,21 @@ begin
       PerformFileOpen(OpenDialog.FileName);
 end;
 
-procedure TfrmSender.SetFileName(const FileName: string; Value: boolean);
+procedure TfrmSender.SetFileName(const FileName: string; Reset, SetNewFile: boolean);
 var
   FPath: string;
 begin
   // \83^\83C\83g\83\8b\95Ï\8dX\82Æ\83t\83@\83C\83\8b\83p\83X\83Z\83b\83g
   // \82à\82µ\81A\91æ\93ñ\88ø\90\94\82ªfalse\82È\82ç\83^\83C\83g\83\8b\82¾\82¯\95Ï\8dX
-  if Value then
-    FFileName := FileName;
+  if Reset then
+  begin
+    SetFileModified(false);               // \95Ï\8dX\96³\82µ\82É
+    FScriptBackupModified := false;       // \8e©\93®\95Û\91\88ê\8e\9e\92â\8e~
+    DeleteBackupFile(FScriptBackupFile);  // \88ê\8e\9e\83t\83@\83C\83\8b\8dí\8f\9c\82Ö
+  end;
+
+  if SetNewFile then
+    FFileName := FileName;                // \8d¡\8c»\8dÝ\82Ì\95Ò\8fW\83t\83@\83C\83\8b\96¼
 
   FPath := ExtractFileName(FileName);
 
@@ -3769,7 +3772,7 @@ begin
     if Res = idYes then
     begin
       PerformFileSave(SaveDialog.FileName);
-      SetFileName(SaveDialog.FileName, true);
+      SetFileName(SaveDialog.FileName, true, true);
     end;
   end else
     Res := idCancel;
@@ -3832,7 +3835,7 @@ var
   FPath: string;
 begin
   // \8fã\8f\91\95Û\91\82Ì\88ê\8e\9e\83t\83@\83C\83\8b\82ð\8dí\8f\9c
-  if not Pref.ScriptBackupMode or (FileName = '') or
+  if Pref.NoDeleteBackupFile or (FileName = '') or
     (StdBackupFile = FileName) then exit;
 
   FPath := FScriptBackupDir + FileName;
@@ -3845,32 +3848,4 @@ begin
   end;
 end;
 
-{$IFDEF PASS}
-procedure TfrmSender.CopyDataMessage(var WMCopyData: TWMCopyData);
-var
-  Param: string;
-  HeadValue: THeadValue;
-begin
-  // \83e\83X\83g\97p
-  if WMCopyData.CopyDataStruct.dwData = 1 then
-  begin
-    Param := PChar(WMCopyData.CopyDataStruct.lpData);
-    HeadValue := THeadValue.Create(Param);
-    try
-      if HeadValue['Script'] <> '' then
-        DispatchBottle(HeadValue, Now(), 0, 0)
-      else if HeadValue['Type'] = 'Vote' then
-        frmLog.VoteLog(HeadValue['MID'], StrToIntDef(HeadValue['Num'], 0))
-      else if HeadValue['Type'] = 'Agree' then
-        frmLog.AgreeLog(HeadValue['MID'], StrToIntDef(HeadValue['Num'], 0))
-      else if (HeadValue['Num'] <> '') AND (HeadValue['Channel'] = '') AND
-        (HeadValue['Entry'] = '') then
-          StatusBar.Panels[PanelMembers].Text := HeadValue['Num'] + '\90l';
-    finally
-      HeadValue.Free;
-    end;
-  end;
-end;
-{$ENDIF}
-
 end.