From b97a01eca4f01f8bcedecffa51a1769a10d77832 Mon Sep 17 00:00:00 2001 From: PaulCombal Date: Tue, 10 Dec 2019 09:17:02 +0100 Subject: [PATCH] RC1 --- TODO | 5 ----- src/common/Downloader.cpp | 3 ++- src/common/functions.cpp | 7 +++++++ src/common/functions.h | 6 ++++++ src/controller/GameServerManager.cpp | 2 ++ src/controller/MyGameServer.cpp | 4 +++- src/controller/MySteam.cpp | 3 ++- src/controller/MySteamClient.h | 8 +++++++- src/controller/SteamAppDAO.cpp | 8 +++++++- src/gui/MainPickerWindowFactory.cpp | 5 +++-- src/json/ProcessedGameServerRequest.cpp | 3 +++ src/json/yajlHelpers.cpp | 8 ++++++-- src/main.cpp | 1 + src/schema_parser/KeyValue.cpp | 2 ++ src/sockets/MyClientSocket.cpp | 3 +++ src/sockets/MyGameSocket.cpp | 5 ++++- src/sockets/MyServerSocket.cpp | 9 +++++++-- 17 files changed, 65 insertions(+), 17 deletions(-) delete mode 100644 TODO diff --git a/TODO b/TODO deleted file mode 100644 index 9effd3c..0000000 --- a/TODO +++ /dev/null @@ -1,5 +0,0 @@ -// Too soon -// Migrate to gtkmm 4 https://developer.gnome.org/gtkmm-tutorial/unstable/gtkmm-tutorial.html#changes-gtkmm4 - -make zenity wrapper (Also chnage old zenity calls) -use zenity before crashes + better log messages \ No newline at end of file diff --git a/src/common/Downloader.cpp b/src/common/Downloader.cpp index 25f11bf..d23c52a 100644 --- a/src/common/Downloader.cpp +++ b/src/common/Downloader.cpp @@ -33,12 +33,13 @@ Downloader::download_file(const std::string& file_url, const std::string& local_ } else { std::cerr << "An error occurred creating curl. Please report it to the developers!" << std::endl; + zenity("An error occurred creating curl. Please report it to the developers!"); exit(EXIT_FAILURE); } if(res != 0) { std::cerr << "Curl errored with status " << res << ". (file: " << file_url << ")" << std::endl; - std::cout << "An error occurred while fetching an icon, are you connected to the internet?" << std::endl; + zenity("An error occurred while fetching an icon, are you connected to the internet?"); exit(EXIT_FAILURE); } } diff --git a/src/common/functions.cpp b/src/common/functions.cpp index df34e89..a1f20c5 100644 --- a/src/common/functions.cpp +++ b/src/common/functions.cpp @@ -27,6 +27,7 @@ void read_count(int fd, void *buf, size_t count) bytes = read(fd, (void*)((char*)buf+i), count-i); if ((bytes == -1) || (bytes == 0 && errno > 0)) { std::cerr << "Read pipe encountered fatal error." << std::endl; + zenity(); exit(EXIT_FAILURE); } } @@ -41,6 +42,7 @@ void write_count(int fd, void *buf, size_t count) bytes = write(fd, (void*)((char*)buf+i), count-i); if ((bytes == -1) || (bytes == 0 && errno > 0)) { std::cerr << "Write pipe encountered fatal error." << std::endl; + zenity(); exit(EXIT_FAILURE); } } @@ -80,6 +82,7 @@ void mkdir_default(const char *pathname) int mkdir_error = mkdir(pathname, S_IRWXU | S_IRWXG | S_IROTH); if (mkdir_error != 0 && errno != EEXIST) { std::cerr << "Unable to create the folder " << pathname << ", errno " << errno << ")." << std::endl; + zenity("Unable to create the folder " + std::string(pathname) + ", errno " + std::to_string(errno) + "."); exit(EXIT_FAILURE); } } @@ -106,4 +109,8 @@ void escape_html(std::string& data) { } } data.swap(buffer); +} + +void zenity(const std::string text, const std::string type) { + system( std::string("zenity " + type + " --text=\"" + text + "\"").c_str() ); } \ No newline at end of file diff --git a/src/common/functions.h b/src/common/functions.h index 149790e..bbef2ff 100644 --- a/src/common/functions.h +++ b/src/common/functions.h @@ -59,3 +59,9 @@ std::string get_achievement_icon_path(AppId_t app_id, std::string id); * From https://stackoverflow.com/a/5665377 */ void escape_html(std::string& data); + +/** + * Show a regular dialog box. Return value is ignored for now, + * but feel free to add functionnlitie to this + */ +void zenity(const std::string text = "An internal error occurred, please open a Github issue with the console output to get it fixed!", const std::string type = "--error --no-wrap"); diff --git a/src/controller/GameServerManager.cpp b/src/controller/GameServerManager.cpp index 94fc932..5eea366 100644 --- a/src/controller/GameServerManager.cpp +++ b/src/controller/GameServerManager.cpp @@ -3,6 +3,7 @@ #include "MySteamClient.h" #include "MySteam.h" #include "../globals.h" +#include "../common/functions.h" #include #include #include @@ -34,6 +35,7 @@ GameServerManager::quick_server_create(AppId_t appid) } else if (pid == -1) { std::cerr << "Could not fork in GameServerManager." << std::endl; + zenity("Could not fork in GameServerManager."); exit(EXIT_FAILURE); } else { diff --git a/src/controller/MyGameServer.cpp b/src/controller/MyGameServer.cpp index 5e6fe69..6bb6843 100644 --- a/src/controller/MyGameServer.cpp +++ b/src/controller/MyGameServer.cpp @@ -1,4 +1,5 @@ #include "MyGameServer.h" +#include "../common/functions.h" #include MyGameServer::MyGameServer(AppId_t appid) @@ -15,7 +16,8 @@ MyGameServer::run() if (!SteamAPI_Init()) { std::cerr << "An error occurred launching the Steam API. Aborting." << std::endl; - std::cerr << "Make sure you are trying to run an app you own, and running with launch.sh" << std::endl; + std::cerr << "Make sure you are trying to run an app you own." << std::endl; + zenity("Make sure you are trying to run an app you own."); exit(EXIT_FAILURE); } diff --git a/src/controller/MySteam.cpp b/src/controller/MySteam.cpp index 8fe572f..1c98c08 100644 --- a/src/controller/MySteam.cpp +++ b/src/controller/MySteam.cpp @@ -35,7 +35,7 @@ MySteam::MySteam() { } else { std::cerr << "Unable to locate the steam directory." << std::endl; - system("zenity --error --no-wrap --text=\"Unable to find your Steam installation directory.. Please report this on Github!\""); + zenity("Unable to find your Steam installation directory.. Please report this on Github!"); exit(EXIT_FAILURE); } } @@ -167,6 +167,7 @@ MySteam::refresh_achievements() { if (m_ipc_socket == nullptr) { std::cerr << "Connection to game is broken" << std::endl; + zenity("Connection to game is broken"); exit(EXIT_FAILURE); } diff --git a/src/controller/MySteamClient.h b/src/controller/MySteamClient.h index bd0eb4a..e99c8cc 100644 --- a/src/controller/MySteamClient.h +++ b/src/controller/MySteamClient.h @@ -1,5 +1,6 @@ #pragma once #include "../../steam/steam_api.h" +#include "../common/functions.h" #include "../globals.h" #include "MySteam.h" #include @@ -48,6 +49,7 @@ public: if (!m_handle) { std::cerr << "Error opening the Steam Client library. Exiting. Info:" << std::endl; std::cerr << dlerror() << std::endl; + zenity(); exit(EXIT_FAILURE); } @@ -57,6 +59,7 @@ public: if ((error = dlerror()) != NULL) { std::cerr << "Error reading the CreateInterface symbol from the Steam Client library. Exiting. Info:" << std::endl; std::cerr << error << std::endl; + zenity(); exit(EXIT_FAILURE); } @@ -65,20 +68,23 @@ public: m_user = m_steamclient->ConnectToGlobalUser(m_pipe); if (m_pipe == 0 || m_user == 0) { - std::cout << "Uh oh. We could communicate with Steam.. Make sure you launched Steam and logged into your account." << std::endl; + std::cout << "We could interact with Steam.. Make sure you launched Steam and logged into your account." << std::endl; std::cerr << "Unable to create Steam Pipe or connect to global user. Exitting." << std::endl; + zenity("We could interact with Steam.. Make sure you launched Steam and logged into your account."); exit(EXIT_FAILURE); } m_steamapps = m_steamclient->GetISteamApps(m_user, m_pipe, STEAMAPPS_INTERFACE_VERSION); if (m_steamapps == NULL) { std::cerr << "Unable to get ISteamApps interface for MySteamClient. Exitting." << std::endl; + zenity(); exit(EXIT_FAILURE); } m_steamuser = m_steamclient->GetISteamUser(m_user, m_pipe, STEAMUSER_INTERFACE_VERSION); if (m_steamuser == NULL) { std::cerr << "Unable to get ISteamUser interface for MySteamClient. Exitting." << std::endl; + zenity(); exit(EXIT_FAILURE); } }; diff --git a/src/controller/SteamAppDAO.cpp b/src/controller/SteamAppDAO.cpp index f8bfb03..7498917 100644 --- a/src/controller/SteamAppDAO.cpp +++ b/src/controller/SteamAppDAO.cpp @@ -46,6 +46,7 @@ SteamAppDAO::need_to_redownload(const char * file_path) { std::cerr << "~/.cache/SamRewritten/app_names exists but an error occurred analyzing it. To avoid further complications, "; std::cerr << "the program will stop here. Before retrying make sure you have enough privilege to read and write to "; std::cerr << "your home folder folder." << std::endl; + zenity("An error occurred writing the cache files. Try deleting the cache folder (" + std::string(g_cache_folder) + ") and make sure you have enough permissions to write to it."); exit(EXIT_FAILURE); } } @@ -167,10 +168,12 @@ SteamAppDAO::parse_app_names(const char * file_path, std::map= sizeof(fileData) - 1) { std::cerr << "app_names file too big (just increase the buffer size)" << std::endl; + zenity(); exit(EXIT_FAILURE); } @@ -185,6 +188,8 @@ SteamAppDAO::parse_app_names(const char * file_path, std::map #include @@ -12,7 +13,7 @@ MainPickerWindowFactory::create() { } catch(const Glib::Error& e) { std::cerr << "Fatal error: " << e.what() << std::endl; - system("zenity --no-wrap --error --text='Unable to load the UI file.. Was the installation completed? Please report this to us on Github!'"); + zenity("Unable to load the UI file.. Was the installation completed? Please report this to us on Github!"); exit(EXIT_FAILURE); } @@ -25,7 +26,7 @@ MainPickerWindowFactory::create() { } std::cerr << "Fatal error: Could not get derived widget main_window." << std::endl; - system("zenity --no-wrap --error --text='Unable to load the main window.. Please report this to us on Github!'"); + zenity("Unable to load the main window.. Please report this to us on Github!"); exit(EXIT_FAILURE); return nullptr; } \ No newline at end of file diff --git a/src/json/ProcessedGameServerRequest.cpp b/src/json/ProcessedGameServerRequest.cpp index ea91424..7e35083 100644 --- a/src/json/ProcessedGameServerRequest.cpp +++ b/src/json/ProcessedGameServerRequest.cpp @@ -1,4 +1,5 @@ #include "ProcessedGameServerRequest.h" +#include "../common/functions.h" #include SAM_ACTION @@ -27,6 +28,7 @@ ProcessedGameServerRequest::ProcessedGameServerRequest(const std::string& reques if (m_fulltree == NULL) { std::cerr << "Parsing error. Data: " << std::endl; std::cerr << request << std::endl; + zenity(); exit(EXIT_FAILURE); } @@ -36,6 +38,7 @@ ProcessedGameServerRequest::ProcessedGameServerRequest(const std::string& reques yajl_val v = yajl_tree_get(m_fulltree, path, yajl_t_string); if (v == NULL || !YAJL_IS_STRING(v)) { std::cerr << "failed to get " << SAM_ACTION_STR << std::endl; + zenity(); exit(EXIT_FAILURE); } diff --git a/src/json/yajlHelpers.cpp b/src/json/yajlHelpers.cpp index 3bc7e03..2bced02 100644 --- a/src/json/yajlHelpers.cpp +++ b/src/json/yajlHelpers.cpp @@ -4,6 +4,7 @@ #include #include #include "../types/Actions.h" +#include "../common/functions.h" void yajl_gen_string_wrap(yajl_gen handle, const char * a) { @@ -25,6 +26,7 @@ decode_ack(std::string response) { if (node == NULL) { std::cerr << "Parsing error. Data: " << std::endl; std::cerr << response << std::endl; + zenity(); exit(EXIT_FAILURE); } const char * path[] = { SAM_ACK_STR, (const char*)0 }; @@ -112,12 +114,14 @@ encode_achievements(yajl_gen handle, std::vector achievements) { std::vector decode_achievements(std::string response) { std::vector achievements; + char error_buffer[500]; //parse response - yajl_val node = yajl_tree_parse(response.c_str(), NULL, 0); + yajl_val node = yajl_tree_parse(response.c_str(), error_buffer, 500); if (node == NULL) { - std::cerr << "parsing error"; + std::cerr << "Parsing error: " << error_buffer << std::endl; + zenity(); exit(EXIT_FAILURE); } diff --git a/src/main.cpp b/src/main.cpp index d404be3..bef48cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,6 +35,7 @@ main(int argc, char *argv[]) { if (getuid() == 0) { std::cout << "Do not run this application as root" << std::endl; + zenity("Please do not run this application as root.."); exit(EXIT_FAILURE); } diff --git a/src/schema_parser/KeyValue.cpp b/src/schema_parser/KeyValue.cpp index b3d1f07..ca56296 100644 --- a/src/schema_parser/KeyValue.cpp +++ b/src/schema_parser/KeyValue.cpp @@ -24,6 +24,7 @@ // The original SAM is available at https://github.com/gibbed/SteamAchievementManager // To comply with copyright, the above license is included. +#include "../common/functions.h" #include "KeyValue.h" #include @@ -118,6 +119,7 @@ std::string KeyValue::as_string(std::string default_value) { std::cout << "Stats parser encountered fatal error!" << std::endl; std::cout << "as_string attempted on non-string type" << std::endl; std::cout << "exiting now to avoid complications" << std::endl; + zenity(); exit(EXIT_FAILURE); } diff --git a/src/sockets/MyClientSocket.cpp b/src/sockets/MyClientSocket.cpp index 7f7c45f..c93ad07 100644 --- a/src/sockets/MyClientSocket.cpp +++ b/src/sockets/MyClientSocket.cpp @@ -1,6 +1,7 @@ #include "MyClientSocket.h" #include "../types/Actions.h" #include "../json/yajlHelpers.h" +#include "../common/functions.h" #include #include @@ -26,6 +27,7 @@ MyClientSocket::connect_to_server() m_socket_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); if (m_socket_fd == -1) { std::cerr << "Unable to create client socket." << std::endl; + zenity(); exit(EXIT_FAILURE); } @@ -38,6 +40,7 @@ MyClientSocket::connect_to_server() if (retries == 20) { std::cerr << "Unable to connect to server after 20 retries: " << m_socket_path << std::endl; + zenity(); exit(EXIT_FAILURE); } } diff --git a/src/sockets/MyGameSocket.cpp b/src/sockets/MyGameSocket.cpp index df3362a..83bcc58 100644 --- a/src/sockets/MyGameSocket.cpp +++ b/src/sockets/MyGameSocket.cpp @@ -6,6 +6,7 @@ #include "../json/yajlHelpers.h" #include "../globals.h" #include "../common/PerfMon.h" +#include "../common/functions.h" MyGameSocket::MyGameSocket(AppId_t appid) : MyServerSocket(appid), @@ -47,6 +48,7 @@ MyGameSocket::process_request(std::string request, bool& quit) { if (yajl_gen_map_close(handle) != yajl_gen_status_ok) { std::cerr << "Failed to make json." << std::endl; + zenity(); exit(EXIT_FAILURE); } @@ -64,7 +66,8 @@ MyGameSocket::get_achievements() { ISteamUserStats *stats_api = SteamUserStats(); if (!stats_api->RequestCurrentStats()) { - std::cerr << "ERROR: User not logged in, exiting" << std::endl; + std::cerr << "ERROR: User not logged in, exiting." << std::endl; + zenity("Please login to Steam before using SamRewritten. If this is the case, please report it with a Github issue."); exit(EXIT_FAILURE); } diff --git a/src/sockets/MyServerSocket.cpp b/src/sockets/MyServerSocket.cpp index 237119a..4e96697 100644 --- a/src/sockets/MyServerSocket.cpp +++ b/src/sockets/MyServerSocket.cpp @@ -11,7 +11,8 @@ MyServerSocket::MyServerSocket(AppId_t appid) : MySocket(appid) { std::cerr << "It looks like the server before me did not shutdown properly." << std::endl; if(unlink(m_socket_path.c_str()) < 0) { - std::cout << "Something is wrong. Are you the right user? Exiting." << std::endl; + std::cout << "Unable to unlink previous socket. Exitting." << std::endl; + zenity("Unable to clean up after a previous failure. Please try running SamRewritten as the same user than last time you used it."); exit(EXIT_FAILURE); } } @@ -20,6 +21,7 @@ MyServerSocket::MyServerSocket(AppId_t appid) : MySocket(appid) if ((m_socket_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0)) == -1) { std::cerr << "Could not create the server socket. Exiting. Code: " << errno << std::endl; + zenity("An error occurred starting SamRewritten, please report it to Github with the following code to get directions: " + std::to_string(errno)); exit(EXIT_FAILURE); } @@ -29,13 +31,15 @@ MyServerSocket::MyServerSocket(AppId_t appid) : MySocket(appid) strncpy(addr.sun_path, m_socket_path.c_str(), sizeof(addr.sun_path) - 1); if(bind(m_socket_fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_un)) == -1) { - std::cerr << "Failed to bind server socket " << m_socket_path << std::endl; + std::cerr << "Failed to bind server socket: " << m_socket_path << std::endl; + zenity(); exit(EXIT_FAILURE); } if (listen(m_socket_fd, 20) < 0) { std::cerr << "Unable to listen to the socket. Exiting." << std::endl; + zenity(); exit(EXIT_FAILURE); } @@ -52,6 +56,7 @@ MyServerSocket::run_server() if (data_socket == -1) { std::cerr << "Server failed to accept. Exiting." << std::endl; + zenity(); exit(EXIT_FAILURE); }