11/*
22 * AssistantComputerControl
33 * Made by Albert MN.
4- * Updated: v1.4.3, 20 -04-2021
4+ * Updated: v1.4.3, 21 -04-2021
55 *
66 * Use:
77 * - Main class. Starts everything.
2727namespace AssistantComputerControl {
2828 class MainProgram {
2929 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
3131 appName = "AssistantComputerControl" ,
3232
3333 sentryToken = "super_secret" ;
@@ -39,6 +39,7 @@ class MainProgram {
3939 testingAction = false ,
4040 aboutVersionAwaiting = false ,
4141 hasAskedForSetupAgain = false ,
42+ hasStarted = false ,
4243 reopenSettingsOnClose = false ;
4344
4445 public TestStatus currentTestStatus = TestStatus . ongoing ;
@@ -72,8 +73,6 @@ static void Main(string[] args) {
7273 Console . WriteLine ( "Log location; " + logFilePath ) ;
7374 CheckSettings ( ) ;
7475
75-
76-
7776 var config = new NLog . Config . LoggingConfiguration ( ) ;
7877 var logfile = new NLog . Targets . FileTarget ( "logfile" ) { FileName = logFilePath } ;
7978 var logconsole = new NLog . Targets . ConsoleTarget ( "logconsole" ) ;
@@ -121,7 +120,7 @@ void ActualMain() {
121120 }
122121 }
123122 } 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 ) ;
125124 }
126125 /* End "copy settings" */
127126
@@ -214,10 +213,6 @@ void ActualMain() {
214213 handler = new ConsoleEventDelegate ( ConsoleEventCallback ) ;
215214 SetConsoleCtrlHandler ( handler , true ) ;
216215
217- //Check if software starts with Windows
218- if ( ! ACCStartsWithWindows ( ) )
219- sysIcon . AddOpenOnStartupMenu ( ) ;
220-
221216 //Create shortcut folder if doesn't exist
222217 if ( ! Directory . Exists ( shortcutLocation ) ) {
223218 Directory . CreateDirectory ( shortcutLocation ) ;
@@ -271,7 +266,7 @@ void ActualMain() {
271266 watcher . Created += new FileSystemEventHandler ( new ActionChecker ( ) . FileFound ) ;
272267 watcher . Renamed += new RenamedEventHandler ( new ActionChecker ( ) . FileFound ) ;
273268 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" ) ; } ;
275270
276271 DoDebug ( "\n [" + messageBoxTitle + "] Initiated. \n Listening in: \" " + CheckPath ( ) + "\" for \" ." + Properties . Settings . Default . ActionFileExtension + "\" extensions" ) ;
277272
@@ -305,6 +300,22 @@ void ActualMain() {
305300 //If newly updated
306301 if ( Properties . Settings . Default . LastKnownVersion != softwareVersion ) {
307302 //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+
308319 Properties . Settings . Default . LastUpdated = DateTime . Now ;
309320 if ( gettingStarted != null ) {
310321 DoDebug ( "'AboutVersion' window awaits, as 'Getting Started' is showing" ) ;
@@ -316,6 +327,10 @@ void ActualMain() {
316327 Properties . Settings . Default . Save ( ) ;
317328 }
318329
330+ //Check if software starts with Windows
331+ if ( ! ACCStartsWithWindows ( ) )
332+ sysIcon . AddOpenOnStartupMenu ( ) ;
333+
319334 /* 'Evalufied' user feedback implementation */
320335 if ( ( DateTime . Now - Properties . Settings . Default . LastUpdated ) . TotalDays >= 7 && Properties . Settings . Default . TimesOpened >= 7
321336 && gettingStarted == null
@@ -346,6 +361,7 @@ void ActualMain() {
346361 ActionMods . CheckMods ( ) ;
347362 TaskSchedulerSetup ( ) ;
348363
364+ hasStarted = true ;
349365 SystemEvents . SessionSwitch += new SessionSwitchEventHandler ( SystemEvents_SessionSwitch ) ; //On wake up from sleep
350366 Application . Run ( ) ;
351367 }
@@ -631,14 +647,11 @@ public static void SetStartup(bool status, bool setThroughSoftware = false) {
631647 //Create "Task Scheduler" service; run ACC on startup & log on, added by Shelby Marvell
632648 try {
633649 using ( TaskService ts = new TaskService ( ) ) {
634- var ps1File = Path . Combine ( MainProgram . currentLocation , "ExtraCleanupper.ps1" ) ;
635-
636650 TaskDefinition td = ts . NewTask ( ) ;
637- td . Principal . LogonType = TaskLogonType . S4U ;
651+ td . Principal . LogonType = TaskLogonType . InteractiveToken ;
638652 td . Principal . RunLevel = TaskRunLevel . Highest ;
639653 td . RegistrationInfo . Author = "Albert MN. | AssistantComputerControl" ;
640654 td . RegistrationInfo . Description = "AssistantComputerControl startup - Runs ACC on reboot/login" ;
641- td . Triggers . Add ( new BootTrigger ( ) ) ;
642655 td . Triggers . Add ( new LogonTrigger ( ) ) ;
643656 td . Actions . Add ( new ExecAction ( Application . ExecutablePath , null , null ) ) ;
644657
@@ -742,8 +755,9 @@ private static bool PathIsFile(string path) {
742755
743756 public static void DefaultPathIssue ( ) {
744757 //Path is program root - most likely an error, alert user
745- //new Thread(() => {
746758 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+
747761 if ( dialogResult == DialogResult . Yes ) {
748762 Properties . Settings . Default . HasCompletedTutorial = false ;
749763 Properties . Settings . Default . ActionFilePath = "" ;
@@ -755,7 +769,6 @@ public static void DefaultPathIssue() {
755769
756770 ShowGettingStarted ( ) ;
757771 }
758- //}).Start();
759772 }
760773
761774 public static string CheckPath ( ) {
@@ -777,7 +790,9 @@ public static string CheckPath() {
777790 }
778791 }
779792
780- if ( gettingStarted is null && path == currentLocation && ! hasAskedForSetupAgain ) {
793+ if ( hasStarted && gettingStarted is null && path == currentLocation && ! hasAskedForSetupAgain ) {
794+ DoDebug ( "Did it here" ) ;
795+
781796 hasAskedForSetupAgain = true ;
782797 DefaultPathIssue ( ) ;
783798 }
0 commit comments