220 lines
5.6 KiB
C++
220 lines
5.6 KiB
C++
#include "app_cfg.h"
|
|
#include "base/HGInc.h"
|
|
#include "base/HGUtility.h"
|
|
#include "base/HGIni.h"
|
|
#include "HGUIGlobal.h"
|
|
#include "HGString.h"
|
|
#ifdef HG_CMP_MSC
|
|
#include <shlobj.h>
|
|
#endif
|
|
|
|
bool removeSection(const HGChar* appName)
|
|
{
|
|
HGChar cfgPath[512];
|
|
GetConfigPath(cfgPath, 512);
|
|
strcat(cfgPath, "default.ini");
|
|
HGResult ret = HGBase_RemoveProfileSection(cfgPath, appName);
|
|
|
|
if (ret == HGBASE_ERR_OK)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
bool searchKeyName(const HGChar* appName, const HGChar* key)
|
|
{
|
|
HGChar cfgPath[512];
|
|
GetConfigPath(cfgPath, 512);
|
|
strcat(cfgPath, "default.ini");
|
|
|
|
HGResult ret = HGBase_SearchProfileConfig(cfgPath, appName, key);
|
|
if (ret == HGBASE_ERR_OK)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
QString getDefaultCfgValue(const char* appName, const char* key, const QString& def)
|
|
{
|
|
HGChar cfgPath[512];
|
|
GetConfigPath(cfgPath, 512);
|
|
strcat(cfgPath, "default.ini");
|
|
|
|
HGChar value[2048] = { 0 };
|
|
HGBase_GetProfileString(cfgPath, appName, key, getStdString(def).c_str(), value, 2048);
|
|
return StdStringToUtf8(value).c_str();
|
|
}
|
|
|
|
int getDefaultCfgValue(const char* appName, const char* key, int def)
|
|
{
|
|
HGChar cfgPath[512];
|
|
GetConfigPath(cfgPath, 512);
|
|
strcat(cfgPath, "default.ini");
|
|
|
|
HGInt value = 0;
|
|
HGBase_GetProfileInt(cfgPath, appName, key, def, &value);
|
|
return value;
|
|
}
|
|
|
|
bool getDefaultCfgValue(const char* appName, const char* key, bool def)
|
|
{
|
|
HGChar cfgPath[512];
|
|
GetConfigPath(cfgPath, 512);
|
|
strcat(cfgPath, "default.ini");
|
|
|
|
HGInt value = 0;
|
|
HGBase_GetProfileInt(cfgPath, appName, key, (HGInt)def, &value);
|
|
return (bool)value;
|
|
}
|
|
|
|
QString getCfgValue(const char *appName, const char *key, const QString &def)
|
|
{
|
|
HGChar cfgPath[512];
|
|
HGBase_GetConfigPath(cfgPath, 512);
|
|
strcat(cfgPath, "config.ini");
|
|
|
|
HGChar value[512] = {0};
|
|
HGBase_GetProfileString(cfgPath, appName, key, getStdString(def).c_str(), value, 512);
|
|
return StdStringToUtf8(value).c_str();
|
|
}
|
|
|
|
int getCfgValue(const char *appName, const char *key, int def)
|
|
{
|
|
HGChar cfgPath[512];
|
|
HGBase_GetConfigPath(cfgPath, 512);
|
|
strcat(cfgPath, "config.ini");
|
|
|
|
HGInt value = 0;
|
|
HGBase_GetProfileInt(cfgPath, appName, key, def, &value);
|
|
return value;
|
|
}
|
|
|
|
bool getCfgValue(const char *appName, const char *key, bool def)
|
|
{
|
|
HGChar cfgPath[512];
|
|
HGBase_GetConfigPath(cfgPath, 512);
|
|
strcat(cfgPath, "config.ini");
|
|
|
|
HGInt value = 0;
|
|
HGBase_GetProfileInt(cfgPath, appName, key, (HGInt)def, &value);
|
|
return (bool)value;
|
|
}
|
|
|
|
void saveDefaultCfgValue(const char* appName, const char* key, const QString& value)
|
|
{
|
|
HGChar cfgPath[512];
|
|
GetConfigPath(cfgPath, 512);
|
|
HGBase_CreateDir(cfgPath);
|
|
strcat(cfgPath, "default.ini");
|
|
|
|
HGBase_SetProfileString(cfgPath, appName, key, getStdString(value).c_str());
|
|
}
|
|
|
|
void saveDefaultCfgValue(const char* appName, const char* key, int value)
|
|
{
|
|
HGChar cfgPath[512];
|
|
GetConfigPath(cfgPath, 512);
|
|
HGBase_CreateDir(cfgPath);
|
|
strcat(cfgPath, "default.ini");
|
|
|
|
HGBase_SetProfileInt(cfgPath, appName, key, value);
|
|
}
|
|
|
|
void saveDefaultCfgValue(const char* appName, const char* key, float value)
|
|
{
|
|
HGChar cfgPath[512];
|
|
GetConfigPath(cfgPath, 512);
|
|
HGBase_CreateDir(cfgPath);
|
|
strcat(cfgPath, "default.ini");
|
|
|
|
HGBase_SetProfileInt(cfgPath, appName, key, value);
|
|
}
|
|
|
|
void saveDefaultCfgValue(const char* appName, const char* key, bool value)
|
|
{
|
|
HGChar cfgPath[512];
|
|
GetConfigPath(cfgPath, 512);
|
|
HGBase_CreateDir(cfgPath);
|
|
strcat(cfgPath, "default.ini");
|
|
|
|
HGBase_SetProfileInt(cfgPath, appName, key, (HGInt)value);
|
|
}
|
|
|
|
void saveCfgValue(const char *appName, const char *key, const QString &value)
|
|
{
|
|
HGChar cfgPath[512];
|
|
HGBase_GetConfigPath(cfgPath, 512);
|
|
HGBase_CreateDir(cfgPath);
|
|
strcat(cfgPath, "config.ini");
|
|
|
|
HGBase_SetProfileString(cfgPath, appName, key, getStdString(value).c_str());
|
|
}
|
|
|
|
void saveCfgValue(const char *appName, const char *key, int value)
|
|
{
|
|
HGChar cfgPath[512];
|
|
HGBase_GetConfigPath(cfgPath, 512);
|
|
HGBase_CreateDir(cfgPath);
|
|
strcat(cfgPath, "config.ini");
|
|
|
|
HGBase_SetProfileInt(cfgPath, appName, key, value);
|
|
}
|
|
|
|
void saveCfgValue(const char *appName, const char *key, bool value)
|
|
{
|
|
HGChar cfgPath[512];
|
|
HGBase_GetConfigPath(cfgPath, 512);
|
|
HGBase_CreateDir(cfgPath);
|
|
strcat(cfgPath, "config.ini");
|
|
|
|
HGBase_SetProfileInt(cfgPath, appName, key, (HGInt)value);
|
|
}
|
|
|
|
HGResult GetConfigPath(HGChar* configPath, HGUInt maxLen)
|
|
{
|
|
if (NULL == configPath || 0 == maxLen)
|
|
{
|
|
return HGBASE_ERR_INVALIDARG;
|
|
}
|
|
|
|
const char* appName = "HuaGoScan";
|
|
#if defined(OEM_HANWANG)
|
|
appName = "HanvonScan";
|
|
#elif defined(OEM_LISICHENG)
|
|
appName = "LanxumScan";
|
|
#elif defined(OEM_CANGTIAN)
|
|
appName = "CumtennScan";
|
|
#elif defined(OEM_ZHONGJING)
|
|
appName = "MicrotekScan";
|
|
#elif defined(OEM_ZIGUANG)
|
|
appName = "UniScan";
|
|
#endif
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
CHAR cfgPath[MAX_PATH] = { 0 };
|
|
BOOL ret = SHGetSpecialFolderPathA(NULL, cfgPath, CSIDL_APPDATA, FALSE);
|
|
if (!ret)
|
|
return HGBASE_ERR_FAIL;
|
|
if (cfgPath[strlen(cfgPath) - 1] != '\\')
|
|
strcat(cfgPath, "\\");
|
|
|
|
strcat(cfgPath, appName);
|
|
strcat(cfgPath, "\\Cfg\\");
|
|
#else
|
|
char cfgPath[512] = { 0 };
|
|
struct passwd* pw = getpwuid(getuid());
|
|
strcpy(cfgPath, pw->pw_dir);
|
|
if (cfgPath[strlen(cfgPath) - 1] != '/')
|
|
strcat(cfgPath, "/");
|
|
|
|
strcat(cfgPath, ".");
|
|
strcat(cfgPath, appName);
|
|
strcat(cfgPath, "/Cfg/");
|
|
#endif
|
|
|
|
if (maxLen < strlen(cfgPath) + 1)
|
|
return HGBASE_ERR_FAIL;
|
|
strcpy(configPath, cfgPath);
|
|
return HGBASE_ERR_OK;
|
|
}
|