public ResourceCompilerResult Compile(string resourceFile, string outputDir)
        {
            if (_win32ResourceCompiler == null)
                throw new PBException("win32 resource compiler is not defined");
            if (!zFile.Exists(_win32ResourceCompiler))
                throw new PBException("resource compiler cannot be found \"{0}\"", _win32ResourceCompiler);
            if (!zFile.Exists(resourceFile))
                throw new PBException("resource file cannot be found \"{0}\"", resourceFile);
            // attention si le fichier .rc est en utf8+bom le .exe n'aura pas d'icone
            if (zfile.IsBom(resourceFile))
                throw new PBException("resource file encoding is utf8 + bom \"{0}\"", resourceFile);

            if (!zDirectory.Exists(outputDir))
                zDirectory.CreateDirectory(outputDir);

            string resourceFilename = zPath.GetFileNameWithoutExtension(resourceFile);
            string compiledResourceFile = resourceFilename + ".res";
            compiledResourceFile = zpath.PathSetDirectory(compiledResourceFile, outputDir);
            if (zFile.Exists(compiledResourceFile) && zFile.Exists(resourceFile))
            {
                var fiResource = zFile.CreateFileInfo(resourceFile);
                var fiCompiledResource = zFile.CreateFileInfo(compiledResourceFile);
                if (fiCompiledResource.LastWriteTime > fiResource.LastWriteTime)
                    return new ResourceCompilerResult { CompiledResourceFile = compiledResourceFile, Success = true };
            }

            _resourceCompiling = resourceFile;
            _resourceResults = new ResourceCompilerResult { CompiledResourceFile = compiledResourceFile };

            ProcessStartInfo processStartInfo = new ProcessStartInfo();
            processStartInfo.FileName = _win32ResourceCompiler;
            //    Resgen.exe PibLink_resource.resx PibLink.PibLink_resource.resources /str:cs,PibLink,PibLink_resource
            //    rc.exe /fo test.res test.rc
            processStartInfo.Arguments = "/fo \"" + compiledResourceFile + "\" \"" + resourceFile + "\"";
            processStartInfo.UseShellExecute = false;
            processStartInfo.RedirectStandardError = true;
            processStartInfo.WorkingDirectory = zPath.GetDirectoryName(resourceFile);
            Trace.WriteLine("  \"{0}\" {1}", _win32ResourceCompiler, processStartInfo.Arguments);
            //Trace.WriteLine("  WorkingDirectory \"{0}\"", processStartInfo.WorkingDirectory);

            Process process = new Process();
            process.StartInfo = processStartInfo;
            process.ErrorDataReceived += CompileResource_EventErrorDataReceived;
            process.Start();
            process.BeginErrorReadLine();

            while (!process.HasExited)
            {
            }

            if (process.ExitCode != 0)
            {
                _resourceResults.Messages.Add(new ResourceCompilerMessage { File = resourceFile, Message = string.Format("error compiling win32 resource, exit code {0}", process.ExitCode) });
            }
            else
                _resourceResults.Success = true;

            return _resourceResults;
        }
