123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- using DirectShowLib;
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace ImpulseVision
- {
- class ApplicationParameters
- {
- #region <Переменные>
- private bool autoRun;
- private Point points;//положение окна
- private Size sizes;//размеры окна
- private int countDay;
- public bool AutoRun
- {
- get { return GetStatusAutoRun(); }
- set
- {
- autoRun = value;
- if (autoRun)
- {
- SetAutoRun(Application.ExecutablePath);
- }
- else
- {
- RemoveAutoRun();
- }
- }
- }
- /// <summary>
- /// положение формы
- /// </summary>
- public Point Points
- {
- get { return GetFormLocation(); }
- set
- {
- points = value;
- if (points.X != -1 && points.Y != -1)
- {
- SetFormLocation(points);
- }
- else
- {
- RemoveFormLocation();
- }
- }
- }
- public Size Sizes
- {
- get { return GetSizeForm(); }
- set
- {
- sizes = value;
- if (sizes.Width != -1 && sizes.Height != -1)
- {
- SetSizeWindow(sizes);
- }
- else
- {
- RemoveSizeWindow();
- }
- }
- }
- public int CountDay
- {
- get { return GetCountDay(); }
- set
- {
- countDay = value;
- if (countDay != -1)
- {
- SetSaveLogFiles(countDay);
- }
- else
- {
- RemoveSaveLogFiles();
- }
- }
- }
- #endregion
- public ApplicationParameters()
- {
- }
- public struct FormParameters
- {
- public bool startingWithWindows;
- public Point points;
- public Size sizes;
- public int countDay;
- }
- /// <summary>
- /// получение параметров формы
- /// </summary>
- private FormParameters GetParameters()
- {
- //получить параметры из реестра и возвратить в качестве структуры
- return new FormParameters();
- }
- public void DeleteAllParameter()
- {
- RegistryKey Reg = Registry.CurrentUser.OpenSubKey("Software", true);
- try
- {
- Reg.DeleteSubKeyTree("AppDemo");
- MessageBox.Show("Ключ реестра удалён!");
- }
- catch
- {
- MessageBox.Show("Указанного ключа реестра не существует!");
- }
- Reg.Close();
- }
- #region --Загрузка вместе с ОС--
- /// <summary>
- /// задание параметров автозагрузки
- /// </summary>
- private void SetAutoRun(string executablePath)
- {
- RegistryKey Reg = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run\");
- try
- {
- executablePath = executablePath.Replace("/", "\\");
- Reg.SetValue("ImpulseVisionApp", executablePath);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "ImpulseVision", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- Reg.Close();
- StreamWriter Sw = new StreamWriter(Application.StartupPath + "\\autorun.txt");
- Sw.Close();
- }
- /// <summary>
- /// получение статуса автозагрузки
- /// </summary>
- /// <returns>включена или выключена (true/false)</returns>
- private bool GetStatusAutoRun()
- {
- bool Status = false;
- RegistryKey Reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run\",true);
- if (Reg != null)
- {
- Status = Reg.GetValue("ImpulseVisionApp") != null;
- }
- Reg.Close();
- return Status;
- }
- /// <summary>
- /// удаление автозагрузки
- /// </summary>
- private void RemoveAutoRun()
- {
- RegistryKey Reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run\", true);
- if (Reg != null)
- {
- if (Reg.GetValue("ImpulseVisionApp") != null)
- {
- Reg.DeleteValue("ImpulseVisionApp");
- }
- }
- Reg.Close();
- if (File.Exists(Application.StartupPath + "\\autorun.txt"))
- {
- File.Delete(Application.StartupPath + "\\autorun.txt");
- }
- }
- #endregion
- #region --Положение формы--
- /// <summary>
- /// установка параметров положения формы
- /// </summary>
- private void SetFormLocation(Point points)
- {
- int PosX = points.X;
- int PosY = points.Y;
- RegistryKey Reg = Registry.CurrentUser.CreateSubKey("Software\\ImpulseVisionApp", true);
- Reg.SetValue("LocX", points.X);
- Reg.SetValue("LocY", points.Y);
- Reg.Close();
- }
- private Point GetFormLocation()
- {
- int PosX = -1;
- int PosY = -1;
- RegistryKey Reg = Registry.CurrentUser.OpenSubKey("Software\\ImpulseVisionApp", true);
- if(Reg != null)
- {
- if (Reg.GetValue("LocX") != null)
- {
- PosX = (int)Reg.GetValue("LocX");
- }
- if (Reg.GetValue("LocY") != null)
- {
- PosY = (int)Reg.GetValue("LocY");
- }
- }
- Reg.Close();
- return new Point(PosX, PosY);
- }
- /// <summary>
- /// удаление сохранения положения формы
- /// </summary>
- private void RemoveFormLocation()
- {
- RegistryKey Reg = Registry.CurrentUser.OpenSubKey("Software\\ImpulseVisionApp", true);
- if(Reg != null)
- {
- if (Reg.GetValue("LocX") != null)
- {
- Reg.DeleteValue("LocX");
- }
- if (Reg.GetValue("LocY") != null)
- {
- Reg.DeleteValue("LocY");
- }
- }
- Reg.Close();
- }
- #endregion
- #region --Размеры окна--
- /// <summary>
- /// установка настроек для сохранения размеров окна
- /// </summary>
- private void SetSizeWindow(Size sizes)
- {
- RegistryKey Reg = Registry.CurrentUser.OpenSubKey("Software\\ImpulseVisionApp", true);
- if (Reg == null)
- Reg = Registry.CurrentUser.CreateSubKey("Software\\ImpulseVisionApp");
- Reg.SetValue("width", sizes.Width);
- Reg.SetValue("height", sizes.Height);
- Reg.Close();
- }
- /// <summary>
- /// получение ранее сохранённых размеров формы
- /// </summary>
- /// <returns></returns>
- private Size GetSizeForm()
- {
- int Wigth = -1, Height = -1;
- RegistryKey Reg = Registry.CurrentUser.OpenSubKey("Software\\ImpulseVisionApp");
- if(Reg != null)
- {
- if (Reg.GetValue("width") != null)
- {
- Wigth = (int)Reg.GetValue("width");
- }
- if (Reg.GetValue("height") != null)
- {
- Height = (int)Reg.GetValue("height");
- }
- }
- Reg.Close();
- return new Size(Wigth, Height);
- }
- /// <summary>
- /// удалить настройки для сохранения размеров окна
- /// </summary>
- private void RemoveSizeWindow()
- {
- RegistryKey Reg = Registry.CurrentUser.OpenSubKey("Software\\ImpulseVisionApp", true);
- if (Reg != null)
- {
- if(Reg.GetValue("width") != null)
- Reg.DeleteValue("width");
- if(Reg.GetValue("height") != null)
- Reg.DeleteValue("height");
- }
- Reg.Close();
- }
- #endregion
- #region --Хранение файлов журнала--
- /// <summary>
- /// установка количества дней хранения файлов журнала
- /// </summary>
- private void SetSaveLogFiles(int countDay)
- {
- RegistryKey Reg = Registry.CurrentUser.OpenSubKey("Software\\ImpulseVisionApp", true);
- if (Reg == null)
- Reg = Registry.CurrentUser.CreateSubKey("Software\\ImpulseVisionApp");
- Reg.SetValue("countDay", countDay);
- Reg.Close();
- }
- private int GetCountDay()
- {
- int CountDay = 2;
- RegistryKey Reg = Registry.CurrentUser.OpenSubKey("Software\\ImpulseVisionApp");
- if (Reg != null)
- {
- if (Reg.GetValue("countDay") != null)
- {
- CountDay = (int)Reg.GetValue("countDay");
- }
- Reg.Close();
- }
- return CountDay;
- }
- /// <summary>
- /// удаление параметра для сохранения файлов журнала
- /// </summary>
- private void RemoveSaveLogFiles()
- {
- RegistryKey Reg = Registry.CurrentUser.OpenSubKey("Software\\ImpulseVisionApp", true);
- if(Reg != null)
- {
- if (Reg.GetValue("countDay") != null)
- {
- Reg.DeleteValue("countDay");
- }
- }
- }
- #endregion
- }
- }
|