Beispiel #1
0
        private void comboBox_filterselect_SelectedIndexChanged(object sender, EventArgs e)
        {
            int sel = comboBox_filterselect.SelectedIndex;

            if (comboBox_filterselect.SelectedIndex == -1)
            {
                filterName     = null;
                filterFileName = null;
                return;
            }
            else if (comboBox_filterselect.SelectedIndex == 0)
            {
                // load defualt filter
                DefaultNfoFilter def = new DefaultNfoFilter();
                displayFilter(def);
                filterName     = AppConstants.DefaultNfoFilterName;
                filterFileName = null;
            }
            else
            {
                NFO_Filter_File file = null;

                string name = (string)comboBox_filterselect.SelectedItem;
                if (filterFiles.TryGetValue(name, out file) == true)
                {
                    displayFilter(file.filter);
                    filterFileName = file.fileName;
                    filterName     = file.filter.name;
                }
                else
                {
                    MessageBox.Show("Failed to find the filter file for '" + name + "'.", "NFO_Helper", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #2
0
        private void button_load_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.AddExtension     = true;
            dlg.DefaultExt       = AppConstants.NfoFilterFileExtension;
            dlg.Filter           = "NFO Filter files (*" + AppConstants.NfoFilterFileExtension + ")| *" + AppConstants.NfoFilterFileExtension + "|All files (*.*)|*.*";
            dlg.FilterIndex      = 0;
            dlg.RestoreDirectory = true;
            dlg.Title            = "NFO_Helper - Load NFO Filter File...";
#if DEBUG
            dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
#else
            dlg.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
#endif
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string          name = Path.GetFileNameWithoutExtension(dlg.FileName); // get the 'last part' of the filename before the extension as the filtername.
                NFO_Filter_File temp = null;
                if (filterFiles.TryGetValue(name, out temp) == true)
                {
                    MessageBox.Show("A Filter with this name is already known. Please use a different name.", "NFO_Helper", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                NFO_Filter_File file = new NFO_Filter_File();
                file.fileName = dlg.FileName;
                try
                {
                    file.parseFile(dlg.FileName);
                }
                catch (NfoReadWriteException ex)
                {
                    MessageBox.Show("Failed to load NFO Filter File: " + ex.Message, "NFO_Helper", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // save the name of this filter, so it can be pulled by the main form.
                filterName     = file.filter.name;
                filterFileName = file.fileName;

                // persist this filename to the app configuration.
                if (String.IsNullOrEmpty(global::NFO_Helper.Settings.Default.KnownFilterFilenames) == false)
                {
                    global::NFO_Helper.Settings.Default.KnownFilterFilenames += ";";
                }
                global::NFO_Helper.Settings.Default.KnownFilterFilenames += filterFileName;
                global::NFO_Helper.Settings.Default.Save();

                // add the filtername to the combobox & set that as the current selection.
                // add to the filterFiles before changing the selection!
                int newIdx = comboBox_filterselect.Items.Add(file.filter.name);
                filterFiles.Add(name, file);
                comboBox_filterselect.SelectedIndex = newIdx;
            }
        }
Beispiel #3
0
        public FilterForm(NFO_Filter currentFilter)
        {
            InitializeComponent();

            filterFiles = new Dictionary <string, NFO_Filter_File>();
            filterItems = new Dictionary <string, FilterItem>();
            filterItems.Add(NFOConstants.Title, new NFO_Helper.FilterItem(NFOConstants.Title, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.OriginalTitle, new NFO_Helper.FilterItem(NFOConstants.OriginalTitle, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Year, new NFO_Helper.FilterItem(NFOConstants.Year, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Tagline, new NFO_Helper.FilterItem(NFOConstants.Tagline, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Rating, new NFO_Helper.FilterItem(NFOConstants.Rating, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Outline, new NFO_Helper.FilterItem(NFOConstants.Outline, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Runtime, new NFO_Helper.FilterItem(NFOConstants.Runtime, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Id, new NFO_Helper.FilterItem(NFOConstants.Id, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Trailer, new NFO_Helper.FilterItem(NFOConstants.Trailer, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Genres, new NFO_Helper.FilterItem(NFOConstants.Genres, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Director, new NFO_Helper.FilterItem(NFOConstants.Director, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Actors, new NFO_Helper.FilterItem(NFOConstants.Actors, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Set, new NFO_Helper.FilterItem(NFOConstants.Set, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Votes, new NFO_Helper.FilterItem(NFOConstants.Votes, this.listBox_available, this.listBox_filter));
            filterItems.Add(NFOConstants.Thumb, new NFO_Helper.FilterItem(NFOConstants.Thumb, this.listBox_available, this.listBox_filter));

            button_up.Text   = char.ConvertFromUtf32(708);
            button_down.Text = char.ConvertFromUtf32(709);

            comboBox_filterselect.Items.Insert(0, AppConstants.DefaultNfoFilterName);

            // prepare any filter files that have been previously used.
            string listStr = global::NFO_Helper.Settings.Default.KnownFilterFilenames;

            if (String.IsNullOrEmpty(listStr) == false)
            {
                string   validTokens = "";
                char[]   delims      = { ';' };
                string[] tokens      = listStr.Split(delims);
                foreach (string token in tokens)
                {
                    NFO_Filter_File file = new NFO_Filter_File();
                    file.fileName = token;
                    try
                    {
                        file.parseFile(token);
                    }
                    catch (NfoReadWriteException)
                    {
                        continue;
                    }

                    NFO_Filter_File temp = null;
                    if (filterFiles.TryGetValue(file.filter.name, out temp) == true)
                    {
                        // skip this one, there is one with this name already present.
                        continue;
                    }
                    else
                    {
                        filterFiles.Add(file.filter.name, file);
                        comboBox_filterselect.Items.Add(file.filter.name);
                        if (String.IsNullOrEmpty(validTokens) == false)
                        {
                            validTokens += ";";
                        }
                        validTokens += file.fileName;
                    }
                }
                if (String.Compare(listStr, validTokens) != 0)
                {
                    // at least one of the tokens was not used! update the config!
                    global::NFO_Helper.Settings.Default.KnownFilterFilenames = validTokens;
                    global::NFO_Helper.Settings.Default.Save();
                }
            }

            if (String.Compare(currentFilter.name, AppConstants.DefaultNfoFilterName) == 0)
            {
                comboBox_filterselect.SelectedIndex = 0;
                // changing selected index will update filter.
            }
            else if (String.Compare(currentFilter.name, AppConstants.TempNfoFilterName) == 0)
            {
                // we will not set a selection, so we must update the display manually.
                displayFilter(currentFilter);
                filterName     = AppConstants.TempNfoFilterName;
                filterFileName = null;
            }
            else
            {
                // find this one in the combobox & set that as the selection.
                int index = 0;
                foreach (string item in comboBox_filterselect.Items)
                {
                    if (item == currentFilter.name)
                    {
                        comboBox_filterselect.SelectedIndex = index;
                        // changing selected index will update filter.
                        break;
                    }
                    index++;
                }
            }
            // Note: setting the combobox selection will trigger the display to be updated with the contents of that filter.
        }