public static string ToString(CiconResult p_result) { string result = null; switch (p_result) { case CiconResult.FailBegin: result = "컴파일된 파일 오픈에 실패했습니다."; break; case CiconResult.Failed: result = "컴파일된 파일 아이콘 업로드 적용에 실패했습니다."; break; case CiconResult.FailUpdate: result = "컴파일된 파일 아이콘 업로드에 실패했습니다."; break; case CiconResult.NotExistBinFile: result = "지정된 경로에 컴파일된 파일이 없습니다."; break; case CiconResult.NotExistImageFile: result = "지정된 경로에 아이콘 파일이 없습니다."; break; case CiconResult.Success: result = "아이콘 변경 완료"; break; } return(result); }
public CiconResult ChangeIcon(string p_exeFilePath, Icons p_icons) { // Load executable IntPtr handleExe = WinAPI.BeginUpdateResource(p_exeFilePath, false); if (handleExe == null) { return(CiconResult.FailBegin); } ushort startindex = 159; ushort index = 1; CiconResult result = CiconResult.Success; bool ret = true; foreach (var icon in p_icons) { // Replace the icon // todo :Improve the return value handling of UpdateResource ret = WinAPI.UpdateResource(handleExe, RT_ICON, index, 0x409, icon.Data, icon.Size); index++; } var groupdata = p_icons.ToGroupData(); // todo :Improve the return value handling of UpdateResource ret = WinAPI.UpdateResource(handleExe, RT_GROUP_ICON, startindex, 0x409, groupdata, (uint)groupdata.Length); if (ret) { if (WinAPI.EndUpdateResource(handleExe, false)) { result = CiconResult.Success; } else { result = CiconResult.Failed; } } else { result = CiconResult.FailUpdate; } return(result); }
static void Main(string[] args) { string ahkPath = null; string icoPath = null; string destPath = null; if (args.Length < 1) { Console.WriteLine("최소 1개 이상의 인수가 필요합니다."); return; } if (args[0].Equals("/?") || args[0].Equals("/help")) { Console.WriteLine("-a : 스크립트 경로 (필수)" + Environment.NewLine + "-i : 아이콘 경로 (생략 가능)" + Environment.NewLine + "-d : 목적지 경로 (생략 가능)" + Environment.NewLine + "/? or /help : 도움말" + Environment.NewLine + @"예) -a C:\script.ahk -i C:\ico.ico"); return; } if (args.Length / 2 == 0) { Console.WriteLine("인수 갯수가 올바르지 않습니다."); return; } for (int i = 0; i < args.Length; i += 2) { switch (args[i]) { case "-i": icoPath = args[i + 1]; break; case "-a": ahkPath = args[i + 1]; break; case "-d": destPath = args[i + 1]; break; default: Console.Write("알수없는 인수 입니다.: " + args[i] + " " + args[i + 1]); return; } } if (ahkPath == null) { Console.WriteLine("필수 입력인 스크립트 인수가 없습니다."); return; } Core core = new Core(ahkPath, icoPath, destPath); CResult Result = core.Compile(); Console.WriteLine(Util.ToString(Result)); if (icoPath != null) { CiconResult iconResult = core.ChangeIco(); Console.WriteLine(Util.ToString(iconResult)); } }