Beispiel #1
0
        /// <summary>
        /// Gets current map preview as a bitmap.
        /// </summary>
        /// <returns>Map preview as a bitmap. Null if the preview could not be loaded.</returns>
        public Bitmap GetMapPreview()
        {
            if (previewBitmap != null)
            {
                return(previewBitmap);
            }

            string[] keys = GetKeys("PreviewPack");

            if (keys == null || keys.Length == 0)
            {
                return(null);
            }

            int previewWidth  = PreviewWidth;
            int previewHeight = PreviewHeight;

            if (previewWidth < 1 || previewHeight < 1)
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            foreach (string key in keys)
            {
                sb.Append(GetKey("PreviewPack", key, string.Empty));
            }

            byte[] dataDest = new byte[previewWidth * previewHeight * 3];

            string errorMsg = MapPackHelper.ParseMapPackData(sb.ToString(), ref dataDest);

            if (errorMsg != null)
            {
                return(null);
            }

            previewBitmap = GraphicsUtils.CreateBitmapFromImageData(previewWidth, previewHeight, dataDest);
            return(previewBitmap);
        }
Beispiel #2
0
        /// <summary>
        /// Parses and decompresses Base64-encoded and compressed data from specified section of map file.
        /// </summary>
        /// <param name="sectionName">Name of the section.</param>
        /// <param name="outputData">Array to put the decompressed data to.</param>
        /// <param name="useLCW">If set to true, treat data as LCW-compressed instead of LZO.</param>
        /// <returns>Error message if something went wrong, otherwise null.</returns>
        private string ParseEncodedMapSectionData(string sectionName, ref byte[] outputData, bool useLCW = false)
        {
            Logger.Info("Parsing " + sectionName + ".");
            string[] values = GetValues(sectionName);

            string msgStart = "Error parsing " + sectionName + ": ";

            if (values == null || values.Length < 1)
            {
                return(msgStart + "Data is empty.");
            }

            string errorMsg = MapPackHelper.ParseMapPackData(values, ref outputData, useLCW);

            if (errorMsg != null)
            {
                return(msgStart + errorMsg);
            }

            return(null);
        }