From 9d6670d99d392d814cfaf48fa21a7547602be05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20R=C3=B3=C5=BCa=C5=84ski?= Date: Sun, 27 Oct 2019 00:30:10 +0200 Subject: [PATCH] v0.1.5-alpha - Refactor the time-stamp related code: - use global variables to store the current time and time-stamp strings, - change code to be more reusable, - change time-stamp format for file names to `YYYYMMDDTHHMMSS-record-time.txt` - move time-stamp related variables and functions to separate file,`vst_utils.h` --- includes/vst_console.h | 13 +++---------- includes/vst_time.h | 14 ++------------ includes/vst_utils.h | 38 ++++++++++++++++++++++++++++++++++++++ main.c | 1 + 4 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 includes/vst_utils.h diff --git a/includes/vst_console.h b/includes/vst_console.h index 1bed18f..aaa83d5 100644 --- a/includes/vst_console.h +++ b/includes/vst_console.h @@ -209,18 +209,11 @@ WriteDebugMessage(HANDLE hConsole) void WriteDebugLog(TCHAR *message) { - SYSTEMTIME stLocalTime; - - GetLocalTime(&stLocalTime); + WriteTimeStampDebugString(); FILE *fpDebugInfo = fopen("debug/debug.log", "a"); - fprintf(fpDebugInfo, "%04d-%02d-%02d %02d:%02d:%02d: ", // - stLocalTime.wYear, // - stLocalTime.wMonth, // - stLocalTime.wDay, // - stLocalTime.wHour, // - stLocalTime.wMinute, // - stLocalTime.wSecond); + + fprintf(fpDebugInfo, szTimeStampDebug); fprintf(fpDebugInfo, message); fclose(fpDebugInfo); diff --git a/includes/vst_time.h b/includes/vst_time.h index 90c7649..ad5d587 100644 --- a/includes/vst_time.h +++ b/includes/vst_time.h @@ -108,21 +108,11 @@ void WriteRecordTimeToFile( playtime *RecordTime, TCHAR szFolderName[128], TCHAR FileName[128]) { - SYSTEMTIME stLocalTime; - TCHAR szLocalTime[64]; TCHAR szFullPath[MAX_PATH]; - GetLocalTime(&stLocalTime); + WriteTimeStampFileString(); - sprintf(szLocalTime, "%04d-%02d-%02d-%02d-%02d-%02d", // - stLocalTime.wYear, // - stLocalTime.wMonth, // - stLocalTime.wDay, // - stLocalTime.wHour, // - stLocalTime.wMinute, // - stLocalTime.wSecond); - - sprintf(szFullPath, "%s/%s-%s", szFolderName, szLocalTime, FileName); + sprintf(szFullPath, "%s/%s-%s", szFolderName, szTimeStampFile, FileName); UINT8 Seconds = RecordTime->Time.Seconds; UINT8 Minutes = RecordTime->Time.Minutes; diff --git a/includes/vst_utils.h b/includes/vst_utils.h new file mode 100644 index 0000000..217a998 --- /dev/null +++ b/includes/vst_utils.h @@ -0,0 +1,38 @@ +#ifndef _VST_UTILS_H +#define _VST_UTILS_H + +SYSTEMTIME stLocalTime; +TCHAR szTimeStampDebug[64]; +TCHAR szTimeStampFile[64]; + +void +WriteTimeStampDebugString() +{ + GetLocalTime(&stLocalTime); + + sprintf(szTimeStampDebug, // + "%04d-%02d-%02d %02d:%02d:%02d: ", // + stLocalTime.wYear, // + stLocalTime.wMonth, // + stLocalTime.wDay, // + stLocalTime.wHour, // + stLocalTime.wMinute, // + stLocalTime.wSecond); +} + +void +WriteTimeStampFileString() +{ + GetLocalTime(&stLocalTime); + + sprintf(szTimeStampFile, // + "%04d%02d%02dT%02d%02d%02d", // + stLocalTime.wYear, // + stLocalTime.wMonth, // + stLocalTime.wDay, // + stLocalTime.wHour, // + stLocalTime.wMinute, // + stLocalTime.wSecond); +} + +#endif \ No newline at end of file diff --git a/main.c b/main.c index 159bfc5..04a71ce 100644 --- a/main.c +++ b/main.c @@ -14,6 +14,7 @@ DWORD processID; DWORD processVersion; BOOL DEBUG; +#include "includes/vst_utils.h" #include "includes/vst_console.h" #include "includes/vst_process.h" #include "includes/vst_emulation.h"