Exemplo n.º 1
0
        /// <summary>
        /// Setup will create and apply the SoundManager sound scheme, create data directory
        /// </summary>
        /// <param name="forceResetSounds">Also reset all sounds to their default values</param>
        /// <param name="systemIntegration">Also setup maximum system integration</param>
        public static void Setup(bool forceResetSounds, bool systemIntegration)
        {
            bool createDataDir = !Directory.Exists(DataFolder);

            if (createDataDir)
            {
                Directory.CreateDirectory(DataFolder);
            }

            SoundScheme.Setup();

            if (forceResetSounds || createDataDir)
            {
                foreach (SoundEvent soundEvent in SoundEvent.GetAll())
                {
                    SoundScheme.CopyDefault(soundEvent);
                }
            }

            SoundScheme.Apply(SoundScheme.GetSchemeSoundManager(), true);

            if (systemIntegration)
            {
                SoundArchive.AssocFiles();
                if (BgSoundPlayer.RequiredForThisWindowsVersion)
                {
                    BgSoundPlayer.RegisteredForStartup = true;
                    Process.Start(Application.ExecutablePath, ArgumentBgSoundPlayer);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Import the specified Zip file into the SoundManager sound scheme
 /// </summary>
 /// <param name="zipfile">Input Zip file</param>
 public static void Import(string zipfile)
 {
     using (ZipFile zip = ZipFile.Read(zipfile))
     {
         foreach (SoundEvent soundEvent in SoundEvent.GetAll())
         {
             if (TryExtract(zip, soundEvent.FileName, SoundEvent.DataDirectory) ||
                 TryExtract(zip, soundEvent.LegacyFileName, SoundEvent.DataDirectory, soundEvent.FileName))
             {
                 SoundScheme.Update(soundEvent, soundEvent.FilePath);
             }
             else
             {
                 SoundScheme.Remove(soundEvent);
             }
         }
         SchemeMeta.ResetAll();
         if (!TryExtract(zip, Path.GetFileName(SchemeMeta.SchemeImageFilePath), SoundEvent.DataDirectory))
         {
             TryExtract(zip, "visuel.bmp", SoundEvent.DataDirectory, Path.GetFileName(SchemeMeta.SchemeImageFilePath));
         }
         if (!TryExtract(zip, Path.GetFileName(SchemeMeta.SchemeInfoFilePath), SoundEvent.DataDirectory))
         {
             TryExtract(zip, "infos.ini", SoundEvent.DataDirectory, Path.GetFileName(SchemeMeta.SchemeInfoFilePath));
         }
         SchemeMeta.ReloadFromDisk();
         SoundScheme.Apply(SoundScheme.GetSchemeSoundManager(), Settings.MissingSoundUseDefault);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Remove a sound event
 /// </summary>
 private void soundContextMenu_Remove_Click(object sender, EventArgs e)
 {
     if (soundList.FocusedItem != null)
     {
         SoundEvent soundEvent = soundList.FocusedItem.Tag as SoundEvent;
         SoundScheme.Remove(soundEvent);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Reset a sound event to the default system sound
 /// </summary>
 private void soundContextMenu_Reset_Click(object sender, EventArgs e)
 {
     if (soundList.FocusedItem != null)
     {
         SoundEvent soundEvent = soundList.FocusedItem.Tag as SoundEvent;
         SoundScheme.CopyDefault(soundEvent);
         soundContextMenu_Play_Click(sender, e);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Apply the specified sound scheme in registry
        /// </summary>
        /// <param name="scheme">Sound scheme to apply</param>
        /// <param name="missingSoundsUseDefault">When a sound is missing, use the default system sound instead.</param>
        public static void Apply(SoundScheme scheme, bool missingSoundsUseDefault)
        {
            string schemeName = SchemeDefault;

            if (scheme != null)
            {
                schemeName = scheme.internalName;
            }

            RegistryKey nameKey = RegCurrentUser.OpenSubKey(RegNames + schemeName);

            if (nameKey == null)
            {
                throw new ArgumentException("The specified scheme does not exist in Registry.", "schemeName");
            }
            else
            {
                nameKey.Close();
            }

            RegistryKey apps = RegCurrentUser.OpenSubKey(RegApps);

            foreach (string appName in apps.GetSubKeyNames())
            {
                RegistryKey app = apps.OpenSubKey(appName);
                foreach (string soundName in app.GetSubKeyNames())
                {
                    RegistryKey sound        = app.OpenSubKey(soundName, true);
                    RegistryKey schemeSound  = sound.OpenSubKey(schemeName);
                    RegistryKey defaultSound = sound.OpenSubKey(SchemeDefault);
                    RegistryKey currentSound = sound.OpenSubKey(SchemeCurrent, true) ?? sound.CreateSubKey(SchemeCurrent);

                    string soundPath = null;
                    if (schemeSound != null)
                    {
                        soundPath = schemeSound.GetValue(null) as string;
                    }
                    if ((soundPath == null || !File.Exists(Environment.ExpandEnvironmentVariables(soundPath))) && defaultSound != null && missingSoundsUseDefault)
                    {
                        soundPath = defaultSound.GetValue(null) as string;
                    }
                    if (soundPath != null && !File.Exists(Environment.ExpandEnvironmentVariables(soundPath)))
                    {
                        soundPath = null;
                    }

                    currentSound.SetValue(null, soundPath ?? "");
                    currentSound.Close();
                    sound.Close();
                }
            }

            RegistryKey currentScheme = RegCurrentUser.OpenSubKey(RegSchemes, true);

            currentScheme.SetValue(null, schemeName);
            currentScheme.Close();
        }
Exemplo n.º 6
0
 /// <summary>
 /// Play the specified system event sound.
 /// The sound currently associated with the event is played, which is not necessarily from the SoundManager scheme.
 /// </summary>
 /// <param name="soundEvent">System event to play</param>
 private static void PlaySound(SoundEvent soundEvent)
 {
     if (soundEvent != null)
     {
         string soundFile = SoundScheme.GetCurrentFile(soundEvent);
         if (soundFile != null && File.Exists(soundFile))
         {
             try
             {
                 new SoundPlayer(soundFile).PlaySync();
             }
             catch (InvalidOperationException) { /* Invalid WAV file */ }
         }
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Replace the sound file associated with the specified sound event
 /// </summary>
 private void replaceSoundEvent(SoundEvent soundEvent, string soundFile)
 {
     try
     {
         SoundScheme.Update(soundEvent, soundFile);
         soundContextMenu_Play_Click(this, EventArgs.Empty);
         SoundScheme.Apply(SoundScheme.GetSchemeSoundManager(), Settings.MissingSoundUseDefault);
     }
     catch (Exception loadException)
     {
         MessageBox.Show(
             Translations.Get("sound_load_failed_text") + '\n' + loadException.Message,
             Translations.Get("sound_load_failed_title"),
             MessageBoxButtons.OK,
             MessageBoxIcon.Error
             );
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Copy default sound from the specified sound scheme to the SoundManager sound scheme
        /// </summary>
        /// <param name="source">If not specified, sounds are copied from the default sound sheme</param>
        public static void CopyDefault(SoundEvent soundEvent, SoundScheme source = null)
        {
            bool defaultFileFound = false;

            string originalScheme = SchemeDefault;

            if (source != null)
            {
                originalScheme = source.internalName;
            }

            foreach (string registryKey in soundEvent.RegistryKeys)
            {
                RegistryKey defaultSoundKey  = RegCurrentUser.OpenSubKey(RegApps + registryKey + '\\' + originalScheme);
                string      defaultSoundPath = null;
                if (defaultSoundKey != null)
                {
                    defaultSoundPath = Environment.ExpandEnvironmentVariables(defaultSoundKey.GetValue(null) as string ?? "");
                }
                if (!Directory.Exists(Path.GetDirectoryName(soundEvent.FilePath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(soundEvent.FilePath));
                }
                if (File.Exists(defaultSoundPath))
                {
                    Update(soundEvent, defaultSoundPath);
                    defaultFileFound = true;
                }
            }
            if (soundEvent.Imageres && ImageresPatcher.IsWindowsVista7)
            {
                if (FileSystemAdmin.IsAdmin())
                {
                    ImageresPatcher.Restore();
                }
                ImageresPatcher.ExtractDefault(soundEvent.FilePath);
            }
            else if (!defaultFileFound)
            {
                Remove(soundEvent);
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Reset all sound events to the specified system sound sheme
 /// </summary>
 private void loadSystemScheme(bool warning, SoundScheme scheme)
 {
     if (!warning || MessageBox.Show(
             Translations.Get("reset_warn_text"),
             Translations.Get("reset_warn_title"),
             MessageBoxButtons.OKCancel,
             MessageBoxIcon.Warning
             ) == DialogResult.OK)
     {
         foreach (SoundEvent soundEvent in SoundEvent.GetAll())
         {
             SoundScheme.CopyDefault(soundEvent, scheme);
         }
         SchemeMeta.ResetAll();
         if (scheme != null)
         {
             SchemeMeta.Name   = scheme.ToString();
             SchemeMeta.Author = "";
             SchemeMeta.About  = "";
         }
         RefreshSchemeMetadata();
         imageContextMenu_Remove_Click(this, EventArgs.Empty);
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Uninstall will remove application data from the user directory, sound scheme from the registry, and disable all system integration
 /// </summary>
 /// <returns></returns>
 public static void Uninstall()
 {
     if (BgSoundPlayer.RegisteredForStartup)
     {
         BgSoundPlayer.RegisteredForStartup = false;
         foreach (Process process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Application.ExecutablePath)))
         {
             if (process.Id != Process.GetCurrentProcess().Id)
             {
                 process.Kill();
             }
         }
     }
     SoundArchive.UnAssocFiles();
     SoundScheme.Uninstall();
     if (Directory.Exists(SoundEvent.DataDirectory))
     {
         Directory.Delete(SoundEvent.DataDirectory, true);
     }
     if (Directory.Exists(DataFolder))
     {
         Directory.Delete(DataFolder, true);
     }
 }
Exemplo n.º 11
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);
                }
            }
        }