diff --git a/client/connectdlg_common.cpp b/client/connectdlg_common.cpp index 7515b6099e..02a768d148 100644 --- a/client/connectdlg_common.cpp +++ b/client/connectdlg_common.cpp @@ -21,6 +21,7 @@ #include #include +#include #ifdef FREECIV_MSWINDOWS #include @@ -50,7 +51,7 @@ bool server_quitting = false; -static char challenge_fullname[MAX_LEN_PATH]; +static QString challenge_fullname{}; static bool client_has_hack = false; int internal_server_port; @@ -318,9 +319,9 @@ static void randomize_string(char *str, size_t n) and then sends the string to the server. If the server can open and read the string, then the client is given hack access. */ -void send_client_wants_hack(const char *filename) +void send_client_wants_hack(const QString &filename) { - if (filename[0] != '\0') { + if (!filename.isEmpty()) { struct packet_single_want_hack_req req; struct section_file *file; auto sdir = freeciv_storage_dir(); @@ -334,9 +335,7 @@ void send_client_wants_hack(const char *filename) } QDir().mkpath(sdir); - - fc_snprintf(challenge_fullname, sizeof(challenge_fullname), "%s/%s", - qUtf8Printable(sdir), filename); + challenge_fullname = sdir + QStringLiteral("/") + filename; // generate an authentication token randomize_string(req.token, sizeof(req.token)); @@ -345,7 +344,7 @@ void send_client_wants_hack(const char *filename) secfile_insert_str(file, req.token, "challenge.token"); if (!secfile_save(file, challenge_fullname)) { qCritical("Couldn't write token to temporary file: %s", - challenge_fullname); + qUtf8Printable(challenge_fullname)); } secfile_destroy(file); @@ -360,11 +359,12 @@ void send_client_wants_hack(const char *filename) void handle_single_want_hack_reply(bool you_have_hack) { // remove challenge file - if (challenge_fullname[0] != '\0') { - if (fc_remove(challenge_fullname) == -1) { - qCritical("Couldn't remove temporary file: %s", challenge_fullname); + if (!challenge_fullname.isEmpty()) { + if (!QFile::remove(challenge_fullname)) { + qCritical("Couldn't remove temporary file: %s", + qUtf8Printable(challenge_fullname)); } - challenge_fullname[0] = '\0'; + challenge_fullname.clear(); } if (you_have_hack) { diff --git a/client/connectdlg_common.h b/client/connectdlg_common.h index 1b610e2dec..21a80efb56 100644 --- a/client/connectdlg_common.h +++ b/client/connectdlg_common.h @@ -19,7 +19,7 @@ void client_kill_server(bool force); bool is_server_running(); bool can_client_access_hack(); -void send_client_wants_hack(const char *filename); +void send_client_wants_hack(const QString &filename); void send_save_game(const char *filename); void set_ruleset(const char *ruleset); diff --git a/utility/support.cpp b/utility/support.cpp index 8df6b5d4a4..73fb28d3a2 100644 --- a/utility/support.cpp +++ b/utility/support.cpp @@ -267,25 +267,6 @@ FILE *fc_fopen(const char *filename, const char *opentype) #endif // FREECIV_MSWINDOWS } -/** - Wrapper function for remove() with filename conversion to local - encoding on Windows. - */ -int fc_remove(const char *filename) -{ -#ifdef FREECIV_MSWINDOWS - int result; - char *filename_in_local_encoding = - internal_to_local_string_malloc(filename); - - result = remove(filename_in_local_encoding); - free(filename_in_local_encoding); - return result; -#else // FREECIV_MSWINDOWS - return remove(filename); -#endif // FREECIV_MSWINDOWS -} - /** Returns last error code. */ diff --git a/utility/support.h b/utility/support.h index d87174256f..4b222ef541 100644 --- a/utility/support.h +++ b/utility/support.h @@ -123,7 +123,6 @@ int fc_strcoll(const char *str0, const char *str1); int fc_stricoll(const char *str0, const char *str1); FILE *fc_fopen(const char *filename, const char *opentype); -int fc_remove(const char *filename); fc_errno fc_get_errno(); const char *fc_strerror(fc_errno err);