public virtual void AddResourcesAndIcons(Module module, CompilerParameters options, ErrorNodeList errors){ if (options == null) return; CompilerOptions coptions = options as CompilerOptions; string win32ResourceFilePath = options.Win32Resource; if (win32ResourceFilePath != null && win32ResourceFilePath.Length > 0){ if (!File.Exists(win32ResourceFilePath) && options.OutputAssembly != null) win32ResourceFilePath = PathWrapper.Combine(Path.GetDirectoryName(options.OutputAssembly), win32ResourceFilePath); try{ module.AddWin32ResourceFile(win32ResourceFilePath); }catch(OutOfMemoryException){ errors.Add(this.CreateErrorNode(Error.InvalidWin32ResourceFileContent, win32ResourceFilePath)); }catch(NullReferenceException){ errors.Add(this.CreateErrorNode(Error.InvalidWin32ResourceFileContent, win32ResourceFilePath)); }catch(Exception e){ errors.Add(this.CreateErrorNode(Error.Win32ResourceFileNotRead, win32ResourceFilePath, e.Message)); } } if (coptions != null && coptions.Win32Icon != null && coptions.Win32Icon.Length > 0){ string win32iconFilePath = coptions.Win32Icon; if (!File.Exists(win32iconFilePath) && options.OutputAssembly != null) win32iconFilePath = PathWrapper.Combine(Path.GetDirectoryName(options.OutputAssembly), win32iconFilePath); try{ module.AddWin32Icon(win32iconFilePath); }catch(OutOfMemoryException){ errors.Add(this.CreateErrorNode(Error.AutoWin32ResGenFailed, this.CreateErrorNode(Error.Win32IconFileNotRead, win32iconFilePath, this.CreateErrorNode(Error.InvalidData).GetMessage()).GetMessage())); }catch(NullReferenceException){ errors.Add(this.CreateErrorNode(Error.AutoWin32ResGenFailed, this.CreateErrorNode(Error.Win32IconFileNotRead, win32iconFilePath, this.CreateErrorNode(Error.InvalidData).GetMessage()).GetMessage())); }catch(Exception e){ errors.Add(this.CreateErrorNode(Error.AutoWin32ResGenFailed, this.CreateErrorNode(Error.Win32IconFileNotRead, win32iconFilePath, e.Message).GetMessage())); } } if (coptions != null && (win32ResourceFilePath == null || win32ResourceFilePath.Length == 0)) module.AddWin32VersionInfo(coptions); if (coptions != null && coptions.EmbeddedResources != null && coptions.EmbeddedResources.Count > 0){ if (module.Resources == null) module.Resources = new ResourceList(); for (int i = 0, n = coptions.EmbeddedResources.Count; i < n; i++){ string resource = coptions.EmbeddedResources[i]; if (resource == null) continue; string resourceFileName = resource; string resourceName = Path.GetFileName(resource); int firstComma = resource.IndexOf(','); if (firstComma > 0){ resourceFileName = resource.Substring(0, firstComma); resourceName = resource.Substring(firstComma+1); }else if (coptions.RootNamespace != null && coptions.RootNamespace.Length > 0){ resourceName = coptions.RootNamespace + "." + resourceName; } byte[] resourceContents = null; resourceFileName = PathWrapper.Combine(Path.GetDirectoryName(options.OutputAssembly), resourceFileName); try{ using (System.IO.FileStream resStream = File.OpenRead(resourceFileName)){ long size = resStream.Length; if (size > int.MaxValue) continue; //TODO: error message int len = (int)size; resourceContents = new byte[len]; resStream.Read(resourceContents, 0, len); } }catch(Exception e){ errors.Add(this.CreateErrorNode(Error.CannotReadResource, Path.GetFileName(resourceFileName), e.Message)); } Resource res = new Resource(); res.Name = resourceName; res.IsPublic = true; //TODO: get this value from the resource string res.DefiningModule = module; res.Data = resourceContents; module.Resources.Add(res); } } if (coptions != null && coptions.LinkedResources != null && coptions.LinkedResources.Count > 0){ if (module.Resources == null) module.Resources = new ResourceList(); for (int i = 0, n = coptions.LinkedResources.Count; i < n; i++){ string resource = coptions.LinkedResources[i]; if (resource == null) continue; string resourceFileName = resource; string resourceName = resource; int firstComma = resource.IndexOf(','); if (firstComma > 0){ resourceFileName = resource.Substring(0, firstComma); resourceName = resource.Substring(firstComma+1); } Resource res = new Resource(); res.Name = resourceName; res.IsPublic = true; res.DefiningModule = new Module(); res.DefiningModule.Kind = ModuleKindFlags.ManifestResourceFile; res.DefiningModule.Name = resourceFileName; res.DefiningModule.Location = PathWrapper.Combine(Path.GetDirectoryName(options.OutputAssembly), resourceFileName); ; res.Data = null; module.Resources.Add(res); } } }