using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MeterVision.Config
{
    //INI配置文件
    public class ConfigIni
    {
  

        private static readonly string IniFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.ini");

        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
        private static readonly int iCapacity = 255;   //最大长度

        public static string ReadIniValue(string Section, string def, string Key)
        {
            try
            {
                if (File.Exists(IniFilePath))
                {
                    StringBuilder strValue = new StringBuilder(iCapacity);
                    int i = GetPrivateProfileString(Section, Key, def, strValue, iCapacity, IniFilePath);
                    return strValue.ToString().Trim();
                }
                else
                {
                    return def;
                }
            }
            catch (Exception ex)
            {
                //LogTool.Error(string.Format("{0}--{1}", Section, Key), ex);
                MessageBox.Show($"读配置文件：{ex.Message}");
                return def;
            }

        }

        public static string WriteIniValue(string Section, string Key, string Value)
        {
            return WritePrivateProfileString(Section, Key, Value, IniFilePath).ToString();
        }



    }


    //[file_path]
    //    onnx=N_I_RP_RGB_ns_4PB_5d0_94c_241221_2GPU_11_t1.25_0.70_v1.35_0.56.onnx
    //    ai_dll = freeAI.dll
    //output=d:\MeterVision_output\
    //[page_size]
    //    single=10
    //stand=10
    //stand_detail=20
    //patch=10
    //patch_detail=20
    //[window_size]
//    dialog_image=
//dialog_stand=
    //--------------------------------------------
}
