Skip to content

Commit 989fab8

Browse files
author
Albert Møller Nielsen
committed
fixing merge error
2 parents a5c87a5 + 5aa5689 commit 989fab8

File tree

6 files changed

+173
-118
lines changed

6 files changed

+173
-118
lines changed
3.06 MB
Binary file not shown.
Binary file not shown.

Advanced Installer/Advanced Installer.aiproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<OutputsToImport>PrimaryOutput;References</OutputsToImport>
3131
</ProjectReference>
3232
</ItemGroup>
33-
<Import Condition="'$(AdvancedInstallerMSBuildTargets)' != ''" Project="$(AdvancedInstallerMSBuildTargets)\AdvInstExtTasks.Targets" />
34-
<Import Condition="'$(AdvancedInstallerMSBuildTargets)' == ''" Project="$(MSBuildExtensionsPath32)\Caphyon\Advanced Installer\AdvInstExtTasks.Targets" />
33+
<Target Name="Build">
34+
<Error Text="This project requires Advanced Installer tool. Please download it from https://www.advancedinstaller.com/download.html" />
35+
</Target>
36+
<Import Project="$(AdvancedInstallerMSBuildTargets)\AdvInstExtTasks.Targets" Condition="'$(AdvancedInstallerMSBuildTargets)' != ''" />
37+
<Import Project="$(MSBuildExtensionsPath32)\Caphyon\Advanced Installer\AdvInstExtTasks.Targets" Condition="('$(AdvancedInstallerMSBuildTargets)' == '') And (Exists('$(MSBuildExtensionsPath32)\Caphyon\Advanced Installer\AdvInstExtTasks.Targets'))" />
3538
</Project>
Lines changed: 24 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Net.Http;
4-
using System.Net.Http.Headers;
5-
using System.Threading.Tasks;
1+
using System;
62

