示例#1
0
        private void AddBooks(IEnumerable <FileInfo> files, ZipArchive archive, BackupMeta backup, ref int counter)
        {
            foreach (var fileInfo in files)
            {
                var book = new VocabularyBook();
                if (VocabularyFile.ReadVhfFile(fileInfo.FullName, book))
                {
                    var vhr      = VocabularyFile.ReadVhrFile(book);
                    var success  = TryAddFile(fileInfo.FullName, archive, $"vhf\\{counter}.vhf");
                    var success2 = false;

                    if (success && vhr && CbSaveResults.Checked)
                    {
                        success2 = TryAddFile(Path.Combine(Settings.Default.VhrPath, book.VhrCode + ".vhr"), archive,
                                              $"vhr\\{book.VhrCode}.vhr");
                    }
                    if (success)
                    {
                        backup.Books.Add(new BackupMeta.BookMeta(counter, BackupMeta.ShrinkPath(fileInfo.FullName),
                                                                 success2 ? book.VhrCode : ""));
                        counter++;

                        if (success2)
                        {
                            backup.Results.Add(book.VhrCode + ".vhr");
                        }
                    }
                }
            }
        }
示例#2
0
文件: MainForm.cs 项目: AtjonTV/vocup
        private void TsmiExport_Click(object sender, EventArgs e)
        {
            if (UnsavedChanges)
            {
                var dialogResult = MessageBox.Show(Messages.CsvExportSave,
                                                   Messages.CsvExportSaveT, MessageBoxButtons.YesNoCancel);

                if (dialogResult == DialogResult.Yes)
                {
                    SaveFile(false);
                }
                else if (dialogResult == DialogResult.Cancel)
                {
                    return;
                }
            }

            using (var saveDialog = new SaveFileDialog
            {
                Title = Words.Export,
                Filter = "CSV (*.csv)|*.csv",
                FileName = CurrentBook.Name
            })
            {
                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    VocabularyFile.ExportCsvFile(saveDialog.FileName, CurrentBook);
                }
            }
        }
示例#3
0
 private void ImportCsv(bool ansiEncoding = false)
 {
     using (OpenFileDialog openDialog = new OpenFileDialog
     {
         Title = Words.Import,
         Filter = $"CSV (*.csv)|*.csv"
     })
     {
         if (openDialog.ShowDialog() == DialogResult.OK)
         {
             if (CurrentBook != null)
             {
                 VocabularyFile.ImportCsvFile(openDialog.FileName, CurrentBook, false, ansiEncoding);
             }
             else
             {
                 VocabularyBook book = new VocabularyBook();
                 if (VocabularyFile.ImportCsvFile(openDialog.FileName, book, true, ansiEncoding))
                 {
                     book.Notify();
                     book.UnsavedChanges = true;
                     LoadBook(book);
                 }
             }
         }
     }
 }
示例#4
0
文件: MainForm.cs 项目: AtjonTV/vocup
 private void TsmiImport_Click(object sender, EventArgs e)
 {
     using (var openDialog = new OpenFileDialog
     {
         Title = Words.Import,
         Filter = "CSV (*.csv)|*.csv"
     })
     {
         if (openDialog.ShowDialog() == DialogResult.OK)
         {
             if (CurrentBook != null)
             {
                 VocabularyFile.ImportCsvFile(openDialog.FileName, CurrentBook, false);
             }
             else
             {
                 var book = new VocabularyBook();
                 if (VocabularyFile.ImportCsvFile(openDialog.FileName, book, true))
                 {
                     book.Notify();
                     book.UnsavedChanges = true;
                     LoadBook(book);
                 }
             }
         }
     }
 }
示例#5
0
 public Vocabulary(VocabularyFile vocabularyFile)
 {
     _index = vocabularyFile.NumberOfWords;
     foreach (var word in vocabularyFile.VocabularyEntries)
     {
         _words[word.Term] = word;
     }
 }
