コード例 #1
0
        private void mainWindow_Load(object sender, EventArgs e)
        {
            Logger.Instance.Log4.Info($"MCE Controller v{System.Windows.Forms.Application.ProductVersion}" +
                                      $" - OS: {Environment.OSVersion.ToString()} on {(Environment.Is64BitProcess ? "x64" : "x86")}" +
                                      $" - .NET: {Environment.Version.ToString()}");

            // Load AppSettings
            Settings = AppSettings.Deserialize($@"{Program.ConfigPath}{AppSettings.SettingsFileName}");

            // Configure logging (some logging already happened).
            Logger.Instance.TextBoxThreshold = LogManager.GetLogger("MCEControl").Logger.Repository.LevelMap[Instance.Settings.TextBoxLogThreshold];
            Logger.Instance.Log4.Info($"Logger: Logging to {Logger.Instance.LogFile}");

            // Telemetry
            TelemetryService.Instance.Start("MCE Controller");
            Logger.Instance.Log4.Info($"Telemetry: {(TelemetryService.Instance.TelemetryEnabled ? "Enabled" : "Disabled")}");

            // Updates
            UpdateService.Instance.GotLatestVersion += GotLatestVersionHandler;
            UpdateService.Instance.CheckVersion();

            // Commands
            if (cmdWindow == null)
            {
                cmdWindow = new CommandWindow();
            }

            // watch .command file for changes
            watcher = new CommandFileWatcher($@"{Program.ConfigPath}MCEControl.commands");
            watcher.ChangedEvent += (o, a) => CmdTable_CommandsChangedEvent(o, a);
            LoadCommands();

            if (Settings.HideOnStartup)
            {
                Opacity = 0;
                Win32.PostMessage(Handle, (UInt32)WM.SYSCOMMAND, (UInt32)SC.CLOSE, 0);
            }

            SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);

            // Location can not be changed in constructor, has to be done here
            // Use Window's default for location initially. Size needs highDPI conversion.
            if (Settings.WindowLocation.IsEmpty || Settings.WindowSize.IsEmpty)
            {
                Size = new Size(this.LogicalToDeviceUnits(1024), this.LogicalToDeviceUnits(640));
            }
            else
            {
                Location = Settings.WindowLocation;
                Size     = Settings.WindowSize;
            }

            SetStatus($"Version: {Application.ProductVersion}");
            Start();
        }
コード例 #2
0
ファイル: MainWindow.cs プロジェクト: aldolo69/mcec
        private void MainWindowLoad(object sender, EventArgs e)
        {
            CheckVersion();
            // Location can not be changed in constructor, has to be done here
            Location = Settings.WindowLocation;
            Size     = Settings.WindowSize;

            CmdTable = CommandTable.Deserialize(Settings.DisableInternalCommands);
            if (CmdTable == null)
            {
                MessageBox.Show(this, Resources.MCEController_commands_read_error, Resources.App_FullName);
                _notifyIcon.Visible = false;
                Opacity             = 100;
            }
            else
            {
                AddLogEntry("MCEC: " + CmdTable.NumCommands + " commands available.");
                Opacity = (double)Settings.Opacity / 100;

                if (Settings.HideOnStartup)
                {
                    Opacity = 0;
                    Win32.PostMessage(Handle, (UInt32)WM.SYSCOMMAND, (UInt32)SC.CLOSE, 0);
                }
            }

            if (_cmdWindow == null)
            {
                _cmdWindow = new CommandWindow();
            }
            //_cmdWindow.Visible = Settings.ShowCommandWindow;

            //var t = new System.Timers.Timer() {
            //    AutoReset = false,
            //    Interval = 2000
            //};
            //t.Elapsed += (sender, args) => Start();
            //AddLogEntry("Starting services...");
            //t.Start();
            Start();
        }