using System;
using System.Collections.Generic;
using System.Text;
using Halo3Map.Map;
using Halo3Map;
using System.IO;

namespace Engineer
{
    public static class MiscFunctions
    {
        /// <summary>
        /// Calculates amount of padding needed for a block of data
        /// </summary>
        /// <param name="size">Size of data block</param>
        /// <param name="paddingchunksize">Amount to pad(ex. 512, 1024, 2048, ect</param>
        /// <returns>Padding Size</returns>
        public static int Padding(int size, int paddingchunksize)
        {
            int temp1 = 0;
            Math.DivRem(size, paddingchunksize, out temp1);
            if (temp1 == 0) { return 0; }
            int temp2 = paddingchunksize - temp1;
            return temp2;
        }

        public static string GetMapInfoFileName(string internalname, Map_Type type)
        {
            string path = "";
            string notfound = AppSettings.Settings.MapFolder + "images\\term_8.blf";
            if (type == Map_Type.multi_player)
            {                
                path = AppSettings.Settings.MapFolder + "images\\m_" + internalname + ".blf";

                if (File.Exists(path))
                    return path;
                else if(File.Exists(path.Replace("images\\m_", "images\\dlc_")))
                {
                    return path.Replace("images\\m_", "images\\dlc_");
                }
                else return notfound;
            }
            else if (type == Map_Type.single_player)
            {
                string[] temp = internalname.Split('_');
                path = AppSettings.Settings.MapFolder + "images\\c_" + temp[0] + ".blf";

                if (File.Exists(path))
                    return path;
                else return notfound;
            }

            return notfound;
        }
    }
}
