OpenBarnyard
 
Loading...
Searching...
No Matches
TUtil_Win.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "Toshi/T2Allocator.h"
3#include "Toshi/TUtil.h"
4
5#include <queue>
6#include <windows.h>
7
8//-----------------------------------------------------------------------------
9// Enables memory debugging.
10// Note: Should be the last include!
11//-----------------------------------------------------------------------------
12#include "Core/TMemoryDebugOn.h"
13
15
16void TUtil::TrimLog( const TCHAR* fileName, TSIZE trimTo )
17{
18 // and yes they actually did it with std
19
20 WIN32_FIND_DATAA ffd;
21 std::queue<std::string> queue;
22
23 HANDLE hFind = FindFirstFileA( fileName, &ffd );
24
25 if ( INVALID_HANDLE_VALUE == hFind )
26 {
27 FindClose( hFind );
28 return;
29 }
30
31 do
32 {
33 if ( ffd.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE )
34 {
35 queue.push( ffd.cFileName );
36 }
37
38 BOOL found = FindNextFileA( hFind, &ffd );
39
40 if ( !found )
41 {
42 FindClose( hFind );
43 do
44 {
45 DeleteFileA( queue.front().c_str() );
46 queue.pop();
47 } while ( queue.size() > trimTo );
48 return;
49 }
50
51 } while ( TTRUE );
52}
53
55{
56 time_t t = time( NULL );
57 TCHAR* str = ctime( &t );
58 return strtok( str, "\n" );
59}
60
61// Note from AdventureT: GetUnixSeconds is 1:1 just time() from <time.h>
62
63//uint64_t TUtil::GetUnixSeconds(uint64_t* pOut)
64//{
65// // 007f0f93
66// // https://stackoverflow.com/questions/20370920/convert-current-time-from-windows-to-unix-timestamp-in-c-or-c
67// // Get the number of seconds since January 1, 1970 12:00am UTC
68// // Code released into public domain; no attribution required.
69// const uint64_t UNIX_TIME_START = 0x019DB1DED53E8000; // January 1, 1970 (start of Unix epoch) in "ticks"
70// const uint64_t TICKS_PER_SECOND = 10000000; // a tick is 100ns
71
72// FILETIME ft;
73// GetSystemTimeAsFileTime(&ft); //returns ticks in UTC
74
75// // Copy the low and high parts of FILETIME into a LARGE_INTEGER
76// // This is so we can access the full 64-bits as an Int64 without causing an alignment fault
77// LARGE_INTEGER li;
78// li.LowPart = ft.dwLowDateTime;
79// li.HighPart = ft.dwHighDateTime;
80
81// // Convert ticks since 1/1/1970 into seconds
82// uint64_t result = (li.QuadPart - UNIX_TIME_START) / TICKS_PER_SECOND;
83
84// if (pOut != NULL) { *pOut = result; }
85// return result;
86//}
87
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
size_t TSIZE
Definition Typedefs.h:9
char TCHAR
Definition Typedefs.h:20
#define TTRUE
Definition Typedefs.h:25
static void TrimLog(const TCHAR *fileExtension, TSIZE trimTo)
Definition TUtil_Win.cpp:16
static const TCHAR * GetTime()
Definition TUtil_Win.cpp:54