summaryrefslogtreecommitdiff
blob: aa92ff6c81ee3bc83827a58209b998cca8d87998 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
From 17816ed02f59bab9c27310e7f24c73266b0a3003 Mon Sep 17 00:00:00 2001
From: persmule <persmule@gmail.com>
Date: Wed, 5 Oct 2016 13:47:46 +0800
Subject: [PATCH] Add a routine to set file name conversion for amuled which
 based on wxAppConsole

---
 src/amule.h    |  7 +++++++
 src/amuled.cpp | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/src/amule.h b/src/amule.h
index f25702f60..240c02dd9 100644
--- a/src/amule.h
+++ b/src/amule.h
@@ -553,6 +553,13 @@ private:
 	int OnExit();
 
 	virtual int InitGui(bool geometry_enable, wxString &geometry_string);
+	// The GTK wxApps sets its file name conversion properly
+	// in wxApp::Initialize(), while wxAppConsole::Initialize()
+	// does not, leaving wxConvFile being set to wxConvLibc. File
+	// name conversion should be set otherwise amuled will abort to
+	// handle non-ASCII file names which monolithic amule can handle.
+	// This function are overrided to perform this.
+	virtual bool Initialize(int& argc_, wxChar **argv_);
 
 #ifdef AMULED_APPTRAITS
 	struct sigaction m_oldSignalChildAction;
diff --git a/src/amuled.cpp b/src/amuled.cpp
index 486da5973..86e1ff8b8 100644
--- a/src/amuled.cpp
+++ b/src/amuled.cpp
@@ -704,6 +704,41 @@ int CamuleDaemonApp::InitGui(bool ,wxString &)
 	return 0;
 }
 
+bool CamuleDaemonApp::Initialize(int& argc_, wxChar **argv_)
+{
+	if ( !wxAppConsole::Initialize(argc_, argv_) ) {
+		return false;
+	}
+
+#ifdef __UNIX__
+	wxString encName;
+#if wxUSE_INTL
+	// if a non default locale is set,
+	// assume that the user wants his
+        // filenames in this locale too
+        encName = wxLocale::GetSystemEncodingName().Upper();
+
+        // But don't consider ASCII in this case.
+	if ( !encName.empty() ) {
+		if ( encName == wxT("US-ASCII") ) {
+			// This means US-ASCII when returned
+			// from GetEncodingFromName().
+			encName.clear();
+		}
+        }
+#endif // wxUSE_INTL
+
+	// in this case, UTF-8 is used by default.
+        if ( encName.empty() ) {
+		encName = wxT("UTF-8");
+	}
+
+	static wxConvBrokenFileNames fileconv(encName);
+	wxConvFileName = &fileconv;
+#endif // __UNIX__
+
+	return true;
+}
 
 int CamuleDaemonApp::OnExit()
 {
-- 
2.16.4