Skip to content

Commit

Permalink
v0.1.5-alpha
Browse files Browse the repository at this point in the history
- 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`
  • Loading branch information
tomasz-rozanski committed Oct 26, 2019
1 parent 9bc635d commit 9d6670d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
13 changes: 3 additions & 10 deletions includes/vst_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 2 additions & 12 deletions includes/vst_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions includes/vst_utils.h
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9d6670d

Please sign in to comment.