73
namespace AssistantComputerControl {
84
class AnalyticsSettings {
9-
const string sendDataUrl = "https://acc.albe.pw/api/ReceiveAnalyticsData.php";
10-
const string sendSharingUrl = "https://acc.albe.pw/api/IsSharing.php";
11-
public const string sentryToken = "https://[email protected]/1287269";
12-
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
8+
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";
1313

1414
public static readonly string[] actions = new String[] { //No changing this order!
1515
"shutdown", //0
@@ -43,31 +43,13 @@ class AnalyticsSettings {
4343
"unknown",
4444
};
4545

46-
public static void UpdateSharing(bool doShare) {
47-
Properties.Settings.Default.SendAnonymousAnalytics = doShare;
48-
Properties.Settings.Default.Save();
49-
50-
//Notify server whether
51-
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", @"jmF}AXK6NH!#{@/:ZHV#qK6r#YxytM>K/W6#5q/}tEK!&*_Gd\_YNUBNN/$a+$r");
52-
53-
var parameters = new Dictionary<string, string> {
54-
["uid"] = Properties.Settings.Default.UID,
55-
["share"] = doShare ? "true" : "false"
56-
};
57-
58-
try {
59-
var response = client.PostAsync(sendSharingUrl, new FormUrlEncodedContent(parameters)).Result;
60-
var contents = response.Content.ReadAsStringAsync().Result;
61-
MainProgram.DoDebug("Posted user response");
62-
} catch (Exception e) {
63-
MainProgram.DoDebug("Failed to send analytics data - something wrong with the server?");
64-
MainProgram.DoDebug(e.ToString());
65-
}
66-
67-
SetupAnalytics();
46+
class KeyHandler {
47+
public bool Status { get; set; }
48+
public string Message { get; set; }
49+
public string Key { get; set; }
6850
}
69-
70-
public static void SetupAnalytics() {
51+
52+
public static void SetupAnalyticsAsync() {
7153
//Unique user-ID
7254
if (Properties.Settings.Default.UID == "" || Properties.Settings.Default.UID == null) {
7355
string newUID = Guid.NewGuid().ToString("N");
@@ -97,12 +79,12 @@ public static void SetupAnalytics() {
9779

9880
//Populate new analytics array with old values
9981
int i = 0;
100-
foreach(int ac in oldSettings) {
82+
foreach (int ac in oldSettings) {
10183
if (i != newSettings.Length)
10284
newSettings[i] = ac;
10385
i++;
10486
}
105-
87+
10688
Properties.Settings.Default.TotalActionsExecuted = newSettings;
10789
Properties.Settings.Default.Save();
10890
}
@@ -113,22 +95,11 @@ public static void SetupAnalytics() {
11395
Properties.Settings.Default.Save();
11496
}
11597

116-
DateTime dateTime = DateTime.UtcNow.Date;
117-
string thisDay = dateTime.ToString("yyyy/MM/dd");
118-
if (Properties.Settings.Default.AnalyticsUnsentData && Properties.Settings.Default.AnalyticsThisDay == thisDay) {
119-
//Resume data for today
120-
ScheduleAnalyticsSend();
121-
} else if (Properties.Settings.Default.AnalyticsUnsentData && Properties.Settings.Default.AnalyticsThisDay != thisDay) {
122-
//Didn't send last time - sending now
123-
SendAnalyticsData();
124-
}
125-
12698
MainProgram.DoDebug("Annonymous analytics setup done");
12799
} else {
128100
MainProgram.DoDebug("Annonymous analytics are not being shared");
129101
}
130102
}
131-
132103
public static void PrintAnalytics() {
133104
int i = 0
134105
, totalCount = 0;
@@ -150,25 +121,17 @@ public static void AddCount(string action, string type) {
150121
if (pos > -1) {
151122
//MainProgram.DoDebug("Added +1 to " + action + " at pos " + pos);
152123
Properties.Settings.Default.TotalActionsExecuted[pos]++;
153-
154-
if (!Properties.Settings.Default.AnalyticsUnsentData) {
155-
Properties.Settings.Default.AnalyticsUnsentData = true;
156-
ScheduleAnalyticsSend();
157-
}
158124
Properties.Settings.Default.Save();
159125
} else {
160126
MainProgram.DoDebug("Could not find action \"" + action + "\" in action-array (analytics)");
161127
}
128+
129+
SendAnalyticsData();
162130
}
163131
public static void AddCount(int action, string type) {
164132
AddTypeCount(type);
165133
if (actions[action] != null) {
166134
Properties.Settings.Default.TotalActionsExecuted[action]++;
167-
168-
if (!Properties.Settings.Default.AnalyticsUnsentData) {
169-
Properties.Settings.Default.AnalyticsUnsentData = true;
170-
ScheduleAnalyticsSend();
171-
}
172135
Properties.Settings.Default.Save();
173136
} else {
174137
MainProgram.DoDebug("Could not find action with index \"" + action + "\" in action-array (analytics)");
@@ -190,67 +153,14 @@ private static void AddTypeCount(string type) {
190153
}
191154
}
192155

193-
static void ScheduleAnalyticsSend() {
194-
//Time when method needs to be called
195-
MainProgram.DoDebug("Analytics scheduled to be sent at 00:00");
196-
197-
DateTime dateTime = DateTime.UtcNow.Date;
198-
Properties.Settings.Default.AnalyticsThisDay = dateTime.ToString("yyyy/MM/dd");
199-
Properties.Settings.Default.Save();
200-
201-
var DailyTime = "00:00:00";
202-
var timeParts = DailyTime.Split(new char[1] { ':' });
203-
204-
var dateNow = DateTime.Now;
205-
var date = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day,
206-
int.Parse(timeParts[0]), int.Parse(timeParts[1]), int.Parse(timeParts[2]));
207-
TimeSpan ts;
208-
if (date > dateNow)
209-
ts = date - dateNow;
210-
else {
211-
date = date.AddDays(1);
212-
ts = date - dateNow;
213-
}
214-
215-
Task.Delay(ts).ContinueWith((x) => SendAnalyticsData());
216-
}
217-
218156
public static string SendAnalyticsData() {
157+
//Sends analytics data to the server
219158
if (Properties.Settings.Default.SendAnonymousAnalytics) {
220-
if (MainProgram.HasInternet()) {
221-
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", @"jmF}AXK6NH!#{@/:ZHV#qK6r#YxytM>K/W6#5q/}tEK!&*_Gd\_YNUBNN/$a+$r");
222-
223-
var parameters = new Dictionary<string, string> {
224-
["uid"] = Properties.Settings.Default.UID,
225-
["actions"] = string.Join(",", Properties.Settings.Default.TotalActionsExecuted),
226-
["assistants"] = string.Join(",", Properties.Settings.Default.AssistantType),
227-
["start_with_windows"] = Properties.Settings.Default.StartWithWindows ? "true" : "false",
228-
["version"] = MainProgram.softwareVersion,
229-
["beta_program"] = Properties.Settings.Default.BetaProgram ? "true" : "false",
230-
["date"] = Properties.Settings.Default.AnalyticsThisDay
231-
};
232-
233-
try {
234-
var response = client.PostAsync(sendDataUrl, new FormUrlEncodedContent(parameters)).Result;
235-
var contents = response.Content.ReadAsStringAsync().Result;
236-
237-
//Success
238-
Properties.Settings.Default.AnalyticsUnsentData = false;
239-
Properties.Settings.Default.Save();
240-
MainProgram.DoDebug("Analytics successfully posted");
241-
return contents;
242-
} catch (Exception e) {
243-
MainProgram.DoDebug("Failed to send analytics data - something wrong with the server?");
244-
MainProgram.DoDebug(e.ToString());
245-
return "";
246-
}
247-
} else {
248-
MainProgram.DoDebug("Failed to send analytics data; no internet connection");
249-
return "";
250-
}
159+
//Do it (sensitive code)
251160
} else {
252-
return "";
161+
//Don't do it (does nothing here)
253162
}
163+
return "";
254164
}
255165
}
256-
}
166+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Runtime.InteropServices;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace AssistantComputerControl {
9+
public static class FlashWindow {
10+
[DllImport("user32.dll")]
11+
[return: MarshalAs(UnmanagedType.Bool)]
12+
private static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
13+
14+
[StructLayout(LayoutKind.Sequential)]
15+
private struct FLASHWINFO {
16+
/// <summary>
17+
/// The size of the structure in bytes.
18+
/// </summary>
19+
public uint cbSize;
20+
/// <summary>
21+
/// A Handle to the Window to be Flashed. The window can be either opened or minimized.
22+
/// </summary>
23+
public IntPtr hwnd;
24+
/// <summary>
25+
/// The Flash Status.
26+
/// </summary>
27+
public uint dwFlags;
28+
/// <summary>
29+
/// The number of times to Flash the window.
30+
/// </summary>
31+
public uint uCount;
32+
/// <summary>
33+
/// The rate at which the Window is to be flashed, in milliseconds. If Zero, the function uses the default cursor blink rate.
34+
/// </summary>
35+
public uint dwTimeout;
36+
}
37+
38+
/// <summary>
39+
/// Stop flashing. The system restores the window to its original stae.
40+
/// </summary>
41+
public const uint FLASHW_STOP = 0;
42+
43+
/// <summary>
44+
/// Flash the window caption.
45+
/// </summary>
46+
public const uint FLASHW_CAPTION = 1;
47+
48+
/// <summary>
49+
/// Flash the taskbar button.
50+
/// </summary>
51+
public const uint FLASHW_TRAY = 2;
52+
53+
/// <summary>
54+
/// Flash both the window caption and taskbar button.
55+
/// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
56+
/// </summary>
57+
public const uint FLASHW_ALL = 3;
58+
59+
/// <summary>
60+
/// Flash continuously, until the FLASHW_STOP flag is set.
61+
/// </summary>
62+
public const uint FLASHW_TIMER = 4;
63+
64+
/// <summary>
65+
/// Flash continuously until the window comes to the foreground.
66+
/// </summary>
67+
public const uint FLASHW_TIMERNOFG = 12;
68+
69+
70+
/// <summary>
71+
/// Flash the spacified Window (Form) until it recieves focus.
72+
/// </summary>
73+
/// <param name="form">The Form (Window) to Flash.</param>
74+
/// <returns></returns>
75+
public static bool Flash(System.Windows.Forms.Form form) {
76+
// Make sure we're running under Windows 2000 or later
77+
if (Win2000OrLater) {
78+
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL | FLASHW_TIMERNOFG, uint.MaxValue, 0);
79+
return FlashWindowEx(ref fi);
80+
}
81+
return false;
82+
}
83+
84+
private static FLASHWINFO Create_FLASHWINFO(IntPtr handle, uint flags, uint count, uint timeout) {
85+
FLASHWINFO fi = new FLASHWINFO();
86+
fi.cbSize = Convert.ToUInt32(Marshal.SizeOf(fi));
87+
fi.hwnd = handle;
88+
fi.dwFlags = flags;
89+
fi.uCount = count;
90+
fi.dwTimeout = timeout;
91+
return fi;
92+
}
93+
94+
/// <summary>
95+
/// Flash the specified Window (form) for the specified number of times
96+
/// </summary>
97+
/// <param name="form">The Form (Window) to Flash.</param>
98+
/// <param name="count">The number of times to Flash.</param>
99+
/// <returns></returns>
100+
public static bool Flash(System.Windows.Forms.Form form, uint count) {
101+
if (Win2000OrLater) {
102+
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL, count, 0);
103+
return FlashWindowEx(ref fi);
104+
}
105+
return false;
106+
}
107+
108+
/// <summary>
109+
/// Start Flashing the specified Window (form)
110+
/// </summary>
111+
/// <param name="form">The Form (Window) to Flash.</param>
112+
/// <returns></returns>
113+
public static bool Start(System.Windows.Forms.Form form) {
114+
if (Win2000OrLater) {
115+
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL, uint.MaxValue, 0);
116+
return FlashWindowEx(ref fi);
117+
}
118+
return false;
119+
}
120+
121+
/// <summary>
122+
/// Stop Flashing the specified Window (form)
123+
/// </summary>
124+
/// <param name="form"></param>
125+
/// <returns></returns>
126+
public static bool Stop(System.Windows.Forms.Form form) {
127+
if (Win2000OrLater) {
128+
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_STOP, uint.MaxValue, 0);
129+
return FlashWindowEx(ref fi);
130+
}
131+
return false;
132+
}
133+
134+
/// <summary>
135+
/// A boolean value indicating whether the application is running on Windows 2000 or later.
136+
/// </summary>
137+
private static bool Win2000OrLater {
138+
get { return System.Environment.OSVersion.Version.Major >= 5; }
139+
}
140+
}
141+
}

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ For more nerdy technical info you can go to the [Wiki](https://github.com/Albert
4141

4242
So as you can see no coding is required! But if you're up for it and want to add your own features to the project it's easy! The entire project is made made in C# and the code is opensource and quite simple, so feel free to use the code in your own fork or even better; submit pull requests!
4343

44-
### Opensource & services we like
44+
### Things ACC likes
4545
* Huge thanks to [readme.io](https://readme.io/) and [Advanced Installer](https://www.advancedinstaller.com/) for letting us use their services for free, giving back to the opensource community
4646
* [Json.NET](https://www.newtonsoft.com/json); free Json library for .NET
47-
* _Based on idea by YouTuber [Hylke Jellema](https://www.youtube.com/user/hylke101)'s [video](https://www.youtube.com/watch?v=gOt1IyEAIxA)_
47+
* [Sentry.IO](https://sentry.io/welcome/); great issue-tracking making it much easier to resolve issues
48+
* _Software based on idea by YouTuber [Hylke Jellema](https://www.youtube.com/user/hylke101)'s [video](https://www.youtube.com/watch?v=gOt1IyEAIxA)_

0 commit comments

Comments
 (0)