using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace WWPipeLine.Commons
{
public class IniHelper
{
private static readonly string DEFAULT_SECTION = "DEFAULT";
public static readonly string KEY_WORKSPACE_PATH = "WorkspaceName";
public static readonly string KEY_WorkspaceMapIndex_PATH = "WorkspaceMapIndex";
public static readonly string KEY_WorkspaceDatasourceIndex_PATH = "WorkspaceDatasourceIndex";
//public static readonly string KEY_ConfigsMenus_PATH = "ConfigsMenusPath";
public static readonly string KEY_ConfigsNpgsql_PATH = "ConfigsNpgsql";
public static readonly string KEY_LoginUser_PATH = "LoginUser";
public static readonly string KEY_LoginPass_PATH = "LoginPass";
public static readonly string KEY_MapCenterX_PATH = "MapCenterX";
public static readonly string KEY_MapCenterY_PATH = "MapCenterY";
public static readonly string KEY_MapScale_PATH = "MapScale";
public static readonly string KEY_bsURL_PATH = "bsURL";
public static readonly string KEY_webTool_PATH = "webTool";
public static readonly string KEY_GISversion_PATH = "GISversion";
private static string iniCfgPath
{
get
{
return Paths.ApplicationConfigDir + "/" + "default.ini";
}
}
public static string Read(string key, string defaultVal = "")
{
var val = new StringBuilder();
GetPrivateProfileString(DEFAULT_SECTION, key, defaultVal, val, 1024, iniCfgPath);
return val.ToString();
}
public static void Write(string key, string val)
{
WritePrivateProfileString(DEFAULT_SECTION, key, val, iniCfgPath);
}
///
/// 写入INI文件
///
/// 节点名称[如[TypeName]]
/// 键
/// 值
/// 文件路径
///
[DllImport("kernel32")]
public static extern bool WritePrivateProfileString(string section, string key, string val, string filepath);
///
/// 读取INI文件
///
/// 节点名称
/// 键
/// 值
/// stringbulider对象
/// 字节大小
/// 文件路径
///
[DllImport("kernel32")]
public static extern bool GetPrivateProfileString(string section, string key, string def, StringBuilder retval, int size, string filePath);
}
}