当前位置: 首页>>代码示例>>C#>>正文


C# Module.AddWin32ResourceFile方法代码示例

本文整理汇总了C#中Module.AddWin32ResourceFile方法的典型用法代码示例。如果您正苦于以下问题:C# Module.AddWin32ResourceFile方法的具体用法?C# Module.AddWin32ResourceFile怎么用?C# Module.AddWin32ResourceFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Module的用法示例。


在下文中一共展示了Module.AddWin32ResourceFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddResourcesAndIcons

 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);
     }
   }
 }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:97,代码来源:Compiler.cs


注:本文中的Module.AddWin32ResourceFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。