Example #1
0
        public HiddenMain()
        {
            this.Hide();

            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
            // Prepare the configuration file path
            if (! Directory.Exists(this._sConfPath)) {
                DirectoryInfo confDirInfo = Directory.CreateDirectory(this._sConfPath);
                confDirInfo.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
            }
            // The config file map
            ExeConfigurationFileMap confFileMap = new ExeConfigurationFileMap();
            confFileMap.ExeConfigFilename = this._sConfPath + "totp.config";

            // Prepare related objects
            this._confApp = ConfigurationManager.OpenMappedExeConfiguration(confFileMap, ConfigurationUserLevel.None);
            this._TOTPSecret = (TOTP_Secret)this._confApp.GetSection(this._sTOTPSectionName);
            if (null == this._TOTPSecret) {
                this._TOTPSecret = new TOTP_Secret();
                this._confApp.Sections.Add(this._sTOTPSectionName, this._TOTPSecret);

                this._TOTPSecret.SectionInformation.ProtectSection(this._sSecretProtect);
                this._TOTPSecret.SectionInformation.ForceSave = true;

                this._confApp.Save(ConfigurationSaveMode.Full, true);
            }
            this._TOTPAccounts = this._TOTPSecret.TOTPAccounts;
            if (this._TOTPAccounts.Count == 0) {
                this.AddNewAcct(null, null);
            }

            // Load accounts in menu
            for (int i = 0; i < this._TOTPAccounts.Count; i++) {
                this._TOTPAccounts[i].MenuItem = this.CreateAcctMenu(this._TOTPAccounts[i].ID);

                this.msTrayIcon.Items.Insert(i+1,
                                            this._TOTPAccounts[i].MenuItem);
            }

            // Tooltip
            this.trayIcon.ShowBalloonTip(5000);

            // Start timer
            this.timer1.Start();
        }
Example #2
0
        public HiddenMain()
        {
            this.Hide();

            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
            // Prepare the configuration file path
            if (!Directory.Exists(this._sConfPath))
            {
                DirectoryInfo confDirInfo = Directory.CreateDirectory(this._sConfPath);
                confDirInfo.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
            }
            // The config file map
            ExeConfigurationFileMap confFileMap = new ExeConfigurationFileMap();

            confFileMap.ExeConfigFilename = this._sConfPath + "totp.config";

            // Prepare related objects
            this._confApp    = ConfigurationManager.OpenMappedExeConfiguration(confFileMap, ConfigurationUserLevel.None);
            this._TOTPSecret = (TOTP_Secret)this._confApp.GetSection(this._sTOTPSectionName);
            if (null == this._TOTPSecret)
            {
                this._TOTPSecret = new TOTP_Secret();
                this._confApp.Sections.Add(this._sTOTPSectionName, this._TOTPSecret);

                this._TOTPSecret.SectionInformation.ProtectSection(this._sSecretProtect);
                this._TOTPSecret.SectionInformation.ForceSave = true;

                this._confApp.Save(ConfigurationSaveMode.Full, true);
            }
            this._TOTPAccounts = this._TOTPSecret.TOTPAccounts;
            if (this._TOTPAccounts.Count == 0)
            {
                this._intFirstRun = 1;
                this.AddNewAcct(null, null);
            }

            // Load accounts in menu
            for (int i = 0; i < this._TOTPAccounts.Count; i++)
            {
                this._TOTPAccounts[i].MenuItem    = this.CreateAcctMenu(this._TOTPAccounts[i].ID);
                this._TOTPAccounts[i].CurrentCode =
                    TOTP_GA.GeneratePassword(this._TOTPAccounts[i].Key, this._counter[0], this._TOTPAccounts[i].CodeLen);

                this.msTrayIcon.Items.Insert(i + 1,
                                             this._TOTPAccounts[i].MenuItem);
            }

            // Tooltip only on first run
            if (this._intFirstRun == 1)
            {
                this.trayIcon.ShowBalloonTip(5000);
            }

            // Start timer
            this.timer1.Start();
        }