Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor encodings #2145

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/client_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ int client_main(int argc, char *argv[])
#ifdef ENABLE_NLS
(void) bindtextdomain("freeciv21-nations", get_locale_dir());
#endif
init_character_encodings(gui_character_encoding, gui_use_transliteration);
init_character_encodings();
#ifdef ENABLE_NLS
bind_textdomain_codeset("freeciv21-nations", get_internal_encoding());
bind_textdomain_codeset("freeciv21-nations", "UTF-8");
#endif

QCommandLineParser parser;
Expand Down
22 changes: 11 additions & 11 deletions client/connectdlg_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QUuid>

#include <cstring>
#include <qglobal.h>

#ifdef FREECIV_MSWINDOWS
#include <windows.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -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);

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion client/connectdlg_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 0 additions & 2 deletions client/gui_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ void real_science_report_dialog_update(void *);

extern void city_font_update();

const bool gui_use_transliteration = false;
const char *const gui_character_encoding = "UTF-8";
const char *client_string = "gui-qt";
static fc_client *freeciv_qt;

Expand Down
7 changes: 3 additions & 4 deletions client/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3788,7 +3788,6 @@ static const char *get_last_option_file_name(bool *allow_digital_boolean)
fc_strlcpy(name_buffer, OPTION_FILE_NAME, sizeof(name_buffer));
#else
int major, minor;
struct stat buf;

name = freeciv_storage_dir();
if (name.isEmpty()) {
Expand All @@ -3807,7 +3806,7 @@ static const char *get_last_option_file_name(bool *allow_digital_boolean)
fc_snprintf(name_buffer, sizeof(name_buffer),
"%s/freeciv-client-rc-%d.%d", qUtf8Printable(name),
major, minor);
if (0 == fc_stat(name_buffer, &buf)) {
if (QFileInfo::exists(name_buffer)) {
if (MAJOR_NEW_OPTION_FILE_NAME != major
|| MINOR_NEW_OPTION_FILE_NAME != minor) {
qInfo(_("Didn't find '%s' option file, "
Expand All @@ -3831,7 +3830,7 @@ static const char *get_last_option_file_name(bool *allow_digital_boolean)
fc_snprintf(name_buffer, sizeof(name_buffer),
"%s/.freeciv-client-rc-%d.%d",
qUtf8Printable(QDir::homePath()), major, minor);
if (0 == fc_stat(name_buffer, &buf)) {
if (QFileInfo::exists(name_buffer)) {
qInfo(_("Didn't find '%s' option file, "
"loading from '%s' instead."),
get_current_option_file_name()
Expand All @@ -3848,7 +3847,7 @@ static const char *get_last_option_file_name(bool *allow_digital_boolean)
// Try with the old one.
fc_snprintf(name_buffer, sizeof(name_buffer), "%s/%s",
qUtf8Printable(name), OLD_OPTION_FILE_NAME);
if (0 == fc_stat(name_buffer, &buf)) {
if (QFileInfo::exists(name_buffer)) {
qInfo(_("Didn't find '%s' option file, "
"loading from '%s' instead."),
get_current_option_file_name(), OLD_OPTION_FILE_NAME);
Expand Down
Loading
Loading