Example #1
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);
     }
 }
Example #2
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);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Instantiate a new Background Sound Player.
        /// Will play the startup/logon sound and create a hidden window, which is required by the ShutdownBlockReason API.
        /// </summary>
        public BgSoundPlayer()
        {
            this.Text = Program.DisplayName;
            this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);

            this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            this.ShowInTaskbar   = false;
            this.StartPosition   = FormStartPosition.Manual;
            this.Location        = new System.Drawing.Point(-2000, -2000);
            this.Size            = new System.Drawing.Size(1, 1);

            foreach (SoundEvent soundEvent in SoundEvent.GetAll())
            {
                switch (soundEvent.FileName.Replace(".wav", "").ToLower())
                {
                case "startup":
                    soundStartup = soundEvent;
                    break;

                case "shutdown":
                    soundShutdown = soundEvent;
                    break;

                case "logon":
                    soundLogon = soundEvent;
                    break;

                case "logoff":
                    soundLogoff = soundEvent;
                    break;
                }
            }

            string bootTime = GetBootTimestamp().ToString();

            bootTime = bootTime.Substring(0, bootTime.Length - 1) + '0';
            string lastBootTime = "";

            if (File.Exists(LastBootFile))
            {
                lastBootTime = File.ReadAllText(LastBootFile);
            }
            if (bootTime != lastBootTime && File.Exists(soundStartup.FilePath))
            {
                File.WriteAllText(LastBootFile, bootTime);
                PlaySound(soundStartup);
            }
            else
            {
                PlaySound(soundLogon);
            }

            SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);
            SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
        }
Example #4
0
 /// <summary>
 /// Export the SoundManager sound scheme to the specified Zip file
 /// </summary>
 /// <param name="zipfile">Output Zip file</param>
 public static void Export(string zipfile)
 {
     using (ZipFile zip = new ZipFile())
     {
         foreach (SoundEvent soundEvent in SoundEvent.GetAll())
         {
             if (File.Exists(soundEvent.FilePath))
             {
                 zip.AddFile(soundEvent.FilePath, "");
             }
         }
         if (File.Exists(SchemeMeta.SchemeImageFilePath))
         {
             zip.AddFile(SchemeMeta.SchemeImageFilePath, "");
         }
         if (File.Exists(SchemeMeta.SchemeInfoFilePath))
         {
             zip.AddFile(SchemeMeta.SchemeInfoFilePath, "");
         }
         zip.Save(zipfile);
     }
 }
Example #5
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);
     }
 }
Example #6
0
        // ============================ //
        // == Sound sheme management == //
        // ============================ //

        /// <summary>
        /// Create the "SoundManager" sound scheme in registry
        /// </summary>
        public static void Setup()
        {
            RegistryKey name = RegCurrentUser.CreateSubKey(RegNames + SchemeManager);

            name.SetValue(null, Program.DisplayName);
            name.Close();

            foreach (SoundEvent soundEvent in SoundEvent.GetAll())
            {
                foreach (string registryKey in soundEvent.RegistryKeys)
                {
                    string      eventKeyPath = RegApps + registryKey + '\\' + SchemeManager;
                    RegistryKey eventKey     = RegCurrentUser.OpenSubKey(eventKeyPath, true) ?? RegCurrentUser.CreateSubKey(eventKeyPath);
                    eventKey.SetValue(null, soundEvent.FilePath);
                    eventKey.Close();
                }
            }

            //Windows 7 : Also backup imageres.dll when creating sound scheme
            if (ImageresPatcher.IsWindowsVista7 && FileSystemAdmin.IsAdmin())
            {
                ImageresPatcher.Backup();
            }
        }
Example #7
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);
                }
            }
        }