public MapPreviewPanel(HaloMap Map)
 {
     InitializeComponent();
     label1.Text = Map.Map_Header.internalName;
     if (AppSettings.Settings.MapInfo_Folder != "")
     {
         string[] files = Directory.GetFiles(AppSettings.Settings.MapInfo_Folder);
         foreach (string str in files)
         {
             try
             {
                 FileStream stream = new FileStream(str, FileMode.Open);
                 InfoFile   file   = new InfoFile(stream);
                 stream.Close();
                 if (file.MapFileName == Map.Map_Header.internalName)
                 {
                     label1.Text       = file.EnglishName;
                     richTextBox1.Text = file.EnglishDescription;
                     if (AppSettings.Settings.Images_Folder != "")
                     {
                         string path = AppSettings.Settings.Images_Folder + @"\" + file.MapImageFileName + ".blf";
                         if (File.Exists(path))
                         {
                             stream = new FileStream(path, FileMode.Open);
                             BLFImageFile file2 = new BLFImageFile(stream);
                             stream.Close();
                             pictureBox1.Image = file2.BLFImage;
                         }
                     }
                     break;
                 }
             }
             catch
             {
             }
         }
     }
 }
Example #2
0
        public void SaveProject(string directory, int mapID)
        {
            //Copy the .map files

            #region Map File Copy

            //Get our map short filename array
            string[] temp         = MapLocation.Split('\\');
            string   mapshortform = temp[temp.Length - 1];
            if (directory + mapshortform != MapLocation)
            {
                //If the file exists...
                if (File.Exists(directory + mapshortform))
                {
                    //Delete it.
                    File.Delete(directory + mapshortform);
                }
                //Copy the map to the save project directory
                File.Copy(MapLocation, directory + mapshortform);
            }

            //Open this map
            HaloMap map = new HaloMap(directory + mapshortform);

            //Create our tag indexer
            int scnr_index = -1;
            //Loop through each tag till we find our scnr
            for (int i = 0; i < map.IndexItems.Count; i++)
            {
                if (map.IndexItems[i].Class == "scnr")
                {
                    scnr_index = i;
                    break;
                }
            }

            //If our scnr index hasnt been set.
            if (scnr_index == -1)
            {
                throw new Exception("Could not find [scnr] tag in the map file. Cannot continue.");
            }

            //Open IO
            map.OpenIO();

            //Go to this tag's offset + 8
            map.IO.Out.BaseStream.Position = map.IndexItems[scnr_index].Offset + 8;

            //Write our map id
            map.IO.Out.Write(mapID);

            //Close IO
            map.CloseIO();
            #endregion

            //Save the blf's.

            #region BLF Images

            //Base bitmap
            BLFImageFile blfimage = new BLFImageFile();
            blfimage.BLFImage = Image_File;
            string blfStarterString = directory + "m_" + mapshortform.Substring(0, mapshortform.Length - 4);
            blfimage.SaveBLFImage(new FileStream(blfStarterString + ".blf", FileMode.Create),
                                  BLFImageFile.BLFImageType.BaseImage);
            blfimage.SaveBLFImage(new FileStream(blfStarterString + "_sm.blf", FileMode.Create),
                                  BLFImageFile.BLFImageType.Sm);
            BLFImageTransformer.BLF_ImageResults blfimageresults =
                BLFImageTransformer.CreateTransformedImages(Image_File);
            blfimage.BLFImage = blfimageresults.FilmBitmap;
            blfimage.SaveBLFImage(new FileStream(blfStarterString + "_film.blf", FileMode.Create),
                                  BLFImageFile.BLFImageType.Film);
            blfimage.BLFImage = blfimageresults.ClipBitmap;
            blfimage.SaveBLFImage(new FileStream(blfStarterString + "_clip.blf", FileMode.Create),
                                  BLFImageFile.BLFImageType.Clip);
            blfimage.BLFImage = blfimageresults.VariantBitmap;
            blfimage.SaveBLFImage(new FileStream(blfStarterString + "_variant.blf", FileMode.Create),
                                  BLFImageFile.BLFImageType.Variant);

            #endregion

            //Save the mapinfo

            #region Map Info

            Info_File.BLFHeader        = new BLF_Header();
            Info_File.BLFHeader.Map_ID = mapID;
            Info_File.SaveInfoFile(new FileStream(directory + mapshortform + "info", FileMode.Create));

            #endregion

            //Done..
            MessageBox.Show("Done.");
        }