Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/teraterm/teraterm/filesys_log.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8896 by zmatsuo, Tue Aug 18 15:27:45 2020 UTC revision 8897 by zmatsuo, Tue Aug 18 15:27:54 2020 UTC
# Line 26  Line 26 
26   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27   */   */
28    
29  /* TERATERM.EXE, file transfer routines */  /* TERATERM.EXE, log routines */
30  #include <stdio.h>  #include <stdio.h>
31  #include <io.h>  #include <io.h>
32  #include <process.h>  #include <process.h>
# Line 55  Line 55 
55  #include "filesys.h"  #include "filesys.h"
56    
57  typedef struct {  typedef struct {
   HWND HMainWin;  
   HWND HWin;  
   WORD OpId;  
   char DlgCaption[40];  
   
58    char FullName[MAX_PATH];    char FullName[MAX_PATH];
59    int DirLen;    int DirLen;
60    
   int NumFname, FNCount;  
   HANDLE FnStrMemHandle;  
   PCHAR FnStrMem;  
   int FnPtr;  
   
61    BOOL FileOpen;    BOOL FileOpen;
62    HANDLE FileHandle;    HANDLE FileHandle;
63    LONG FileSize, ByteCount;    LONG FileSize, ByteCount;
64    BOOL OverWrite;    BOOL OverWrite;
65    
   BOOL LogFlag;  
   HANDLE LogFile;  
   WORD LogState;  
   WORD LogCount;  
   
66    BOOL Success;    BOOL Success;
67    BOOL NoMsg;    BOOL NoMsg;
68    
69    char LogDefaultPath[MAX_PATH];    char LogDefaultPath[MAX_PATH];
70    BOOL HideDialog;    BOOL HideDialog;
71    
   BYTE LogLineBuf[16];  
   int FlushLogLineBuf;  
   
   int ProgStat;  
   
72    DWORD StartTime;    DWORD StartTime;
73    
74    // log rotate    // log rotate
# Line 98  typedef struct { Line 78  typedef struct {
78    
79    HANDLE LogThread;    HANDLE LogThread;
80    DWORD LogThreadId;    DWORD LogThreadId;
   
   DWORD FileMtime;  
81    HANDLE LogThreadEvent;    HANDLE LogThreadEvent;
82  } TFileVar_;  } TFileVar_;
83  typedef TFileVar_ *PFileVar_;  typedef TFileVar_ *PFileVar_;
# Line 128  static enum enumLineEnd eLineEnd = Line_ Line 106  static enum enumLineEnd eLineEnd = Line_
106  // 遅延書き込み用スレッドのメッセージ  // 遅延書き込み用スレッドのメッセージ
107  #define WM_DPC_LOGTHREAD_SEND (WM_APP + 1)  #define WM_DPC_LOGTHREAD_SEND (WM_APP + 1)
108    
109  static void CloseFileSync(PFileVar ptr);  static void FileTransEnd_(void);
110  static void FileTransEnd_(WORD OpId);  static void Log1Bin(BYTE b);
111    static void LogBinSkip(int add);
112    static BOOL CreateLogBuf(void);
113    static BOOL CreateBinBuf(void);
114    
115  static PFileTransDlg FLogDlg = NULL;  static PFileTransDlg FLogDlg = NULL;
116    
# Line 141  static BOOL OpenFTDlg_(PFileVar fv) Line 121  static BOOL OpenFTDlg_(PFileVar fv)
121          FTDlg = new CFileTransDlg();          FTDlg = new CFileTransDlg();
122    
123          fv->StartTime = 0;          fv->StartTime = 0;
124          fv->ProgStat = 0;          cv.FilePause &= ~OpLog;
         cv.FilePause &= ~fv->OpId;  
125    
126          if (fv->OpId != OpLog) {          if (ts.LogHideDialog)
127                  fv->HideDialog = ts.FTHideDialog;                  fv->HideDialog = TRUE;
         }  
