Example #1
0
 private void TryBackupRegistryForBiVersion(BiVersionInfo versionInfo)
 {
     if (versionInfo != null && Program.settings.includeRegistryWithUpdateBackup)
     {
         RegistryBackup.BackupNow(BiUpdateHelperSettings.GetBeforeUpdatesRegistryBackupLocation() + Path.DirectorySeparatorChar + "BI_REG_" + versionInfo.cpu_32_64 + "-" + versionInfo.version + ".reg");
     }
 }
Example #2
0
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		static void Main()
		{
			string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
			Globals.Initialize(exePath);
			PrivateAccessor.SetStaticFieldValue(typeof(Globals), "errorFilePath", Globals.WritableDirectoryBase + "BiUpdateHelper_Log.txt");

			FileInfo fiExe = new FileInfo(exePath);
			Environment.CurrentDirectory = fiExe.Directory.FullName;

			settings = new BiUpdateHelperSettings();
			settings.Load();
			if (string.IsNullOrWhiteSpace(settings.secret))
			{
				settings.secret = Hash.GetSHA256Hex(Guid.NewGuid().ToString());
				settings.Save();
			}
			settings.SaveIfNoExist();

			RegistryUtil.Force32BitRegistryAccess = settings.bi32OnWin64;

			AutoFixBad32BitSetting();

			PerformanceData.PerformanceDataCollector.onReportUploaded = () =>
			{
				settings.Load();
				settings.lastUsageReportAt = TimeUtil.GetTimeInMsSinceEpoch();
				settings.Save();
			};
			PerformanceData.PerformanceDataCollector.getSecretString = () =>
			{
				return Program.settings.secret;
			};

			if (Environment.UserInteractive)
			{
				string Title = "BiUpdateHelper " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + " Service Manager";
				string ServiceName = "BiUpdateHelper";
				ButtonDefinition btnRegKey = new ButtonDefinition("BI Registration Info", btnRegkey_Click);
				ButtonDefinition btnSettings = new ButtonDefinition("Edit Service Settings", btnSettings_Click);
				ButtonDefinition btnCameraConfigLinks = new ButtonDefinition("Camera Config Links", btnCameraConfigLinks_Click);
				ButtonDefinition btnRegistryBackupNow = new ButtonDefinition("Take Registry Backup Now", btnRegistryBackupNow_Click);
				ButtonDefinition btnPerfData = new ButtonDefinition("Performance Data", btnPerfData_Click);
				ButtonDefinition[] customButtons = new ButtonDefinition[] { btnRegKey, btnSettings, btnCameraConfigLinks, btnRegistryBackupNow, btnPerfData };

				System.Windows.Forms.Application.Run(new ServiceManager(Title, ServiceName, customButtons));
			}
			else
			{
				ServiceBase[] ServicesToRun;
				ServicesToRun = new ServiceBase[]
				{
					new MainSvc()
				};
				ServiceBase.Run(ServicesToRun);
			}
		}
Example #3
0
 private void btnViewRegistryBackups_Click(object sender, EventArgs e)
 {
     Process.Start(BiUpdateHelperSettings.GetRegistryBackupLocation());
 }