示例#6
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            string path;

            using (var save = new SaveFileDialog
            {
                Title = Words.SaveVocabularyBook,
                FileName = TbMotherTongue.Text + " - " + TbForeignLang.Text,
                InitialDirectory = Settings.Default.VhfPath,
                Filter = Words.VocupVocabularyBookFile + " (*.vhf)|*.vhf"
            })
            {
                if (save.ShowDialog() == DialogResult.OK)
                {
                    path = save.FileName;
                }
                else
                {
                    DialogResult = DialogResult.Cancel;
                    return;
                }
            }

            Cursor.Current = Cursors.WaitCursor;

            var result = new VocabularyBook
            {
                MotherTongue = TbMotherTongue.Text,
                ForeignLang  = TbForeignLang.Text,
                FilePath     = path
            };

            foreach (var book in books)
            {
                foreach (var word in book.Words)
                {
                    CopyWord(word, result);
                }
            }

            result.GenerateVhrCode();

            if (!VocabularyFile.WriteVhfFile(path, result) ||
                !VocabularyFile.WriteVhrFile(result))
            {
                MessageBox.Show(Messages.VocupFileWriteError, Messages.VocupFileWriteErrorT, MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                DialogResult = DialogResult.Abort;
            }
            else
            {
                DialogResult = DialogResult.OK;
            }

            Cursor.Current = Cursors.Default;
        }
示例#7
0
文件: MainForm.cs 项目: AtjonTV/vocup
        public void ReadFile(string path)
        {
            var book = new VocabularyBook();

            if (VocabularyFile.ReadVhfFile(path, book))
            {
                VocabularyFile.ReadVhrFile(book);
                book.Notify();
                LoadBook(book);
            }
        }
示例#8
0
        public void Set(string index, Vocabulary vocabulary)
        {
            var path = GetFileName(index);
            var obj  = new VocabularyFile()
            {
                NumberOfWords     = vocabulary.NumberOfWords,
                VocabularyEntries = vocabulary.GetAll()
            };

            var jsonText = JsonConvert.SerializeObject(obj);

            File.WriteAllText(path, jsonText);
            _vocabularys[index] = vocabulary;
        }
示例#9
0
        private bool SaveFile(bool saveAsNewFile)
        {
            //Datei-Speichern-unter Dialogfeld öffnen
            if (string.IsNullOrWhiteSpace(CurrentBook.FilePath) ||
                string.IsNullOrWhiteSpace(CurrentBook.VhrCode) ||
                saveAsNewFile)
            {
                using (SaveFileDialog save = new SaveFileDialog
                {
                    Title = Words.SaveVocabularyBook,
                    FileName = CurrentBook.MotherTongue + " - " + CurrentBook.ForeignLang,
                    InitialDirectory = Settings.Default.VhfPath,
                    Filter = Words.VocupVocabularyBookFile + " (*.vhf)|*.vhf"
                })
                {
                    if (save.ShowDialog() == DialogResult.OK)
                    {
                        CurrentBook.FilePath = save.FileName;
                        CurrentBook.GenerateVhrCode();
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            Cursor.Current = Cursors.WaitCursor;

            if (VocabularyFile.WriteVhfFile(CurrentBook.FilePath, CurrentBook) &&
                VocabularyFile.WriteVhrFile(CurrentBook))
            {
                CurrentBook.UnsavedChanges = false;

                Settings.Default.LastFile = CurrentBook.FilePath;
                Settings.Default.Save();

                Cursor.Current = Cursors.Default;
                return(true);
            }
            else
            {
                Cursor.Current = Cursors.Default;
                return(false);
            }
        }
示例#10
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            var addFile = new OpenFileDialog
            {
                Title            = Words.AddVocabularyBooks,
                InitialDirectory = Settings.Default.VhfPath,
                Filter           = Words.VocupVocabularyBookFile + " (*.vhf)|*.vhf",
                Multiselect      = true
            };

            if (addFile.ShowDialog() == DialogResult.OK)
            {
                foreach (var file in addFile.FileNames)
                {
                    var book = new VocabularyBook();
                    if (!VocabularyFile.ReadVhfFile(file, book))
                    {
                        continue;
                    }
                    VocabularyFile.ReadVhrFile(book);
                    var conflict = books
                                   .Where(x => x.FilePath.Equals(book.FilePath, StringComparison.OrdinalIgnoreCase))
                                   .FirstOrDefault();
                    if (conflict != null)
                    {
                        if (MessageBox.Show(Messages.MergeOverride, Messages.MergeOverrideT, MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Warning) == DialogResult.No)
                        {
                            continue;
                        }
                        books.Remove(conflict);
                        LbFiles.Items.Remove(conflict.FilePath);
                    }

                    books.Add(book);
                    LbFiles.Items.Add(book.FilePath);
                }

                ValidateInput();
            }

            addFile.Dispose();
        }