Beispiel #2
0
        public ResourceCompilerResult Compile(ResourceFile resource, string outputDir)
        {
            if (_resourceCompiler == null)
            {
                throw new PBException("resource compiler is not defined");
            }
            if (!zFile.Exists(_resourceCompiler))
            {
                throw new PBException("resource compiler cannot be found \"{0}\"", _resourceCompiler);
            }
            if (!zFile.Exists(resource.File))
            {
                throw new PBException("resource file cannot be found \"{0}\"", resource.File);
            }

            if (!zDirectory.Exists(outputDir))
            {
                zDirectory.CreateDirectory(outputDir);
            }

            //string resourceFile = resource.File;
            string resourceFilename = zPath.GetFileNameWithoutExtension(resource.File);
            //string nameSpace = null;
            //if (attributes.ContainsKey("namespace"))
            //    nameSpace = attributes["namespace"];
            string compiledResourceFile = resourceFilename + ".resources";

            if (resource.Namespace != null)
            {
                compiledResourceFile = resource.Namespace + "." + compiledResourceFile;
            }
            //"WRunSource.Class.PibLink."
            compiledResourceFile = zpath.PathSetDirectory(compiledResourceFile, outputDir);
            if (zFile.Exists(compiledResourceFile) && zFile.Exists(resource.File))
            {
                var fiResource         = zFile.CreateFileInfo(resource.File);
                var fiCompiledResource = zFile.CreateFileInfo(compiledResourceFile);
                if (fiCompiledResource.LastWriteTime > fiResource.LastWriteTime)
                {
                    //return pathCompiledResource;
                    return new ResourceCompilerResult {
                               CompiledResourceFile = compiledResourceFile, Success = true
                    }
                }
                ;
            }

            _resourceCompiling = resource.File;
            _resourceResults   = new ResourceCompilerResult {
                CompiledResourceFile = compiledResourceFile
            };

            //if (_resourceCompiler == null)
            //    throw new PBException("error resource compiler is not defined");
            //if (!zFile.Exists(_resourceCompiler))
            //    throw new PBException("error resource compiler cannot be found {0}", _resourceCompiler);
            ProcessStartInfo processStartInfo = new ProcessStartInfo();

            processStartInfo.FileName = _resourceCompiler;
            //    Resgen.exe PibLink_resource.resx PibLink.PibLink_resource.resources /str:cs,PibLink,PibLink_resource
            processStartInfo.Arguments = resource.File + " " + compiledResourceFile;
            if (resource.Namespace != null)
            {
                processStartInfo.Arguments += " /str:cs," + resource.Namespace + "," + resourceFilename;
            }
            //WriteLine(1, "  {0} {1}", _resourceCompiler, processStartInfo.Arguments);
            Trace.WriteLine("  {0} {1}", _resourceCompiler, processStartInfo.Arguments);
            processStartInfo.UseShellExecute       = false;
            processStartInfo.RedirectStandardError = true;
            processStartInfo.WorkingDirectory      = zPath.GetDirectoryName(resource.File);

            Process process = new Process();

            process.StartInfo = processStartInfo;
            //process.ErrorDataReceived += new DataReceivedEventHandler(CompileResource_EventErrorDataReceived);
            process.ErrorDataReceived += CompileResource_EventErrorDataReceived;
            process.Start();
            process.BeginErrorReadLine();

            while (!process.HasExited)
            {
            }

            if (process.ExitCode != 0)
            {
                _resourceResults.Messages.Add(new ResourceCompilerMessage {
                    File = resource.File, Message = string.Format("error compiling resource, exit code {0}", process.ExitCode)
                });
                //_resourceResults.HasError = true;
            }
            else
            {
                _resourceResults.Success = true;
            }

            //return compiledResourceFile;
            return(_resourceResults);
        }
Beispiel #3
0
        public ResourceCompilerResult Compile(string resourceFile, string outputDir)
        {
            if (_win32ResourceCompiler == null)
            {
                throw new PBException("win32 resource compiler is not defined");
            }
            if (!zFile.Exists(_win32ResourceCompiler))
            {
                throw new PBException("resource compiler cannot be found \"{0}\"", _win32ResourceCompiler);
            }
            if (!zFile.Exists(resourceFile))
            {
                throw new PBException("resource file cannot be found \"{0}\"", resourceFile);
            }
            // attention si le fichier .rc est en utf8+bom le .exe n'aura pas d'icone
            if (zfile.IsBom(resourceFile))
            {
                throw new PBException("resource file encoding is utf8 + bom \"{0}\"", resourceFile);
            }

            if (!zDirectory.Exists(outputDir))
            {
                zDirectory.CreateDirectory(outputDir);
            }

            string resourceFilename     = zPath.GetFileNameWithoutExtension(resourceFile);
            string compiledResourceFile = resourceFilename + ".res";

            compiledResourceFile = zpath.PathSetDirectory(compiledResourceFile, outputDir);
            if (zFile.Exists(compiledResourceFile) && zFile.Exists(resourceFile))
            {
                var fiResource         = zFile.CreateFileInfo(resourceFile);
                var fiCompiledResource = zFile.CreateFileInfo(compiledResourceFile);
                if (fiCompiledResource.LastWriteTime > fiResource.LastWriteTime)
                {
                    return new ResourceCompilerResult {
                               CompiledResourceFile = compiledResourceFile, Success = true
                    }
                }
                ;
            }

            _resourceCompiling = resourceFile;
            _resourceResults   = new ResourceCompilerResult {
                CompiledResourceFile = compiledResourceFile
            };

            ProcessStartInfo processStartInfo = new ProcessStartInfo();

            processStartInfo.FileName = _win32ResourceCompiler;
            //    Resgen.exe PibLink_resource.resx PibLink.PibLink_resource.resources /str:cs,PibLink,PibLink_resource
            //    rc.exe /fo test.res test.rc
            processStartInfo.Arguments             = "/fo \"" + compiledResourceFile + "\" \"" + resourceFile + "\"";
            processStartInfo.UseShellExecute       = false;
            processStartInfo.RedirectStandardError = true;
            processStartInfo.WorkingDirectory      = zPath.GetDirectoryName(resourceFile);
            Trace.WriteLine("  \"{0}\" {1}", _win32ResourceCompiler, processStartInfo.Arguments);
            //Trace.WriteLine("  WorkingDirectory \"{0}\"", processStartInfo.WorkingDirectory);

            Process process = new Process();

            process.StartInfo          = processStartInfo;
            process.ErrorDataReceived += CompileResource_EventErrorDataReceived;
            process.Start();
            process.BeginErrorReadLine();

            while (!process.HasExited)
            {
            }

            if (process.ExitCode != 0)
            {
                _resourceResults.Messages.Add(new ResourceCompilerMessage {
                    File = resourceFile, Message = string.Format("error compiling win32 resource, exit code {0}", process.ExitCode)
                });
            }
            else
            {
                _resourceResults.Success = true;
            }

            return(_resourceResults);
        }
