using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace DDUtilityApp.MESDOWNLOADER { public static class Util { public static int GetFileMerge(List filePaths) { int rtnBint = 9; // 기본 실패 코드 if (filePaths.Count == 0) { Console.WriteLine("병합할 파일이 없습니다."); return 1; } // 실행 시간 측정을 위한 Stopwatch 시작 Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 첫 번째 파일명에서 경로 제외 string firstFileName = Path.GetFileName(filePaths.First()); string mergedFileName = "merge_" + firstFileName; // 병합된 파일을 저장할 경로 (첫 번째 파일과 동일한 폴더) string mergedFilePath = Path.Combine(Path.GetDirectoryName(filePaths.First()), mergedFileName); try { using (StreamWriter writer = new StreamWriter(mergedFilePath, false)) // false: 새 파일 생성 { foreach (string file in filePaths) { if (File.Exists(file)) { using (StreamReader reader = new StreamReader(file)) { writer.Write(reader.ReadToEnd()); } Console.WriteLine($"{file} -> 병합 완료"); } else { Console.WriteLine($"파일 없음: {file}"); } } } // 실행 시간 측정 종료 stopwatch.Stop(); Console.WriteLine($"모든 파일이 {mergedFileName}로 병합되었습니다."); Console.WriteLine($"병합 실행 시간: {stopwatch.ElapsedMilliseconds} ms"); rtnBint = 0; // 성공 코드 } catch (Exception ex) { Console.WriteLine($"오류 발생: {ex.Message}"); } return rtnBint; } public static string GetStr(object str ) { return string.IsNullOrEmpty(str.ToString())?"": str.ToString(); } public static string GetBase64(string base64, string type = "decoded") { string rtnStr = string.Empty; if (string.IsNullOrEmpty(base64) == false) { if (type == "decoded") // Base64 디코딩 rtnStr = Encoding.UTF8.GetString(Convert.FromBase64String(base64)); else // Base64 디코딩 rtnStr = Convert.ToBase64String(Encoding.UTF8.GetBytes(base64)); } return rtnStr; } public static string[] GetUser(string userInfo) { string[] rtnArry = null; if (string.IsNullOrEmpty(userInfo) == false) { rtnArry = GetBase64(userInfo).Split(':'); } return rtnArry; } } }