-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathConfig.cs
159 lines (141 loc) · 3.59 KB
/
Config.cs
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Collections.Generic;
using System.IO;
namespace Joycon
{
public static class Config
{
static string PATH;
static Dictionary<string, string> variables = new Dictionary<string, string>();
const int settingsNum = 10; // currently - ProgressiveScan, StartInTray + special buttons
public static string GetDefaultValue(string s)
{
switch (s)
{
case "ProgressiveScan":
return "1";
case "capture":
//return "key_" + ((int)WindowsInput.Events.KeyCode.PrintScreen);
return "key_";
case "reset_mouse":
return "joy_" + ((int)Joycon.Button.STICK);
}
return "0";
}
public static void Init(List<KeyValuePair<string, float[]>> caliData, String packageName)
{
foreach (string s in new string[] { "ProgressiveScan", "StartInTray", "capture", "home", "sl_l", "sl_r", "sr_l", "sr_r", "reset_mouse", "active_gyro" })
variables[s] = GetDefaultValue(s);
PATH = "/data/data/" + packageName + "/msettings";
if (File.Exists(PATH))
{
int lineNO = 0;
using (StreamReader file = new StreamReader(PATH))
{
string line = String.Empty;
while ((line = file.ReadLine()) != null)
{
string[] vs = line.Split();
try
{
if (lineNO < settingsNum)
{ // load in basic settings
variables[vs[0]] = vs[1];
}
else
{ // load in calibration presets
caliData.Clear();
for (int i = 0; i < vs.Length; i++)
{
string[] caliArr = vs[i].Split(',');
float[] newArr = new float[6];
for (int j = 1; j < caliArr.Length; j++)
{
newArr[j - 1] = float.Parse(caliArr[j]);
}
caliData.Add(new KeyValuePair<string, float[]>(
caliArr[0],
newArr
));
}
}
}
catch { }
lineNO++;
}
}
// if old settings
if (lineNO < settingsNum)
{
File.Delete(PATH);
Init(caliData, packageName);
}
}
else
{
using (StreamWriter file = new StreamWriter(PATH))
{
foreach (string k in variables.Keys)
file.WriteLine(String.Format("{0} {1}", k, variables[k]));
string caliStr = "";
for (int i = 0; i < caliData.Count; i++)
{
string space = " ";
if (i == 0) space = "";
caliStr += space + caliData[i].Key + "," + String.Join(",", caliData[i].Value);
}
file.WriteLine(caliStr);
}
}
}
public static int IntValue(string key)
{
if (!variables.ContainsKey(key))
{
return 0;
}
return Int32.Parse(variables[key]);
}
public static string Value(string key)
{
if (!variables.ContainsKey(key))
{
return "";
}
return variables[key];
}
public static bool SetValue(string key, string value)
{
if (!variables.ContainsKey(key))
return false;
variables[key] = value;
return true;
}
public static void SaveCaliData(List<KeyValuePair<string, float[]>> caliData)
{
string[] txt = File.ReadAllLines(PATH);
if (txt.Length < settingsNum + 1) // no custom calibrations yet
Array.Resize(ref txt, txt.Length + 1);
string caliStr = "";
for (int i = 0; i < caliData.Count; i++)
{
string space = " ";
if (i == 0) space = "";
caliStr += space + caliData[i].Key + "," + String.Join(",", caliData[i].Value);
}
txt[2] = caliStr;
File.WriteAllLines(PATH, txt);
}
public static void Save()
{
string[] txt = File.ReadAllLines(PATH);
int NO = 0;
foreach (string k in variables.Keys)
{
txt[NO] = String.Format("{0} {1}", k, variables[k]);
NO++;
}
File.WriteAllLines(PATH, txt);
}
}
}