Ejemplo n.º 1
0
        /// <summary>
        /// создание итема в списке для невалидной книги
        /// </summary>
        private void createNotValidateBookItem(string FilePath, FB2UnionGenres fb2g,
                                               FB2Validator fv2Validator, SharpZipLibWorker sharpZipLib)
        {
            if (File.Exists(FilePath))
            {
                string TempDir = Settings.Settings.TempDirPath;
                string FileExt = Path.GetExtension(FilePath);
                ListViewItem.ListViewSubItem[] subItems;
                if (FilesWorker.isFB2File(FilePath) || FilesWorker.isFB2Archive(FilePath))
                {
                    ListViewItem item = new ListViewItem(FilePath, FilesWorker.isFB2File(FilePath) ? 1 : 2);
                    try {
                        if (FilesWorker.isFB2File(FilePath))
                        {
                            item.ForeColor = Colors.FB2ForeColor;
                            subItems       = createSubItemsWithMetaData(FilePath, FileExt, item, ref fb2g, ref fv2Validator);
                        }
                        else
                        {
                            // для zip-архивов
                            FilesWorker.RemoveDir(TempDir);
                            sharpZipLib.UnZipFB2Files(FilePath, TempDir);
                            string [] files = Directory.GetFiles(TempDir);
                            if (FilesWorker.isFB2File(files[0]))
                            {
                                item.ForeColor = Colors.ZipFB2ForeColor;
                                subItems       = createSubItemsWithMetaData(files[0], FileExt, item, ref fb2g, ref fv2Validator);
                            }
                            else
                            {
                                item.ForeColor = Colors.BadZipForeColor;
                                subItems       = WorksWithBooks.createEmptySubItemsForItem(item);
                            }
                        }
                        if (subItems != null)
                        {
                            item.SubItems.AddRange(subItems);
                        }
                    } catch (Exception ex) {
                        Debug.DebugMessage(
                            null, ex, "FB2NotValidateForm.createNotValidateBookItem(): Создание итема в списке для невалидной книги."
                            );
                        subItems = WorksWithBooks.createEmptySubItemsForItem(item);
                        if (subItems != null)
                        {
                            item.SubItems.AddRange(subItems);
                            item.ForeColor = Colors.BadZipForeColor;
                        }
                    }

                    item.Tag       = new ListViewItemType("f", FilePath);
                    item.BackColor = Colors.FileBackColor;

                    if (subItems != null)
                    {
                        m_listViewFB2Files.Items.Add(item);
                    }
                }
            }
        }