Пример #1
0
        internal void Save()
        {
            if (transient && !is_main)
            {
                return;
            }

            if (types != null)
            {
                for (int i = 0; i < num_types; ++i)
                {
                    if (!types [i].is_created)
                    {
                        throw new NotSupportedException("Type '" + types [i].FullName + "' was not completed.");
                    }
                }
            }

            if ((global_type != null) && (global_type_created == null))
            {
                global_type_created = global_type.CreateType();
            }

            if (resources != null)
            {
                for (int i = 0; i < resources.Length; ++i)
                {
                    IResourceWriter rwriter;
                    if (resource_writers != null && (rwriter = resource_writers [resources [i].name] as IResourceWriter) != null)
                    {
                        ResourceWriter writer = (ResourceWriter)rwriter;
                        writer.Generate();
                        MemoryStream mstream = (MemoryStream)writer._output;
                        resources [i].data = new byte [mstream.Length];
                        mstream.Seek(0, SeekOrigin.Begin);
                        mstream.Read(resources [i].data, 0, (int)mstream.Length);
                        continue;
                    }
                    Stream stream = resources [i].stream;

                    // According to MSDN docs, the stream is read during assembly save, not earlier
                    if (stream != null)
                    {
                        try {
                            long len = stream.Length;
                            resources [i].data = new byte [len];
                            stream.Seek(0, SeekOrigin.Begin);
                            stream.Read(resources [i].data, 0, (int)len);
                        } catch {
                            /* do something */
                        }
                    }
                }
            }

            build_metadata(this);

            string fileName = fqname;

            if (assemblyb.AssemblyDir != null)
            {
                fileName = Path.Combine(assemblyb.AssemblyDir, fileName);
            }

            try {
                // We mmap the file, so unlink the previous version since it may be in use
                File.Delete(fileName);
            } catch {
                // We can safely ignore
            }
            using (FileStream file = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                WriteToFile(file.Handle);

            //
            // The constant 0x80000000 is internal to Mono, it means `make executable'
            //
            File.SetAttributes(fileName, (FileAttributes)(unchecked ((int)0x80000000)));

            if (types != null && symbolWriter != null)
            {
                for (int i = 0; i < num_types; ++i)
                {
                    types [i].GenerateDebugInfo(symbolWriter);
                }
                symbolWriter.Close();
            }
        }
Пример #2
0
 public void Dispose()
 {
     m_writer.Close();
     Patch();
 }