示例#1
0
        public byte[] Unpack(string itemName)
        {
            byte[]  result = new byte[1];
            SubItem subItem;

            if (HasItem(itemName, out subItem))
            {
                int          ptr = posDictionary[itemName];
                BinaryReader br  = new BinaryReader(ms);
                br.BaseStream.Seek(ptr, SeekOrigin.Begin);
                Logger.Print(string.Format("{0:x8}", ptr));
                if (subItem.IsCompressed)
                {
                    int    filehdr        = br.ReadInt32();
                    int    compressSize   = br.ReadInt32();
                    uint   fileType       = br.ReadUInt32();
                    int    decompressSize = br.ReadInt32();
                    byte[] zipdata        = br.ReadBytes(compressSize - 0x10);

                    LBC.Decompress(zipdata, zipdata.Length, decompressSize, out result);
                }
                else
                {
                    int filehdr        = br.ReadInt32();
                    int decompressSize = br.ReadInt32();
                    br.BaseStream.Seek(-8, SeekOrigin.Current);
                    result = br.ReadBytes(decompressSize);
                }
            }

            return(result);
        }
示例#2
0
        public byte[] Repack(string baseDir, string lbName, string srcDir, string patchDir, List <SubItem> subItems)
        {
            byte[] dst;
            this.Load(IOHelper.PathCombine(srcDir, lbName));
            using (MemoryStream dstStream = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(dstStream))
                {
                    bw.Seek(0, SeekOrigin.Begin);
                    for (int i = 0; i < subItems.Count; i++)
                    {
                        SubItem vItem = subItems[i];
                        byte[]  vDataBytes;
                        if (File.Exists(IOHelper.PathCombine(patchDir, baseDir, vItem.FileName)))
                        {
                            //如果存在补丁文件,从补丁目录读取并压缩数据
                            vDataBytes = File.ReadAllBytes(IOHelper.PathCombine(patchDir, baseDir, vItem.FileName));
                        }
                        else
                        {
                            //如果不存在补丁文件,从原始目录读取
                            vDataBytes = File.ReadAllBytes(IOHelper.PathCombine(srcDir, baseDir, vItem.FileName));
                        }
                        if ((vItem.NeedReCompress == true) && (vItem.IsCompressed == true))
                        {
                            byte[] compressDataBytes;
                            int    compressLenght = 0;
                            LBC.Compress(vDataBytes, out compressDataBytes, out compressLenght);
                            bw.Write((int)vItem.FileID);
                            bw.Write((int)compressLenght + 0x10);
                            bw.Write((uint)vItem.ExtMagic);
                            bw.Write((int)vDataBytes.Length);
                            bw.Write(compressDataBytes);
                            bw.AlignPosition(0x40);
                        }

                        else if ((vItem.NeedReCompress == false) && (vItem.IsCompressed == true))
                        {
                            bw.Write(vDataBytes);
                            bw.AlignPosition(0x40);
                        }
                        else
                        {
                            bw.Write(vDataBytes);
                            bw.AlignPosition(0x40);
                        }
                    }
                    bw.Write((int)0xff);
                    bw.Write((int)0x10);
                    bw.Write((uint)0x30444e45);
                    bw.Write((int)0);
                    bw.Write(Enumerable.Repeat((byte)0, 0x30).ToArray());
                    dst = dstStream.ToArray();
                }
            }

            return(dst);
        }
示例#3
0
        private void UpdateBook(object sender, RoutedEventArgs e)
        {
            lbc = ComboBox_LBC.SelectedItem as LBC;

            book.Publisher_id = ComboBox_Publisher.SelectedIndex + 1;
            book.LBC_Id       = lbc.LBC_id;
            book.Genre_id     = ComboBox_Genrename.SelectedIndex + 1;
            book.AuthorSign   = AuthorSign(TextBox_Author.Text.Trim());
            Connection.library.SaveChanges();
            new BooksWindows().Show();
            Close();
        }
示例#4
0
 static void test()
 {
     using (FileStream fs = File.OpenRead("test.LB"))
     {
         int          length    = 0x269a - 0x10;
         int          decLen    = 0x501e;
         int          offset    = 0x4d0;
         byte[]       dataBytes = new byte[length];
         BinaryReader br        = new BinaryReader(fs);
         br.BaseStream.Seek(offset, SeekOrigin.Begin);
         dataBytes = br.ReadBytes(length);
         byte[] outBytes = new byte[decLen];
         LBC.Decompress(dataBytes, length, decLen, out outBytes);
         File.WriteAllBytes("test.dec", outBytes);
     }
 }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int _LBCtemperatureHumidity = 0;
            int _LBCturbolence          = 0;

            DA.GetData(0, ref _LBCtemperatureHumidity);
            DA.GetData(1, ref _LBCturbolence);

            List <BoundaryCondition> boundaryCondition = Enum.GetValues(typeof(BoundaryCondition))
                                                         .Cast <BoundaryCondition>()
                                                         .ToList();

            LBC lbc = new LBC(boundaryCondition[_LBCtemperatureHumidity], boundaryCondition[_LBCturbolence]);

            DA.SetData(0, lbc);
        }
