This commit is contained in:
PaulCombal 2019-12-10 09:17:02 +01:00
parent e4288926e7
commit b97a01eca4
17 changed files with 65 additions and 17 deletions

5
TODO
View File

@ -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

View File

@ -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);
}
}

View File

@ -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() );
}

View File

@ -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");

View File

@ -3,6 +3,7 @@
#include "MySteamClient.h"
#include "MySteam.h"
#include "../globals.h"
#include "../common/functions.h"
#include <signal.h>
#include <iostream>
#include <unistd.h>
@ -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 {

View File

@ -1,4 +1,5 @@
#include "MyGameServer.h"
#include "../common/functions.h"
#include <iostream>
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);
}

View File

@ -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);
}

View File

@ -1,5 +1,6 @@
#pragma once
#include "../../steam/steam_api.h"
#include "../common/functions.h"
#include "../globals.h"
#include "MySteam.h"
#include <iostream>
@ -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);
}
};

View File

@ -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<AppId_t, std::stri
/* file read error handling */
if (rd == 0 && !feof(stdin)) {
std::cerr << "error encountered on file read" << std::endl;
std::cerr << "Error encountered on file read: " << file_path << std::endl;
zenity();
exit(EXIT_FAILURE);
} else if (rd >= 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<AppId_t, std::stri
} else {
std::cerr << "Unknown error" << std::endl;
}
zenity();
exit(EXIT_FAILURE);
}
@ -193,6 +198,7 @@ SteamAppDAO::parse_app_names(const char * file_path, std::map<AppId_t, std::stri
yajl_val v = yajl_tree_get(node, path, yajl_t_array);
if (v == NULL) {
std::cerr << "app_names contains valid JSON, but its format is not supported" << std::endl;
zenity();
exit(EXIT_FAILURE);
}

View File

@ -1,4 +1,5 @@
#include "MainPickerWindowFactory.h"
#include "../common/functions.h"
#include <gtkmm-3.0/gtkmm/builder.h>
#include <iostream>
@ -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;
}

View File

@ -1,4 +1,5 @@
#include "ProcessedGameServerRequest.h"
#include "../common/functions.h"
#include <iostream>
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);
}

View File

@ -4,6 +4,7 @@
#include <iostream>
#include <cstring>
#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<Achievement_t> achievements) {
std::vector<Achievement_t>
decode_achievements(std::string response) {
std::vector<Achievement_t> 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);
}

View File

@ -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);
}

View File

@ -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 <strings.h>
@ -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);
}

View File

@ -1,6 +1,7 @@
#include "MyClientSocket.h"
#include "../types/Actions.h"
#include "../json/yajlHelpers.h"
#include "../common/functions.h"
#include <thread>
#include <chrono>
@ -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);
}
}

View File

@ -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);
}

View File

@ -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);
}