using System;
using System.Text;
using System.Runtime.InteropServices;


namespace CSVDownloader.File {
    class ConfigReader : IConfigReader{

        [DllImport("kernel32.dll", EntryPoint = "GetPrivateProfileStringW", CharSet = CharSet.Unicode, SetLastError = true)]
        static extern uint GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName);

        private String filepath_;

        private uint buff_size = 256;

        /// <summary>
        ///  ファイルパスを設定する
        /// </summary>
        /// <param name="filepath"></param>
        public ConfigReader(String filepath)
        {
            filepath_ = filepath;

        }
        /// <summary>
        /// ファイルの値を取得する
        /// </summary>
        /// <param name="section">セクション名</param>
        /// <param name="key">キー名</param>
        /// <returns>取得値</returns>
         public  String Read(String section, String key)
        {
            StringBuilder sb = new StringBuilder(Convert.ToInt32(buff_size));
            GetPrivateProfileString(section, key, "", sb, buff_size, filepath_);
            return sb.ToString();
        }
    }
}
