diff --git a/globals.cpp b/globals.cpp index 85ff0e3..8318b80 100644 --- a/globals.cpp +++ b/globals.cpp @@ -1,4 +1,5 @@ #include +#include #include "globals.h" // Points to the system-specific designated cache directory @@ -18,6 +19,8 @@ const std::filesystem::path APP_DIR = std::filesystem::path(std::getenv("APPDATA // Points to last known Portal 2 game files directory std::filesystem::path GAME_DIR; +// Points to info/error log file (set during runtime) +std::ofstream LOGFILE; // Points to the external repository file const std::filesystem::path REPO_PATH = APP_DIR / "repositories.txt"; diff --git a/globals.h b/globals.h index 346b00a..18c148a 100644 --- a/globals.h +++ b/globals.h @@ -2,6 +2,7 @@ #define GLOBALS_H #include +#include // Comment this line to target Linux, uncomment to target Windows // #define TARGET_WINDOWS @@ -10,6 +11,7 @@ extern std::filesystem::path CACHE_DIR; extern bool CACHE_ENABLE; extern const std::filesystem::path APP_DIR; extern std::filesystem::path GAME_DIR; +extern std::ofstream LOGFILE; extern const std::filesystem::path REPO_PATH; extern int SPPLICE_INSTALL_STATE; extern int SPPLICE_NETCON_PORT; diff --git a/main.cpp b/main.cpp index 729a991..4cf4fe1 100644 --- a/main.cpp +++ b/main.cpp @@ -96,7 +96,7 @@ void checkCacheOverride (const std::filesystem::path &configPath) { std::ifstream configFile(configPath); if (!configFile.is_open()) { - std::cerr << "Failed to open " << configPath << " for reading." << std::endl; + std::cerr << "[E] Failed to open " << configPath.c_str() << " for reading." << std::endl; return; } @@ -105,7 +105,7 @@ void checkCacheOverride (const std::filesystem::path &configPath) { configFile.close(); if (!std::filesystem::exists(customCacheDir)) { - std::cerr << "Invalid cache directory " << customCacheDir << "." << std::endl; + std::cerr << "[E] Invalid cache directory " << customCacheDir.c_str() << "." << std::endl; return; } @@ -127,14 +127,16 @@ int main (int argc, char *argv[]) { try { // Ensure CACHE_DIR exists std::filesystem::create_directories(CACHE_DIR); } catch (const std::filesystem::filesystem_error& e) { - std::cerr << "Failed to create temporary directory " << CACHE_DIR << ": " << e.what() << std::endl; + std::cerr << "[E] Failed to create temporary directory " << CACHE_DIR.c_str() << ": " << e.what() << std::endl; } try { // Ensure APP_DIR exists std::filesystem::create_directories(APP_DIR); } catch (const std::filesystem::filesystem_error& e) { - std::cerr << "Failed to create application directory " << APP_DIR << ": " << e.what() << std::endl; + std::cerr << "[E] Failed to create application directory " << APP_DIR.c_str() << ": " << e.what() << std::endl; } + // Open the log file + LOGFILE = std::ofstream(APP_DIR / "log.txt"); // Set up high-DPI scaling QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); @@ -187,7 +189,7 @@ int main (int argc, char *argv[]) { if (!CACHE_ENABLE) { std::ofstream disableCacheFile(APP_DIR / "disable_cache"); if (!disableCacheFile.is_open()) { - std::cerr << "Failed to create disable_cache file." << std::endl; + LOGFILE << "[E] Failed to create disable_cache file." << std::endl; } } else { std::filesystem::remove(APP_DIR / "disable_cache"); @@ -229,7 +231,7 @@ int main (int argc, char *argv[]) { // Write the new cache directory to the config file std::ofstream configFile(APP_DIR / "cache_dir.txt"); if (!configFile.is_open()) { - std::cerr << "Failed to open cache config file for writing." << std::endl; + LOGFILE << "[E] Failed to open cache config file for writing." << std::endl; } else { configFile << CACHE_DIR.string(); } diff --git a/tools/curl.cpp b/tools/curl.cpp index 8e951cc..0afc3a6 100644 --- a/tools/curl.cpp +++ b/tools/curl.cpp @@ -43,7 +43,7 @@ bool ToolsCURL::downloadFile (const std::string &url, const std::filesystem::pat std::ofstream ofs(outputPath, std::ios::binary); if (!ofs.is_open()) { - std::cerr << "Failed to open file for writing: " << outputPath << std::endl; + LOGFILE << "[E] Failed to open file for writing: " << outputPath.c_str() << std::endl; return false; } @@ -51,7 +51,7 @@ bool ToolsCURL::downloadFile (const std::string &url, const std::filesystem::pat CURL *curl = curl_easy_init(); if (!curl) { - std::cerr << "Failed to initialize CURL" << std::endl; + LOGFILE << "[E] Failed to initialize CURL" << std::endl; return false; } @@ -67,7 +67,7 @@ bool ToolsCURL::downloadFile (const std::string &url, const std::filesystem::pat curl_easy_cleanup(curl); if (response != CURLE_OK) { - std::cerr << "Failed to download file from \"" << url << "\": " << curl_easy_strerror(response) << std::endl; + LOGFILE << "[E] Failed to download file from \"" << url.c_str() << "\": " << curl_easy_strerror(response) << std::endl; return false; } @@ -82,7 +82,7 @@ std::string ToolsCURL::downloadString (const std::string &url) { CURL *curl = curl_easy_init(); if (!curl) { - std::cerr << "Failed to initialize CURL" << std::endl; + LOGFILE << "[E] Failed to initialize CURL" << std::endl; return ""; } @@ -99,7 +99,7 @@ std::string ToolsCURL::downloadString (const std::string &url) { // Check for errors if (response != CURLE_OK) { - std::cerr << "Failed to download string from \"" << url << "\": " << curl_easy_strerror(response) << std::endl; + LOGFILE << "[E] Failed to download string from \"" << url.c_str() << "\": " << curl_easy_strerror(response) << std::endl; return ""; } @@ -117,7 +117,7 @@ CURL* ToolsCURL::wsConnect (const std::string &url) { CURL *curl = curl_easy_init(); if (!curl) { - std::cerr << "Failed to initialize CURL" << std::endl; + LOGFILE << "[E] Failed to initialize CURL" << std::endl; return nullptr; } @@ -129,7 +129,7 @@ CURL* ToolsCURL::wsConnect (const std::string &url) { // Check for errors if (response != CURLE_OK) { - std::cerr << "Failed to connect to \"" << url << "\": " << curl_easy_strerror(response) << std::endl; + LOGFILE << "[E] Failed to connect to \"" << url.c_str() << "\": " << curl_easy_strerror(response) << std::endl; return nullptr; } @@ -157,7 +157,7 @@ bool ToolsCURL::wsSend (CURL *curl, const std::string &message) { // Log errors, return false if response not OK if (response != CURLE_OK) { - std::cerr << "Failed to send message to WebSocket: " << curl_easy_strerror(response) << std::endl; + LOGFILE << "[E] Failed to send message to WebSocket: " << curl_easy_strerror(response) << std::endl; return false; } @@ -180,7 +180,7 @@ std::string ToolsCURL::wsReceive (CURL *curl, size_t size) { // Log errors, return empty string if response not OK if (response != CURLE_OK) { - std::cerr << "Failed to receive message from WebSocket: " << curl_easy_strerror(response) << std::endl; + LOGFILE << "[E] Failed to receive message from WebSocket: " << curl_easy_strerror(response) << std::endl; return ""; } diff --git a/tools/install.cpp b/tools/install.cpp index 822885f..7bd59ff 100644 --- a/tools/install.cpp +++ b/tools/install.cpp @@ -50,7 +50,7 @@ bool ToolsInstall::extractLocalFile (const std::filesystem::path path, const std archive_write_disk_set_options(extracted, ARCHIVE_EXTRACT_TIME); if ((r = archive_read_open_filename_w(archive, path.wstring().c_str(), 10240))) { - std::cerr << "Could not open file: " << archive_error_string(archive) << std::endl; + LOGFILE << "[E] Could not open file: " << archive_error_string(archive) << std::endl; return false; } @@ -60,7 +60,7 @@ bool ToolsInstall::extractLocalFile (const std::filesystem::path path, const std std::filesystem::path full_path = dest / archive_entry_pathname(entry); archive_entry_set_pathname_utf8(entry, full_path.string().c_str()); - std::cout << "Extracting: " << archive_entry_pathname(entry) << std::endl; + LOGFILE << "[I] Extracting: " << archive_entry_pathname(entry) << std::endl; archive_write_header(extracted, entry); const void* buff; @@ -71,13 +71,13 @@ bool ToolsInstall::extractLocalFile (const std::filesystem::path path, const std r = archive_read_data_block(archive, &buff, &size, &offset); if (r == ARCHIVE_EOF) break; if (r != ARCHIVE_OK) { - std::cerr << "Archive read error: " << archive_error_string(archive) << std::endl; + LOGFILE << "[E] Archive read error: " << archive_error_string(archive) << std::endl; output = false; break; } r = archive_write_data_block(extracted, buff, size, offset); if (r != ARCHIVE_OK) { - std::cerr << "Archive write error: " << archive_error_string(extracted) << std::endl; + LOGFILE << "[E] Archive write error: " << archive_error_string(extracted) << std::endl; output = false; break; } @@ -183,13 +183,13 @@ bool startPortal2 (const std::vector extraArgs) { std::string steamPath = ToolsInstall::getProcessPath("steam"); if (steamPath.length() == 0) { - std::cerr << "Failed to find Steam process path. Is Steam running?" << std::endl; + LOGFILE << "[E] Failed to find Steam process path. Is Steam running?" << std::endl; return false; } pid_t pid = fork(); if (pid == -1) { - std::cerr << "Failed to fork process." << std::endl; + LOGFILE << "[E] Failed to fork process." << std::endl; return false; } @@ -218,7 +218,7 @@ bool startPortal2 (const std::vector extraArgs) { execv(steamPath.c_str(), const_cast(args.data())); // execv only returns on error - std::cerr << "Failed to call Steam binary from fork." << std::endl; + LOGFILE << "[E] Failed to call Steam binary from fork." << std::endl; // If the above failed, revert to using the Steam browser protocol std::string command = "xdg-open steam://run/620//-tempcontent"; @@ -229,7 +229,7 @@ bool startPortal2 (const std::vector extraArgs) { } if (system(command.c_str()) != 0) { - std::cerr << "Failed to open Steam URI." << std::endl; + LOGFILE << "[E] Failed to open Steam URI." << std::endl; } // Exit from the child process @@ -245,7 +245,7 @@ bool startPortal2 (const std::vector extraArgs) { std::wstring steamPath = ToolsInstall::getProcessPath("steam.exe"); if (steamPath.length() == 0) { - std::cerr << "Failed to find Steam process path. Is Steam running?" << std::endl; + LOGFILE << "[E] Failed to find Steam process path. Is Steam running?" << std::endl; return false; } @@ -301,7 +301,7 @@ bool startPortal2 (const std::vector extraArgs) { bool linkDirectory (const std::filesystem::path target, const std::filesystem::path linkName) { if (symlink(target.c_str(), linkName.c_str()) != 0) { - std::cerr << "Failed to create symbolic link " << target << " -> " << linkName << std::endl; + LOGFILE << "[E] Failed to create symbolic link " << target.c_str() << " -> " << linkName.c_str() << std::endl; return false; } return true; @@ -334,7 +334,7 @@ bool linkDirectory (const std::filesystem::path target, const std::filesystem::p wcscat(szTarget, L"\\"); if (!CreateDirectoryW(szJunction, NULL)) { - std::cerr << "Failed to create directory for junction " << linkName << ": " << GetLastError() << std::endl; + LOGFILE << "[E] Failed to create directory for junction " << linkName.c_str() << ": " << GetLastError() << std::endl; return false; } @@ -342,24 +342,24 @@ bool linkDirectory (const std::filesystem::path target, const std::filesystem::p HANDLE hToken = NULL; TOKEN_PRIVILEGES tp; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) { - std::cerr << "Failed to open process token: " << GetLastError() << std::endl; + LOGFILE << "[E] Failed to open process token: " << GetLastError() << std::endl; return false; } if (!LookupPrivilegeValue(NULL, SE_RESTORE_NAME, &tp.Privileges[0].Luid)) { - std::cerr << "Failed to look up SE_RESTORE_NAME privilege: " << GetLastError() << std::endl; + LOGFILE << "[E] Failed to look up SE_RESTORE_NAME privilege: " << GetLastError() << std::endl; return false; } tp.PrivilegeCount = 1; tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) { - std::cerr << "Failed to adjust process privileges: " << GetLastError() << std::endl; + LOGFILE << "[E] Failed to adjust process privileges: " << GetLastError() << std::endl; return false; } if (hToken) CloseHandle(hToken); HANDLE hDir = CreateFileW(szJunction, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, NULL); if (hDir == INVALID_HANDLE_VALUE) { - std::cerr << "Failed to create junction file " << linkName << ": " << GetLastError() << std::endl; + LOGFILE << "[E] Failed to create junction file " << linkName.c_str() << ": " << GetLastError() << std::endl; return false; } @@ -380,7 +380,7 @@ bool linkDirectory (const std::filesystem::path target, const std::filesystem::p CloseHandle(hDir); RemoveDirectoryW(szJunction); - std::cerr << "Failed to create reparse point " << target << " -> " << linkName << ": " << dr << std::endl; + LOGFILE << "[E] Failed to create reparse point " << target.c_str() << " -> " << linkName.c_str() << ": " << dr << std::endl; return false; } @@ -395,7 +395,7 @@ bool linkDirectory (const std::filesystem::path target, const std::filesystem::p bool linkFile (const std::filesystem::path target, const std::filesystem::path linkName) { if (symlink(target.c_str(), linkName.c_str()) != 0) { - std::cerr << "Failed to create symbolic link " << target << " -> " << linkName << std::endl; + LOGFILE << "[E] Failed to create symbolic link " << target.c_str() << " -> " << linkName.c_str() << std::endl; return false; } return true; @@ -412,7 +412,7 @@ bool linkFile (const std::filesystem::path target, const std::filesystem::path l BOOL result = CreateHardLinkW(linkNameWStr.c_str(), targetWStr.c_str(), NULL); if (result == 0) { - std::cerr << "Failed to create hard link " << target << " -> " << linkName << ": " << GetLastError() << std::endl; + LOGFILE << "[E] Failed to create hard link " << target.c_str() << " -> " << linkName.c_str() << ": " << GetLastError() << std::endl; return false; } return true; @@ -425,7 +425,7 @@ bool linkFile (const std::filesystem::path target, const std::filesystem::path l bool unlinkDirectory (const std::filesystem::path target) { if (unlink(target.c_str()) != 0) { - std::cerr << "Failed to remove symbolic link " << target << std::endl; + LOGFILE << "[E] Failed to remove symbolic link " << target.c_str() << std::endl; return false; } return true; @@ -446,7 +446,7 @@ bool unlinkDirectory (const std::filesystem::path target) { if (success) { return true; } else { - std::cerr << "Failed to remove junction " << target << ": " << GetLastError() << std::endl; + LOGFILE << "[E] Failed to remove junction " << target.c_str() << ": " << GetLastError() << std::endl; return false; } @@ -458,7 +458,7 @@ bool isDirectoryLink (const std::filesystem::path linkName) { struct stat path_stat; if (lstat(linkName.c_str(), &path_stat) != 0) { - std::cerr << "Failed to stat path " << linkName << std::endl; + LOGFILE << "[E] Failed to stat path " << linkName.c_str() << std::endl; return false; } return S_ISLNK(path_stat.st_mode); @@ -470,7 +470,7 @@ bool isDirectoryLink (const std::filesystem::path linkName) { DWORD attributes = GetFileAttributesW(linkName.wstring().c_str()); if (attributes == INVALID_FILE_ATTRIBUTES) { - std::cerr << "Failed to get file attributes for " << linkName << std::endl; + LOGFILE << "[E] Failed to get file attributes for " << linkName.c_str() << std::endl; return false; } @@ -534,7 +534,7 @@ std::string ToolsInstall::installPackageFile (const std::filesystem::path packag #endif GAME_DIR = std::filesystem::path(gameProcessPath).parent_path(); - std::cout << "Found Portal 2 at " << GAME_DIR << std::endl; + LOGFILE << "[I] Found Portal 2 at " << GAME_DIR.c_str() << std::endl; std::filesystem::path tempcontentPath = GAME_DIR / "portal2_tempcontent"; diff --git a/tools/js.cpp b/tools/js.cpp index d598c24..67a8f06 100644 --- a/tools/js.cpp +++ b/tools/js.cpp @@ -38,12 +38,12 @@ struct customJS { int argc = duk_get_top(ctx); - std::cout << "[JS] "; + LOGFILE << "[JS I] " << std::endl; for (int i = 0; i < argc; i ++) { const char *str = duk_to_string(ctx, i); - if (str) std::cout << str << " "; + if (str) LOGFILE << str << " " << std::endl; } - std::cout << std::endl; + LOGFILE << std::endl; return 0; @@ -52,12 +52,12 @@ struct customJS { int argc = duk_get_top(ctx); - std::cerr << "[JS] "; + LOGFILE << "[JS E] " << std::endl; for (int i = 0; i < argc; i ++) { const char *str = duk_to_string(ctx, i); - if (str) std::cerr << str << " "; + if (str) LOGFILE << str << " "; } - std::cerr << std::endl; + LOGFILE << std::endl; return 0; @@ -195,7 +195,7 @@ struct customJS { #ifdef TARGET_WINDOWS const HWND m_hEngine = FindWindowA("Valve001", 0); if (m_hEngine == NULL) { - std::cerr << "Failed to find engine window." << std::endl; + LOGFILE << "[E] Failed to find engine window." << std::endl; return duk_generic_error(ctx, "game.send: Failed to send command"); } @@ -235,14 +235,14 @@ struct customJS { // Open the file in binary mode std::ifstream file(logPath, std::ios::binary); if (!file) { - std::cerr << "Failed to open file: " << logPath << std::endl; + LOGFILE << "[E] Failed to open file: " << logPath.c_str() << std::endl; return duk_generic_error(ctx, "game.read: Failed to read from socket"); } // Seek to the desired offset, return to start of file on failure file.seekg(consoleLogOffset); if (!file) { - std::cerr << "Failed to seek to offset: " << consoleLogOffset << std::endl; + LOGFILE << "[E] Failed to seek to offset: " << consoleLogOffset << std::endl; consoleLogOffset = 0; duk_push_string(ctx, ""); return 1; @@ -395,7 +395,7 @@ void ToolsJS::runFile (const std::filesystem::path &filePath) { // Check if the input file exists if (!std::filesystem::exists(filePath)) { - std::cerr << "JavaScript file " << filePath << " not found." << std::endl; + LOGFILE << "[E] JavaScript file " << filePath.c_str() << " not found." << std::endl; return; } @@ -465,7 +465,7 @@ void ToolsJS::runFile (const std::filesystem::path &filePath) { const std::string code = fileBuffer.str(); duk_push_lstring(ctx, code.c_str(), code.length()); if (duk_peval(ctx) != 0) { - std::cerr << "[" << filePath.string() << "] " << duk_safe_to_string(ctx, -1) << std::endl; + LOGFILE << "[E] [" << filePath.c_str() << "] " << duk_safe_to_string(ctx, -1) << std::endl; } // Clean up the context diff --git a/tools/netcon.cpp b/tools/netcon.cpp index 62deffc..c425ada 100644 --- a/tools/netcon.cpp +++ b/tools/netcon.cpp @@ -42,7 +42,7 @@ int ToolsNetCon::attemptConnection () { if (++openSockets == 1) { WSADATA wsaData; if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { - std::cerr << "WSAStartup failed." << std::endl; + LOGFILE << "[E] WSAStartup failed." << std::endl; return -1; } } @@ -51,7 +51,7 @@ int ToolsNetCon::attemptConnection () { // Create a socket int sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { - std::cerr << "Failed to create a network socket for TCP console." << std::endl; + LOGFILE << "[E] Failed to create a network socket for TCP console." << std::endl; return -1; } @@ -79,7 +79,7 @@ bool ToolsNetCon::sendCommand (int sockfd, std::string command) { // Attempt to send data if (send(sockfd, command.c_str(), command.length(), 0) < 0) { - std::cerr << "Failed to send command to TCP console server." << std::endl; + LOGFILE << "[E] Failed to send command to TCP console server." << std::endl; return false; } return true; @@ -107,7 +107,7 @@ std::string ToolsNetCon::readConsole (int sockfd, size_t size) { // Handle the poll result if (result == SOCKET_ERROR) { - std::cerr << "Failed to receive data from TCP console server." << std::endl; + LOGFILE << "[E] Failed to receive data from TCP console server." << std::endl; // Return ASCII End of Transmission return "\x04"; } else if (result == 0 || !(pfd.revents & POLLIN)) { @@ -122,7 +122,7 @@ std::string ToolsNetCon::readConsole (int sockfd, size_t size) { // Attempt to receive data int received = recv(sockfd, buffer, size, 0); if (received <= 0) { - std::cerr << "Failed to receive data from TCP console server." << std::endl; + LOGFILE << "[E] Failed to receive data from TCP console server." << std::endl; // Return ASCII End of Transmission return "\x04"; } diff --git a/tools/package.cpp b/tools/package.cpp index b7971d9..b678a35 100644 --- a/tools/package.cpp +++ b/tools/package.cpp @@ -133,10 +133,10 @@ void PackageItemWorker::installPackage (const ToolsPackage::PackageData *package // Download the package file if we don't have a valid cache if (CACHE_ENABLE && validateFileVersion(filePath, package->version)) { - std::cout << "Cached package found, skipping download" << std::endl; + LOGFILE << "[I] Cached package found, skipping download" << std::endl; } else { if (CACHE_ENABLE && !updateFileVersion(filePath, package->version)) { - std::cout << "Couldn't open package version file for writing" << std::endl; + LOGFILE << "[W] Couldn't open package version file for writing" << std::endl; } if (!ToolsCURL::downloadFile(package->file, filePath)) { ToolsQT::displayErrorPopup("Installation aborted", "Failed to download package file."); diff --git a/tools/repo.cpp b/tools/repo.cpp index 0f1f3e3..38108ee 100644 --- a/tools/repo.cpp +++ b/tools/repo.cpp @@ -52,17 +52,17 @@ void ToolsRepo::writeToFile (const std::string &url) { if (line == url) return; } } else { - std::cerr << "Failed to open " << REPO_PATH << " for reading." << std::endl; + LOGFILE << "[E] Failed to open " << REPO_PATH.c_str() << " for reading." << std::endl; } std::ofstream file(REPO_PATH, std::ios::app); // Append the URL to the end of the file if (file.is_open()) { - file << url << std::endl; + file << url; file.close(); } else { - std::cerr << "Failed to open " << REPO_PATH << " for writing." << std::endl; + LOGFILE << "[E] Failed to open " << REPO_PATH.c_str() << " for writing." << std::endl; } } @@ -74,12 +74,12 @@ std::vector ToolsRepo::readFromFile () { // Check if the file exists if (!std::filesystem::exists(REPO_PATH)) { - std::cout << REPO_PATH << " does not exist, creating it..." << std::endl; + LOGFILE << REPO_PATH.c_str() << " does not exist, creating it..." << std::endl; // If it doesn't, write a blank file and exit std::ofstream file(REPO_PATH); if (!file.is_open()) { - std::cerr << "Failed to create " << REPO_PATH << std::endl; + LOGFILE << "[E] Failed to create " << REPO_PATH.c_str() << std::endl; } return output; @@ -89,7 +89,7 @@ std::vector ToolsRepo::readFromFile () { std::ifstream file(REPO_PATH); if (!file.is_open()) { - std::cerr << "Failed to open " << REPO_PATH << " for reading." << std::endl; + LOGFILE << "[E] Failed to open " << REPO_PATH.c_str() << " for reading." << std::endl; return output; } @@ -109,7 +109,7 @@ void ToolsRepo::removeFromFile (const std::string &url) { // Check if the file exists if (!std::filesystem::exists(REPO_PATH)) { - std::cout << REPO_PATH << " does not exist." << std::endl; + LOGFILE << REPO_PATH.c_str() << " does not exist." << std::endl; return; } @@ -118,7 +118,7 @@ void ToolsRepo::removeFromFile (const std::string &url) { std::ofstream tempFile(tempPath); if (!tempFile.is_open()) { - std::cerr << "Failed to open " << tempPath << " for writing." << std::endl; + LOGFILE << "[E] Failed to open " << tempPath.c_str() << " for writing." << std::endl; return; } @@ -126,7 +126,7 @@ void ToolsRepo::removeFromFile (const std::string &url) { std::ifstream file(REPO_PATH); if (!file.is_open()) { - std::cerr << "Failed to open " << REPO_PATH << " for reading." << std::endl; + LOGFILE << "[E] Failed to open " << REPO_PATH.c_str() << " for reading." << std::endl; return; } @@ -134,7 +134,7 @@ void ToolsRepo::removeFromFile (const std::string &url) { std::string line; while (std::getline(file, line)) { if (line == url) continue; - tempFile << line << std::endl; + tempFile << line; } file.close();