mirror of
https://github.com/vczh-libraries/Release.git
synced 2026-03-27 01:23:05 +08:00
Update import
This commit is contained in:
224
Import/Vlpp.Linux.cpp
Normal file
224
Import/Vlpp.Linux.cpp
Normal file
@@ -0,0 +1,224 @@
|
||||
/***********************************************************************
|
||||
THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY
|
||||
DEVELOPER: Zihan Chen(vczh)
|
||||
***********************************************************************/
|
||||
#include "Vlpp.h"
|
||||
|
||||
/***********************************************************************
|
||||
.\CONSOLE.LINUX.CPP
|
||||
***********************************************************************/
|
||||
/***********************************************************************
|
||||
Author: Zihan Chen (vczh)
|
||||
Licensed under https://github.com/vczh-libraries/License
|
||||
***********************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#ifndef VCZH_GCC
|
||||
static_assert(false, "Do not build this file for Windows applications.");
|
||||
#endif
|
||||
|
||||
namespace vl
|
||||
{
|
||||
namespace console
|
||||
{
|
||||
|
||||
/***********************************************************************
|
||||
Console
|
||||
***********************************************************************/
|
||||
|
||||
void Console::Write(const wchar_t* string, vint length)
|
||||
{
|
||||
std::wstring s(string, string + length);
|
||||
std::wcout << s << std::ends;
|
||||
}
|
||||
|
||||
WString Console::Read()
|
||||
{
|
||||
std::wstring s;
|
||||
std::getline(std::wcin, s, L'\n');
|
||||
return s.c_str();
|
||||
}
|
||||
|
||||
void Console::SetColor(bool red, bool green, bool blue, bool light)
|
||||
{
|
||||
int color = (blue ? 1 : 0) * 4 + (green ? 1 : 0) * 2 + (red ? 1 : 0);
|
||||
if (light)
|
||||
wprintf(L"\x1B[00;3%dm", color);
|
||||
else
|
||||
wprintf(L"\x1B[01;3%dm", color);
|
||||
}
|
||||
|
||||
void Console::SetTitle(const WString& string)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
.\PRIMITIVES\DATETIME.LINUX.CPP
|
||||
***********************************************************************/
|
||||
/***********************************************************************
|
||||
Author: Zihan Chen (vczh)
|
||||
Licensed under https://github.com/vczh-libraries/License
|
||||
***********************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
#include <memory.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifndef VCZH_GCC
|
||||
static_assert(false, "Do not build this file for Windows applications.");
|
||||
#endif
|
||||
|
||||
namespace vl
|
||||
{
|
||||
|
||||
/***********************************************************************
|
||||
DateTime
|
||||
***********************************************************************/
|
||||
|
||||
DateTime ConvertTMToDateTime(tm* timeinfo, vint milliseconds)
|
||||
{
|
||||
time_t timer = mktime(timeinfo);
|
||||
DateTime dt;
|
||||
dt.year = timeinfo->tm_year + 1900;
|
||||
dt.month = timeinfo->tm_mon + 1;
|
||||
dt.day = timeinfo->tm_mday;
|
||||
dt.dayOfWeek = timeinfo->tm_wday;
|
||||
dt.hour = timeinfo->tm_hour;
|
||||
dt.minute = timeinfo->tm_min;
|
||||
dt.second = timeinfo->tm_sec;
|
||||
dt.milliseconds = milliseconds;
|
||||
|
||||
// in Linux and macOS, filetime will be mktime(t) * 1000 + gettimeofday().tv_usec / 1000
|
||||
dt.filetime = (vuint64_t)timer * 1000 + milliseconds;
|
||||
dt.totalMilliseconds = (vuint64_t)timer * 1000 + milliseconds;
|
||||
return dt;
|
||||
}
|
||||
|
||||
DateTime DateTime::LocalTime()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, nullptr);
|
||||
tm* timeinfo = localtime(&tv.tv_sec);
|
||||
return ConvertTMToDateTime(timeinfo, tv.tv_usec / 1000);
|
||||
}
|
||||
|
||||
DateTime DateTime::UtcTime()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, nullptr);
|
||||
tm* timeinfo = gmtime(&tv.tv_sec);
|
||||
return ConvertTMToDateTime(timeinfo, tv.tv_usec / 1000);
|
||||
}
|
||||
|
||||
DateTime DateTime::FromDateTime(vint _year, vint _month, vint _day, vint _hour, vint _minute, vint _second, vint _milliseconds)
|
||||
{
|
||||
tm timeinfo;
|
||||
memset(&timeinfo, 0, sizeof(timeinfo));
|
||||
timeinfo.tm_year = _year - 1900;
|
||||
timeinfo.tm_mon = _month - 1;
|
||||
timeinfo.tm_mday = _day;
|
||||
timeinfo.tm_hour = _hour;
|
||||
timeinfo.tm_min = _minute;
|
||||
timeinfo.tm_sec = _second;
|
||||
timeinfo.tm_isdst = -1;
|
||||
return ConvertTMToDateTime(&timeinfo, _milliseconds);
|
||||
}
|
||||
|
||||
DateTime DateTime::FromFileTime(vuint64_t filetime)
|
||||
{
|
||||
time_t timer = (time_t)(filetime / 1000);
|
||||
tm* timeinfo = localtime(&timer);
|
||||
return ConvertTMToDateTime(timeinfo, filetime % 1000);
|
||||
}
|
||||
|
||||
DateTime DateTime::ToLocalTime()
|
||||
{
|
||||
time_t localTimer = time(nullptr);
|
||||
time_t utcTimer = mktime(gmtime(&localTimer));
|
||||
time_t timer = (time_t)(filetime / 1000) + localTimer - utcTimer;
|
||||
tm* timeinfo = localtime(&timer);
|
||||
return ConvertTMToDateTime(timeinfo, milliseconds);
|
||||
}
|
||||
|
||||
DateTime DateTime::ToUtcTime()
|
||||
{
|
||||
time_t timer = (time_t)(filetime / 1000);
|
||||
tm* timeinfo = gmtime(&timer);
|
||||
return ConvertTMToDateTime(timeinfo, milliseconds);
|
||||
}
|
||||
|
||||
DateTime DateTime::Forward(vuint64_t milliseconds)
|
||||
{
|
||||
return FromFileTime(filetime + milliseconds);
|
||||
}
|
||||
|
||||
DateTime DateTime::Backward(vuint64_t milliseconds)
|
||||
{
|
||||
return FromFileTime(filetime - milliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
.\STRINGS\CONVERSION.LINUX.CPP
|
||||
***********************************************************************/
|
||||
/***********************************************************************
|
||||
Author: Zihan Chen (vczh)
|
||||
Licensed under https://github.com/vczh-libraries/License
|
||||
***********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <wctype.h>
|
||||
|
||||
namespace vl
|
||||
{
|
||||
/***********************************************************************
|
||||
String Conversions (buffer walkthrough)
|
||||
***********************************************************************/
|
||||
|
||||
vint _wtoa(const wchar_t* w, char* a, vint chars)
|
||||
{
|
||||
return wcstombs(a, w, chars - 1) + 1;
|
||||
}
|
||||
|
||||
vint _atow(const char* a, wchar_t* w, vint chars)
|
||||
{
|
||||
return mbstowcs(w, a, chars - 1) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
.\UNITTEST\UNITTEST.LINUX.CPP
|
||||
***********************************************************************/
|
||||
/***********************************************************************
|
||||
Author: Zihan Chen (vczh)
|
||||
Licensed under https://github.com/vczh-libraries/License
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef VCZH_GCC
|
||||
static_assert(false, "Do not build this file for Windows applications.");
|
||||
#endif
|
||||
|
||||
namespace vl
|
||||
{
|
||||
namespace unittest
|
||||
{
|
||||
/***********************************************************************
|
||||
UnitTest
|
||||
***********************************************************************/
|
||||
|
||||
bool UnitTest::IsDebuggerAttached()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
282
Import/Vlpp.Windows.cpp
Normal file
282
Import/Vlpp.Windows.cpp
Normal file
@@ -0,0 +1,282 @@
|
||||
/***********************************************************************
|
||||
THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY
|
||||
DEVELOPER: Zihan Chen(vczh)
|
||||
***********************************************************************/
|
||||
#include "Vlpp.h"
|
||||
|
||||
/***********************************************************************
|
||||
.\CONSOLE.WINDOWS.CPP
|
||||
***********************************************************************/
|
||||
/***********************************************************************
|
||||
Author: Zihan Chen (vczh)
|
||||
Licensed under https://github.com/vczh-libraries/License
|
||||
***********************************************************************/
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#ifndef VCZH_MSVC
|
||||
static_assert(false, "Do not build this file for non-Windows applications.");
|
||||
#endif
|
||||
|
||||
namespace vl
|
||||
{
|
||||
namespace console
|
||||
{
|
||||
|
||||
/***********************************************************************
|
||||
Console
|
||||
***********************************************************************/
|
||||
|
||||
void Console::Write(const wchar_t* string, vint length)
|
||||
{
|
||||
HANDLE outHandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD fileMode = 0;
|
||||
DWORD written = 0;
|
||||
if ((GetFileType(outHandle) & FILE_TYPE_CHAR) && GetConsoleMode(outHandle, &fileMode))
|
||||
{
|
||||
WriteConsole(outHandle, string, (int)length, &written, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
int codePage = GetConsoleOutputCP();
|
||||
int charCount = WideCharToMultiByte(codePage, 0, string, -1, 0, 0, 0, 0);
|
||||
char* codePageBuffer = new char[charCount];
|
||||
WideCharToMultiByte(codePage, 0, string, -1, codePageBuffer, charCount, 0, 0);
|
||||
WriteFile(outHandle, codePageBuffer, charCount - 1, &written, 0);
|
||||
delete[] codePageBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
WString Console::Read()
|
||||
{
|
||||
WString result;
|
||||
DWORD count;
|
||||
for (;;)
|
||||
{
|
||||
wchar_t buffer;
|
||||
ReadConsole(GetStdHandle(STD_INPUT_HANDLE), &buffer, 1, &count, 0);
|
||||
if (buffer == L'\r')
|
||||
{
|
||||
ReadConsole(GetStdHandle(STD_INPUT_HANDLE), &buffer, 1, &count, 0);
|
||||
break;
|
||||
}
|
||||
else if (buffer == L'\n')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = result + WString::FromChar(buffer);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Console::SetColor(bool red, bool green, bool blue, bool light)
|
||||
{
|
||||
WORD attribute = 0;
|
||||
if (red)attribute |= FOREGROUND_RED;
|
||||
if (green)attribute |= FOREGROUND_GREEN;
|
||||
if (blue)attribute |= FOREGROUND_BLUE;
|
||||
if (light)attribute |= FOREGROUND_INTENSITY;
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), attribute);
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_INPUT_HANDLE), attribute);
|
||||
}
|
||||
|
||||
void Console::SetTitle(const WString& string)
|
||||
{
|
||||
SetConsoleTitle(string.Buffer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
.\PRIMITIVES\DATETIME.WINDOWS.CPP
|
||||
***********************************************************************/
|
||||
/***********************************************************************
|
||||
Author: Zihan Chen (vczh)
|
||||
Licensed under https://github.com/vczh-libraries/License
|
||||
***********************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifndef VCZH_MSVC
|
||||
static_assert(false, "Do not build this file for non-Windows applications.");
|
||||
#endif
|
||||
|
||||
namespace vl
|
||||
{
|
||||
|
||||
/***********************************************************************
|
||||
DateTime
|
||||
***********************************************************************/
|
||||
|
||||
DateTime SystemTimeToDateTime(const SYSTEMTIME& systemTime)
|
||||
{
|
||||
DateTime dateTime;
|
||||
dateTime.year = systemTime.wYear;
|
||||
dateTime.month = systemTime.wMonth;
|
||||
dateTime.dayOfWeek = systemTime.wDayOfWeek;
|
||||
dateTime.day = systemTime.wDay;
|
||||
dateTime.hour = systemTime.wHour;
|
||||
dateTime.minute = systemTime.wMinute;
|
||||
dateTime.second = systemTime.wSecond;
|
||||
dateTime.milliseconds = systemTime.wMilliseconds;
|
||||
|
||||
FILETIME fileTime;
|
||||
SystemTimeToFileTime(&systemTime, &fileTime);
|
||||
ULARGE_INTEGER largeInteger;
|
||||
largeInteger.HighPart = fileTime.dwHighDateTime;
|
||||
largeInteger.LowPart = fileTime.dwLowDateTime;
|
||||
dateTime.filetime = largeInteger.QuadPart;
|
||||
dateTime.totalMilliseconds = dateTime.filetime / 10000;
|
||||
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
SYSTEMTIME DateTimeToSystemTime(const DateTime& dateTime)
|
||||
{
|
||||
ULARGE_INTEGER largeInteger;
|
||||
largeInteger.QuadPart = dateTime.filetime;
|
||||
FILETIME fileTime;
|
||||
fileTime.dwHighDateTime = largeInteger.HighPart;
|
||||
fileTime.dwLowDateTime = largeInteger.LowPart;
|
||||
|
||||
SYSTEMTIME systemTime;
|
||||
FileTimeToSystemTime(&fileTime, &systemTime);
|
||||
return systemTime;
|
||||
}
|
||||
|
||||
DateTime DateTime::LocalTime()
|
||||
{
|
||||
SYSTEMTIME systemTime;
|
||||
GetLocalTime(&systemTime);
|
||||
return SystemTimeToDateTime(systemTime);
|
||||
}
|
||||
|
||||
DateTime DateTime::UtcTime()
|
||||
{
|
||||
SYSTEMTIME utcTime;
|
||||
GetSystemTime(&utcTime);
|
||||
return SystemTimeToDateTime(utcTime);
|
||||
}
|
||||
|
||||
DateTime DateTime::FromDateTime(vint _year, vint _month, vint _day, vint _hour, vint _minute, vint _second, vint _milliseconds)
|
||||
{
|
||||
SYSTEMTIME systemTime;
|
||||
memset(&systemTime, 0, sizeof(systemTime));
|
||||
systemTime.wYear = (WORD)_year;
|
||||
systemTime.wMonth = (WORD)_month;
|
||||
systemTime.wDay = (WORD)_day;
|
||||
systemTime.wHour = (WORD)_hour;
|
||||
systemTime.wMinute = (WORD)_minute;
|
||||
systemTime.wSecond = (WORD)_second;
|
||||
systemTime.wMilliseconds = (WORD)_milliseconds;
|
||||
|
||||
FILETIME fileTime;
|
||||
SystemTimeToFileTime(&systemTime, &fileTime);
|
||||
FileTimeToSystemTime(&fileTime, &systemTime);
|
||||
return SystemTimeToDateTime(systemTime);
|
||||
}
|
||||
|
||||
DateTime DateTime::FromFileTime(vuint64_t filetime)
|
||||
{
|
||||
ULARGE_INTEGER largeInteger;
|
||||
largeInteger.QuadPart = filetime;
|
||||
FILETIME fileTime;
|
||||
fileTime.dwHighDateTime = largeInteger.HighPart;
|
||||
fileTime.dwLowDateTime = largeInteger.LowPart;
|
||||
|
||||
SYSTEMTIME systemTime;
|
||||
FileTimeToSystemTime(&fileTime, &systemTime);
|
||||
return SystemTimeToDateTime(systemTime);
|
||||
}
|
||||
|
||||
DateTime DateTime::ToLocalTime()
|
||||
{
|
||||
SYSTEMTIME utcTime = DateTimeToSystemTime(*this);
|
||||
SYSTEMTIME localTime;
|
||||
SystemTimeToTzSpecificLocalTime(NULL, &utcTime, &localTime);
|
||||
return SystemTimeToDateTime(localTime);
|
||||
}
|
||||
|
||||
DateTime DateTime::ToUtcTime()
|
||||
{
|
||||
SYSTEMTIME localTime = DateTimeToSystemTime(*this);
|
||||
SYSTEMTIME utcTime;
|
||||
TzSpecificLocalTimeToSystemTime(NULL, &localTime, &utcTime);
|
||||
return SystemTimeToDateTime(utcTime);
|
||||
}
|
||||
|
||||
DateTime DateTime::Forward(vuint64_t milliseconds)
|
||||
{
|
||||
return FromFileTime(filetime + milliseconds * 10000);
|
||||
}
|
||||
|
||||
DateTime DateTime::Backward(vuint64_t milliseconds)
|
||||
{
|
||||
return FromFileTime(filetime - milliseconds * 10000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
.\STRINGS\CONVERSION.WINDOWS.CPP
|
||||
***********************************************************************/
|
||||
/***********************************************************************
|
||||
Author: Zihan Chen (vczh)
|
||||
Licensed under https://github.com/vczh-libraries/License
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef VCZH_MSVC
|
||||
static_assert(false, "Do not build this file for non-Windows applications.");
|
||||
#endif
|
||||
|
||||
namespace vl
|
||||
{
|
||||
/***********************************************************************
|
||||
String Conversions (buffer walkthrough)
|
||||
***********************************************************************/
|
||||
|
||||
vint _wtoa(const wchar_t* w, char* a, vint chars)
|
||||
{
|
||||
return WideCharToMultiByte(CP_THREAD_ACP, 0, w, -1, a, (int)(a ? chars : 0), 0, 0);
|
||||
}
|
||||
|
||||
vint _atow(const char* a, wchar_t* w, vint chars)
|
||||
{
|
||||
return MultiByteToWideChar(CP_THREAD_ACP, 0, a, -1, w, (int)(w ? chars : 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
.\UNITTEST\UNITTEST.WINDOWS.CPP
|
||||
***********************************************************************/
|
||||
/***********************************************************************
|
||||
Author: Zihan Chen (vczh)
|
||||
Licensed under https://github.com/vczh-libraries/License
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef VCZH_MSVC
|
||||
static_assert(false, "Do not build this file for non-Windows applications.");
|
||||
#endif
|
||||
|
||||
namespace vl
|
||||
{
|
||||
namespace unittest
|
||||
{
|
||||
/***********************************************************************
|
||||
UnitTest
|
||||
***********************************************************************/
|
||||
|
||||
bool UnitTest::IsDebuggerAttached()
|
||||
{
|
||||
return IsDebuggerPresent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
438
Import/Vlpp.cpp
438
Import/Vlpp.cpp
File diff suppressed because it is too large
Load Diff
2441
Import/Vlpp.h
2441
Import/Vlpp.h
File diff suppressed because it is too large
Load Diff
1721
Import/VlppOS.Linux.cpp
Normal file
1721
Import/VlppOS.Linux.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2054
Import/VlppOS.Windows.cpp
Normal file
2054
Import/VlppOS.Windows.cpp
Normal file
File diff suppressed because it is too large
Load Diff
3509
Import/VlppOS.cpp
3509
Import/VlppOS.cpp
File diff suppressed because it is too large
Load Diff
@@ -1885,6 +1885,8 @@ namespace vl
|
||||
protected:
|
||||
WString fullPath;
|
||||
|
||||
static void NormalizeDelimiters(collections::Array<wchar_t>& buffer);
|
||||
static void TrimLastDelimiter(WString& fullPath);
|
||||
void Initialize();
|
||||
|
||||
static void GetPathComponents(WString path, collections::List<WString>& components);
|
||||
@@ -1904,7 +1906,7 @@ namespace vl
|
||||
|
||||
/// <summary>Create a root path.</summary>
|
||||
/// <remarks><see cref="GetFullPath"/> returns different values for root path on different platforms. Do not rely on the value.</remarks>
|
||||
FilePath();
|
||||
FilePath() = default;
|
||||
/// <summary>Create a file path.</summary>
|
||||
/// <param name="_filePath">Content of the file path. If it is a relative path, it will be converted to an absolute path.</param>
|
||||
FilePath(const WString& _filePath);
|
||||
@@ -1914,7 +1916,7 @@ namespace vl
|
||||
/// <summary>Copy a file path.</summary>
|
||||
/// <param name="_filePath">The file path to copy.</param>
|
||||
FilePath(const FilePath& _filePath);
|
||||
~FilePath();
|
||||
~FilePath() = default;
|
||||
|
||||
static vint Compare(const FilePath& a, const FilePath& b);
|
||||
bool operator==(const FilePath& filePath)const{ return Compare(*this, filePath) == 0; }
|
||||
@@ -1964,11 +1966,11 @@ namespace vl
|
||||
|
||||
public:
|
||||
/// <summary>Create an empty reference. An empty reference does not refer to any file.</summary>
|
||||
File();
|
||||
File() = default;
|
||||
/// <summary>Create a reference to a specified file. The file is not required to exist.</summary>
|
||||
/// <param name="_filePath">The specified file.</param>
|
||||
File(const FilePath& _filePath);
|
||||
~File();
|
||||
~File() = default;
|
||||
|
||||
/// <summary>Get the file path of the file.</summary>
|
||||
/// <returns>The file path.</returns>
|
||||
@@ -2031,13 +2033,15 @@ namespace vl
|
||||
private:
|
||||
FilePath filePath;
|
||||
|
||||
bool CreateNonRecursively()const;
|
||||
bool DeleteNonRecursively()const;
|
||||
public:
|
||||
/// <summary>Create a reference to the root folder.</summary>
|
||||
Folder();
|
||||
Folder() = default;
|
||||
/// <summary>Create a reference to a specified folder. The folder is not required to exist.</summary>
|
||||
/// <param name="_filePath">The specified folder.</param>
|
||||
Folder(const FilePath& _filePath);
|
||||
~Folder();
|
||||
~Folder() = default;
|
||||
|
||||
/// <summary>Get the file path of the folder.</summary>
|
||||
/// <returns>The file path.</returns>
|
||||
|
||||
Reference in New Issue
Block a user