1
1
/*
2
2
* AssistantComputerControl
3
3
* Made by Albert MN.
4
- * Updated: v1.4.3, 20 -04-2021
4
+ * Updated: v1.4.3, 21 -04-2021
5
5
*
6
6
* Use:
7
7
* - Main class. Starts everything.
27
27
namespace AssistantComputerControl {
28
28
class MainProgram {
29
29
public const string softwareVersion = "1.4.3" ,
30
- releaseDate = "2021-04-20 23:18 :00" , //YYYY-MM-DD H:i:s - otherwise it gives an error
30
+ releaseDate = "2021-04-21 00:33 :00" , //YYYY-MM-DD H:i:s - otherwise it gives an error
31
31
appName = "AssistantComputerControl" ,
32
32
33
33
sentryToken = "super_secret" ;
@@ -39,6 +39,7 @@ class MainProgram {
39
39
testingAction = false ,
40
40
aboutVersionAwaiting = false ,
41
41
hasAskedForSetupAgain = false ,
42
+ hasStarted = false ,
42
43
reopenSettingsOnClose = false ;
43
44
44
45
public TestStatus currentTestStatus = TestStatus . ongoing ;
@@ -72,8 +73,6 @@ static void Main(string[] args) {
72
73
Console . WriteLine ( "Log location; " + logFilePath ) ;
73
74
CheckSettings ( ) ;
74
75
75
-
76
-
77
76
var config = new NLog . Config . LoggingConfiguration ( ) ;
78
77
var logfile = new NLog . Targets . FileTarget ( "logfile" ) { FileName = logFilePath } ;
79
78
var logconsole = new NLog . Targets . ConsoleTarget ( "logconsole" ) ;
@@ -121,7 +120,7 @@ void ActualMain() {
121
120
}
122
121
}
123
122
} catch ( Exception e ) {
124
- Console . WriteLine ( "Error getting settings from older versions of ACC" + e . Message ) ;
123
+ Console . WriteLine ( "Error getting settings from older versions of ACC; " + e . Message ) ;
125
124
}
126
125
/* End "copy settings" */
127
126
@@ -214,10 +213,6 @@ void ActualMain() {
214
213
handler = new ConsoleEventDelegate ( ConsoleEventCallback ) ;
215
214
SetConsoleCtrlHandler ( handler , true ) ;
216
215
217
- //Check if software starts with Windows
218
- if ( ! ACCStartsWithWindows ( ) )
219
- sysIcon . AddOpenOnStartupMenu ( ) ;
220
-
221
216
//Create shortcut folder if doesn't exist
222
217
if ( ! Directory . Exists ( shortcutLocation ) ) {
223
218
Directory . CreateDirectory ( shortcutLocation ) ;
@@ -271,7 +266,7 @@ void ActualMain() {
271
266
watcher . Created += new FileSystemEventHandler ( new ActionChecker ( ) . FileFound ) ;
272
267
watcher . Renamed += new RenamedEventHandler ( new ActionChecker ( ) . FileFound ) ;
273
268
watcher . Deleted += new FileSystemEventHandler ( new ActionChecker ( ) . FileFound ) ;
274
- watcher . Error += delegate { DoDebug ( "Something wen't wrong TEST " ) ; } ;
269
+ watcher . Error += delegate { DoDebug ( "Something wen't wrong" ) ; } ;
275
270
276
271
DoDebug ( "\n [" + messageBoxTitle + "] Initiated. \n Listening in: \" " + CheckPath ( ) + "\" for \" ." + Properties . Settings . Default . ActionFileExtension + "\" extensions" ) ;
277
272
@@ -305,6 +300,22 @@ void ActualMain() {
305
300
//If newly updated
306
301
if ( Properties . Settings . Default . LastKnownVersion != softwareVersion ) {
307
302
//Up(or down)-grade, display version notes
303
+ DoDebug ( "ACC has been updated" ) ;
304
+
305
+ if ( Properties . Settings . Default . LastKnownVersion != "" && new System . Version ( Properties . Settings . Default . LastKnownVersion ) < new System . Version ( "1.4.3" ) ) {
306
+ //Had issues before; fixed now
307
+ DoDebug ( "Upgraded to 1.4.3, fixed startup - now starting with Windows" ) ;
308
+
309
+ try {
310
+ RegistryKey rk = Registry . CurrentUser . OpenSubKey ( "SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run" , true ) ;
311
+ rk . DeleteValue ( appName , false ) ;
312
+ } catch {
313
+ DoDebug ( "Failed to remove old start with win run" ) ;
314
+ }
315
+
316
+ SetStartup ( true ) ;
317
+ }
318
+
308
319
Properties . Settings . Default . LastUpdated = DateTime . Now ;
309
320
if ( gettingStarted != null ) {
310
321
DoDebug ( "'AboutVersion' window awaits, as 'Getting Started' is showing" ) ;
@@ -316,6 +327,10 @@ void ActualMain() {
316
327
Properties . Settings . Default . Save ( ) ;
317
328
}
318
329
330
+ //Check if software starts with Windows
331
+ if ( ! ACCStartsWithWindows ( ) )
332
+ sysIcon . AddOpenOnStartupMenu ( ) ;
333
+
319
334
/* 'Evalufied' user feedback implementation */
320
335
if ( ( DateTime . Now - Properties . Settings . Default . LastUpdated ) . TotalDays >= 7 && Properties . Settings . Default . TimesOpened >= 7
321
336
&& gettingStarted == null
@@ -346,6 +361,7 @@ void ActualMain() {
346
361
ActionMods . CheckMods ( ) ;
347
362
TaskSchedulerSetup ( ) ;
348
363
364
+ hasStarted = true ;
349
365
SystemEvents . SessionSwitch += new SessionSwitchEventHandler ( SystemEvents_SessionSwitch ) ; //On wake up from sleep
350
366
Application . Run ( ) ;
351
367
}
@@ -631,14 +647,11 @@ public static void SetStartup(bool status, bool setThroughSoftware = false) {
631
647
//Create "Task Scheduler" service; run ACC on startup & log on, added by Shelby Marvell
632
648
try {
633
649
using ( TaskService ts = new TaskService ( ) ) {
634
- var ps1File = Path . Combine ( MainProgram . currentLocation , "ExtraCleanupper.ps1" ) ;
635
-
636
650
TaskDefinition td = ts . NewTask ( ) ;
637
- td . Principal . LogonType = TaskLogonType . S4U ;
651
+ td . Principal . LogonType = TaskLogonType . InteractiveToken ;
638
652
td . Principal . RunLevel = TaskRunLevel . Highest ;
639
653
td . RegistrationInfo . Author = "Albert MN. | AssistantComputerControl" ;
640
654
td . RegistrationInfo . Description = "AssistantComputerControl startup - Runs ACC on reboot/login" ;
641
- td . Triggers . Add ( new BootTrigger ( ) ) ;
642
655
td . Triggers . Add ( new LogonTrigger ( ) ) ;
643
656
td . Actions . Add ( new ExecAction ( Application . ExecutablePath , null , null ) ) ;
644
657
@@ -742,8 +755,9 @@ private static bool PathIsFile(string path) {
742
755
743
756
public static void DefaultPathIssue ( ) {
744
757
//Path is program root - most likely an error, alert user
745
- //new Thread(() => {
746
758
DialogResult dialogResult = MessageBox . Show ( "It seems the path to the cloud service wasn't set correctly. Choose \" Yes\" to go through the setup again. If this doesn't work, try restarting the ACC software." , "Whoops, problem!" , MessageBoxButtons . YesNo ) ;
759
+ DoDebug ( dialogResult . ToString ( ) ) ;
760
+
747
761
if ( dialogResult == DialogResult . Yes ) {
748
762
Properties . Settings . Default . HasCompletedTutorial = false ;
749
763
Properties . Settings . Default . ActionFilePath = "" ;
@@ -755,7 +769,6 @@ public static void DefaultPathIssue() {
755
769
756
770
ShowGettingStarted ( ) ;
757
771
}
758
- //}).Start();
759
772
}
760
773
761
774
public static string CheckPath ( ) {
@@ -777,7 +790,9 @@ public static string CheckPath() {
777
790
}
778
791
}
779
792
780
- if ( gettingStarted is null && path == currentLocation && ! hasAskedForSetupAgain ) {
793
+ if ( hasStarted && gettingStarted is null && path == currentLocation && ! hasAskedForSetupAgain ) {
794
+ DoDebug ( "Did it here" ) ;
795
+
781
796
hasAskedForSetupAgain = true ;
782
797
DefaultPathIssue ( ) ;
783
798
}
0 commit comments