#include <iostream> #include <fstream> #include <string> #include <curl/curl.h> #include…
- User
#include #include #include #include <curl/curl.h> #include #include #include <windows.h> #include "nlohmann/json.hpp" // Ensure this points correctly to the json.hpp file from nlohmann/json
// Make sure you are using the nlohmann json namespace using json = nlohmann::json;
// Curl write callback std::size_t writeCallback(void* contents, std::size_t size, std::size_t nmemb, std::string* s) { size_t newLength = size * nmemb; try { s->append((char*)contents, newLength); } catch (std::bad_alloc& e) { // Handle memory bad_alloc error return 0; } return newLength; }
// Function to perform HTTP GET request bool performRequest(const std::string& url, const std::string& savePath) { CURL* curl = curl_easy_init(); if (!curl) { std::cerr << "Curl initialization failed!" << std::endl; return false; }
codeCURLcode res; std::string response_string; curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string); res = curl_easy_perform(curl); if (res != CURLE_OK) { std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl; curl_easy_cleanup(curl); return false; } std::ofstream outFile(savePath); if (!outFile.is_open()) { std::cerr << "Failed to open " << savePath << std::endl; curl_easy_cleanup(curl); return false; } outFile << response_string; outFile.close(); curl_easy_cleanup(curl); return true;}
// Function to load JSON configuration json loadConfig(const std::string& configPath) { std::ifstream configFile(configPath); json configJson; if (configFile.is_open()) { configFile >> configJson; } else { std::cerr << "Unable to open config file" << std::endl; std::exit(EXIT_FAILURE); } return configJson; }
// Function to launch and wait for an external process void launchAndWait(const std::string& executablePath) { STARTUPINFOA si; // Specific use of STARTUPINFOA for ANSI characters. ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); PROCESS_INFORMATION pi;
code - Assistant
- User
The executable should run in the background, and add a trigger when closing a particular exe + its name in the config
- Assistant
- User
The main application should be closed after another application is closed by a trigger
- Assistant
- User
Severity Code Description Project File Line Suppression State Details Error C2440 '': cannot convert from 'WCHAR [260]' to 'std::string' CoopLoader C:\Users\artem\Desktop\singleplayer_to_multiplayer_v_0.2\CoopLoader\CoopLoader\CoopLoader\CoopLoader.cpp 77 Error (active) E0289 no instance of constructor "std::basic_string<_Elem, _Traits, _Alloc>::basic_string [with _Elem=char, _Traits=std::char_traits, _Alloc=std::allocator]" matches the argument list CoopLoader C:\Users\artem\Desktop\singleplayer_to_multiplayer_v_0.2\CoopLoader\CoopLoader\CoopLoader\CoopLoader.cpp 77
Fix that errors
- Assistant
- User
bool isProcessRunning(const std::string& processName) { HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot) { PROCESSENTRY32 pe32; pe32.dwSize = sizeof(PROCESSENTRY32); if (Process32First(hSnapshot, &pe32)) { do { if (std::string(pe32.szExeFile) == processName) { CloseHandle(hSnapshot); return true; } } while (Process32Next(hSnapshot, &pe32)); } CloseHandle(hSnapshot); } return false;
Fix the part of the code
- Assistant