Beispiel #4
0
        public ResourceCompilerResult Compile(ResourceFile resource, string outputDir)
        {
            if (_resourceCompiler == null)
                throw new PBException("resource compiler is not defined");
            if (!zFile.Exists(_resourceCompiler))
                throw new PBException("resource compiler cannot be found \"{0}\"", _resourceCompiler);
            if (!zFile.Exists(resource.File))
                throw new PBException("resource file cannot be found \"{0}\"", resource.File);

            if (!zDirectory.Exists(outputDir))
                zDirectory.CreateDirectory(outputDir);

            //string resourceFile = resource.File;
            string resourceFilename = zPath.GetFileNameWithoutExtension(resource.File);
            //string nameSpace = null;
            //if (attributes.ContainsKey("namespace"))
            //    nameSpace = attributes["namespace"];
            string compiledResourceFile = resourceFilename + ".resources";
            if (resource.Namespace != null)
                compiledResourceFile = resource.Namespace + "." + compiledResourceFile;
            //"WRunSource.Class.PibLink."
            compiledResourceFile = zpath.PathSetDirectory(compiledResourceFile, outputDir);
            if (zFile.Exists(compiledResourceFile) && zFile.Exists(resource.File))
            {
                var fiResource = zFile.CreateFileInfo(resource.File);
                var fiCompiledResource = zFile.CreateFileInfo(compiledResourceFile);
                if (fiCompiledResource.LastWriteTime > fiResource.LastWriteTime)
                    //return pathCompiledResource;
                    return new ResourceCompilerResult { CompiledResourceFile = compiledResourceFile, Success = true };
            }

            _resourceCompiling = resource.File;
            _resourceResults = new ResourceCompilerResult { CompiledResourceFile = compiledResourceFile };

            //if (_resourceCompiler == null)
            //    throw new PBException("error resource compiler is not defined");
            //if (!zFile.Exists(_resourceCompiler))
            //    throw new PBException("error resource compiler cannot be found {0}", _resourceCompiler);
            ProcessStartInfo processStartInfo = new ProcessStartInfo();
            processStartInfo.FileName = _resourceCompiler;
            //    Resgen.exe PibLink_resource.resx PibLink.PibLink_resource.resources /str:cs,PibLink,PibLink_resource
            processStartInfo.Arguments = resource.File + " " + compiledResourceFile;
            if (resource.Namespace != null)
                processStartInfo.Arguments += " /str:cs," + resource.Namespace + "," + resourceFilename;
            //WriteLine(1, "  {0} {1}", _resourceCompiler, processStartInfo.Arguments);
            Trace.WriteLine("  {0} {1}", _resourceCompiler, processStartInfo.Arguments);
            processStartInfo.UseShellExecute = false;
            processStartInfo.RedirectStandardError = true;
            processStartInfo.WorkingDirectory = zPath.GetDirectoryName(resource.File);

            Process process = new Process();
            process.StartInfo = processStartInfo;
            //process.ErrorDataReceived += new DataReceivedEventHandler(CompileResource_EventErrorDataReceived);
            process.ErrorDataReceived += CompileResource_EventErrorDataReceived;
            process.Start();
            process.BeginErrorReadLine();

            while (!process.HasExited)
            {
            }

            if (process.ExitCode != 0)
            {
                _resourceResults.Messages.Add(new ResourceCompilerMessage { File = resource.File, Message = string.Format("error compiling resource, exit code {0}", process.ExitCode) });
                //_resourceResults.HasError = true;
            }
            else
                _resourceResults.Success = true;

            //return compiledResourceFile;
            return _resourceResults;
        }