public static void SortLocFiles(DirectoryInfo langFolder) { if (!langFolder.Exists) { return; } var files = langFolder.GetFiles(); foreach (var fil in files) { switch (fil.Extension) { case ".dotx": case ".docx": case ".dotm": ListWord.Add(fil.FullName); break; case ".xltx": case ".xlsx": case ".xltm": ListExcel.Add(fil.FullName); break; case ".potx": case ".pptx": case ".potm": ListPpt.Add(fil.FullName); // Console.WriteLine(fil.Directory.Name); // To get the file language folder name break; } } }
static void Main(string[] args) { string pathInput; string langInput; Console.WriteLine(DateTime.Now + " " + "Developed by Moravia Publishing & Media team. All rights reserved."); Console.WriteLine("========================================"); // 1. Input folder or file path Console.WriteLine(">>> Please input the complete Folder or single File Path: "); PathInput: pathInput = Console.ReadLine(); if (string.IsNullOrEmpty(pathInput) && string.IsNullOrWhiteSpace(pathInput)) { Console.WriteLine("<!> Empty or invalid directory, please re-enter: "); goto PathInput; } // 2. Input language name or code e.g 'Japanese' or 'Japan' or 'JAP' Console.WriteLine("\n" + ">>> Please input Target Language Name or Code: "); LangInput: langInput = Console.ReadLine(); if (string.IsNullOrEmpty(langInput) && string.IsNullOrWhiteSpace(langInput)) { Console.WriteLine("<!> Unable to identify, please double check and re-enter: (e.g.\"Japanese\" or \"Jap\"): "); goto LangInput; } //TODO: detect language TargetLang = langInput; // Transfer input path to DirectoryInfo if (!File.Exists(pathInput) && Directory.Exists(pathInput)) { if (!pathInput.EndsWith("\\")) { pathInput += "\\"; } var dirInfo = new DirectoryInfo(pathInput); try { SortLocFiles(dirInfo); } catch (IOException e) { Console.WriteLine("Fail to sort files: " + e.Message); return; } /* * //Get all subfolder names and add into LocalLanguage List * try * { * ListLangFolders(dirInfo); * } * catch (Exception ex) * { * Console.WriteLine("Error when create folders list: " + ex.Message); * return; * } * foreach (var lang in ListLang) * try * { * var langDirInfo = new DirectoryInfo(pathInput + lang + "\\"); * SortLocFiles(langDirInfo); * } * catch (IOException e) * { * Console.WriteLine("Fail to sort files: " + e.Message); * return; * } */ } else if (File.Exists(pathInput)) { var fileInfo = new FileInfo(pathInput); switch (fileInfo.Extension) { case ".pptx": //case ".potx": //case ".potm": ListPpt.Add(fileInfo.FullName); break; } } KillProcess(); Console.WriteLine("========================================"); Console.WriteLine(">>> Succeeded to load " + ListPpt.Count.ToString() + " files."); Console.WriteLine(">>> Please hold on until progress complete. It may take a while..."); Console.WriteLine("========================================"); // PowerPointHandler if (ListPpt.Count > 0) { foreach (var f in ListPpt) { if (f.Contains("~$")) { continue; } Console.Write("\r\n" + "Processing: " + f); Common.WriteLine("\r\n" + f + "\r\n"); var objPpt = new PowerPointHandler(f, TargetLang); objPpt.PptMain(f); Common.WriteSglText(f); } } // Write all Console content to text Common.WriteAllText(pathInput); // End Console.WriteLine("========================================"); Console.WriteLine("All files process complete! You are good to go!"); Console.ReadLine(); }
private static void Main(string[] args) { Console.WriteLine(DateTime.Now + " " + "Developed by Moravia Publishing & Media automation team. All rights reserved." + "\n"); Console.WriteLine("Please input the root directory of loc templates folders >> "); Console.WriteLine("========================================"); Input: var dirInput = Console.ReadLine(); Console.WriteLine("========================================"); Console.WriteLine("In progress of processing, please hold on and wait for a while :) "); Console.WriteLine("========================================"); // Check if input path is empty if (string.IsNullOrEmpty(dirInput) && string.IsNullOrWhiteSpace(dirInput)) { Console.WriteLine("Empty or invalid directory, please double check and re-enter it!"); goto Input; } // Transfer input directory string to DirectoryInfo if (!File.Exists(dirInput) && Directory.Exists(dirInput)) { if (!dirInput.EndsWith("\\")) { dirInput = dirInput + "\\"; } var dirInfo = new DirectoryInfo(dirInput); // Get all subfolder names and add into LocalLanguage List try { ListLangFolders(dirInfo); } catch (Exception ex) { Console.WriteLine("Error when create folders list: " + ex.Message); return; } foreach (var lang in ListLang) { try { var langDirInfo = new DirectoryInfo(dirInput + lang + "\\"); SortLocFiles(langDirInfo); } catch (IOException e) { Console.WriteLine("Fail to sort files: " + e.Message); return; } } } else if (File.Exists(dirInput)) { var fileInfo = new FileInfo(dirInput); switch (fileInfo.Extension) { case ".dotx": case ".docx": case ".dotm": ListWord.Add(fileInfo.FullName); break; case ".xltx": case ".xlsx": case ".xltm": ListExcel.Add(fileInfo.FullName); break; case ".potx": case ".pptx": case ".potm": ListPpt.Add(fileInfo.FullName); break; } } KillProcess(); // PowerPointHandler if (ListPpt.Count > 0) { foreach (var f in ListPpt) { if (f.Contains("~$")) { continue; } Console.Write("\r\n" + "Processing: "); Common.WriteLine("\r\n" + f + "\r\n"); var objPpt = new PowerPointHandler(f); objPpt.PptMain(f); Common.WriteSglText(f); } } // WordHandler if (ListWord.Count > 0) { foreach (var f in ListWord) { if (f.Contains("~$")) { continue; } Console.Write("\r\n" + "Processing: "); Common.WriteLine("\r\n" + f + "\r\n"); var objWordHandler = new WordHandler(f); objWordHandler.WordMain(f); Common.WriteSglText(f); } } // Process ExcelHandler files if (ListExcel.Count > 0) { foreach (var f in ListExcel) { if (f.Contains("~$")) { continue; } Console.Write("\r\n" + "Processing: "); Common.WriteLine("\r\n" + f + "\r\n"); var objExcelHandler = new ExcelHandler(f); objExcelHandler.ExcelMain(f); Common.WriteSglText(f); } } // Write all Console content to text Common.WriteAllText(dirInput); // End Console.WriteLine("========================================"); Console.WriteLine("All files process complete! You are good to go!"); Console.ReadLine(); }