Ejemplo n.º 1
0
        public static void SaveFile(string path, List <AllText> allText)
        {
            FileStream ExportStream = new FileStream(path, FileMode.Create);

            for (int i = 0; i < allText.Count; i++)
            {
                if (MainMenu.settings.exportRealID)
                {
                    TextCollector.SaveString(ExportStream, ((allText[i].realID) + ") " + allText[i].orName + "\r\n"), MainMenu.settings.ASCII_N);
                }
                else
                {
                    TextCollector.SaveString(ExportStream, ((allText[i].number + 1) + ") " + allText[i].orName + "\r\n"), MainMenu.settings.ASCII_N);
                }
                TextCollector.SaveString(ExportStream, (allText[i].orText + "\r\n"), MainMenu.settings.ASCII_N);
                if (MainMenu.settings.exportRealID)
                {
                    TextCollector.SaveString(ExportStream, ((allText[i].realID) + ") " + allText[i].trName + "\r\n"), MainMenu.settings.ASCII_N);
                }
                else
                {
                    TextCollector.SaveString(ExportStream, ((allText[i].number + 1) + ") " + allText[i].trName + "\r\n"), MainMenu.settings.ASCII_N);
                }
                TextCollector.SaveString(ExportStream, (allText[i].trText + "\r\n"), MainMenu.settings.ASCII_N);
            }
            ExportStream.Close();
        }
Ejemplo n.º 2
0
        private void button13_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "txt files (*.txt) | *.txt";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string path = ofd.FileName;
                textBox1.Text = path;
                textBox3.Text = path;
                allText       = new List <AllText>();

                ImportTXTFromConvertedFile(path, ref allText, MainMenu.settings.ASCII_N);

                List <AllText> duplicates = new List <AllText>();

                for (int i = 0; i < allText.Count; i++)
                {
                    if (allText[i].exported == false && allText[i].isChecked == false)
                    {
                        allText[i].exported = true;
                        for (int j = 0; j < allText.Count; j++)
                        {
                            if (TextCollector.IsStringsSame(allText[i].orText, allText[j].orText, false) && allText[j].exported == false)
                            {
                                allText[j].exported = true;
                                allText.Insert(i + 1, allText[j]);
                                allText[i + 1].exported = true;
                                duplicates.Add(allText[i]);
                                duplicates.Add(allText[j]);
                                allText.RemoveAt(j + 1);
                            }
                        }
                    }

                    allText[i].isChecked = true;
                }

                if (duplicates.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "txt file (*.txt) | *.txt";
                    FileInfo fi = new FileInfo(path);
                    sfd.FileName = fi.Name.Remove(fi.Name.Length - 4, 4) + "_dup.txt";
                    duplicates   = duplicates.GroupBy(x => x.number).Select(g => g.First()).ToList();

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        if (File.Exists(sfd.FileName))
                        {
                            File.Delete(sfd.FileName);
                        }
                        FileStream   fws = new FileStream(sfd.FileName, FileMode.CreateNew);
                        StreamWriter sw  = new StreamWriter(fws);

                        foreach (AllText dup in duplicates)
                        {
                            sw.WriteLine(dup.number + ") " + dup.orName);
                            sw.WriteLine(dup.orText);
                            sw.WriteLine(dup.number + ") " + dup.trName);
                            sw.WriteLine(dup.trText);
                        }

                        sw.Close();
                        fws.Close();
                    }
                }
            }
        }