Exemplo n.º 1
0
        public override bool Export(string filename, IPackage package)
        {
            ScriptResource.ScriptResource resource = CreateResource(package) as ScriptResource.ScriptResource;

            FileStream fileStream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);

            try
            {
                BinaryReader stream = resource.Assembly;

                if (stream.BaseStream.CanSeek)
                {
                    stream.BaseStream.Position = 0;
                }

                new BinaryWriter(fileStream).Write(stream.ReadBytes((int)stream.BaseStream.Length));
                return(true);
            }
            catch (Exception ex)
            {
                MainForm.IssueError(ex, "Export failed.");
                return(false);
            }
            finally
            {
                fileStream.Close();
            }
        }
Exemplo n.º 2
0
        public static string getAssemblyName(ScriptResource.ScriptResource s3sa)
        {
            try
            {
                byte[] data = new byte[s3sa.Assembly.BaseStream.Length];
                s3sa.Assembly.BaseStream.Read(data, 0, data.Length);
                Assembly assy = Assembly.Load(data);

                return(assy.FullName.Split(',')[0] + ".dll");
            }
            catch
            {
            }
            return("*.dll");
        }
Exemplo n.º 3
0
        public override bool Import(string filename, IPackage package)
        {
            ScriptResource.ScriptResource resource = CreateResource(package) as ScriptResource.ScriptResource;

            FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read);

            try
            {
                resource.Assembly = new BinaryReader(stream);

                package.ReplaceResource(mEntry, resource);
                return(true);
            }
            catch (Exception ex)
            {
                MainForm.IssueError(ex, "Import failed.");
                return(false);
            }
            finally
            {
                stream.Close();
            }
        }
Exemplo n.º 4
0
        protected override void Set(IResourceIndexEntry entry, IPackage package)
        {
            base.Set(entry, package);

            mResource = ResourceHandlers.CreateResource(entry, package) as ScriptResource.ScriptResource;
        }
Exemplo n.º 5
0
        protected override void Set(IResourceIndexEntry entry, IPackage package)
        {
            base.Set(entry, package);

            mResource = ResourceHandlers.CreateResource(entry, package) as ScriptResource.ScriptResource;
        }
Exemplo n.º 6
0
        internal static BinaryReader AddAssembly(Package package, string instanceName)
        {
            BinaryReader result = null;

            try
            {
                TGIBlock tgi   = new TGIBlock(0, null, 0x073FAA07, 0, FNV64.GetHash(instanceName));
                byte[]   array = new byte[0];
                using (FileStream fileStream = File.OpenRead(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BroadcastTemplate.dll")))
                {
                    using (BinaryReader binaryReader = new BinaryReader(fileStream))
                    {
                        array = new byte[fileStream.Length];
                        binaryReader.Read(array, 0, (int)fileStream.Length);
                    }
                }
                byte[]      array2 = Encoding.ASCII.GetBytes(instanceName);
                int         num    = 0;
                List <byte> list   = new List <byte>();
                List <byte> list2  = new List <byte>();
                for (int i = 0; i < array.Length; i++)
                {
                    byte b = array[i];
                    if (b == AssemblyTemplate[num])
                    {
                        list2.Add(b);
                        num++;
                        if (num >= AssemblyTemplate.Length)
                        {
                            list.AddRange(array2);
                            list2.Clear();
                            num = 0;
                        }
                    }
                    else
                    {
                        list.AddRange(list2);
                        list2.Clear();
                        num = 0;
                        list.Add(b);
                    }
                }
                ScriptResource.ScriptResource assembly = new ScriptResource.ScriptResource(0, null);
                using (MemoryStream s = new MemoryStream(list.ToArray()))
                {
                    result            = new BinaryReader(s);
                    assembly.Assembly = result;
                }
                ResourceIndexEntry entry = (ResourceIndexEntry)package.AddResource(tgi, null, true);
                package.ReplaceResource(entry, assembly);
                return(result);
            }
            catch
            {
                if (result != null)
                {
                    result.Close();
                }
                throw;
            }
        }