128    
129          if (FTDlg!=NULL)          if (FTDlg!=NULL)
130          {          {
131                    char DlgCaption[40];
132                    strncpy_s(DlgCaption, _countof(DlgCaption),"Tera Term: ", _TRUNCATE);
133                    char uimsg[MAX_UIMSG];
134                    get_lang_msg("FILEDLG_TRANS_TITLE_LOG", uimsg, sizeof(uimsg), TitLog, ts.UILanguageFile);
135                    strncat_s(DlgCaption, _countof(DlgCaption), uimsg, _TRUNCATE);
136    
137                  CFileTransDlgInfo info;                  CFileTransDlgInfo info;
138                  info.UILanguageFile = ts.UILanguageFile;                  info.UILanguageFile = ts.UILanguageFile;
139                  info.OpId = fv->OpId;                  info.OpId = OpLog;
140                  info.DlgCaption = fv->DlgCaption;                  info.DlgCaption = DlgCaption;
141                  info.FileName = &fv->FullName[fv->DirLen];                  info.FileName = &fv->FullName[fv->DirLen];
142                  info.FullName = fv->FullName;                  info.FullName = fv->FullName;
143                  info.HideDialog = fv->HideDialog;                  info.HideDialog = fv->HideDialog;
144                  info.HMainWin = fv->HMainWin;                  info.HMainWin = HVTWin;
145                  FTDlg->Create(hInst, &info);                  FTDlg->Create(hInst, &info);
146                  FTDlg->RefreshNum(fv->StartTime, fv->FileSize, fv->ByteCount);                  FTDlg->RefreshNum(fv->StartTime, fv->FileSize, fv->ByteCount);
147          }          }
148    
149  //      if (fv->OpId==OpLog)          FLogDlg = FTDlg; /* Log */
                 FLogDlg = FTDlg; /* Log */  
 #if 0  
         else  
                 SendDlg = FTDlg; /* File send */  
 #endif  
150    
151          fv->StartTime = GetTickCount();          fv->StartTime = GetTickCount();
152    
153          return (FTDlg!=NULL);          return (FTDlg!=NULL);
154  }  }
155    
 static void ShowFTDlg(WORD OpId)  
 {  
 //      if (OpId == OpLog)  
         {  
                 if (FLogDlg != NULL) {  
                         FLogDlg->ShowWindow(SW_SHOWNORMAL);  
                         SetForegroundWindow(FLogDlg->GetSafeHwnd());  
                 }  
         }  
 #if 0  
         else {  
                 if (SendDlg != NULL) {  
                         SendDlg->ShowWindow(SW_SHOWNORMAL);  
                         SetForegroundWindow(SendDlg->GetSafeHwnd());  
                 }  
         }  
 #endif  
 }  
   
 static BOOL NewFileVar_(PFileVar *fv)  
 {  
         if ((*fv)==NULL)  
         {  
                 *fv = (PFileVar)malloc(sizeof(TFileVar));  
                 if ((*fv)!=NULL)  
                 {  
                         char FileDirExpanded[MAX_PATH];  
                         ExpandEnvironmentStrings(ts.FileDir, FileDirExpanded, sizeof(FileDirExpanded));  
                         memset(*fv, 0, sizeof(TFileVar));  
                         strncpy_s((*fv)->FullName, sizeof((*fv)->FullName), FileDirExpanded, _TRUNCATE);  
                         AppendSlash((*fv)->FullName,sizeof((*fv)->FullName));  
                         (*fv)->DirLen = strlen((*fv)->FullName);  
                         (*fv)->FileOpen = FALSE;  
                         (*fv)->OverWrite = ((ts.FTFlag & FT_RENAME) == 0);  
                         (*fv)->HMainWin = HVTWin;  
                         (*fv)->Success = FALSE;  
                         (*fv)->NoMsg = FALSE;  
                         (*fv)->HideDialog = FALSE;  
                 }  
         }  
   
         return ((*fv)!=NULL);  
 }  
   
 static void FreeFileVar_(PFileVar *fv)  
 {  
         if ((*fv)!=NULL)  
         {  
                 CloseFileSync(*fv);  
                 //if ((*fv)->FileOpen) _lclose((*fv)->FileHandle);  
                 if ((*fv)->FnStrMemHandle != 0)  
                 {  
                         GlobalUnlock((*fv)->FnStrMemHandle);  
                         GlobalFree((*fv)->FnStrMemHandle);  
                 }  
                 free(*fv);  
                 *fv = NULL;  
         }  
 }  
   