Example #4
0
 private static void btnRegistryBackupNow_Click(object sender, EventArgs e)
 {
     RegistryBackup.BackupNow(BiUpdateHelperSettings.GetManualRegistryBackupLocation() + Path.DirectorySeparatorChar + "BI_REG_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".reg");
 }
Example #5
0
        private void UpdateWatch()
        {
            try
            {
                try
                {
                    Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal;
                }
                catch (ThreadAbortException) { throw; }
                catch { }
                cpuCounterTotal       = new PerformanceCounter("Processor", "% Processor Time", "_Total");
                interruptCounterTotal = new PerformanceCounter("Processor", "% Interrupt Time", "_Total");
                DateTime lastDailyRegistryBackup = DateTime.MinValue;
                while (true)
                {
                    Thread.Sleep(1500);
                    Verbose("Starting Iteration");
                    try
                    {
                        PerformanceDataCollector.HandlePossiblePerfDataReport();
                        DateTime now = DateTime.Now;
                        if (lastDailyRegistryBackup.Year != now.Year || lastDailyRegistryBackup.Month != now.Month || lastDailyRegistryBackup.Day != now.Day)
                        {
                            lastDailyRegistryBackup = now;
                            if (Program.settings.dailyRegistryBackups)
                            {
                                RegistryBackup.BackupNow(BiUpdateHelperSettings.GetDailyRegistryBackupLocation() + Path.DirectorySeparatorChar + "BI_REG_" + DateTime.Now.ToString("yyyy-MM-dd") + ".reg");
                            }
                        }
                        // Build a list of unique directories that have an active blueiris.exe.
                        // There is not likely to be more than one directory, though a single directory
                        // can easily have two blueiris.exe (service and GUI).
                        List <BiUpdateMapping> biUpdateMap = GetUpdateInfo();

                        if (biUpdateMap.Count == 0)
                        {
                            Verbose("No Blue Iris processes detected");
                        }
                        else
                        {
                            foreach (BiUpdateMapping mapping in biUpdateMap)
                            {
                                if (mapping.updateProcs.Length > 0)
                                {
                                    // Blue Iris is currently being updated.  Kill the blueiris.exe processes if configured to do so.
                                    Logger.Info("Blue Iris update detected in path: " + mapping.dirPath);
                                    if (Program.settings.includeRegistryWithUpdateBackup)
                                    {
                                        BiVersionInfo versionInfo = GetBiVersionInfo(mapping);
                                        TryBackupRegistryForBiVersion(versionInfo);
                                    }
                                    if (Program.settings.killBlueIrisProcessesDuringUpdate2)
                                    {
                                        Logger.Info("Killing " + mapping.GetNumProcsLabel());
                                        mapping.KillBiProcs();
                                    }
                                    Verbose("Waiting for update to complete");
                                    mapping.WaitUntilUpdateProcsStop(TimeSpan.FromMinutes(5));
                                }
                                else
                                {
                                    // Blue Iris is not being updated in this directory.

                                    if (Program.settings.killBlueIrisProcessesDuringUpdate2 && (blueIrisServiceStopping || systemInFrozenState))
                                    {
                                        mapping.KillBiProcs();

                                        if (blueIrisServiceStopping)
                                        {
                                            Logger.Info("Blue Iris service found in stopping state. Killed " + mapping.GetNumProcsLabel());
                                        }
                                        else if (systemInFrozenState)
                                        {
                                            Logger.Info("System freeze with high interrupt % detected. Killed " + mapping.GetNumProcsLabel());
                                        }
                                        continue;
                                    }

                                    // Back up the update file if configured to do so.
                                    if (!Program.settings.backupUpdateFiles)
                                    {
                                        continue;
                                    }

                                    //Check for the existence of an update.exe file
                                    FileInfo fiUpdate = new FileInfo(mapping.dirPath + "update.exe");
                                    if (!fiUpdate.Exists)
                                    {
                                        Verbose("No update file to back up in path: " + mapping.dirPath);
                                        continue;
                                    }

                                    Verbose("Backing up update file: " + fiUpdate.FullName);

                                    // Get Blue Iris process(es) (necessary to learn if it is 64 or 32 bit)
                                    BiVersionInfo versionInfo = GetBiVersionInfo(mapping);
                                    if (versionInfo == null)
                                    {
                                        continue;                                         // BI is probably not running
                                    }
                                    FileInfo targetUpdateFile = new FileInfo(mapping.dirPath + "update" + versionInfo.cpu_32_64 + "_" + versionInfo.version + ".exe");
                                    if (targetUpdateFile.Exists)
                                    {
                                        // A backed-up update file for the active Blue Iris version already exists, so we should do nothing now
                                        Verbose("Target update file \"" + targetUpdateFile.FullName + "\" already exists.  Probably, the new update file hasn't been installed yet.");
                                        TryBackupRegistryForBiVersion(versionInfo);
                                    }
                                    else
                                    {
                                        // Find out if the file can be opened exclusively (meaning it is finished downloading, etc)
                                        bool fileIsUnlocked = false;
                                        try
                                        {
                                            using (FileStream fs = new FileStream(fiUpdate.FullName, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
                                            {
                                                fileIsUnlocked = true;
                                            }
                                        }
                                        catch (ThreadAbortException) { throw; }
                                        catch (Exception) { }

                                        if (fileIsUnlocked)
                                        {
                                            // This is a pretty good sign that the update is not curently being installed, so we should be safe to rename the update file.
                                            Logger.Info("Renaming update file to: " + targetUpdateFile.FullName);
                                            fiUpdate.MoveTo(targetUpdateFile.FullName);
                                        }
                                        else
                                        {
                                            Verbose("Update file could not be exclusively locked. Backup will not occur this iteration.");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (ThreadAbortException) { throw; }
                    catch (Exception ex)
                    {
                        Logger.Debug(ex);
                    }
                }
            }
            catch (ThreadAbortException) { }
            catch (Exception ex)
            {
                Logger.Debug(ex);
            }
        }