private void ExportAndMerge()
            {
                string newDisassembledCode = null;

                if ((this.CodePatches2 != null && this.CodePatches2.Length > 0) || numberedStrings.Count > 0)
                {
                    this.ainFile = ainFile.Clone();
                }


                if (this.CodePatches2 != null && this.CodePatches2.Length > 0)
                {
                    //this.ainFile = ainFile.Clone();
                    var    compiler = new Compiler.Compiler(ainFile);
                    byte[] codeBytes;
                    compiler.CompileCode(this.CodePatches2.ToString(), out codeBytes, out newDisassembledCode, true, this.CodePatches);
                    if (newDisassembledCode == null || compiler.Errors.Count > 0)
                    {
                        var errorsListForm = new ErrorsListForm();
                        errorsListForm.SetErrorList(compiler.Errors);
                        errorsListForm.Show();
                        return;
                    }

                    //foreach (var func in functionsToOutput)
                    //{
                    //    this.CodePatches[func.Name] = "";
                    //}
                }

                currentFunctionName = "";
                stringDictionary    = null;
                messageDictionary   = null;
                stringNumber        = 0;
                messageNumber       = 0;

                //var ainFile = this.ainFile;
                if (numberedStrings.Count > 0)
                {
                    //this.ainFile = ainFile.Clone();
                    var stringExportImport = new StringExportImport(ainFile);
                    int firstMessage       = stringExportImport.GetFirstMessageIdNumber();
                    int lastMessage        = firstMessage + ainFile.Messages.Count;
                    int firstString        = stringExportImport.GetFirstStringIdNumber();
                    int lastString         = firstString + ainFile.Strings.Count;

                    foreach (var pair in numberedStrings)
                    {
                        int    number  = pair.Key;
                        string message = pair.Value;
                        if (number >= firstMessage && number < lastMessage)
                        {
                            ainFile.Messages[number - firstMessage] = message;
                        }
                        else if (number >= firstString && number < lastString)
                        {
                            ainFile.Strings[number - firstString] = message;
                        }
                    }
                }

                using (TemporaryFile tempFile = new TemporaryFile("jam", true))
                {
                    var saver   = new ExplorerForm.SaveProjectInBackground();
                    var options = new CodeDisplayOptions();
                    options.AnnotateWithDecompiledCode = false;
                    options.MergeDuplicateStrings      = true;
                    options.MergeDuplicateMessages     = true;
                    var writer = new AssemblerProjectWriter(ainFile, options);
                    writer.BeforeWritingInstruction += new EventHandler <InstructionInfoEventArgs>(writer_BeforeWritingInstruction);
                    writer.BeforeWritingString      += new EventHandler <InstructionInfoEventArgs>(writer_BeforeWritingString);
                    saver.SaveAsProject(writer, tempFile.FileName, true);
                    if (newDisassembledCode != null)
                    {
                        using (var fs = new FileStream(tempFile.FileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
                        {
                            using (var sw = new StreamWriter(fs, Extensions.TextEncoding))
                            {
                                sw.WriteLine();
                                sw.WriteLine(newDisassembledCode);
                                sw.Flush();
                                fs.Flush();
                                sw.Close();
                                fs.Close();
                            }
                        }
                    }


                    //WaitForFileLock(tempFile.FileName, 2000);

                    //tempFile.FileName

                    var builder = new ExplorerForm.BuildProjectInBackground();
                    builder.ForceUniqueMessages = true;
                    builder.Run(tempFile.FileName, this.outputFileName, true);
                }
            }