@@ -22,14 +22,16 @@ public partial class Form1 : Form
22
22
private bool InitDone = false ;
23
23
private string TOMLPath ;
24
24
private FlexGUIConfig flexGUIConfig ;
25
- private System . Text . Encoding enc1252 ;
25
+ private Encoding legacyEncoding ;
26
26
private string flexasioGuiVersion = "0.31" ;
27
27
private string flexasioVersion = "1.8" ;
28
28
private string tomlName = "FlexASIO.toml" ;
29
29
private string docUrl = "https://github.com/dechamps/FlexASIO/blob/master/CONFIGURATION.md" ;
30
30
31
31
[ DllImport ( @"C:\Program Files\FlexASIO\x64\FlexASIO.dll" ) ]
32
32
public static extern int Initialize ( string PathName , bool TestMode ) ;
33
+ [ DllImport ( @"kernel32.dll" ) ]
34
+ public static extern uint GetACP ( ) ;
33
35
34
36
public Form1 ( )
35
37
{
@@ -40,7 +42,10 @@ public Form1()
40
42
System . Globalization . CultureInfo customCulture = ( System . Globalization . CultureInfo ) System . Threading . Thread . CurrentThread . CurrentCulture . Clone ( ) ;
41
43
customCulture . NumberFormat . NumberDecimalSeparator = "." ;
42
44
Encoding . RegisterProvider ( CodePagesEncodingProvider . Instance ) ;
43
- enc1252 = Encoding . GetEncoding ( 1252 ) ;
45
+
46
+ // get the value of the "Language for non-Unicode programs" setting (1252 for English)
47
+ // note: in Win11 this could be UTF-8 already, since it's natively supported
48
+ legacyEncoding = Encoding . GetEncoding ( ( int ) GetACP ( ) ) ;
44
49
45
50
System . Threading . Thread . CurrentThread . CurrentCulture = customCulture ;
46
51
CultureInfo . DefaultThreadCurrentCulture = customCulture ;
@@ -110,11 +115,12 @@ public Form1()
110
115
GenerateOutput ( ) ;
111
116
}
112
117
113
- private string W1252fromUTF ( string s )
118
+ private string DescrambleUTF8 ( string s )
114
119
{
115
- byte [ ] bytes = Encoding . Default . GetBytes ( s ) ;
116
- byte [ ] output = Encoding . Convert ( Encoding . UTF8 , enc1252 , bytes ) ;
117
- return Encoding . UTF8 . GetString ( output ) ;
120
+ // portaudio incorrectly returns UTF-8 strings as if they were ANSI (CP1252 for most Latin systems, CP1251 for Cyrillic, etc...)
121
+ // this line fixes the issue by reading the input as CP* and parsing it as UTF-8
122
+ var bytes = legacyEncoding . GetBytes ( s ) ;
123
+ return Encoding . UTF8 . GetString ( bytes ) ;
118
124
}
119
125
120
126
private TreeNode [ ] GetDevicesForBackend ( string Backend , bool Input )
@@ -134,14 +140,14 @@ private TreeNode[] GetDevicesForBackend(string Backend, bool Input)
134
140
{
135
141
if ( deviceInfo . maxInputChannels > 0 )
136
142
{
137
- treeNodes . Add ( new TreeNode ( W1252fromUTF ( deviceInfo . name ) ) ) ;
143
+ treeNodes . Add ( new TreeNode ( DescrambleUTF8 ( deviceInfo . name ) ) ) ;
138
144
}
139
145
}
140
146
else
141
147
{
142
148
if ( deviceInfo . maxOutputChannels > 0 )
143
149
{
144
- treeNodes . Add ( new TreeNode ( W1252fromUTF ( deviceInfo . name ) ) ) ;
150
+ treeNodes . Add ( new TreeNode ( DescrambleUTF8 ( deviceInfo . name ) ) ) ;
145
151
}
146
152
}
147
153
}
0 commit comments