Beispiel #1
0
        private void LoadFromKey(string key, TextBox txtReg, TextBox txtName, TextBox txtEmail)
        {
            bool original32BitRegistryAccessFlag = RegistryUtil.Force32BitRegistryAccess;

            try
            {
                byte[] regKeyData = RegistryUtil.GetHKLMValue <byte[]>(@"SOFTWARE\Perspective Software\Blue Iris\Registration", key, null);

                if (regKeyData == null)
                {
                    RegistryUtil.Force32BitRegistryAccess = !RegistryUtil.Force32BitRegistryAccess;
                    regKeyData = RegistryUtil.GetHKLMValue <byte[]>(@"SOFTWARE\Perspective Software\Blue Iris\Registration", key, null);
                }
                if (regKeyData == null)
                {
                    txtReg.Text = "Not Found!";
                }
                else if (regKeyData.Length < 41)
                {
                    txtReg.Text = "Unrecognized format!";
                }
                else
                {
                    string keyPart5 = Encoding.ASCII.GetString(regKeyData, 16, 5);
                    string keyPart1 = Encoding.ASCII.GetString(regKeyData, 21, 5);
                    string keyPart3 = Encoding.ASCII.GetString(regKeyData, 26, 5);
                    string keyPart2 = Encoding.ASCII.GetString(regKeyData, 31, 5);
                    string keyPart4 = Encoding.ASCII.GetString(regKeyData, 36, 5);

                    txtReg.Text = keyPart1 + '-' + keyPart2 + '-' + keyPart3 + '-' + keyPart4 + '-' + keyPart5;
                }

                string name = RegistryUtil.GetHKLMValue <string>(@"SOFTWARE\Perspective Software\Blue Iris\Registration", "name", null);
                if (name == null)
                {
                    txtName.Text = "";
                }
                else
                {
                    txtName.Text = name;
                }

                string email = RegistryUtil.GetHKLMValue <string>(@"SOFTWARE\Perspective Software\Blue Iris\Registration", "email", null);
                if (email == null)
                {
                    txtEmail.Text = "";
                }
                else
                {
                    txtEmail.Text = email;
                }
            }
            finally
            {
                RegistryUtil.Force32BitRegistryAccess = original32BitRegistryAccessFlag;
            }
        }
Beispiel #2
0
 public UserInfo(RegistryKey key, string name)
 {
     this.name        = name;
     admin            = RegistryUtil.GetStringValue(key, "admin") == "1";
     password_encoded = RegistryUtil.GetStringValue(key, "password");
     selgroups        = RegistryUtil.GetStringValue(key, "selgroups");
     noalerts         = RegistryUtil.GetStringValue(key, "noalerts") == "1";
     lanonly          = RegistryUtil.GetStringValue(key, "lanonly") == "1";
     enabled          = RegistryUtil.GetStringValue(key, "enabled") == "1";
     usegroups        = RegistryUtil.GetStringValue(key, "usegroups") == "1";
 }
Beispiel #3
0
        private string GetUpdateDir5_1()
        {
            string      tempPath = null;
            RegistryKey options  = RegistryUtil.HKLM.OpenSubKey("SOFTWARE\\Perspective Software\\Blue Iris\\Options");

            if (options != null)
            {
                tempPath = RegistryUtil.GetStringValue(options, "temppath");
            }
            if (string.IsNullOrWhiteSpace(tempPath))
            {
                tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Blue Iris", "temp");
            }
            return(tempPath.TrimEnd('/', '\\') + Path.DirectorySeparatorChar);
        }
