public List <string> GetEngineList(string platform)
        {
            var comparer = new EngineDownload.VersionNumberComparer();
            var list     = new DirectoryInfo(Path.Combine(Global.MapPath("~"), "engine", platform ?? "win32")).GetFiles().Select(x => x.Name).Select(Path.GetFileNameWithoutExtension).OrderBy(x => x, comparer).ToList();

            return(list);
        }
        public static void RemoveResourceFiles(Resource resource)
        {
            var file = String.Format("{0}/{1}", Global.MapPath("~/Resources"), resource.InternalName.EscapePath());

            Utils.SafeDelete(String.Format("{0}.minimap.jpg", file));
            Utils.SafeDelete(String.Format("{0}.thumbnail.jpg", file));
            Utils.SafeDelete(String.Format("{0}.heightmap.jpg", file));
            Utils.SafeDelete(String.Format("{0}.metalmap.jpg", file));
            Utils.SafeDelete(String.Format("{0}.metadata.xml.gz", file));
            foreach (var content in resource.ResourceContentFiles)
            {
                Utils.SafeDelete(GetTorrentPath(content));
            }
        }
        static void StoreMetadata(string md5,
                                  Resource resource,
                                  byte[] serializedData,
                                  byte[] torrentData,
                                  byte[] minimap,
                                  byte[] metalMap,
                                  byte[] heightMap)
        {
            var file = String.Format("{0}/{1}", Global.MapPath("~/Resources"), resource.InternalName.EscapePath());

            resource.LastChange = DateTime.UtcNow;

            if (minimap != null)
            {
                File.WriteAllBytes(String.Format("{0}.minimap.jpg", file), minimap);
            }
            if (metalMap != null)
            {
                File.WriteAllBytes(String.Format("{0}.metalmap.jpg", file), metalMap);
            }
            if (heightMap != null)
            {
                File.WriteAllBytes(String.Format("{0}.heightmap.jpg", file), heightMap);
            }
            if (torrentData != null)
            {
                File.WriteAllBytes(GetTorrentPath(resource.InternalName, md5), torrentData);
            }
            if (serializedData != null)
            {
                File.WriteAllBytes(String.Format("{0}.metadata.xml.gz", file), serializedData);
                if (minimap != null)
                {
                    var map = (Map) new XmlSerializer(typeof(Map)).Deserialize(new MemoryStream(serializedData.Decompress()));

                    if (string.IsNullOrEmpty(resource.AuthorName))
                    {
                        if (!string.IsNullOrEmpty(map.Author))
                        {
                            resource.AuthorName = map.Author;
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(map.Description))
                            {
                                var m = Regex.Match(map.Description, "by ([\\w]+)", RegexOptions.IgnoreCase);
                                if (m.Success)
                                {
                                    resource.AuthorName = m.Groups[1].Value;
                                }
                            }
                        }
                    }

                    if (resource.MapIsSpecial == null)
                    {
                        resource.MapIsSpecial = map.ExtractorRadius > 120 || map.MaxWind > 40;
                    }
                    resource.MapSizeSquared = (map.Size.Width / 512) * (map.Size.Height / 512);
                    resource.MapSizeRatio   = (float)map.Size.Width / map.Size.Height;
                    resource.MapWidth       = map.Size.Width / 512;
                    resource.MapHeight      = map.Size.Height / 512;

                    using (var im = Image.FromStream(new MemoryStream(minimap)))
                    {
                        int w, h;
                        if (resource.MapSizeRatio > 1)
                        {
                            w = ThumbnailSize;
                            h = (int)(w / resource.MapSizeRatio);
                        }
                        else
                        {
                            h = ThumbnailSize;
                            w = (int)(h * resource.MapSizeRatio);
                        }

                        using (var correctMinimap = new Bitmap(w, h, PixelFormat.Format24bppRgb))
                        {
                            using (var graphics = Graphics.FromImage(correctMinimap))
                            {
                                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                graphics.DrawImage(im, 0, 0, w, h);
                            }

                            var jgpEncoder    = ImageCodecInfo.GetImageEncoders().First(x => x.FormatID == ImageFormat.Jpeg.Guid);
                            var encoderParams = new EncoderParameters(1);
                            encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, 100L);

                            var target = String.Format("{0}/{1}.thumbnail.jpg",
                                                       Global.MapPath("~/Resources"),
                                                       resource.InternalName.EscapePath());
                            correctMinimap.Save(target, jgpEncoder, encoderParams);
                        }
                    }
                }
            }
        }
 public static string GetTorrentPath(string name, string md5)
 {
     return(Global.MapPath(String.Format("~/Resources/{0}", (object)GetTorrentFileName(name, md5))));
 }