[General] Small refactoring
This commit is contained in:
parent
77bda3aea3
commit
9d08e84627
@ -202,7 +202,7 @@ namespace Components
|
||||
return false;
|
||||
}
|
||||
|
||||
Utils::IO::CreateDirectory(download->mod);
|
||||
Utils::IO::CreateDir(download->mod);
|
||||
Utils::IO::WriteFile(path, fDownload.buffer);
|
||||
|
||||
return true;
|
||||
|
@ -346,7 +346,7 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
Utils::IO::CreateDirectory(Utils::String::VA("raw/mapdump/%s/textures", world->baseName));
|
||||
Utils::IO::CreateDir(Utils::String::VA("raw/mapdump/%s/textures", world->baseName));
|
||||
mtl.append(Utils::String::VA("# Material Count: %d\n", materialCount));
|
||||
|
||||
Logger::Print("Exporting materials and faces...\n");
|
||||
|
@ -139,17 +139,17 @@ namespace Components
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Minidump uploader class implementation
|
||||
const std::string MinidumpUpload::queuedMinidumpsFolder = "minidumps\\";
|
||||
const std::string MinidumpUpload::QueuedMinidumpsFolder = "minidumps\\";
|
||||
|
||||
#ifdef DISABLE_BITMESSAGE
|
||||
const std::vector<std::string> MinidumpUpload::targetUrls =
|
||||
const std::vector<std::string> MinidumpUpload::TargetUrls =
|
||||
{
|
||||
"https://reich.io/upload.php",
|
||||
"https://hitlers.kz/upload.php"
|
||||
};
|
||||
#else
|
||||
const std::string MinidumpUpload::targetAddress = "BM-2cSksR7gyyFcNK7MaFoxGCjRJWxtoGckdj";
|
||||
const unsigned int MinidumpUpload::maxSegmentSize = 200 * 1024; // 200 kB
|
||||
const std::string MinidumpUpload::TargetAddress = "BM-2cSksR7gyyFcNK7MaFoxGCjRJWxtoGckdj";
|
||||
const unsigned int MinidumpUpload::MaxSegmentSize = 200 * 1024; // 200 kB
|
||||
#endif
|
||||
|
||||
MinidumpUpload::MinidumpUpload()
|
||||
@ -168,24 +168,9 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
bool MinidumpUpload::EnsureQueuedMinidumpsFolderExists()
|
||||
{
|
||||
BOOL success = CreateDirectoryA(MinidumpUpload::queuedMinidumpsFolder.data(), nullptr);
|
||||
|
||||
if (success != TRUE)
|
||||
{
|
||||
success = (GetLastError() == ERROR_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
return (success == TRUE);
|
||||
}
|
||||
|
||||
Minidump* MinidumpUpload::CreateQueuedMinidump(LPEXCEPTION_POINTERS exceptionInfo, int minidumpType)
|
||||
{
|
||||
// Note that most of the Path* functions are DEPRECATED and they have been replaced by Cch variants that only work on Windows 8+.
|
||||
// If you plan to drop support for Windows 7, please upgrade these calls to prevent accidental buffer overflows!
|
||||
|
||||
if (!EnsureQueuedMinidumpsFolderExists()) return nullptr;
|
||||
Utils::IO::CreateDir(MinidumpUpload::QueuedMinidumpsFolder);
|
||||
|
||||
// Current executable name
|
||||
char exeFileName[MAX_PATH];
|
||||
@ -203,7 +188,7 @@ namespace Components
|
||||
|
||||
// Combine with queuedMinidumpsFolder
|
||||
char filename[MAX_PATH] = { 0 };
|
||||
PathCombineA(filename, MinidumpUpload::queuedMinidumpsFolder.data(), Utils::String::VA("%s-" VERSION "-%s.dmp", exeFileName, filenameFriendlyTime));
|
||||
PathCombineA(filename, MinidumpUpload::QueuedMinidumpsFolder.data(), Utils::String::VA("%s-" VERSION "-%s.dmp", exeFileName, filenameFriendlyTime));
|
||||
|
||||
// Generate the dump
|
||||
return Minidump::Create(filename, exceptionInfo, minidumpType);
|
||||
@ -214,28 +199,28 @@ namespace Components
|
||||
#ifndef DISABLE_BITMESSAGE
|
||||
// Preload public key for our target that will receive minidumps
|
||||
Logger::Print("About to send request for public key for minidump upload address.\n");
|
||||
if (!BitMessage::RequestPublicKey(MinidumpUpload::targetAddress))
|
||||
if (!BitMessage::RequestPublicKey(MinidumpUpload::TargetAddress))
|
||||
{
|
||||
Logger::Error("Failed to request public key for minidump collection address.\n");
|
||||
}
|
||||
Logger::Print("Waiting for public key for minidump upload address.\n");
|
||||
if (!BitMessage::WaitForPublicKey(MinidumpUpload::targetAddress))
|
||||
if (!BitMessage::WaitForPublicKey(MinidumpUpload::TargetAddress))
|
||||
{
|
||||
Logger::Error("Failed to fetch public key for minidump collection address.\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Check if folder exists
|
||||
if (!PathIsDirectoryA(MinidumpUpload::queuedMinidumpsFolder.data()))
|
||||
if (!PathIsDirectoryA(MinidumpUpload::QueuedMinidumpsFolder.data()))
|
||||
{
|
||||
// Nothing to upload
|
||||
Logger::Print("No minidumps to upload.\n");
|
||||
return PathFileExistsA(MinidumpUpload::queuedMinidumpsFolder.data()) == FALSE;
|
||||
return PathFileExistsA(MinidumpUpload::QueuedMinidumpsFolder.data()) == FALSE;
|
||||
}
|
||||
|
||||
// Walk through directory and search for valid minidumps
|
||||
WIN32_FIND_DATAA ffd;
|
||||
HANDLE hFind = FindFirstFileA(Utils::String::VA("%s\\*.dmp", MinidumpUpload::queuedMinidumpsFolder.data()), &ffd);
|
||||
HANDLE hFind = FindFirstFileA(Utils::String::VA("%s\\*.dmp", MinidumpUpload::QueuedMinidumpsFolder.data()), &ffd);
|
||||
if (hFind != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
do
|
||||
@ -243,7 +228,7 @@ namespace Components
|
||||
if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) continue; // ignore directory
|
||||
|
||||
char fullPath[MAX_PATH_SIZE];
|
||||
PathCombineA(fullPath, MinidumpUpload::queuedMinidumpsFolder.data(), ffd.cFileName);
|
||||
PathCombineA(fullPath, MinidumpUpload::QueuedMinidumpsFolder.data(), ffd.cFileName);
|
||||
|
||||
// Only upload if less than 5MB
|
||||
if(Utils::IO::FileSize(fullPath) > (5 * 1024 * 1024)) continue;
|
||||
@ -309,7 +294,7 @@ namespace Components
|
||||
|
||||
#ifdef DISABLE_BITMESSAGE
|
||||
|
||||
for (auto& targetUrl : targetUrls)
|
||||
for (auto& targetUrl : TargetUrls)
|
||||
{
|
||||
Utils::WebIO webio("Firefucks", targetUrl);
|
||||
|
||||
@ -348,19 +333,19 @@ namespace Components
|
||||
return false;
|
||||
#else
|
||||
// BitMessage has a max msg size that is somewhere around 220 KB, split it up as necessary!
|
||||
auto totalParts = compressedMinidump.size() / MinidumpUpload::maxSegmentSize + 1;
|
||||
auto totalParts = compressedMinidump.size() / MinidumpUpload::MaxSegmentSize + 1;
|
||||
extraHeaders.insert({ "Parts", Utils::String::VA("%d", totalParts) });
|
||||
|
||||
for (size_t offset = 0; offset < compressedMinidump.size(); offset += MinidumpUpload::maxSegmentSize)
|
||||
for (size_t offset = 0; offset < compressedMinidump.size(); offset += MinidumpUpload::MaxSegmentSize)
|
||||
{
|
||||
auto extraPartHeaders = extraHeaders;
|
||||
|
||||
auto part = compressedMinidump.substr(offset, std::min(MinidumpUpload::maxSegmentSize, compressedMinidump.size() - offset));
|
||||
auto partNum = offset / MinidumpUpload::maxSegmentSize + 1;
|
||||
auto part = compressedMinidump.substr(offset, std::min(MinidumpUpload::MaxSegmentSize, compressedMinidump.size() - offset));
|
||||
auto partNum = offset / MinidumpUpload::MaxSegmentSize + 1;
|
||||
extraPartHeaders.insert({ "Part", Utils::String::VA("%d", partNum) });
|
||||
|
||||
Logger::Print("Uploading minidump %s (part %d out of %d, %d bytes)...\n", id.data(), partNum, totalParts, part.size());
|
||||
BitMessage::SendMsg(MinidumpUpload::targetAddress, MinidumpUpload::Encode(part, extraPartHeaders));
|
||||
BitMessage::SendMsg(MinidumpUpload::TargetAddress, MinidumpUpload::Encode(part, extraPartHeaders));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -57,17 +57,14 @@ namespace Components
|
||||
// Internally, this will compress the minidump and decorate it with proper markers and first-look headers.
|
||||
static std::string Encode(std::string data, std::map<std::string, std::string> extraHeaders = {});
|
||||
|
||||
// Ensures the queued minidumps folder exists. Will return false if the directory can't be created and does not exist.
|
||||
static bool EnsureQueuedMinidumpsFolderExists();
|
||||
|
||||
// Contains the path to the minidumps folder.
|
||||
static const std::string queuedMinidumpsFolder;
|
||||
static const std::string QueuedMinidumpsFolder;
|
||||
|
||||
#ifdef DISABLE_BITMESSAGE
|
||||
static const std::vector<std::string> targetUrls;
|
||||
static const std::vector<std::string> TargetUrls;
|
||||
#else
|
||||
static const std::string targetAddress;
|
||||
static const unsigned int maxSegmentSize;
|
||||
static const std::string TargetAddress;
|
||||
static const unsigned int MaxSegmentSize;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace Utils
|
||||
auto pos = file.find_last_of("/\\");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
CreateDirectory(file.substr(0, pos));
|
||||
CreateDir(file.substr(0, pos));
|
||||
}
|
||||
|
||||
std::ofstream stream(file, std::ios::binary | std::ofstream::out | (append ? std::ofstream::app : std::ofstream::out));
|
||||
@ -78,7 +78,7 @@ namespace Utils
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CreateDirectory(std::string dir)
|
||||
bool CreateDir(std::string dir)
|
||||
{
|
||||
return std::experimental::filesystem::create_directories(dir);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace Utils
|
||||
bool ReadFile(std::string file, std::string* data);
|
||||
size_t FileSize(std::string file);
|
||||
std::string ReadFile(std::string file);
|
||||
bool CreateDirectory(std::string dir);
|
||||
bool CreateDir(std::string dir);
|
||||
std::vector<std::string> ListFiles(std::string dir);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user