コード例 #1
0
ファイル: MapManager.cs プロジェクト: Amoel/Evershock
        //---------------------------------------------------------------------------

        public void SaveMapMetaData()
        {
            string rootDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TilesetViewer/Maps");

            if (!Directory.Exists(rootDirectory))
            {
                Directory.CreateDirectory(rootDirectory);
            }

            string thumbnailPath = Path.Combine(rootDirectory, string.Format("{0}Thumbnail.png", m_Map.Name));

            m_Control?.SaveToPng(thumbnailPath);

            MapMetaData data     = new MapMetaData(thumbnailPath, m_Map.Name, "");
            string      dataPath = Path.Combine(rootDirectory, string.Format("{0}.data", m_Map.Name));

            try
            {
                using (FileStream stream = new FileStream(@dataPath, FileMode.Create))
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.Write(JsonConvert.SerializeObject(data, Formatting.Indented));
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
コード例 #2
0
        //---------------------------------------------------------------------------
        public void AddPreview(string path)
        {
            MapMetaData data = null;
            try
            {
                using (FileStream stream = new FileStream(@path, FileMode.Open))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        data = JsonConvert.DeserializeObject<MapMetaData>(reader.ReadToEnd());
                    }
                }
            }
            catch (Exception e)
            {

            }
            if (data != null)
            {
                BitmapImage bitmap = new BitmapImage(new Uri(data.ThumbnailPath));
                AddPreview(bitmap, data.MapName, data.MapPath);
            }
        }