示例#1
0
        public MonitorTaskForm(MCEBuddyConf mceOptions, string SourceName)
        {
            InitializeComponent();

            _mceOptions = mceOptions;
            _mjo = mceOptions.GetMonitorTaskByName(SourceName);
        }
示例#2
0
        private bool _newTask = false; // Are we creating a new task

        public ConversionTaskForm(MCEBuddyConf mceOptions, string taskName)
        {
            InitializeComponent();

            maxWidthBar.Maximum = _resolutions.Length - 1;
            _advGrpSize = advancedSettings.Size; // Store the value
            _mceOptions = mceOptions;
            _cjo = _mceOptions.GetConversionTaskByName(taskName);

            // First get the new scale
            using (Graphics g = this.CreateGraphics())
            {
                float _scale = g.DpiX / 96; // Get the system DPI (font scaling)

                _advancedBoxCollapsedSize = (int)(_advancedBoxCollapsedSize * _scale);
            }
        }
示例#3
0
        MCEBuddyConf _mceOptions; // Config options
        
        public SettingsForm(ICore pipeProxy, MCEBuddyConf mceOptions)
        {
            InitializeComponent();

            advGrpSize = advancedSettings.Size; // Store the value
            _pipeProxy = pipeProxy; // Store for use by other forms
            _mceOptions = mceOptions; // We will use this mcebuddy config object everywhere, not work directly on the GlobalMCEbuddyConf object

            // First get the new scale
            using (Graphics g = this.CreateGraphics())
            {
                float _scale = g.DpiX / 96; // Get the system DPI (font scaling)

                // Rescale the columns - for some reason Windows does not rescale the columns in high DPI mode
                this.monitorName.Width = (int)(this.monitorName.Width * _scale);
                this.monitorPath.Width = (int)(this.monitorPath.Width * _scale);
                this.taskName.Width = (int)(this.taskName.Width * _scale);
                this.taskPath.Width = (int)(this.taskPath.Width * _scale);

                _advancedBoxCollapsedSize = (int)(_advancedBoxCollapsedSize * _scale);
            }
        }
