TranslateTool.GenerateDll.Generate C# (CSharp) Method

Generate() public method

public Generate ( ResourceDirectory directory ) : bool
directory ResourceDirectory
return bool
        public bool Generate(ResourceDirectory directory)
        {
            string directoryPath = Path.Combine(OutputDirectory, directory.Culture.Name);
            if (!Directory.Exists(directoryPath))
                Directory.CreateDirectory(directoryPath);

            List<string> resourcesFiles = new List<string>();

            // Find tools.
            alExeName = RunProgram.FindSDKTool("al.exe");
            if (alExeName == null)
                ErrorText += @"Cannot find al.exe in the Windows SDK. Make sure the Windows SDK is installed in c:\Program Files\Microsoft SDKs\Windows";
            resgenExeName = RunProgram.FindSDKTool("resgen.exe");
            if (resgenExeName == null)
                ErrorText += @"Cannot find resgen.exe in the Windows SDK. Make sure the Windows SDK is installed in c:\Program Files\Microsoft SDKs\Windows";
            if (alExeName == null || resgenExeName == null)
                return false;

            // Convert all .resx to .resources.
            foreach (ResXFile resxFile in directory.AllFiles) {
                bool success = ConvertResX(resxFile, directoryPath);
                if (!success) {
                    ErrorText += programRunner.Output;
                    return false;
                }
            }

            // Create response file for AL.
            string responseFileName = Path.Combine(directoryPath, "alresp.txt");
            using (TextWriter responseWriter = new StreamWriter(responseFileName)) {
                responseWriter.WriteLine("/t:lib");

                foreach (ResXFile resxFile in directory.AllFiles) {
                    string resourceFile = GetResourcesName(resxFile, directoryPath);
                    responseWriter.WriteLine("/embed:\"{0}\",\"{1}.{2}\"", resourceFile, Namespace, Path.GetFileName(resourceFile));
                }

                responseWriter.WriteLine("/culture:{0}", directory.Culture.Name);
                responseWriter.WriteLine("/out:\"{0}\"", Path.Combine(directoryPath, DllName+".resources.dll"));
            }

            // Run AL.EXE
            int exitCode = programRunner.Run(alExeName, "\"@" + responseFileName + "\"", directoryPath);
            ErrorText += programRunner.Output;

            if (exitCode == 0) {
                foreach (ResXFile resxFile in directory.AllFiles) {
                    string resourceFile = GetResourcesName(resxFile, directoryPath);
                    File.Delete(resourceFile);
                }

                return true;
            }
            else
                return false;
        }

Usage Example

Example #1
0
        private void generateButton_Click(object sender, EventArgs e)
        {
            GenerateDll generateDll = new GenerateDll();

            generateDll.Namespace       = namespaceTextBox.Text;
            generateDll.DllName         = assemblyTextBox.Text;
            generateDll.OutputDirectory = directoryTextBox.Text;

            bool success = generateDll.Generate(ResDirectory);

            if (success)
            {
                resultLabel.Text = "Generation of resource DLL successful";
            }
            else
            {
                resultLabel.Text = "Generation of resource DLL failed. Errors shown below.";
            }

            errorTextBox.Text      = generateDll.ErrorText;
            okButton.Visible       = true;
            errorTextBox.Visible   = true;
            generateButton.Visible = false;
            this.AcceptButton      = okButton;
        }
All Usage Examples Of TranslateTool.GenerateDll::Generate