private void button2_Click(object sender, EventArgs e) { if (CheckInPaths(pathForOne) && CheckInPaths(pathForTwo) && CheckInPaths(pathForThree)) { if (!string.IsNullOrEmpty(checkPath) && !string.IsNullOrEmpty(languageSelectionText)) { for (int q = 0; q < paths.Count; q++) { sourcePath = paths[q]; button2.Text = "Running..."; button2.Refresh(); StepThroughDirectories(sourcePath); //string[] lpuFiles = System.IO.Directory.GetFiles(sourcePath, languageSelectionText + "*.lpu", SearchOption.AllDirectories); PassoloApp PSL = new PassoloApp(); PSL.Visible = false; for (int i = 0; i < lpuFiles.Length; i++) { if (lpuFiles[i].ContainsMe("\\old\\") || lpuFiles[i].ContainsMe("\\bak\\") || lpuFiles[i].ContainsMe("\\backup\\") || lpuFiles[i].ContainsMe("\\temp\\") || lpuFiles[i].ContainsMe("test")) { //ignore file Console.WriteLine(lpuFiles[i]); } else { PSL.Projects.Open(lpuFiles[i]); String path = @"\\FileSrvwhq2\globalops\global team\Passolo Projects\" + languageForPath; if (formatSelection == "Glossary") { destinationPath = System.IO.Directory.GetDirectories(path, "*Glossaries*", SearchOption.TopDirectoryOnly); } else { destinationPath = System.IO.Directory.GetDirectories(path, "*Standard*", SearchOption.TopDirectoryOnly); } String dateTime = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString(); System.IO.Directory.CreateDirectory(System.IO.Path.Combine(destinationPath[0], dateTime)); System.IO.Directory.CreateDirectory(System.IO.Path.Combine(destinationPath[0], dateTime, Path.GetFileName(sourcePath))); exactPath = System.IO.Path.Combine(destinationPath[0], dateTime, Path.GetFileName(sourcePath), Path.GetFileName(lpuFiles[i]).Replace(".lpu", "") + ".txt"); Console.WriteLine(PSL.ActiveProject.Name); PslTransBundle newBundle = PSL.ActiveProject.PrepareTransBundle(); for (int p = 0; p < PSL.ActiveProject.SourceLists.Count; p++) { newBundle.AddTransList(PSL.ActiveProject.TransLists.Item(p + 1)); newBundle.AddTransList(PSL.ActiveProject.SourceLists.Item(p + 1)); } PSL.DisplayAlerts = PslAlertLevel.pslAlertsNone; if (formatSelection == "Glossary") { PSL.ActiveProject.Export("Trados Text Export", newBundle, exactPath); DateTime firstTime = DateTime.Now; var allLines = File.ReadAllLines(exactPath).ToList(); int line = 0; for (int p = 1; p <= PSL.ActiveProject.TransLists.Count; p++) { for (int n = 1; n <= PSL.ActiveProject.TransLists.Item(p).StringCount; n++) { Boolean contains = false; while (contains == false) { if (line == allLines.Count) { contains = true; } else if (allLines[line].Contains("<Seg L=es-ES>")) { contains = true; string yes = PSL.ActiveProject.TransLists.Item(p).get_String(n).TransComment.ToString(); if (yes.Equals("T9N")) { } string no = PSL.ActiveProject.TransLists.Item(p).get_String(n).Text.ToString(); allLines.Insert(line + 1, "<Comment> " + PSL.ActiveProject.TransLists.Item(p).get_String(n).TransComment.ToString()); //Console.WriteLine(allLines[line - 1]); //Console.WriteLine(allLines[line]); //Console.WriteLine(allLines[line + 1]); line++; } else line++; } } } File.WriteAllLines(exactPath, allLines.ToArray()); DateTime lastTime = DateTime.Now; TimeSpan total = lastTime - firstTime; } else if (formatSelection == "Standard") { PSL.ActiveProject.Export("Customizable Text Export", newBundle, exactPath); } else { MessageBox.Show("Please select a format"); return; } PSL.ActiveProject.Close(); pathToPrint = Path.GetDirectoryName(exactPath); pathToPrint = Path.GetDirectoryName(pathToPrint); } } PSL.Quit(); if (formatSelection == "Standard") { //concatanate files string[] fileCount = Directory.GetFiles(System.IO.Directory.GetParent(exactPath).ToString(), "*.txt", SearchOption.AllDirectories); System.Text.StringBuilder sb = new System.Text.StringBuilder(); if (fileCount.Length > 1) { for (int count = 0; count < fileCount.Count(); count++) { sb.Append(System.IO.File.ReadAllText(fileCount[count], Encoding.Default)); } string buildOutput = sb.ToString(); string newFilePath = System.IO.Directory.GetParent(exactPath).ToString() + @"\newMergedFile.txt"; System.IO.File.WriteAllText(newFilePath, buildOutput, Encoding.Default); //open .txt with excel Excel.Application excelApp = new Excel.Application(); excelApp.Workbooks.OpenText(newFilePath); excelApp.Visible = true; //Check for and remove duplicates Excel.Worksheet xlWorkSheet = (Excel.Worksheet)excelApp.ActiveSheet; xlWorkSheet.Columns.RemoveDuplicates(1, Excel.XlYesNoGuess.xlNo); } } MessageBox.Show("TXT Files were exported to the location: " + pathToPrint); button2.Text = "Finished"; button2.Refresh(); } } } }
/* private void button1_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { checkPath = folderBrowserDialog1.SelectedPath; paths.Add(folderBrowserDialog1.SelectedPath); } } private void button3_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { checkPath = folderBrowserDialog1.SelectedPath; paths.Add(folderBrowserDialog1.SelectedPath); } } private void button4_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { checkPath = folderBrowserDialog1.SelectedPath; paths.Add(folderBrowserDialog1.SelectedPath); } }*/ private void button2_Click(object sender, EventArgs e) { if (CheckInPaths(pathForOne) && CheckInPaths(pathForTwo) && CheckInPaths(pathForThree)) { if (!string.IsNullOrEmpty(checkPath) && !string.IsNullOrEmpty(languageSelectionText)) { for (int q = 0; q < paths.Count; q++) { sourcePath = paths[q]; button2.Text = "Running..."; button2.Refresh(); string[] lpuFiles = System.IO.Directory.GetFiles(sourcePath, languageSelectionText + "*.lpu", SearchOption.AllDirectories); PassoloApp PSL = new PassoloApp(); PSL.Visible = true; for (int i = 0; i < lpuFiles.Length; i++) { PSL.Projects.Open(lpuFiles[i]); String path = @"\\FileSrvwhq2\globalops\global team\Passolo Projects\" + languageForPath; string[] destinationPath = System.IO.Directory.GetDirectories(path, "*Glossaries*", SearchOption.TopDirectoryOnly); String dateTime = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString(); System.IO.Directory.CreateDirectory(System.IO.Path.Combine(destinationPath[0], dateTime)); System.IO.Directory.CreateDirectory(System.IO.Path.Combine(destinationPath[0], dateTime, Path.GetFileName(sourcePath))); String exactPath = System.IO.Path.Combine(destinationPath[0], dateTime, Path.GetFileName(sourcePath), Path.GetFileName(lpuFiles[i]).Replace(".lpu", "") + ".txt"); //Console.WriteLine(PSL.ActiveProject.Name); PslTransBundle newBundle = PSL.ActiveProject.PrepareTransBundle(); for (int p = 0; p < PSL.ActiveProject.SourceLists.Count; p++) { newBundle.AddTransList(PSL.ActiveProject.TransLists.Item(p + 1)); newBundle.AddTransList(PSL.ActiveProject.SourceLists.Item(p + 1)); } PSL.DisplayAlerts = PslAlertLevel.pslAlertsNone; if (formatSelection == Glossary) { PSL.ActiveProject.Export("Trados Text Export", newBundle, exactPath); DateTime firstTime = DateTime.Now; var allLines = File.ReadAllLines(exactPath).ToList(); int line = 0; for (int p = 1; p <= PSL.ActiveProject.TransLists.Count; p++) { for (int n = 1; n <= PSL.ActiveProject.TransLists.Item(p).StringCount; n++) { Boolean contains = false; while (contains == false) { if (line == allLines.Count) { contains = true; } else if (allLines[line].Contains("<Seg L=es-ES>")) { contains = true; string yes = PSL.ActiveProject.TransLists.Item(p).get_String(n).TransComment.ToString(); if (yes.Equals("T9N")) { } string no = PSL.ActiveProject.TransLists.Item(p).get_String(n).Text.ToString(); allLines.Insert(line + 1, "<Comment> " + PSL.ActiveProject.TransLists.Item(p).get_String(n).TransComment.ToString()); Console.WriteLine(allLines[line - 1]); Console.WriteLine(allLines[line]); Console.WriteLine(allLines[line + 1]); line++; } else line++; } } } File.WriteAllLines(exactPath, allLines.ToArray()); DateTime lastTime = DateTime.Now; TimeSpan total = lastTime - firstTime; } else if (formatSelection == Standard) { // File.CreateText(exactPath); PSL.ActiveProject.Export("Trados Text Export", newBundle, exactPath); //duplicates //folder //.txt or .csv } PSL.ActiveProject.Close(); pathToPrint = Path.GetDirectoryName(exactPath); pathToPrint = Path.GetDirectoryName(pathToPrint); } } MessageBox.Show("TXT Files were exported to the location: " + pathToPrint); button2.Text = "Finished"; button2.Refresh(); } else { MessageBox.Show("You need to select at least one source path and the language field."); } } }