Example #1
0
        /// <summary>
        /// Initialize window contents
        /// </summary>
        public FormMain(string importFile = null)
        {
            InitializeComponent();

            // Icon and translations

            this.Text                            = Program.DisplayName;
            this.Icon                            = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            tabPageScheme.Text                   = Translations.Get("tab_current_scheme");
            tabPageSettings.Text                 = Translations.Get("tab_settings");
            soundImageText.Text                  = Translations.Get("no_image");
            soundInfoNameText.Text               = Translations.Get("meta_name");
            soundInfoAuthorText.Text             = Translations.Get("meta_author");
            soundInfoAboutText.Text              = Translations.Get("meta_about");
            buttonOpen.Text                      = Translations.Get("button_open");
            buttonImport.Text                    = Translations.Get("button_import");
            buttonExport.Text                    = Translations.Get("button_export");
            buttonReset.Text                     = Translations.Get("button_reset");
            buttonExit.Text                      = Translations.Get("button_exit");
            imageContextMenu_Change.Text         = Translations.Get("image_change");
            imageContextMenu_Remove.Text         = Translations.Get("image_remove");
            soundContextMenu_Change.Text         = Translations.Get("sound_change");
            soundContextMenu_OpenLocation.Text   = Translations.Get("sound_open_location");
            soundContextMenu_Play.Text           = Translations.Get("sound_play");
            soundContextMenu_Reset.Text          = Translations.Get("sound_reset");
            soundContextMenu_Remove.Text         = Translations.Get("sound_remove");
            groupBoxImport.Text                  = Translations.Get("box_import_system_scheme");
            groupBoxSystemIntegration.Text       = Translations.Get("box_system_integration");
            checkBoxPatchImageres.Text           = Translations.Get("check_box_imageres_patch");
            checkBoxBgSoundPlayer.Text           = Translations.Get("check_box_bg_sound_player");
            checkBoxFileAssoc.Text               = Translations.Get("check_box_file_assoc");
            checkBoxMissingSoundsUseDefault.Text = Translations.Get("check_box_reset_missing_on_load");
            groupBoxMaintenance.Text             = Translations.Get("box_maintenance");
            buttonReinstall.Text                 = Translations.Get("button_reinstall");
            buttonUninstall.Text                 = Translations.Get("button_uninstall");
            tabPageAbout.Text                    = Translations.Get("tab_about");
            labelProgramName.Text                = Program.DisplayName;
            labelProgramVersionAuthor.Text       = "Version " + Program.Version + " - By ORelio";
            labelTranslationAuthor.Text          = Translations.Get("translation_author");
            labelProgramDescription.Text         = Translations.Get("app_desc");
            buttonHelp.Text                      = Translations.Get("button_help");
            buttonWebsite.Text                   = Translations.Get("button_website");
            groupBoxSystemInfo.Text              = Translations.Get("box_system_info");

            // System information

            labelSystemInfo.Text = String.Format(
                "{0} / Windows NT {1}.{2}",
                WindowsVersion.FriendlyName,
                WindowsVersion.WinMajorVersion,
                WindowsVersion.WinMinorVersion
                );

            labelSystemSupportStatus.Text =
                WindowsVersion.IsBetween(Program.WindowsVersionMin, Program.WindowsVersionMax)
                    ? Translations.Get("supported_system_version")
                    : Translations.Get("unsupported_system_version");

            // Load UI settings

            checkBoxPatchImageres.Enabled         = ImageresPatcher.IsWindowsVista7;
            checkBoxPatchImageres.Checked         = ImageresPatcher.IsWindowsVista7 && Settings.WinVista7PatchEnabled;
            checkBoxPatchImageres.CheckedChanged += new System.EventHandler(this.checkBoxPatchImageres_CheckedChanged);

            checkBoxBgSoundPlayer.Enabled         = BgSoundPlayer.RequiredForThisWindowsVersion;
            checkBoxBgSoundPlayer.Checked         = BgSoundPlayer.RequiredForThisWindowsVersion && BgSoundPlayer.RegisteredForStartup;
            checkBoxBgSoundPlayer.CheckedChanged += new EventHandler(checkBoxBgSoundPlayer_CheckedChanged);

            checkBoxMissingSoundsUseDefault.Checked         = Settings.MissingSoundUseDefault;
            checkBoxMissingSoundsUseDefault.CheckedChanged += new EventHandler(checkBoxMissingSoundsUseDefault_CheckedChanged);

            checkBoxFileAssoc.Checked         = SoundArchive.FileAssociation;
            checkBoxFileAssoc.CheckedChanged += new System.EventHandler(this.checkBoxFileAssoc_CheckedChanged);

            // Image and scheme info

            RefreshSchemeMetadata();

            // Sound event list

            soundList.View                     = View.LargeIcon;
            soundList.MultiSelect              = false;
            soundList.LargeImageList           = new ImageList();
            soundList.LargeImageList.ImageSize = new Size(32, 32);
            soundList.ShowItemToolTips         = true;

            foreach (SoundEvent soundEvent in SoundEvent.GetAll())
            {
                string iconName = Path.GetFileNameWithoutExtension(soundEvent.FileName);
                Bitmap icon     = soundIcons.GetObject(iconName, SoundManager.SoundIcons.Culture) as Bitmap;
                if (icon != null)
                {
                    soundList.LargeImageList.Images.Add(iconName, icon);
                }
                ListViewItem item = soundList.Items.Add(soundEvent.DisplayName);
                item.ToolTipText = soundEvent.Description;
                item.ImageKey    = iconName;
                item.Tag         = soundEvent;
            }

            // Load system sound schemes list

            foreach (SoundScheme scheme in SoundScheme.GetSchemeList())
            {
                if (scheme.ToString() != Program.DisplayName && scheme.ToString() != ".None")
                {
                    comboBoxSystemSchemes.Items.Add(scheme);
                }
            }
            if (comboBoxSystemSchemes.Items.Count > 0)
            {
                comboBoxSystemSchemes.SelectedIndex = 0;
            }

            // Auto-import sound scheme passed as program argument

            if (importFile != null && File.Exists(importFile))
            {
                if (MessageBox.Show(
                        String.Concat(Translations.Get("scheme_load_prompt_text"), '\n', Path.GetFileName(importFile)),
                        Translations.Get("scheme_load_prompt_title"),
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    ImportSoundScheme(importFile);
                    foreach (Process process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Application.ExecutablePath)))
                    {
                        if (process.Id != Process.GetCurrentProcess().Id&& process.MainWindowTitle == this.Text)
                        {
                            process.CloseMainWindow();
                        }
                    }
                }
                else
                {
                    Environment.Exit(0);
                }
            }
        }