156  /**  /**
157   *      ファイル名文字列の置き換え   *      ファイル名文字列の置き換え
158   *              &h      ホスト名に置換 (2007.5.14)   *              &h      ホスト名に置換 (2007.5.14)
# Line 733  static INT_PTR CALLBACK LogFnHook(HWND D Line 652  static INT_PTR CALLBACK LogFnHook(HWND D
652          return FALSE;          return FALSE;
653  }  }
654    
655  static BOOL LogStart(void)  static BOOL LogStart(const char *fname)
656  {  {
657          unsigned tid;          unsigned tid;
658    
659          if ((FileLog) || (BinLog)) return FALSE;          strncpy_s(LogVar->FullName, sizeof(LogVar->FullName), fname, _TRUNCATE);
   
         assert(LogVar != NULL);  
   
         if (strlen(&(LogVar->FullName[LogVar->DirLen]))==0) {  
                 // ファイル名が設定されていない  
                 return FALSE;  
         }  
660    
661          if (! LoadTTFILE()) return FALSE;          if (! LoadTTFILE()) return FALSE;
662    
         LogVar->OpId = OpLog;  
663          //(*SetFileVar)(LogVar);          //(*SetFileVar)(LogVar);
664          {          {
665                  int i;                  int i;
# Line 757  static BOOL LogStart(void) Line 668  static BOOL LogStart(void)
668                  GetFileNamePos(fv->FullName,&(fv->DirLen),&i);                  GetFileNamePos(fv->FullName,&(fv->DirLen),&i);
669                  c = fv->FullName[fv->DirLen];                  c = fv->FullName[fv->DirLen];
670                  if (c=='\\'||c=='/') fv->DirLen++;                  if (c=='\\'||c=='/') fv->DirLen++;
                 strncpy_s(fv->DlgCaption, sizeof(fv->DlgCaption),"Tera Term: ", _TRUNCATE);  
                 char uimsg[MAX_UIMSG];  
                 get_lang_msg("FILEDLG_TRANS_TITLE_LOG", uimsg, sizeof(uimsg), TitLog, ts.UILanguageFile);  
                 strncat_s(fv->DlgCaption, sizeof(fv->DlgCaption), uimsg, _TRUNCATE);  
671          }          }
672          FixLogOption();          FixLogOption();
673    
# Line 770  static BOOL LogStart(void) Line 677  static BOOL LogStart(void)
677                  FileLog = FALSE;                  FileLog = FALSE;
678                  if (! CreateBinBuf())                  if (! CreateBinBuf())
679                  {                  {
680                          FileTransEnd_(OpLog);                          FileTransEnd_();
681                          return FALSE;                          return FALSE;
682                  }                  }
683          }          }
# Line 779  static BOOL LogStart(void) Line 686  static BOOL LogStart(void)
686                  FileLog = TRUE;                  FileLog = TRUE;
687                  if (! CreateLogBuf())                  if (! CreateLogBuf())
688                  {                  {
689                          FileTransEnd_(OpLog);                          FileTransEnd_();
690                          return FALSE;                          return FALSE;
691                  }                  }
692          }          }
693          cv.LStart = cv.LogPtr;          cv.LStart = cv.LogPtr;
694          cv.LCount = 0;          cv.LCount = 0;
         if (ts.LogHideDialog)  
                 LogVar->HideDialog = 1;  
695    
696          /* 2007.05.24 Gentaro */          /* 2007.05.24 Gentaro */
697          eLineEnd = Line_LineHead;          eLineEnd = Line_LineHead;
# Line 827  static BOOL LogStart(void) Line 732  static BOOL LogStart(void)
732                          MessageBox(NULL, msg, "Tera Term: File open error", MB_OK | MB_ICONERROR);                          MessageBox(NULL, msg, "Tera Term: File open error", MB_OK | MB_ICONERROR);
733                  }                  }
734    
735                  FileTransEnd_(OpLog);                  FileTransEnd_();
736                  return FALSE;                  return FALSE;
737          }          }
738          LogVar->ByteCount = 0;          LogVar->ByteCount = 0;
# Line 847  static BOOL LogStart(void) Line 752  static BOOL LogStart(void)
752          }          }
753    
754          if (! OpenFTDlg_(LogVar)) {          if (! OpenFTDlg_(LogVar)) {
755                  FileTransEnd_(OpLog);                  FileTransEnd_();
756                  return FALSE;                  return FALSE;
757          }          }
758    
# Line 900  static BOOL LogStart(void) Line 805  static BOOL LogStart(void)
805                  }                  }
806          }          }
807    
808            if (FileLog) {
809                    cv.Log1Byte = LogPut1;
810            }
811            if (BinLog) {
812                    cv.Log1Bin = Log1Bin;
813                    cv.LogBinSkip = LogBinSkip;
814            }
815    
816          return TRUE;          return TRUE;
817  }  }
818    
819    /**
820     * ログへ1byte書き込み
821     *              バッファへ書き込まれる
822     *              実際の書き込みは LogToFile() で行われる
823     */
824  void LogPut1(BYTE b)  void LogPut1(BYTE b)
825  {  {
826          cv.LogBuf[cv.LogPtr] = b;          cv.LogBuf[cv.LogPtr] = b;
# Line 1065  static void LogRotate(void) Line 983  static void LogRotate(void)
983    
984  }  }
985    
986  void LogToFile(void)  /**
987     * バッファ内のログをファイルへ書き込む
988     */
989    static void LogToFile(void)
990  {  {
991          PCHAR Buf;          PCHAR Buf;
992          int Start, Count;          int Start, Count;
# Line 1219  void LogToFile(void) Line 1140  void LogToFile(void)
1140    
1141  }  }
1142    
1143  BOOL CreateLogBuf(void)  static BOOL CreateLogBuf(void)
1144  {  {
1145          if (cv.HLogBuf==NULL)          if (cv.HLogBuf==NULL)
1146          {          {
# Line 1232  BOOL CreateLogBuf(void) Line 1153  BOOL CreateLogBuf(void)
1153          return (cv.HLogBuf!=NULL);          return (cv.HLogBuf!=NULL);
1154  }  }
1155    
1156  void FreeLogBuf(void)  static void FreeLogBuf(void)
1157  {  {
1158          if ((cv.HLogBuf==NULL) || FileLog)          if ((cv.HLogBuf==NULL) || FileLog)
1159                  return;                  return;
# Line 1246  void FreeLogBuf(void) Line 1167  void FreeLogBuf(void)
1167          cv.LCount = 0;          cv.LCount = 0;
1168  }  }
1169    
1170  BOOL CreateBinBuf(void)  static BOOL CreateBinBuf(void)
1171  {  {
1172          if (cv.HBinBuf==NULL)          if (cv.HBinBuf==NULL)
1173          {          {
# Line 1259  BOOL CreateBinBuf(void) Line 1180  BOOL CreateBinBuf(void)
1180          return (cv.HBinBuf!=NULL);          return (cv.HBinBuf!=NULL);
1181  }  }
1182    
1183  void FreeBinBuf(void)  static void FreeBinBuf(void)
1184  {  {
1185          if ((cv.HBinBuf==NULL) || BinLog)          if ((cv.HBinBuf==NULL) || BinLog)
1186                  return;                  return;
# Line 1273  void FreeBinBuf(void) Line 1194  void FreeBinBuf(void)
1194          cv.BCount = 0;          cv.BCount = 0;
1195  }  }
1196    
1197  static void FileTransEnd_(WORD OpId)  static void FileTransEnd_(void)
 /* OpId = 0: close Log and FileSend  
       OpLog: close Log  
  OpSendFile: close FileSend */  
1198  {  {
1199          if (((OpId==0) || (OpId==OpLog)) && (FileLog || BinLog))          FileLog = FALSE;
1200            BinLog = FALSE;
1201            cv.Log1Byte = NULL;
1202            cv.Log1Bin = NULL;
1203            cv.LogBinSkip = NULL;
1204            if (FLogDlg!=NULL)
1205          {          {
1206                  FileLog = FALSE;                  FLogDlg->DestroyWindow();
1207                  BinLog = FALSE;                  FLogDlg = NULL;
                 if (FLogDlg!=NULL)  
                 {  
                         FLogDlg->DestroyWindow();  
                         FLogDlg = NULL;  
                 }  
                 FreeFileVar_(&LogVar);  
                 FreeLogBuf();  
                 FreeBinBuf();  
                 FreeTTFILE();  
1208          }          }
1209            if (LogVar != NULL)
 #if 0  
         if (((OpId==0) || (OpId==OpSendFile)) && FSend)  
1210          {          {
1211                  FSend = FALSE;                  CloseFileSync(LogVar);
1212                  TalkStatus = IdTalkKeyb;                  free(LogVar);
1213                  if (SendDlg!=NULL)                  LogVar = NULL;
1214                  {          }
1215                          SendDlg->DestroyWindow();          FreeLogBuf();
1216                          SendDlg = NULL;          FreeBinBuf();
1217                  }          FreeTTFILE();
                 FreeFileVar_(&SendVar);  
                 FreeTTFILE();  
         }  
 #endif  
   
 //      EndDdeCmnd(0);  
1218  }  }
1219    
1220    
# Line 1413  void FLogAddCommentDlg(HINSTANCE hInst, Line 1319  void FLogAddCommentDlg(HINSTANCE hInst,
1319    
1320  void FLogClose(void)  void FLogClose(void)
1321  {  {
1322          if (LogVar != NULL)          if (LogVar == NULL) {
1323                  FileTransEnd_(OpLog);                  return;
1324            }
1325    
1326            FileTransEnd_();
1327  }  }
1328    
1329    /**
1330     *      ログをオープンする
1331     *      @param[in]      fname   ログファイル名, CreateFile()に渡される
1332     *
1333     *      ログファイル名はstrftimeの展開などは行われない。
1334     *      FLogGetLogFilename() や FLogOpenDialog() で
1335     *      ファイル名を取得できる。
1336     */
1337  BOOL FLogOpen(const char *fname)  BOOL FLogOpen(const char *fname)
1338  {  {
1339          BOOL ret;          BOOL ret;
# Line 1424  BOOL FLogOpen(const char *fname) Line 1341  BOOL FLogOpen(const char *fname)
1341          if (LogVar != NULL) {          if (LogVar != NULL) {
1342                  return FALSE;                  return FALSE;
1343          }          }
1344            if ((FileLog) || (BinLog)) return FALSE;
1345    
1346            //
1347            PFileVar fv = (PFileVar)malloc(sizeof(TFileVar));
1348            if (fv == NULL) {
1349                    return FALSE;
1350            }
1351            LogVar = fv;
1352            memset(fv, 0, sizeof(TFileVar));
1353    
1354            fv->FileOpen = FALSE;
1355            fv->OverWrite = ((ts.FTFlag & FT_RENAME) == 0);
1356            fv->Success = FALSE;
1357            fv->NoMsg = FALSE;
1358            fv->HideDialog = FALSE;
1359    
1360          LogVar->DirLen = 0;          LogVar->DirLen = 0;
1361          LogVar->NoMsg = TRUE;          LogVar->NoMsg = TRUE;
1362          strncpy_s(LogVar->FullName, sizeof(LogVar->FullName), fname, _TRUNCATE);  
1363          ret = LogStart();          ret = LogStart(fname);
1364          return ret;          return ret;
1365  }  }
1366    
# Line 1574  void FLogWindow(int nCmdShow) Line 1506  void FLogWindow(int nCmdShow)
1506    
1507  void FLogShowDlg(void)  void FLogShowDlg(void)
1508  {  {
1509          ShowFTDlg(OpLog);          if (FLogDlg != NULL) {
1510                    FLogDlg->ShowWindow(SW_SHOWNORMAL);
1511                    SetForegroundWindow(FLogDlg->GetSafeHwnd());
1512            }
1513    }
1514    
1515    /**
1516     * ログへ1byte書き込み
1517     *              LogPut1() と違う?
1518     */
1519    //void Log1Bin(PComVar cv, BYTE b)
1520    static void Log1Bin(BYTE b)
1521    {
1522            if (((cv.FilePause & OpLog)!=0) || cv.ProtoFlag) {
1523                    return;
1524            }
1525            if (cv.BinSkip > 0) {
1526                    cv.BinSkip--;
1527                    return;
1528            }
1529            cv.BinBuf[cv.BinPtr] = b;
1530            cv.BinPtr++;
1531            if (cv.BinPtr>=InBuffSize) {
1532                    cv.BinPtr = cv.BinPtr-InBuffSize;
1533            }
1534            if (cv.BCount>=InBuffSize) {
1535                    cv.BCount = InBuffSize;
1536                    cv.BStart = cv.BinPtr;
1537            }
1538            else {
1539                    cv.BCount++;
1540            }
1541    }
1542    
1543    static void LogBinSkip(int add)
1544    {
1545            if (cv.HBinBuf!=0 ) {
1546                    cv.BinSkip += add;
1547            }
1548    }
1549    
1550    /**
1551     *      ログバッファに溜まっているデータのバイト数を返す
1552     */
1553    int FLogGetCount(void)
1554    {
1555            if (FileLog) {
1556                    return cv.LCount;
1557            }
1558            if (BinLog) {
1559                    return cv.BCount;
1560            }
1561            return 0;
1562    }
1563    
1564    /**
1565     * バッファ内のログをファイルへ書き込む
1566     */
1567    void FLogWriteFile(void)
1568    {
1569            if (cv.LogBuf!=NULL)
1570            {
1571                    if (FileLog) {
1572                            LogToFile();
1573                    }
1574                    GlobalUnlock(cv.HLogBuf);
1575                    cv.LogBuf = NULL;
1576            }
1577    
1578            if (cv.BinBuf!=NULL)
1579            {
1580                    if (BinLog) {
1581                            LogToFile();
1582                    }
1583                    GlobalUnlock(cv.HBinBuf);
1584                    cv.BinBuf = NULL;
1585            }
1586  }  }

Legend:
Removed from v.8896  
changed lines
  Added in v.8897

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26