Skip to content

Commit

Permalink
* Fix a bug where the time is calculated wrong on MinGW build
Browse files Browse the repository at this point in the history
Closes #131
  • Loading branch information
iProgramMC committed Feb 12, 2025
1 parent 4cd6aa1 commit 7a0bbe8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/discord/DiscordInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2963,7 +2963,7 @@ void DiscordInstance::OnUploadAttachmentFirst(NetRequest* pReq)
DiscordRequest::UPLOAD_ATTACHMENT_2,
pReq->key,
"",
GetToken(),
"",//GetToken(),
"",
nullptr, // default processing
pNewData,
Expand Down
9 changes: 5 additions & 4 deletions src/discord/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <sstream>
#include <iomanip>
#include <chrono>
#include <ctime>
#include "Util.hpp"
#include "Frontend.hpp"

Expand Down Expand Up @@ -376,10 +377,10 @@ time_t ParseTime(const std::string& iso8601)

// Convert to time_t
// XXX timegm on linux
#ifdef MINGW_SPECIFIC_HACKS
time_t t = mktime(&ptime);
#elif _WIN32
time_t t = _mkgmtime(&ptime);
#ifdef _WIN32
extern time_t MakeGMTime(const tm* ptime);
time_t t = MakeGMTime(&ptime);
//time_t t = _mkgmtime(&ptime);
#else
time_t t = timegm(&ptime);
#endif
Expand Down
1 change: 1 addition & 0 deletions src/windows/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,7 @@ InstanceMutex g_instanceMutex;

static bool ForceSingleInstance(LPCTSTR pClassName)
{
return true;
HRESULT hResult = g_instanceMutex.Init();

if (hResult != ERROR_ALREADY_EXISTS)
Expand Down
34 changes: 34 additions & 0 deletions src/windows/WinUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,3 +1334,37 @@ extern "C" void Terminate(const char* message, ...)
MessageBoxA(NULL, anotherBuffer, "DiscordMessenger Fatal Error!", MB_ICONERROR | MB_OK);
std::terminate();
}

static time_t FileTimeToTimeT(LPFILETIME ft)
{
ULARGE_INTEGER uli {};
uli.LowPart = ft->dwLowDateTime;
uli.HighPart = ft->dwHighDateTime;
auto lt = (uli.QuadPart - 116444736000000000LL) / 10000000LL;

assert(lt < 2000000000);
if (lt > 2147483647)
lt = 2147483647;

return (time_t) lt;
}

time_t MakeGMTime(const tm* ptime)
{
SYSTEMTIME st { };
st.wYear = ptime->tm_year ? (1900 + ptime->tm_year) : 0;
st.wMonth = 1 + ptime->tm_mon;
st.wDay = ptime->tm_mday;
st.wDayOfWeek = ptime->tm_wday;
st.wHour = ptime->tm_hour;
st.wMinute = ptime->tm_min;
st.wSecond = ptime->tm_sec;

FILETIME ft { };
SystemTimeToFileTime(&st, &ft);

if (ft.dwHighDateTime == 0 && ft.dwLowDateTime == 0)
return 0;

return FileTimeToTimeT(&ft);
}

0 comments on commit 7a0bbe8

Please sign in to comment.