Beispiel #4
0
		private static void AutoFixBad32BitSetting()
		{
			if (Environment.Is64BitOperatingSystem)
			{
				// This is a 64 bit OS, so it is possible that our bi32OnWin64 setting is wrong.
				if (RegistryUtil.GetHKLMKey(@"SOFTWARE\Perspective Software\Blue Iris") == null)
				{
					// No BI detected. Try the opposite setting.
					RegistryUtil.Force32BitRegistryAccess = !RegistryUtil.Force32BitRegistryAccess;
					if (RegistryUtil.GetHKLMKey(@"SOFTWARE\Perspective Software\Blue Iris") == null)
						RegistryUtil.Force32BitRegistryAccess = !RegistryUtil.Force32BitRegistryAccess; // No BI detected. Revert setting.
					else
					{
						// Found BI using the opposite setting.  Save the setting.
						settings.bi32OnWin64 = RegistryUtil.Force32BitRegistryAccess;
						settings.Save();
					}
				}
			}
		}
        public static void Reload()
        {
            RegistryKey server = RegistryUtil.HKLM.OpenSubKey("SOFTWARE\\Perspective Software\\Blue Iris\\server");

            if (server == null)
            {
                return;
            }
            enabled = RegistryUtil.GetStringValue(server, "enable") == "1";
            if (enabled)
            {
                try
                {
                    lanIp        = RegistryUtil.GetStringValue(server, "lanip");
                    port         = RegistryUtil.GetIntValue(server, "port", 80);
                    authenticate = (AuthenticationMode)RegistryUtil.GetIntValue(server, "authenticate", 0);
                    secureonly   = RegistryUtil.GetStringValue(server, "secureonly") == "1";
                }
                catch
                {
                    enabled = false;
                }
            }
        }
        public static string GetOsVersion()
        {
            StringBuilder sb       = new StringBuilder();
            string        prodName = RegistryUtil.GetHKLMValue(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "Unknown");

            sb.Append(prodName);

            string release = RegistryUtil.GetHKLMValue(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", "");

            if (string.IsNullOrWhiteSpace(release))
            {
                sb.Append(" v" + RegistryUtil.GetHKLMValue(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", "Unknown"));
            }
            else
            {
                sb.Append(" v" + release);
                string build = RegistryUtil.GetHKLMValue(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuildNumber", "");
                if (string.IsNullOrWhiteSpace(build))
                {
                    build = RegistryUtil.GetHKLMValue(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuildNumber", "");
                }
                if (!string.IsNullOrWhiteSpace(build))
                {
                    sb.Append(" b" + build);
                }
            }
            if (Environment.Is64BitOperatingSystem)
            {
                sb.Append(" (64 bit)");
            }
            else
            {
                sb.Append(" (32 bit)");
            }
            return(sb.ToString());
        }
        /// <summary>
        /// Creates an anonymous usage record.  This method spends 10 seconds measuring CPU usage.  Returns null if any BlueIris.exe processes close while CPU usage is being measured, or if no BlueIris.exe processes were open.
        /// </summary>
        /// <returns></returns>
        public static Upload_Record GetPerfDataRecord()
        {
            Upload_Record record = new Upload_Record();

            // Begin measuring CPU usage.
            using (PerformanceCounter totalCpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"))
            {
                totalCpuCounter.NextValue();
                Stopwatch sw = new Stopwatch();
                sw.Start();
                List <Process> biProcs = Process.GetProcesses().Where(p => p.ProcessName.ToLower() == "blueiris").ToList();
                if (biProcs.Count < 1)
                {
                    Logger.Info("Unable to generate anonymous performance data record because Blue Iris is not running.");
                    return(null);
                }
                TimeSpan[] startTimes = new TimeSpan[biProcs.Count];
                for (int i = 0; i < biProcs.Count; i++)
                {
                    startTimes[i] = biProcs[i].TotalProcessorTime;
                }

                // Wait for CPU usage to happen.
                Thread.Sleep(10000);

                // Take CPU usage measurements.
                record.CpuUsage = (byte)Math.Round(totalCpuCounter.NextValue());
                sw.Stop();
                TimeSpan totalTime = TimeSpan.Zero;
                for (int i = 0; i < biProcs.Count; i++)
                {
                    biProcs[i].Refresh();
                    if (biProcs[i].HasExited)
                    {
                        Logger.Info("Unable to generate anonymous performance data record because Blue Iris exited while CPU usage was being measured.");
                        return(null);
                    }
                    totalTime += biProcs[i].TotalProcessorTime - startTimes[i];
                }
                double fraction = totalTime.TotalMilliseconds / sw.Elapsed.TotalMilliseconds;
                record.BiCpuUsage = (byte)Math.Round((fraction / Environment.ProcessorCount) * 100);
                record.CpuThreads = (short)Environment.ProcessorCount;

                long physicalMemUsage = 0;
                long virtualMemUsage  = 0;
                foreach (Process p in biProcs)
                {
                    if (record.BiVersion == null)
                    {
                        record.BiVersion = p.MainModule.FileVersionInfo.FileVersion + " " + (MainSvc.Is64Bit(p) ? "x64" : "x86");
                    }
                    physicalMemUsage += p.WorkingSet64;
                    virtualMemUsage  += p.VirtualMemorySize64;
                }
                record.BiMemUsageMB            = (int)(physicalMemUsage / 1000000);
                record.BiPeakVirtualMemUsageMB = (int)(virtualMemUsage / 1000000);

                foreach (Process p in biProcs)
                {
                    IntPtr handle = p.MainWindowHandle;
                    if (handle == IntPtr.Zero)
                    {
                        // This is the service.
                    }
                    else
                    {
                        // This is the console.
                        record.ConsoleOpen = true;
                        try
                        {
                            WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
                            if (GetWindowPlacement(handle, ref placement))
                            {
                                if (placement.showCmd == 2)
                                {
                                    // Minimized
                                    record.ConsoleWidth  = -2;
                                    record.ConsoleHeight = -2;
                                }
                                else
                                {
                                    // Not Minimized
                                    RECT Rect = new RECT();
                                    if (GetWindowRect(handle, ref Rect))
                                    {
                                        record.ConsoleWidth  = (short)NumberUtil.Clamp(Rect.right - Rect.left, 0, short.MaxValue);
                                        record.ConsoleHeight = (short)NumberUtil.Clamp(Rect.bottom - Rect.top, 0, short.MaxValue);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Debug(ex);
                        }
                    }
                }
                if (biProcs.Count > 1 && !record.ConsoleOpen)
                {
                    record.ConsoleOpen = true;
                }
            }

            record.Secret = Program.settings.secret;
            record.OS     = GetOsVersion();
            CpuInfo cpuInfo = GetCpuInfo();

            if (cpuInfo == null)
            {
                record.CpuModel = "Unknown";
                record.CpuMHz   = NumberUtil.ParseInt(cpuInfo.maxClockSpeed);
            }
            else
            {
                record.CpuModel = cpuInfo.GetModel();
                record.CpuMHz   = NumberUtil.ParseInt(cpuInfo.maxClockSpeed);
            }
            record.HelperVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            record.HwAccel       = (byte)RegistryUtil.GetHKLMValue <int>(@"SOFTWARE\Perspective Software\Blue Iris\Options", "hwaccel", 0);
            record.ServiceMode   = RegistryUtil.GetHKLMValue <int>(@"SOFTWARE\Perspective Software\Blue Iris\Options", "Service", 0) == 1;
            if (RegistryUtil.GetHKLMValue <int>(@"SOFTWARE\Perspective Software\Blue Iris\Options", "limitlive", 0) == 0)
            {
                record.LivePreviewFPS = -2;
            }
            else
            {
                record.LivePreviewFPS = (short)RegistryUtil.GetHKLMValue <int>(@"SOFTWARE\Perspective Software\Blue Iris\Options", "livefps", -1);
            }

            ComputerInfo computerInfo = new ComputerInfo();

            record.MemMB     = (int)(computerInfo.TotalPhysicalMemory / 1000000);
            record.MemFreeMB = (int)(computerInfo.AvailablePhysicalMemory / 1000000);

            RamInfo ramInfo = GetRamInfo();

            record.RamGiB        = ramInfo.GiB;
            record.RamChannels   = ramInfo.Channels;
            record.DimmLocations = ramInfo.DimmLocations;
            record.RamMHz        = ramInfo.MHz;

            // Get camera info.
            // Get frame rates (only accessible via BI's web server).
            Dictionary <string, double> fpsMap = new Dictionary <string, double>();

            BiServerInfo.Reload();
            if (BiServerInfo.enabled)
            {
                try
                {
                    using (WebClient wc = new WebClient())
                    {
                        string session  = CameraWebInterfaceLinker.GetSecureAuthenticatedSession(wc);
                        string response = wc.UploadString(CameraWebInterfaceLinker.GetJsonURL(), "{\"cmd\":\"camlist\",\"session\":\"" + session + "\"}");
                        wc.UploadString(CameraWebInterfaceLinker.GetJsonURL(), "{\"cmd\":\"logout\",\"session\":\"" + session + "\"}");
                        CamListResponse camListResponse = JsonConvert.DeserializeObject <CamListResponse>(response);
                        if (camListResponse != null && camListResponse.result == "success")
                        {
                            foreach (CameraListCamera camera in camListResponse.data)
                            {
                                if (camera.group == null)
                                {
                                    fpsMap[camera.optionValue] = camera.FPS;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Debug(ex, "Error reading camera list from web server.");
                }
            }

            // Get camera info from registry
            List <Upload_Camera> cameras = new List <Upload_Camera>();

            RegistryKey camerasKey = RegistryUtil.GetHKLMKey(@"SOFTWARE\Perspective Software\Blue Iris\Cameras");

            foreach (string camName in camerasKey.GetSubKeyNames())
            {
                RegistryKey camKey = camerasKey.OpenSubKey(camName);
                if (RegistryUtil.GetIntValue(camKey, "enabled", 0) != 1)
                {
                    continue;
                }
                string        shortName = RegistryUtil.GetStringValue(camKey, "shortname");
                Upload_Camera cam       = new Upload_Camera();

                if (fpsMap.TryGetValue(shortName, out double fps))
                {
                    cam.FPS = (byte)NumberUtil.Clamp(Math.Round(fps), 0, 255);
                }
                else
                {
                    int interval = RegistryUtil.GetIntValue(camKey, "interval", 1000000);
                    if (interval <= 0)
                    {
                        cam.FPS = 0;
                    }
                    else
                    {
                        cam.FPS = (byte)NumberUtil.Clamp(Math.Round(10000000.0 / interval), 0, 255);
                    }
                }
                cam.CapType     = (byte)RegistryUtil.GetIntValue(camKey, "screencap", 0);
                cam.Hwaccel     = (byte)RegistryUtil.GetIntValue(camKey, "ip_hwaccel", 0);
                cam.LimitDecode = RegistryUtil.GetIntValue(camKey, "smartdecode", 0) == 1;
                cam.Pixels      = RegistryUtil.GetIntValue(camKey, "fullxres", 0) * RegistryUtil.GetIntValue(camKey, "fullyres", 0);
                cam.Type        = (byte)RegistryUtil.GetIntValue(camKey, "type", 0);
                RegistryKey motionKey = camKey.OpenSubKey("Motion");
                cam.MotionDetector    = RegistryUtil.GetIntValue(motionKey, "enabled", 0) == 1;
                cam.RecordTriggerType = (byte)RegistryUtil.GetIntValue(motionKey, "continuous", 0);
                RegistryKey clipsKey = camKey.OpenSubKey("Clips");
                cam.RecordFormat = (byte)RegistryUtil.GetIntValue(clipsKey, "movieformat", 0);
                cam.DirectToDisk = RegistryUtil.GetIntValue(clipsKey, "transcode", 0) == 0;
                cam.VCodec       = RegistryUtil.GetStringValue(clipsKey, "vcodec");
                cameras.Add(cam);
            }

            record.cameras = cameras.ToArray();
            record.gpus    = GetGpuInfo().Select(g => new Upload_Gpu()
            {
                Name = g.Name, Version = g.DriverVersion
            }).ToArray();

            return(record);
        }