示例#6
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            MainSettings         _mainSettings  = null;
            List <Configuration> otherSettings_ = new List <Configuration> ();
            bool _runIt = false;

            DA.GetData(0, ref _mainSettings);
            DA.GetDataList(1, otherSettings_);
            DA.GetData(2, ref _runIt);

            SimpleForcingSettings simpleForcingSettings = null;
            TThread          tThread          = null;
            TimeSteps        timeSteps        = null;
            ModelTiming      modelTiming      = null;
            SoilConfig       soilConfig       = null;
            Sources          sources          = null;
            Turbulence       turbulence       = null;
            OutputSettings   outputSettings   = null;
            Cloud            cloud            = null;
            Background       background       = null;
            SolarAdjust      solarAdjust      = null;
            BuildingSettings buildingSettings = null;
            IVS          ivs          = null;
            ParallelCPU  parallelCPU  = null;
            SOR          sor          = null;
            InflowAvg    inflowAvg    = null;
            Facades      facades      = null;
            PlantSetting plantSetting = null;
            LBC          lbc          = null;
            FullForcing  fullForcing  = null;

            if (_runIt)
            {
                try
                {
                    foreach (Configuration o in otherSettings_)
                    {
                        Type obj = o.GetType();

                        if (obj == typeof(SimpleForcingSettings))
                        {
                            simpleForcingSettings = o as SimpleForcingSettings;
                        }
                        else if (obj == typeof(TThread))
                        {
                            tThread = o as TThread;
                        }
                        else if (obj == typeof(TimeSteps))
                        {
                            timeSteps = o as TimeSteps;
                        }
                        else if (obj == typeof(ModelTiming))
                        {
                            modelTiming = o as ModelTiming;
                        }
                        else if (obj == typeof(SoilConfig))
                        {
                            soilConfig = o as SoilConfig;
                        }
                        else if (obj == typeof(Sources))
                        {
                            sources = o as Sources;
                        }
                        else if (obj == typeof(Turbulence))
                        {
                            turbulence = o as Turbulence;
                        }
                        else if (obj == typeof(OutputSettings))
                        {
                            outputSettings = o as OutputSettings;
                        }
                        else if (obj == typeof(Cloud))
                        {
                            cloud = o as Cloud;
                        }
                        else if (obj == typeof(Background))
                        {
                            background = o as Background;
                        }
                        else if (obj == typeof(SolarAdjust))
                        {
                            solarAdjust = o as SolarAdjust;
                        }
                        else if (obj == typeof(BuildingSettings))
                        {
                            buildingSettings = o as BuildingSettings;
                        }
                        else if (obj == typeof(IVS))
                        {
                            ivs = o as IVS;
                        }
                        else if (obj == typeof(ParallelCPU))
                        {
                            parallelCPU = o as ParallelCPU;
                        }
                        else if (obj == typeof(SOR))
                        {
                            sor = o as SOR;
                        }
                        else if (obj == typeof(InflowAvg))
                        {
                            inflowAvg = o as InflowAvg;
                        }
                        else if (obj == typeof(Facades))
                        {
                            facades = o as Facades;
                        }
                        else if (obj == typeof(PlantSetting))
                        {
                            plantSetting = o as PlantSetting;
                        }
                        else if (obj == typeof(LBC))
                        {
                            lbc = o as LBC;
                        }
                        else if (obj == typeof(FullForcing))
                        {
                            fullForcing = o as FullForcing;
                        }
                    }


                    Simx simx = new Simx(_mainSettings)
                    {
                        SimpleForcing    = simpleForcingSettings,
                        TThread          = tThread,
                        TimeSteps        = timeSteps,
                        ModelTiming      = modelTiming,
                        SoilSettings     = soilConfig,
                        Sources          = sources,
                        Turbulence       = turbulence,
                        OutputSettings   = outputSettings,
                        Cloud            = cloud,
                        Background       = background,
                        SolarAdjust      = solarAdjust,
                        BuildingSettings = buildingSettings,
                        IVS          = ivs,
                        ParallelCPU  = parallelCPU,
                        SOR          = sor,
                        InflowAvg    = inflowAvg,
                        Facades      = facades,
                        PlantSetting = plantSetting,
                        LBC          = lbc,
                        FullForcing  = fullForcing
                    };

                    simx.WriteSimx();
                    DA.SetData(0, Path.Combine(Path.GetDirectoryName(_mainSettings.Inx), _mainSettings.Name + ".simx"));
                }
                catch
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Please provide a valid mainSettings.");
                }
            }
        }