示例#4
0
        private void serviceInstaller_AfterInstall(object sender, InstallEventArgs e)
        {
            //MessageBox.Show("Called AfterInstall");

            // Restore the history file from the %HOMEPATH% if it exists
            string installPath = Context.Parameters["TARGETDIR"].Replace(@"\\", @"\").Trim();
            try
            {
                // Copy the backup files back to the MCEBuddy installation directory with .old extensions (except history)
                // Convert History file to unicode while copying it back
                if (File.Exists(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "history")))
                {
                    string sourceHistory = Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "history");
                    string destinationHistory = Path.Combine(installPath, @"config\history");
                    
                    // First check if the file is a UTF16LE file (required for INI files)
                    if (Encodings.GetFileEncoding(sourceHistory) != Encoding.Unicode)
                    {
                        using (StreamReader sourceRead = new StreamReader(sourceHistory)) // Open the source file for reading
                        {
                            FileIO.TryFileDelete(destinationHistory); // Try to delete the destination file first
                            using (FileStream destinationFile = File.Create(destinationHistory)) // Create the destination file
                            {
                                using (StreamWriter destinationWrite = new StreamWriter(destinationFile, new UnicodeEncoding(false, true))) // UTF16, LE with BOM for INI files
                                {
                                    // Read everything from the file
                                    string line;
                                    while ((line = sourceRead.ReadLine()) != null)
                                    {
                                        destinationWrite.WriteLine(line); // Write to the new file
                                    }
                                    destinationWrite.Close();
                                }
                                destinationFile.Close();
                            }
                            sourceRead.Close();
                        }
                    }
                    else // We are good, just copy the file
                        File.Copy(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "history"), Path.Combine(installPath, @"config\history"), true);
                }
                if (File.Exists(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "mcebuddy.conf")))
                    File.Copy(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "mcebuddy.conf"), Path.Combine(installPath, @"config\mcebuddy.conf.old"), true);
                if (File.Exists(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "profiles.conf")))
                    File.Copy(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "profiles.conf"), Path.Combine(installPath, @"config\profiles.conf.old"), true);
                if (File.Exists(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "comskip.ini")))
                    File.Copy(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "comskip.ini"), Path.Combine(installPath, @"comskip\comskip.ini.old"), true);

                // Copy the settings from the last config file (retain user settings) (this will also take care of UTF16LE conversion for ini)
                if (File.Exists(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "mcebuddy.conf")))
                {
                    MCEBuddyConf mceConf = new MCEBuddyConf(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "mcebuddy.conf")); // Read the old config file
                    mceConf.WriteSettings(Path.Combine(installPath, @"config\mcebuddy.conf")); // Write to the new installation file
                }
            }
            catch (Exception exp)
            {
                Log.WriteSystemEventLog("Failed to restore config files. Error:" + exp.ToString(), EventLogEntryType.Error);
            }

            try
            {
                // Install extras (such as filters etc)
                // Check if Haali Media Splitter is installed, else install it
                string haaliKey = "";

                if (Environment.Is64BitOperatingSystem)
                    haaliKey = @"Software\Wow6432Node\HaaliMkx";
                else
                    haaliKey = @"Software\HaaliMkx";    

                if (Registry.LocalMachine.OpenSubKey(haaliKey) == null)
                {
                    if (MessageBox.Show("MCEBuddy suggests installing Haali Media Splitter for MKV playback support.\nPress OK to Install.", "MKV Playback Support Not Found", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        RunCustomApp(Path.Combine(installPath, "extras", "MatroskaSplitter"), "/S", true); // Install Haali Media Splitter (required for MKV playback)
                }

                // WTV Playback: Uninstall Windows Update KB2670838 if the resulting file does not play in MCE/WMP - nothing to do with ffdshow
                // Check if FFDSHOW is installed, else install FFDSHOW for MPEG2/AVI support else NoRecode profiles does not work
                bool modifyReg = true;
                string ffdshowKey = "";

                if (Environment.Is64BitOperatingSystem)
                    ffdshowKey = @"Software\GNU\ffdshow64";
                else
                    ffdshowKey = @"Software\GNU\ffdshow";

                if (Registry.LocalMachine.OpenSubKey(ffdshowKey) == null) // if the key doesn't exist i.e. not installed, it returns null
                {
                    if (MessageBox.Show("MCEBuddy suggests installing FFDShow for MPEG2/AVI playback support.\nPress OK to install.", "FFDShow Not Found", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        if (RunCustomAppWithMediumPrivilege(Path.Combine(installPath, "extras", "ffdshow.exe"), " /silent", true) == true) // FFDShow needs to be installed with Medium Privileges else the installation does not work
                            Registry.LocalMachine.DeleteSubKeyTree(@"Software\GNU"); // Delete all the keys under GNU (we will only create those required later) - TODO: Can we find a clean way to do a custom install for FFDSHOw, default Silent install enables many filters not required
                        else
                        {
                            MessageBox.Show("FFDShow installation error, please install it manually from the Extra's folder in the MCEBuddy Installation directory.\nEnsure you select MPEG2 during installation", "Error installing FFDSHOW");
                            modifyReg = false;
                        }
                    }
                    else
                        modifyReg = false;
                }

                // FFDSHOW, enable the MPEG-2 splitter in the registry (whenever it's installed)
                if (modifyReg)
                {
                    Registry.LocalMachine.CreateSubKey(ffdshowKey); // Create the key if required (since the silent installation does not create one)
                    Registry.LocalMachine.OpenSubKey(ffdshowKey, true).SetValue("mpegAVI", 1, RegistryValueKind.DWord);
                    Registry.LocalMachine.OpenSubKey(ffdshowKey, true).SetValue("mpg2", 1, RegistryValueKind.DWord);
                    Registry.LocalMachine.OpenSubKey(ffdshowKey, true).SetValue("mpg1", 1, RegistryValueKind.DWord);
                }

                // Install ShowAnalyzer - last one, delayed start to avoid MSI install conflict (only 1 at a time)
                if (!Scanner.ShowAnalyzerInstalled()) // only if not installed
                    if (MessageBox.Show("MCEBuddy comes with Comskip commercial detection software built in. However some countries have better commercial detection with ShowAnalyzer.\nPress OK if you would like to install ShowAnalyzer.", "Commercial detection options", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        RunCustomApp(Path.Combine(installPath, "extras", "InstallShowAnalyzerDelayed.bat"), "", false);
            }
            catch (Exception exp)
            {
                Log.WriteSystemEventLog("Failed to install custom apps. Error:" + exp.ToString(), EventLogEntryType.Error);
            }

            try
            {
                //Set the restart properties for the service
                ServiceControlManager scm = new ServiceControlManager();
                scm.SetRestartOnFailure(engineName);
            }
            catch (Exception exp)
            {
                Log.WriteSystemEventLog("Failed to set MCEBuddy service restart parameters. Error:" + exp.ToString(), EventLogEntryType.Error);
            }

            /*string installPath = Context.Parameters["TARGETDIR"].Replace(@"\\", @"\").Trim();
            CreateExposedDirectory(Path.Combine(installPath, "config"));
            CreateExposedDirectory(Path.Combine(installPath, "log"));
            CreateExposedDirectory(Path.Combine(installPath, "working"));*/ //Dont' create directories here since it create Canonical issues, create within application at runtime

            WindowsService.StartService(engineName);
        }
示例#5
0
        private void settingsCmd_Click(object sender, EventArgs e)
        {
            bool active = false;

            try
            {
                active = _pipeProxy.Active();
            }
            catch (Exception e1)
            {
                MessageBox.Show(Localise.GetPhrase("Unable to communicate with engine."), Localise.GetPhrase("Communication Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                Log.WriteSystemEventLog(Localise.GetPhrase("MCEBuddy GUI: Unable to get pipe active status"), EventLogEntryType.Warning);
                Log.WriteSystemEventLog(e1.ToString(), EventLogEntryType.Warning);
                return;
            }

            if (active)
            {
                var res = MessageBox.Show(Localise.GetPhrase("The conversions must be stopped to change settings. Stop the conversions?"), Localise.GetPhrase("Stop Engine"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (res ==  DialogResult.No)
                    return;
            }

            try
            {
                stopCmd.Enabled = addFileCmd.Enabled = cancelFileCmd.Enabled = rescanCmd.Enabled = false; // Disable to Stop command to prevent a race condition
                if (_pipeProxy.EngineRunning()) // Check if engine is stopped, DON'T restop since it will overwrite the mcebuddy.conf file (overwriting any changes made by the user while the engine was stopped)
                    _pipeProxy.Stop(true);
                _isEngineRunning = false; // TODO: Temp hack due to delay in updating this parameter in TryConnect until next fetch
                while (_pipeProxy.EngineRunning())
                    Thread.Sleep(100); // Wait until the engine stops

                GlobalDefs.profilesSummary = _pipeProxy.GetProfilesSummary(); // Get a list of all the profiles and descriptions
            }
            catch (Exception e1)
            {
                Log.WriteSystemEventLog(Localise.GetPhrase("MCEBuddy GUI: Unable to stop MCEBuddy service from settings click"), EventLogEntryType.Warning);
                Log.WriteSystemEventLog(e1.ToString(), EventLogEntryType.Warning);
                
                var res = MessageBox.Show(Localise.GetPhrase("Unable to stop MCEBuddy engine, settings may not be saved. Do you want to continue?"), Localise.GetPhrase("Error Stopping Engine"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (res == DialogResult.No)
                    return;
            }

            Monitor.Enter(_configLock); // Capture this lock so that the TryConnect thread does not update the MCEBuddy config parameters until we finish with the configuration

            // Store the current details when the form loaded (which we need to verify later)
            string loadCulture = MCEBuddyConf.GlobalMCEConfig.GeneralOptions.locale;
            bool loadUPnP = MCEBuddyConf.GlobalMCEConfig.GeneralOptions.uPnPEnable;
            bool loadFirewall = MCEBuddyConf.GlobalMCEConfig.GeneralOptions.firewallExceptionEnabled;
            int loadMaxJobs = MCEBuddyConf.GlobalMCEConfig.GeneralOptions.maxConcurrentJobs;

            // Get engine to reload and return the latest settings (incase the user changed the mcebuddy.conf file while stopped)
            MCEBuddyConf mceOptions;
            try
            {
                ConfSettings? latestConf = _pipeProxy.ReloadAndGetConfigParameters();
                if (latestConf == null)
                    throw new Exception("Engine not stopped, cannot reload configuration settings");
                mceOptions = new MCEBuddyConf((ConfSettings) latestConf);
            }
            catch (Exception e1)
            {
                MessageBox.Show(Localise.GetPhrase("Unable to communicate with engine."), Localise.GetPhrase("Communication Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                Log.WriteSystemEventLog(Localise.GetPhrase("MCEBuddy GUI: Unable to get latest configuration from engine"), EventLogEntryType.Warning);
                Log.WriteSystemEventLog(e1.ToString(), EventLogEntryType.Warning);
                Monitor.Exit(_configLock); // We are done changing the configuration, so release the lock
                return;
            }

            SettingsForm setForm = new SettingsForm(_pipeProxy, mceOptions);
            if (setForm.ShowDialog() != System.Windows.Forms.DialogResult.Abort) // Send the updated settings back to the server if the user pressed okay
            {
                MCEBuddyConf.GlobalMCEConfig.UpdateConfigOptions(mceOptions.ConfigSettings, false); // Update the settings

                try
                {
                    if (_pipeProxy.UpdateConfigParameters(mceOptions.ConfigSettings) == false) // Send the updated parameters to the Engine
                    {
                        Log.WriteSystemEventLog("MCEBuddy GUI: Unable to update Engine Configuration Settings, engine not Stopped", EventLogEntryType.Warning);
                        MessageBox.Show(Localise.GetPhrase("Engine not stopped. Settings have NOT been saved."), Localise.GetPhrase("Unable To Save Settings"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Monitor.Exit(_configLock); // We are done changing the configuration, so release the lock
                        return;
                    }
                }
                catch (Exception e2)
                {
                    Log.WriteSystemEventLog("MCEBuddy GUI: Unable to update Engine Configuration Settings", EventLogEntryType.Warning);
                    Log.WriteSystemEventLog(e2.ToString(), EventLogEntryType.Warning);
                    MessageBox.Show(Localise.GetPhrase("Unable to communicate with engine. Settings have NOT been saved."), Localise.GetPhrase("Communication Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Monitor.Exit(_configLock); // We are done changing the configuration, so release the lock
                    return;
                }
            }

            // Check if the locale or UPnP has changed, if so then restart the app to reload the locale else just close the window
            string closeCulture = MCEBuddyConf.GlobalMCEConfig.GeneralOptions.locale;
            bool closeUPnP = MCEBuddyConf.GlobalMCEConfig.GeneralOptions.uPnPEnable;
            bool closeFirewall = MCEBuddyConf.GlobalMCEConfig.GeneralOptions.firewallExceptionEnabled;
            int closeMaxJobs = MCEBuddyConf.GlobalMCEConfig.GeneralOptions.maxConcurrentJobs;

            if (loadUPnP != closeUPnP)
            {
                try
                {
                    _pipeProxy.SetUPnPState(MCEBuddyConf.GlobalMCEConfig.GeneralOptions.uPnPEnable);
                }
                catch (Exception e3)
                {
                    Log.WriteSystemEventLog("MCEBuddy GUI: Unable to update UPnP Settings", EventLogEntryType.Warning);
                    Log.WriteSystemEventLog(e3.ToString(), EventLogEntryType.Warning);
                    MessageBox.Show(Localise.GetPhrase("Unable to communicate with engine. UPnP settings have not been updated."), Localise.GetPhrase("Communication Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (loadFirewall != closeFirewall)
            {
                try
                {
                    _pipeProxy.SetFirewallException(MCEBuddyConf.GlobalMCEConfig.GeneralOptions.firewallExceptionEnabled);
                }
                catch (Exception e3)
                {
                    Log.WriteSystemEventLog("MCEBuddy GUI: Unable to update firewall exception Settings", EventLogEntryType.Warning);
                    Log.WriteSystemEventLog(e3.ToString(), EventLogEntryType.Warning);
                    MessageBox.Show(Localise.GetPhrase("Unable to communicate with engine. Firewall exception settings have not been updated."), Localise.GetPhrase("Communication Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            Monitor.Exit(_configLock); // We are done changing the configuration and sending the changes, so release the lock - not before sending ALL changes

            // If Culture has changed we may need to restart the application because the phrases only work against English Text.
            // If the current text is not english, then we need to restart the application to reload the english text on the control and then map the phrases against it
            if (loadCulture != closeCulture)
                SetUserLocale(); // this will work since the existing text is in English the new locale can be mapped

            // If the number of concurrent jobs has changed we need to restart the app to reset the GUI otherwise it gets messed up while resizing
            if (loadMaxJobs != closeMaxJobs)
            {
                _exit = true;
                Application.Restart();
            }
        }