summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-06-18 17:55:24 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-06-18 17:55:24 +0300
commitc28759e7c9e63b1d092904b4299afdffec91bcdf (patch)
tree2707a12eddda373f779c1369015e5fac9148902c /src
parent422b84ef2a9ccb27f456e2818a778a8b21b99b3d (diff)
new functions to access mirandaboot.ini from all plugins:
Profile_GetSetting() - reads a string from mirandaboot.ini Profile_GetSettingInt() - reads an integer from mirandaboot.ini
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/database.cpp11
-rw-r--r--src/mir_app/src/db_ini.cpp26
-rw-r--r--src/mir_app/src/db_util.cpp40
-rw-r--r--src/mir_app/src/mir_app.def2
-rw-r--r--src/mir_app/src/mir_app64.def2
-rw-r--r--src/mir_app/src/newplugins.cpp2
-rw-r--r--src/mir_core/src/langpack.cpp6
7 files changed, 68 insertions, 21 deletions
diff --git a/src/mir_app/src/database.cpp b/src/mir_app/src/database.cpp
index 29f5bdd512..af4dd75381 100644
--- a/src/mir_app/src/database.cpp
+++ b/src/mir_app/src/database.cpp
@@ -28,7 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
MDatabaseCommon *currDb = nullptr;
DATABASELINK *currDblink = nullptr;
-// contains the location of mirandaboot.ini
bool g_bDbCreated;
wchar_t g_profileDir[MAX_PATH], g_profileName[MAX_PATH], g_shortProfileName[MAX_PATH];
wchar_t* g_defaultProfile;
@@ -73,7 +72,7 @@ bool IsInsideRootDir(wchar_t* profiledir, bool exact)
int getProfilePath(wchar_t *buf, size_t)
{
wchar_t profiledir[MAX_PATH];
- GetPrivateProfileString(L"Database", L"ProfileDir", L"", profiledir, _countof(profiledir), mirandabootini);
+ Profile_GetSetting(L"Database/ProfileDir", profiledir, mirandabootini);
if (profiledir[0] == 0)
mir_wstrcpy(profiledir, L"%miranda_path%\\Profiles");
@@ -102,7 +101,7 @@ static bool showProfileManager(void)
return 1;
// wanna show it?
- GetPrivateProfileString(L"Database", L"ShowProfileMgr", L"never", Mgr, _countof(Mgr), mirandabootini);
+ Profile_GetSetting(L"Database/ShowProfileMgr", Mgr, L"never");
return (mir_wstrcmpi(Mgr, L"yes") == 0);
}
@@ -112,14 +111,14 @@ bool shouldAutoCreate(wchar_t *szProfile)
return false;
wchar_t ac[32];
- GetPrivateProfileString(L"Database", L"AutoCreate", L"", ac, _countof(ac), mirandabootini);
+ Profile_GetSetting(L"Database/AutoCreate", ac);
return mir_wstrcmpi(ac, L"yes") == 0;
}
static void getDefaultProfile(wchar_t *szProfile, size_t cch)
{
wchar_t defaultProfile[MAX_PATH];
- GetPrivateProfileString(L"Database", L"DefaultProfile", L"", defaultProfile, _countof(defaultProfile), mirandabootini);
+ Profile_GetSetting(L"Database/DefaultProfile", defaultProfile);
if (defaultProfile[0] == 0)
return;
@@ -285,7 +284,7 @@ static int getProfileAutoRun(wchar_t *szProfile)
return false;
wchar_t Mgr[32];
- GetPrivateProfileString(L"Database", L"ShowProfileMgr", L"", Mgr, _countof(Mgr), mirandabootini);
+ Profile_GetSetting(L"Database/ShowProfileMgr", Mgr);
if (mir_wstrcmpi(Mgr, L"never"))
return 0;
diff --git a/src/mir_app/src/db_ini.cpp b/src/mir_app/src/db_ini.cpp
index 2b3c6c7606..c35ac38817 100644
--- a/src/mir_app/src/db_ini.cpp
+++ b/src/mir_app/src/db_ini.cpp
@@ -68,7 +68,7 @@ void CInstallIniDlg::OnInitDialog()
wchar_t szSecurity[11];
const wchar_t *pszSecurityInfo;
- GetPrivateProfileString(L"AutoExec", L"Warn", L"notsafe", szSecurity, _countof(szSecurity), mirandabootini);
+ Profile_GetSetting(L"AutoExec/Warn", szSecurity, L"notsafe");
if (!mir_wstrcmpi(szSecurity, L"all"))
pszSecurityInfo = LPGENW("Security systems to prevent malicious changes are in place and you will be warned before every change that is made.");
else if (!mir_wstrcmpi(szSecurity, L"onlyunsafe"))
@@ -511,22 +511,26 @@ static void DoAutoExec(void)
wchar_t szUse[7], szIniPath[MAX_PATH], szFindPath[MAX_PATH];
wchar_t buf[2048], szSecurity[11], szOverrideSecurityFilename[MAX_PATH], szOnCreateFilename[MAX_PATH];
- GetPrivateProfileString(L"AutoExec", L"Use", L"prompt", szUse, _countof(szUse), mirandabootini);
- if (!mir_wstrcmpi(szUse, L"no")) return;
- GetPrivateProfileString(L"AutoExec", L"Safe", L"CLC Icons CLUI CList SkinSounds", buf, _countof(buf), mirandabootini);
+ Profile_GetSetting(L"AutoExec/Use", szUse, L"prompt");
+ if (!mir_wstrcmpi(szUse, L"no"))
+ return;
+
+ Profile_GetSetting(L"AutoExec/Safe", buf, L"CLC Icons CLUI CList SkinSounds");
ptrA szSafeSections(mir_u2a(buf));
- GetPrivateProfileString(L"AutoExec", L"Unsafe", L"Facebook GG ICQ IRC JABBER MRA MSN SKYPE TWITTER VKontakte", buf, _countof(buf), mirandabootini);
+
+ Profile_GetSetting(L"AutoExec/Unsafe", buf, L"Facebook GG ICQ IRC JABBER MRA MSN SKYPE TWITTER VKontakte");
ptrA szUnsafeSections(mir_u2a(buf));
- GetPrivateProfileString(L"AutoExec", L"Warn", L"notsafe", szSecurity, _countof(szSecurity), mirandabootini);
+
+ Profile_GetSetting(L"AutoExec/Warn", szSecurity, L"notsafe");
int secur = 0;
if (!mir_wstrcmpi(szSecurity, L"none")) secur = 0;
else if (!mir_wstrcmpi(szSecurity, L"notsafe")) secur = 1;
else if (!mir_wstrcmpi(szSecurity, L"onlyunsafe")) secur = 2;
- GetPrivateProfileString(L"AutoExec", L"OverrideSecurityFilename", L"", szOverrideSecurityFilename, _countof(szOverrideSecurityFilename), mirandabootini);
- GetPrivateProfileString(L"AutoExec", L"OnCreateFilename", L"", szOnCreateFilename, _countof(szOnCreateFilename), mirandabootini);
- GetPrivateProfileString(L"AutoExec", L"Glob", L"autoexec_*.ini", szFindPath, _countof(szFindPath), mirandabootini);
+ Profile_GetSetting(L"AutoExec/OverrideSecurityFilename", szOverrideSecurityFilename);
+ Profile_GetSetting(L"AutoExec/OnCreateFilename", szOnCreateFilename);
+ Profile_GetSetting(L"AutoExec/Glob", szFindPath, L"autoexec_*.ini");
if (g_bDbCreated && szOnCreateFilename[0]) {
PathToAbsoluteW(VARSW(szOnCreateFilename), szIniPath);
@@ -563,7 +567,7 @@ static void DoAutoExec(void)
DeleteFile(szIniPath);
else {
wchar_t szOnCompletion[8];
- GetPrivateProfileString(L"AutoExec", L"OnCompletion", L"recycle", szOnCompletion, _countof(szOnCompletion), mirandabootini);
+ Profile_GetSetting(L"AutoExec/OnCompletion", szOnCompletion, L"recycle");
if (!mir_wstrcmpi(szOnCompletion, L"delete"))
DeleteFile(szIniPath);
else if (!mir_wstrcmpi(szOnCompletion, L"recycle")) {
@@ -576,7 +580,7 @@ static void DoAutoExec(void)
}
else if (!mir_wstrcmpi(szOnCompletion, L"rename")) {
wchar_t szRenamePrefix[MAX_PATH], szNewPath[MAX_PATH];
- GetPrivateProfileString(L"AutoExec", L"RenamePrefix", L"done_", szRenamePrefix, _countof(szRenamePrefix), mirandabootini);
+ Profile_GetSetting(L"AutoExec/RenamePrefix", szRenamePrefix, L"done_");
mir_wstrcpy(szNewPath, szFindPath);
mir_wstrcat(szNewPath, szRenamePrefix);
mir_wstrcat(szNewPath, fd.cFileName);
diff --git a/src/mir_app/src/db_util.cpp b/src/mir_app/src/db_util.cpp
index 7b95357a4f..a31ccbe34d 100644
--- a/src/mir_app/src/db_util.cpp
+++ b/src/mir_app/src/db_util.cpp
@@ -66,6 +66,46 @@ MIR_APP_DLL(int) Profile_GetNameW(size_t cbLen, wchar_t *pwszDest)
/////////////////////////////////////////////////////////////////////////////////////////
+MIR_APP_DLL(bool) Profile_GetSetting(const wchar_t *pwszSetting, wchar_t *pwszBuf, size_t cbLen, const wchar_t *pwszDefault)
+{
+ if (pwszSetting == nullptr) {
+ *pwszBuf = 0;
+ return false;
+ }
+
+ if (pwszDefault == nullptr)
+ pwszDefault = L"";
+
+ wchar_t *pBuf = NEWWSTR_ALLOCA(pwszSetting);
+
+ wchar_t *p = wcschr(pBuf, '/');
+ if (p) {
+ *p = 0; p++;
+ GetPrivateProfileStringW(pBuf, p, pwszDefault, pwszBuf, (DWORD)cbLen, mirandabootini);
+ }
+ else GetPrivateProfileStringW(pBuf, L"", pwszDefault, pwszBuf, (DWORD)cbLen, mirandabootini);
+
+ return pwszBuf[0] != 0;
+}
+
+MIR_APP_DLL(int) Profile_GetSettingInt(const wchar_t *pwszSetting, int iDefault)
+{
+ if (pwszSetting == nullptr)
+ return iDefault;
+
+ wchar_t *pBuf = NEWWSTR_ALLOCA(pwszSetting);
+
+ wchar_t *p = wcschr(pBuf, '/');
+ if (p) {
+ *p = 0; p++;
+ return GetPrivateProfileIntW(pBuf, p, iDefault, mirandabootini);
+ }
+
+ return GetPrivateProfileIntW(pBuf, L"", iDefault, mirandabootini);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
MIR_APP_DLL(void) Profile_SetDefault(const wchar_t *pwszPath)
{
extern wchar_t* g_defaultProfile;
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index eb583a156b..27bf47e3d9 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -624,3 +624,5 @@ Srmm_ClickStatusIcon @649
Profile_CheckOpened @653
Idle_Enter @654 NONAME
Idle_GetInfo @655 NONAME
+Profile_GetSetting @656
+Profile_GetSettingInt @657
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index 111d7ba071..263896f0b0 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -624,3 +624,5 @@ Srmm_ClickStatusIcon @649
Profile_CheckOpened @653
Idle_Enter @654 NONAME
Idle_GetInfo @655 NONAME
+Profile_GetSetting @656
+Profile_GetSettingInt @657
diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp
index be9af32af5..42920b4c18 100644
--- a/src/mir_app/src/newplugins.cpp
+++ b/src/mir_app/src/newplugins.cpp
@@ -752,7 +752,7 @@ int LoadNewPluginsModuleInfos(void)
LoadPluginOptions();
- // remember where the mirandaboot.ini goes
+ // remember where the mirandaboot.ini lays
PathToAbsoluteW(L"mirandaboot.ini", mirandabootini);
// look for all *.dll's
diff --git a/src/mir_core/src/langpack.cpp b/src/mir_core/src/langpack.cpp
index bb4ff63b9d..22c19a8552 100644
--- a/src/mir_core/src/langpack.cpp
+++ b/src/mir_core/src/langpack.cpp
@@ -637,9 +637,8 @@ void GetDefaultLang()
PathToAbsoluteW(L".", g_tszRoot);
// look into mirandaboot.ini
- wchar_t tszPath[MAX_PATH], tszLangName[256];
- PathToAbsoluteW(L"\\mirandaboot.ini", tszPath);
- GetPrivateProfileString(L"Language", L"DefaultLanguage", L"", tszLangName, _countof(tszLangName), tszPath);
+ wchar_t tszLangName[256];
+ Profile_GetSetting(L"Language/DefaultLanguage", tszLangName);
if (tszLangName[0]) {
if (!mir_wstrcmpi(tszLangName, L"default")) {
db_set_ws(NULL, "Langpack", "Current", L"default");
@@ -652,6 +651,7 @@ void GetDefaultLang()
}
// try to load langpack that matches UserDefaultUILanguage
+ wchar_t tszPath[MAX_PATH];
if (GetLocaleInfo(MAKELCID(GetUserDefaultUILanguage(), SORT_DEFAULT), LOCALE_SENGLANGUAGE, tszLangName, _countof(tszLangName))) {
mir_snwprintf(tszPath, L"langpack_%s.txt", wcslwr(tszLangName));
if (!LoadLangPack(tszPath)) {