4
4
#include < fstream>
5
5
#include < iostream>
6
6
#include < optional>
7
+ #include < sstream>
7
8
#include < string>
8
9
9
10
#include < rawaccel-settings.h>
@@ -44,12 +45,16 @@ static inline void trim(std::string& s) {
44
45
rtrim (s);
45
46
}
46
47
47
- bool yes () {
48
- for (;;) {
49
- wchar_t c = _getwch ();
50
- if (c == ' y' ) return true ;
51
- else if (c == ' n' ) return false ;
52
- }
48
+ bool ask (std::string_view question) {
49
+ std::cout << question << " (Y/N)" << std::endl;
50
+ wchar_t ch;
51
+ bool yes;
52
+ do
53
+ {
54
+ ch = towupper (_getwch ());
55
+ yes = ch == ' Y' ;
56
+ } while (ch != ' N' && !yes);
57
+ return yes;
53
58
}
54
59
55
60
using ia_settings_t = std::vector<std::pair<std::string, double >>;
@@ -128,10 +133,10 @@ ra::accel_args convert_quake(const ia_settings_t& ia_settings, bool legacy) {
128
133
double offset = get (" Offset" ).value_or (0 );
129
134
130
135
ra::accel_args args;
131
-
132
- double accel_b = std::pow (accel * prescale, power - 1 ) / sens ;
133
- double accel_e = 1 / (power - 1 ) ;
134
- args.accel = std::pow (accel_b, accel_e );
136
+ double powm1 = power - 1 ;
137
+ double rpowm1 = 1 / powm1 ;
138
+ double accel_b = std::pow (accel * prescale, powm1) / sens ;
139
+ args.accel = std::pow (accel_b, rpowm1 );
135
140
args.exponent = power;
136
141
args.legacy_offset = legacy;
137
142
args.offset = offset;
@@ -142,9 +147,7 @@ ra::accel_args convert_quake(const ia_settings_t& ia_settings, bool legacy) {
142
147
args.scale_cap = cap_converted;
143
148
}
144
149
else {
145
- double b = (cap_converted - 1 ) / power;
146
- double e = 1 / (power - 1 );
147
- args.gain_cap = offset + (1 / accel) * std::pow (b, e);
150
+ args.gain_cap = offset + std::pow (cap_converted - 1 , rpowm1) / args.accel ;
148
151
}
149
152
150
153
return args;
@@ -165,16 +168,16 @@ bool try_convert(const ia_settings_t& ia_settings) {
165
168
166
169
switch (static_cast <IA_MODES_ENUM>(mode)) {
167
170
case IA_QL: {
168
- std::cout << " We recommend trying out our new cap and offset styles.\n "
169
- " Use new cap and offset? (y|n) \n " ;
171
+ bool legacy = ! ask ( " We recommend trying out our new cap and offset styles.\n "
172
+ " Use new cap and offset?" ) ;
170
173
ra_settings.modes .x = ra::accel_mode::classic;
171
- ra_settings.argsv .x = convert_quake (ia_settings, ! yes () );
174
+ ra_settings.argsv .x = convert_quake (ia_settings, legacy );
172
175
break ;
173
176
}
174
177
case IA_NAT: {
175
- std::cout << " Raw Accel offers a new mode that you might like more than Natural.\n "
176
- " Wanna try it out now? (y|n) \n " ;
177
- ra_settings.modes .x = yes () ? ra::accel_mode::naturalgain : ra::accel_mode::natural;
178
+ bool nat_gain = ask ( " Raw Accel offers a new mode that you might like more than Natural.\n "
179
+ " Wanna try it out now?" ) ;
180
+ ra_settings.modes .x = nat_gain ? ra::accel_mode::naturalgain : ra::accel_mode::natural;
178
181
ra_settings.argsv .x = convert_natural (ia_settings);
179
182
break ;
180
183
}
@@ -223,29 +226,31 @@ int main()
223
226
}
224
227
225
228
if (opt_path) {
226
- std::cout << " Found " << opt_path->filename () <<
227
- " \n\n Convert and send settings generated from " <<
228
- opt_path->filename () << " ? (y|n)\n " ;
229
- if (!yes ()) return 0 ;
230
- try {
231
- if (!try_convert (parse_ia_settings (opt_path.value ())))
232
- std::cout << " Unable to convert settings.\n " ;
233
- }
234
- catch (DriverNotInstalledException^) {
235
- Console::WriteLine (" \n Driver is not installed." );
236
- }
237
- catch (Exception^ e) {
238
- Console::WriteLine (" \n Error: " + e->ToString ());
239
- }
240
- catch (const std::exception & e) {
241
- std::cout << " Error: " << e.what () << ' \n ' ;
229
+ std::string path = opt_path->filename ().generic_string ();
230
+ std::stringstream ss;
231
+ ss << " Found " << path <<
232
+ " \n\n Convert and send settings generated from " << path << ' ?' ;
233
+ if (ask (ss.str ())) {
234
+ try {
235
+ if (!try_convert (parse_ia_settings (opt_path.value ())))
236
+ std::cout << " Unable to convert settings.\n " ;
237
+ }
238
+ catch (DriverNotInstalledException^) {
239
+ Console::WriteLine (" \n Driver is not installed." );
240
+ }
241
+ catch (Exception^ e) {
242
+ Console::WriteLine (" \n Error: " + e->ToString ());
243
+ }
244
+ catch (const std::exception & e) {
245
+ std::cout << " Error: " << e.what () << ' \n ' ;
246
+ }
242
247
}
243
248
}
244
249
else {
245
250
std::cout << " Drop your InterAccel settings/profile into this directory.\n "
246
251
" Then run this program to generate the equivalent Raw Accel settings.\n " ;
247
252
}
248
-
249
- std::cout << " Press any key to close this window . . .\n " ;
253
+
254
+ std::cout << " Press any key to close this window . . ." << std::endl ;
250
255
_getwch ();
251
256
}
0 commit comments