Ejemplo n.º 1
0
        /// <summary>
        /// Alternative Form_load method since form_load doesnt get called until you first double-click the RemindMe icon due to override SetVisibleCore
        /// </summary>
        private void formLoad()
        {
            try
            {
                BLIO.Log("RemindMe_Load");
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();


                RemindMeIcon.Text = "RemindMe " + IOVariables.RemindMeVersion;



                //set unique user string
                BLIO.WriteUniqueString();


                MaterialMessageFormManager.MakeTodaysRemindersPopup();
                BLIO.Log("Today's reminders popup created");

                //Create an shortcut in the windows startup folder if it doesn't already exist
                if (!System.IO.File.Exists(IOVariables.startupFolderPath + "\\RemindMe" + ".lnk"))
                {
                    FSManager.Shortcuts.CreateShortcut(IOVariables.startupFolderPath, "RemindMe", System.Windows.Forms.Application.StartupPath + "\\" + "RemindMe.exe", "Shortcut of RemindMe");
                }
                else
                {
                    WshShell     shell = new WshShell();                                                                       //Create a new WshShell Interface
                    IWshShortcut link  = (IWshShortcut)shell.CreateShortcut(IOVariables.startupFolderPath + "\\RemindMe.lnk"); //Link the interface to our shortcut

                    //shortcut does exist, let's see if the target of that shortcut isn't the old RemindMe in the programs files
                    if (link.TargetPath.ToString().Contains("StefanGansevlesPrograms") || link.TargetPath.ToString().Contains("Program Files"))
                    {
                        BLIO.Log("Deleting old .lnk shortcut of RemindMe");
                        System.IO.File.Delete(IOVariables.startupFolderPath + "\\RemindMe.lnk");
                        FSManager.Shortcuts.CreateShortcut(IOVariables.startupFolderPath, "RemindMe", IOVariables.applicationFilesFolder + "RemindMe.exe", "Shortcut of RemindMe");
                    }
                }


                //if (Debugger.IsAttached) //Debugging ? show extra option
                //btnDebugMode.Visible = true;


                BLLocalDatabase.Song.InsertWindowsSystemSounds();

                if (BLLocalDatabase.Setting.Settings.AutoUpdate == 1) //I guess some users don't want it? :(
                {
                    tmrUpdateRemindMe.Start();
                }

                //If the setup still exists, delete it
                System.IO.File.Delete(IOVariables.rootFolder + "SetupRemindMe.msi");

                Settings set = BLLocalDatabase.Setting.Settings;
                //Call the timer once
                Thread tr = new Thread(() =>
                {
                    //wait a bit, then call the update timer once. It then runs every 5 minutes
                    Thread.Sleep(5000);
                    tmrUpdateRemindMe_Tick(null, null);
                    BLOnlineDatabase.InsertOrUpdateUser(set.UniqueString);

                    if (set.LastVersion == null)
                    {
                        set.LastVersion = IOVariables.RemindMeVersion;
                    }

                    BLLocalDatabase.Setting.UpdateSettings(set);
                });
                tr.Start();



                this.ShowInTaskbar = true;
                this.Show();
                tmrInitialHide.Start();

                //Random r = new Random();
                //tmrCheckRemindMeMessages.Interval = (r.Next(60, 300)) * 1000; //Random interval between 1 and 5 minutes
                //tmrCheckRemindMeMessages.Start();
                //BLIO.Log("tmrCheckRemindMeMessages.Interval = " + tmrCheckRemindMeMessages.Interval / 1000 + " seconds.");


                stopwatch.Stop();
                BLIO.Log("formLoad() took " + stopwatch.ElapsedMilliseconds + " ms");

                BLIO.Log("RemindMe loaded");
            }
            catch (Exception ex)
            {
                BLIO.Log("Exception in formLoadAsync() -> " + ex.GetType().ToString());
                BLOnlineDatabase.AddException(ex, DateTime.Now, IOVariables.systemLog);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Alternative Form_load method since form_load doesnt get called until you first double-click the RemindMe icon due to override SetVisibleCore
        /// </summary>
        private async Task formLoadAsync()
        {
            BLIO.Log("RemindMe_Load");

            BLIO.WriteUpdateBatch(Application.StartupPath);

            lblVersion.Text = "Version " + IOVariables.RemindMeVersion;

            Settings set = BLSettings.Settings;

            //set unique user string
            if (string.IsNullOrWhiteSpace(set.UniqueString))
            {
                if (File.Exists(IOVariables.uniqueString))
                {
                    set.UniqueString = File.ReadAllText(IOVariables.uniqueString);
                    BLSettings.UpdateSettings(set);
                }

                File.Delete(IOVariables.uniqueString);
            }
            BLIO.WriteUniqueString();

            if (set.LastVersion != null && (new Version(set.LastVersion) < new Version(IOVariables.RemindMeVersion)))
            {
                BLIO.Log("[VERSION CHECK] New version! last version: " + set.LastVersion + "  New version: " + IOVariables.RemindMeVersion);
                //User has a new RemindMe version!
                string releaseNotesString = "";

                foreach (KeyValuePair <string, string> entry in UpdateInformation.ReleaseNotes)
                {
                    if (new Version(entry.Key) > new Version(set.LastVersion))
                    {
                        releaseNotesString += "Version " + entry.Key + "\r\n" + entry.Value + "\r\n\r\n\r\n";
                    }
                }
                WhatsNew wn = new WhatsNew(set.LastVersion, releaseNotesString);
                wn.Show();


                //Before updating the lastVersion, log the update in the db
                BLOnlineDatabase.AddNewUpgrade(DateTime.Now, set.LastVersion, IOVariables.RemindMeVersion);

                //Update the lastVersion
                set.LastVersion = IOVariables.RemindMeVersion;
            }
            else
            {
                BLIO.Log("[VERSION CHECK] No new version! lastVersion: " + set.LastVersion + "  New version: " + IOVariables.RemindMeVersion);
            }

            //Default view should be reminders
            pnlMain.Controls.Add(ucReminders);

            RemindMeMessageFormManager.MakeTodaysRemindersPopup();
            BLIO.Log("Today's reminders popup created");

            //Create an shortcut in the windows startup folder if it doesn't already exist
            if (!File.Exists(IOVariables.startupFolderPath + "\\RemindMe" + ".lnk"))
            {
                FSManager.Shortcuts.CreateShortcut(IOVariables.startupFolderPath, "RemindMe", System.Windows.Forms.Application.StartupPath + "\\" + "RemindMe.exe", "Shortcut of RemindMe");
            }


            if (Debugger.IsAttached) //Debugging ? show extra option
            {
                btnDebugMode.Visible = true;
            }


            BLSongs.InsertWindowsSystemSounds();

            tmrUpdateRemindMe.Start();

            //If the setup still exists, delete it
            File.Delete(IOVariables.rootFolder + "SetupRemindMe.msi");

            //Call the timer once
            Thread tr = new Thread(() =>
            {
                //wait a bit, then call the update timer once. It then runs every 5 minutes
                Thread.Sleep(5000);
                tmrUpdateRemindMe_Tick(null, null);
                BLOnlineDatabase.InsertOrUpdateUser(set.UniqueString);
                Thread.Sleep(1500);
                if (set.LastVersion == null)
                {
                    //First time user! log it in the db
                    BLOnlineDatabase.InsertFirstTimeUser(set.UniqueString);
                    set.LastVersion = IOVariables.RemindMeVersion;
                }
                BLSettings.UpdateSettings(set);
            });

            tr.Start();



            this.Opacity       = 0;
            this.ShowInTaskbar = true;
            this.Show();
            tmrInitialHide.Start();

            //Insert the errorlog.txt into the DB if it is not empty
            if (new FileInfo(IOVariables.errorLog).Length > 0)
            {
                BLOnlineDatabase.InsertLocalErrorLog(set.UniqueString, File.ReadAllText(IOVariables.errorLog), File.ReadLines(IOVariables.errorLog).Count());
                File.WriteAllText(IOVariables.errorLog, "");
            }

            Random r = new Random();

            tmrCheckRemindMeMessages.Interval = (r.Next(60, 300)) * 1000; //Random interval between 1 and 5 minutes
            tmrCheckRemindMeMessages.Start();
            BLIO.Log("tmrCheckRemindMeMessages.Interval = " + tmrCheckRemindMeMessages.Interval / 1000 + " seconds.");
            BLIO.Log("RemindMe loaded");
            Cleanup();
        }