1
- using Newtonsoft . Json ;
2
1
using System ;
3
- using System . Collections . Generic ;
4
- using System . Collections . Specialized ;
5
- using System . Linq ;
6
- using System . Net ;
7
- using System . Net . Http ;
8
- using System . Net . Http . Headers ;
9
- using System . Text ;
10
2
11
3
namespace AssistantComputerControl {
12
4
class AnalyticsSettings {
13
- //private static string requestKey = null; // < version 1.1
14
- const string getKeyUrl = "https://acc.albe.pw/functions/ReceiveAnalyticsData.php" ;
15
- const string sendDataUrl = "https://acc.albe.pw/functions/ReceiveAnalyticsData.php" ;
16
- private static readonly HttpClient client = new HttpClient ( ) ;
5
+ //ACC truly is open source, but for security reasons we will not share this one file with the whole world.
6
+ //This file handles sending analytics to the developers' webserver and contains a few variables that contain -
7
+ //sensitive access-tokens to integrations like Sentry.IO
17
8
18
- public static readonly string [ ] actions = new String [ 13 ] { //No changing this order!
9
+ //The public version of this file is exactly like the full version, but stripped of -
10
+ //API-keys and sensitive information.
11
+ //Cencored items have placeholders to ensure that everyone can fork and run the project without errors
12
+ public const string sentryToken = "super_secret" ;
13
+
14
+ public static readonly string [ ] actions = new String [ ] { //No changing this order!
19
15
"shutdown" , //0
20
16
"restart" , //1
21
17
"open" , //2
@@ -29,9 +25,18 @@ class AnalyticsSettings {
29
25
"next_song" , //10
30
26
"die" , //11
31
27
"hibernate" , //12
28
+ "monitors_off" , //13
29
+ "keypress" , //14
30
+ "write_out" , //15
31
+
32
+ "key_shortcut" , //16
33
+ "create_file" , //17
34
+ "delete_file" , //18
35
+ "append_text" , //19
36
+ "message_box" , //20
32
37
} ;
33
38
34
- public static readonly string [ ] assistants = new String [ 4 ] { //No changing this order!
39
+ public static readonly string [ ] assistants = new String [ ] { //No changing this order!
35
40
"google" ,
36
41
"alexa" ,
37
42
"cortana" ,
@@ -43,7 +48,7 @@ class KeyHandler {
43
48
public string Message { get ; set ; }
44
49
public string Key { get ; set ; }
45
50
}
46
-
51
+
47
52
public static void SetupAnalyticsAsync ( ) {
48
53
//Unique user-ID
49
54
if ( Properties . Settings . Default . UID == "" || Properties . Settings . Default . UID == null ) {
@@ -66,19 +71,20 @@ public static void SetupAnalyticsAsync() {
66
71
67
72
int [ ] actionsExecuted = Properties . Settings . Default . TotalActionsExecuted ;
68
73
if ( actions . Length != actionsExecuted . Length ) {
69
- MainProgram . DoDebug ( actions . Length + "!= " + actionsExecuted . Length ) ;
74
+ // MainProgram.DoDebug(actions.Length + " != " + actionsExecuted.Length);
70
75
71
76
//New action most likely added
72
77
int [ ] oldSettings = actionsExecuted
73
78
, newSettings = new int [ actions . Length ] ;
74
79
75
80
//Populate new analytics array with old values
76
81
int i = 0 ;
77
- foreach ( int ac in oldSettings ) {
78
- newSettings [ i ] = ac ;
82
+ foreach ( int ac in oldSettings ) {
83
+ if ( i != newSettings . Length )
84
+ newSettings [ i ] = ac ;
79
85
i ++ ;
80
86
}
81
-
87
+
82
88
Properties . Settings . Default . TotalActionsExecuted = newSettings ;
83
89
Properties . Settings . Default . Save ( ) ;
84
90
}
@@ -94,7 +100,6 @@ public static void SetupAnalyticsAsync() {
94
100
MainProgram . DoDebug ( "Annonymous analytics are not being shared" ) ;
95
101
}
96
102
}
97
-
98
103
public static void PrintAnalytics ( ) {
99
104
int i = 0
100
105
, totalCount = 0 ;
@@ -114,11 +119,14 @@ public static void AddCount(string action, string type) {
114
119
AddTypeCount ( type ) ;
115
120
int pos = Array . IndexOf ( actions , action ) ;
116
121
if ( pos > - 1 ) {
122
+ //MainProgram.DoDebug("Added +1 to " + action + " at pos " + pos);
117
123
Properties . Settings . Default . TotalActionsExecuted [ pos ] ++ ;
118
124
Properties . Settings . Default . Save ( ) ;
119
125
} else {
120
126
MainProgram . DoDebug ( "Could not find action \" " + action + "\" in action-array (analytics)" ) ;
121
127
}
128
+
129
+ SendAnalyticsData ( ) ;
122
130
}
123
131
public static void AddCount ( int action , string type ) {
124
132
AddTypeCount ( type ) ;
@@ -145,22 +153,14 @@ private static void AddTypeCount(string type) {
145
153
}
146
154
}
147
155
148
- /*public static async System.Threading.Tasks.Task SendDataAsync() { // < for version 1.1
149
- if (ACC_Updater.RemoteFileExists(sendDataUrl)) {
150
- using (var wb = new WebClient()) {
151
-
152
- var values = new Dictionary<string, string> {
153
- { "actions_executed", JsonConvert.SerializeObject(Properties.Settings.Default.TotalActionsExecuted) },
154
- { "thing2", "world" }
155
- };
156
- var content = new FormUrlEncodedContent(values);
157
- var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);
158
-
159
- client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Your Oauth token");
160
-
161
- var responseString = await response.Content.ReadAsStringAsync();
162
- }
156
+ public static string SendAnalyticsData ( ) {
157
+ //Sends analytics data to the server
158
+ if ( Properties . Settings . Default . SendAnonymousAnalytics ) {
159
+ //Do it (sensitive code)
160
+ } else {
161
+ //Don't do it (does nothing here)
163
162
}
164
- }*/
163
+ return "" ;
164
+ }
165
165
}
166
- }
166
+ }
0 commit comments