1- using Newtonsoft . Json ;
21using 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 ;
102
113namespace AssistantComputerControl {
124 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
178
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!
1915 "shutdown" , //0
2016 "restart" , //1
2117 "open" , //2
@@ -29,9 +25,18 @@ class AnalyticsSettings {
2925 "next_song" , //10
3026 "die" , //11
3127 "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
3237 } ;
3338
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!
3540 "google" ,
3641 "alexa" ,
3742 "cortana" ,
@@ -43,7 +48,7 @@ class KeyHandler {
4348 public string Message { get ; set ; }
4449 public string Key { get ; set ; }
4550 }
46-
51+
4752 public static void SetupAnalyticsAsync ( ) {
4853 //Unique user-ID
4954 if ( Properties . Settings . Default . UID == "" || Properties . Settings . Default . UID == null ) {
@@ -66,19 +71,20 @@ public static void SetupAnalyticsAsync() {
6671
6772 int [ ] actionsExecuted = Properties . Settings . Default . TotalActionsExecuted ;
6873 if ( actions . Length != actionsExecuted . Length ) {
69- MainProgram . DoDebug ( actions . Length + "!= " + actionsExecuted . Length ) ;
74+ // MainProgram.DoDebug(actions.Length + " != " + actionsExecuted.Length);
7075
7176 //New action most likely added
7277 int [ ] oldSettings = actionsExecuted
7378 , newSettings = new int [ actions . Length ] ;
7479
7580 //Populate new analytics array with old values
7681 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 ;
7985 i ++ ;
8086 }
81-
87+
8288 Properties . Settings . Default . TotalActionsExecuted = newSettings ;
8389 Properties . Settings . Default . Save ( ) ;
8490 }
@@ -94,7 +100,6 @@ public static void SetupAnalyticsAsync() {
94100 MainProgram . DoDebug ( "Annonymous analytics are not being shared" ) ;
95101 }
96102 }
97-
98103 public static void PrintAnalytics ( ) {
99104 int i = 0
100105 , totalCount = 0 ;
@@ -114,11 +119,14 @@ public static void AddCount(string action, string type) {
114119 AddTypeCount ( type ) ;
115120 int pos = Array . IndexOf ( actions , action ) ;
116121 if ( pos > - 1 ) {
122+ //MainProgram.DoDebug("Added +1 to " + action + " at pos " + pos);
117123 Properties . Settings . Default . TotalActionsExecuted [ pos ] ++ ;
118124 Properties . Settings . Default . Save ( ) ;
119125 } else {
120126 MainProgram . DoDebug ( "Could not find action \" " + action + "\" in action-array (analytics)" ) ;
121127 }
128+
129+ SendAnalyticsData ( ) ;
122130 }
123131 public static void AddCount ( int action , string type ) {
124132 AddTypeCount ( type ) ;
@@ -145,22 +153,14 @@ private static void AddTypeCount(string type) {
145153 }
146154 }
147155
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)
163162 }
164- }*/
163+ return "" ;
164+ }
165165 }
166- }
166+ }
0 commit comments